更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
internal.h 文件参考

浏览源代码.

函数

void ProcPmInit (void)
 
void ProcVmmInit (void)
 
void ProcProcessInit (void)
 
int ProcMatch (unsigned int len, const char *name, struct ProcDirEntry *pde)
 
struct ProcDirEntryProcFindEntry (const char *path)
 
void ProcFreeEntry (struct ProcDirEntry *pde)
 释放 更多...
 
int ProcStat (const char *file, struct ProcStat *buf)
 
void ProcMountsInit (void)
 
void ProcUptimeInit (void)
 
void ProcFsCacheInit (void)
 
void ProcFdInit (void)
 

变量

spinlock_t procfsLock
 
bool procfsInit
 

函数说明

◆ ProcFdInit()

void ProcFdInit ( void  )

在文件 fd_proc.c136 行定义.

137{
138 struct ProcDirEntry *pde = CreateProcEntry("fd", 0, NULL);
139 if (pde == NULL) {
140 PRINT_ERR("creat /proc/fd error.\n");
141 return;
142 }
143
145}
static const struct ProcFileOperations FD_PROC_FOPS
Definition: fd_proc.c:132
struct ProcDirEntry * CreateProcEntry(const char *name, mode_t mode, struct ProcDirEntry *parent)
create a proc node
Definition: proc_file.c:364
proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ? 操作 /proc的 真正结构体
Definition: proc_fs.h:101
const struct ProcFileOperations * procFileOps
驱动程序,每个 /proc 下目录的驱动程序都不一样
Definition: proc_fs.h:106
函数调用图:
这是这个函数的调用关系图:

◆ ProcFindEntry()

struct ProcDirEntry * ProcFindEntry ( const char *  path)

在文件 proc_file.c95 行定义.

96{
97 struct ProcDirEntry *pn = NULL;
98 int isfoundsub;
99 const char *next = NULL;
100 unsigned int len;
101 int leveltotal = 0;
102 int levelcount = 0;
103 const char *p = NULL;
104 const char *name = path;
105
106 while ((p = strchr(name, '/')) != NULL) {
107 leveltotal++;
108 name = p;
109 name++;
110 }
111 if (leveltotal < 1) {
112 return pn;
113 }
114
115 spin_lock(&procfsLock);
116
117 pn = &g_procRootDirEntry;
118
119 while ((pn != NULL) && (levelcount < leveltotal)) {
120 levelcount++;
121 isfoundsub = 0;
122 while (pn != NULL) {
123 next = strchr(path, '/');
124 if (next == NULL) {
125 while (pn != NULL) {
126 if (strcmp(path, pn->name) == 0) {
127 spin_unlock(&procfsLock);
128 return pn;
129 }
130 pn = pn->next;
131 }
132 pn = NULL;
133 spin_unlock(&procfsLock);
134 return pn;
135 }
136
137 len = next - path;
138 if (pn == &g_procRootDirEntry) {
139 if (levelcount == leveltotal) {
140 spin_unlock(&procfsLock);
141 return pn;
142 }
144 }
145 if (ProcMatch(len, path, pn)) {
146 isfoundsub = 1;
147 path += len + 1;
148 break;
149 }
150
151 pn = pn->next;
152 }
153
154 if ((isfoundsub == 1) && (pn != NULL)) {
155 pn = pn->subdir;
156 } else {
157 pn = NULL;
158 spin_unlock(&procfsLock);
159 return pn;
160 }
161 }
162 spin_unlock(&procfsLock);
163 return NULL;
164}
spinlock_t procfsLock
int ProcMatch(unsigned int len, const char *name, struct ProcDirEntry *pn)
Definition: proc_file.c:63
static struct ProcDirEntry g_procRootDirEntry
Definition: proc_file.c:50
int nameLen
Definition: proc_fs.h:112
struct ProcDirEntry * next
Definition: proc_fs.h:108
struct ProcDirEntry * subdir
当前目录项的关系项
Definition: proc_fs.h:108
char name[NAME_MAX]
Definition: proc_fs.h:114
函数调用图:
这是这个函数的调用关系图:

◆ ProcFreeEntry()

void ProcFreeEntry ( struct ProcDirEntry pde)

释放

在文件 proc_file.c388 行定义.

389{
390 if (atomic_dec_and_test(&pn->count))
391 FreeProcEntry(pn);
392}
static void FreeProcEntry(struct ProcDirEntry *entry)
释放proc
Definition: proc_file.c:376
函数调用图:
这是这个函数的调用关系图:

◆ ProcFsCacheInit()

void ProcFsCacheInit ( void  )

在文件 fs_cache_proc.c218 行定义.

219{
220 /* do nothing in release version */
221}
函数调用图:
这是这个函数的调用关系图:

◆ ProcMatch()

int ProcMatch ( unsigned int  len,
const char *  name,
struct ProcDirEntry pde 
)

在文件 proc_file.c63 行定义.

64{
65 if (len != pn->nameLen)
66 return 0;
67 return !strncmp(name, pn->name, len);
68}
这是这个函数的调用关系图:

◆ ProcMountsInit()

void ProcMountsInit ( void  )

在文件 mounts_proc.c90 行定义.

91{
92 struct ProcDirEntry *pde = CreateProcEntry("mounts", 0, NULL);
93 if (pde == NULL) {
94 PRINT_ERR("creat mounts error!\n");
95 return;
96 }
97
98 pde->procFileOps = &MOUNTS_PROC_FOPS;//操作 /proc/mounts 的具体实现
99}
static const struct ProcFileOperations MOUNTS_PROC_FOPS
实现 操作proc file 接口,也可理解为驱动程序不同
Definition: mounts_proc.c:86
函数调用图:
这是这个函数的调用关系图:

◆ ProcPmInit()

void ProcPmInit ( void  )

在文件 power_proc.c148 行定义.

149{
150 struct ProcDirEntry *power = CreateProcEntry("power", S_IFDIR | S_IRWXU | S_IRWXG | S_IROTH, NULL);
151 if (power == NULL) {//创建 文件夹 /proc/power
152 PRINT_ERR("create /proc/power error!\n");
153 return;
154 }
155 power->uid = OS_POWER_PRIVILEGE;
156 power->gid = OS_POWER_PRIVILEGE;
157
158 struct ProcDirEntry *mode = CreateProcEntry("power/power_mode", POWER_FILE_MODE, NULL);
159 if (mode == NULL) {//创建 文件夹 /proc/power/power_mode
160 PRINT_ERR("create /proc/power/power_mode error!\n");
161 goto FREE_POWER;
162 }
163 mode->procFileOps = &PowerMode;
164 mode->uid = OS_POWER_PRIVILEGE;
165 mode->gid = OS_POWER_PRIVILEGE;
166
167 struct ProcDirEntry *lock = CreateProcEntry("power/power_lock", POWER_FILE_MODE, NULL);
168 if (lock == NULL) {//创建 文件夹 /proc/power/power_lock
169 PRINT_ERR("create /proc/power/power_lock error!\n");
170 goto FREE_MODE;
171 }
172 lock->procFileOps = &PowerLock;
173 lock->uid = OS_POWER_PRIVILEGE;
174 lock->gid = OS_POWER_PRIVILEGE;
175
176 struct ProcDirEntry *unlock = CreateProcEntry("power/power_unlock", POWER_FILE_MODE, NULL);
177 if (unlock == NULL) {//创建 文件夹 /proc/power/power_unlock
178 PRINT_ERR("create /proc/power/power_unlock error!\n");
179 goto FREE_LOCK;
180 }
181 unlock->procFileOps = &PowerUnlock;
182 unlock->uid = OS_POWER_PRIVILEGE;
183 unlock->gid = OS_POWER_PRIVILEGE;
184
185 struct ProcDirEntry *count = CreateProcEntry("power/power_count", S_IRUSR | S_IRGRP | S_IROTH, NULL);
186 if (count == NULL) {//创建 文件夹 /proc/power/power_count
187 PRINT_ERR("create /proc/power/power_count error!\n");
188 goto FREE_UNLOCK;
189 }
190 count->procFileOps = &PowerCount;
191 count->uid = OS_POWER_PRIVILEGE;
192 count->gid = OS_POWER_PRIVILEGE;
193
194 return;
195
196FREE_UNLOCK:
197 ProcFreeEntry(unlock);
198FREE_LOCK:
199 ProcFreeEntry(lock);
200FREE_MODE:
202FREE_POWER:
203 ProcFreeEntry(power);
204 return;
205}
void ProcFreeEntry(struct ProcDirEntry *pde)
释放
Definition: proc_file.c:388
static const struct ProcFileOperations PowerLock
proc 拿电源锁操作
Definition: power_proc.c:56
static const struct ProcFileOperations PowerUnlock
Definition: power_proc.c:69
static const struct ProcFileOperations PowerMode
Definition: power_proc.c:110
static const struct ProcFileOperations PowerCount
Definition: power_proc.c:140
uint uid
Definition: proc_fs.h:102
atomic_t count
Definition: proc_fs.h:110
mode_t mode
模式(读|写...)
Definition: proc_fs.h:104
uint gid
Definition: proc_fs.h:103
函数调用图:
这是这个函数的调用关系图:

◆ ProcProcessInit()

void ProcProcessInit ( void  )

在文件 process_proc.c48 行定义.

49{
50 struct ProcDirEntry *pde = CreateProcEntry("process", 0, NULL);//创建 /proc/process
51 if (pde == NULL) {
52 PRINT_ERR("create /proc/process error!\n");
53 return;
54 }
55
57}
static const struct ProcFileOperations PROCESS_PROC_FOPS
对 /proc/process 各种骚操作,只能读
Definition: process_proc.c:44
函数调用图:
这是这个函数的调用关系图:

◆ ProcStat()

int ProcStat ( const char *  file,
struct ProcStat buf 
)

在文件 proc_file.c463 行定义.

464{
465 struct ProcDirEntry *pn = NULL;
466 int len = sizeof(buf->name);
467 int ret;
468
469 pn = ProcFindEntry(file);
470 if (pn == NULL) {
471 return ENOENT;
472 }
473 ret = strncpy_s(buf->name, len, pn->name, len - 1);
474 if (ret != EOK) {
475 return ENAMETOOLONG;
476 }
477 buf->name[len - 1] = '\0';
478 buf->stMode = pn->mode;
479 buf->pPDE = pn;
480
481 return 0;
482}
struct ProcDirEntry * ProcFindEntry(const char *path)
Definition: proc_file.c:95
char name[NAME_MAX]
Definition: proc_fs.h:135
struct ProcDirEntry * pPDE
Definition: proc_fs.h:134
mode_t stMode
Definition: proc_fs.h:133
函数调用图:

◆ ProcUptimeInit()

void ProcUptimeInit ( void  )

在文件 uptime_proc.c77 行定义.

78{
79 struct ProcDirEntry *pde = CreateProcEntry("uptime", 0, NULL);
80 if (pde == NULL) {
81 PRINT_ERR("creat /proc/uptime error!\n");
82 return;
83 }
84
86}
static const struct ProcFileOperations UPTIME_PROC_FOPS
替换了 read 接口的实现
Definition: uptime_proc.c:73
函数调用图:
这是这个函数的调用关系图:

◆ ProcVmmInit()

void ProcVmmInit ( void  )

在文件 vmm_proc.c106 行定义.

107{
108 struct ProcDirEntry *pde = CreateProcEntry("vmm", 0, NULL);//创建目录
109 if (pde == NULL) {
110 PRINT_ERR("create /proc/vmm error!\n");
111 return;
112 }
113
114 pde->procFileOps = &VMM_PROC_FOPS;//每个目录的驱动程序都不一样
115}
static const struct ProcFileOperations VMM_PROC_FOPS
实现 操作proc file 接口,也可理解为驱动程序不同
Definition: vmm_proc.c:101
函数调用图:
这是这个函数的调用关系图:

变量说明

◆ procfsInit

bool procfsInit
extern

在文件 proc_file.c44 行定义.

◆ procfsLock

spinlock_t procfsLock
extern