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

浏览源代码.

结构体

struct  ProcFileOperations
 真正最后能操作pro file的接口,proc本质是个内存文件系统, vfs - > ProcFileOperations 更多...
 
struct  ProcDirEntry
 proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ?
操作 /proc的 真正结构体 更多...
 
struct  ProcFile
 Proc文件结构体,对标 FILE 结构体 更多...
 
struct  ProcStat
 
struct  ProcData
 

类型定义

typedef unsigned short fmode_t
 

函数

struct ProcDirEntryCreateProcEntry (const char *name, mode_t mode, struct ProcDirEntry *parent)
 create a proc node 更多...
 
void RemoveProcEntry (const char *name, struct ProcDirEntry *parent)
 remove a proc node 更多...
 
struct ProcDirEntryProcMkdir (const char *name, struct ProcDirEntry *parent)
 create a proc directory node 更多...
 
struct ProcDirEntryProcCreate (const char *name, mode_t mode, struct ProcDirEntry *parent, const struct ProcFileOperations *procFops)
 create a proc node 更多...
 
void ProcFsInit (void)
 init proc fs 更多...
 

类型定义说明

◆ fmode_t

typedef unsigned short fmode_t

在文件 proc_fs.h53 行定义.

函数说明

◆ CreateProcEntry()

struct ProcDirEntry * CreateProcEntry ( const char *  name,
mode_t  mode,
struct ProcDirEntry parent 
)

create a proc node

Interface for modules using proc below internal proc moudule;

Description:
This API is used to create the node by 'name' and parent vnode
注意
  • This interface should be called after system initialization.
  • The parameter name should be a valid string.
参数
name[IN] Type #const char * The name of the node to be created.
mode[IN] Type mode_t the mode of create's node.
parent[IN] Type #struct ProcDirEntry * the parent node of the node to be created, if pass NULL, default parent node is "/proc".
返回值
#NULLCreate failed.
#ProcDirEntry*Create successfully.
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见

create a proc node

在文件 proc_file.c364 行定义.

365{
366 struct ProcDirEntry *pde = NULL;
367
368 if (S_ISDIR(mode)) {//目录模式 0
369 pde = ProcCreateDir(parent, name, NULL, mode);//无驱动程序
370 } else {
371 pde = ProcCreateFile(parent, name, NULL, mode);//无驱动程序
372 }
373 return pde;
374}
static struct ProcDirEntry * ProcCreateDir(struct ProcDirEntry *parent, const char *name, const struct ProcFileOperations *procFileOps, mode_t mode)
/proc文件系统创建目录的方式
Definition: proc_file.c:319
static struct ProcDirEntry * ProcCreateFile(struct ProcDirEntry *parent, const char *name, const struct ProcFileOperations *procFileOps, mode_t mode)
创建文件项
Definition: proc_file.c:341
proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ? 操作 /proc的 真正结构体
Definition: proc_fs.h:101
struct ProcDirEntry * parent
Definition: proc_fs.h:108
mode_t mode
模式(读|写...)
Definition: proc_fs.h:104
char name[NAME_MAX]
Definition: proc_fs.h:114
函数调用图:
这是这个函数的调用关系图:

◆ ProcCreate()

struct ProcDirEntry * ProcCreate ( const char *  name,
mode_t  mode,
struct ProcDirEntry parent,
const struct ProcFileOperations procFops 
)

create a proc node

Description:
This API is used to create the node by 'name' and parent vnode, And assignment operation function
注意
  • This interface should be called after system initialization.
  • The parameter name should be a valid string.
参数
name[IN] Type #const char * The name of the node to be created.
mode[IN] Type mode_t the mode of create's node.
parent[IN] Type #struct ProcDirEntry * the parent node of the node to be created.
procFops[IN] Type #const struct ProcFileOperations * operation function of the node.
返回值
#NULLCreate failed.
#ProcDirEntry*Create successfully.
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见

在文件 proc_file.c457 行定义.

459{
460 return ProcCreateData(name, mode, parent, procFileOps, NULL);
461}
struct ProcDirEntry * ProcCreateData(const char *name, mode_t mode, struct ProcDirEntry *parent, const struct ProcFileOperations *procFileOps, void *data)
创建数据
Definition: proc_file.c:444
函数调用图:
这是这个函数的调用关系图:

◆ ProcFsInit()

void ProcFsInit ( void  )

init proc fs

Description:
This API is used to init proc fs.
注意
  • None.
参数
NONE
返回值
NONE
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
ProcFsInit

在文件 proc_init.c43 行定义.

44{
45 int ret;
46
47 ret = mkdir(PROCFS_MOUNT_POINT, PROCFS_DEFAULT_MODE);//创建 "/proc"
48 if (ret < 0) {
49 PRINT_ERR("failed to mkdir %s, errno = %d\n", PROCFS_MOUNT_POINT, get_errno());
50 return;
51 }
52 //装载文件系统
53 ret = mount(NULL, PROCFS_MOUNT_POINT, "procfs", 0, NULL);//将null 挂到 /proc 上
54 if (ret) {
55 PRINT_ERR("mount procfs err %d\n", ret);
56 return;
57 }
58
59 ProcMountsInit();//初始化 /proc/mounts
60#if defined(LOSCFG_SHELL_CMD_DEBUG) && defined(LOSCFG_KERNEL_VM)
61 ProcVmmInit();//初始化 /proc/vmm
62#endif
63 ProcProcessInit();//初始化 /proc/process
64 ProcUptimeInit();//初始化 /proc/uptime
66 ProcFdInit();
67#ifdef LOSCFG_KERNEL_PM
68 ProcPmInit();
69#endif
70}
void ProcFsCacheInit(void)
void ProcMountsInit(void)
Definition: mounts_proc.c:90
void ProcUptimeInit(void)
Definition: uptime_proc.c:77
void ProcProcessInit(void)
Definition: process_proc.c:48
void ProcFdInit(void)
Definition: fd_proc.c:136
void ProcPmInit(void)
Definition: power_proc.c:148
void ProcVmmInit(void)
Definition: vmm_proc.c:106
函数调用图:

◆ ProcMkdir()

struct ProcDirEntry * ProcMkdir ( const char *  name,
struct ProcDirEntry parent 
)

create a proc directory node

Description:
This API is used to create the directory node by 'name' and parent vnode
注意
  • This interface should be called after system initialization.
  • The parameter name should be a valid string.
参数
name[IN] Type #const char * The name of the node directory to be created.
parent[IN] Type #struct ProcDirEntry * the parent node of the directory node to be created, if pass NULL, default parent node is "/proc".
返回值
#NULLCreate failed.
#ProcDirEntry*Create successfully.
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见

在文件 proc_file.c439 行定义.

440{
441 return ProcCreateDir(parent, name, NULL, 0);
442}
函数调用图:

◆ RemoveProcEntry()

void RemoveProcEntry ( const char *  name,
struct ProcDirEntry parent 
)

remove a proc node

Description:
This API is used to remove the node by 'name' and parent vnode
注意
  • This interface should be called after system initialization.
  • The parameter name should be a valid string.
参数
name[IN] Type #const char * The name of the node to be removed.
parent[IN] Type #struct ProcDirEntry * the parent node of the node to be remove.
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见

在文件 proc_file.c405 行定义.

406{
407 struct ProcDirEntry *pn = NULL;
408 const char *lastName = name;
409
410 if ((name == NULL) || (strlen(name) == 0) || (procfsInit == false)) {
411 return;
412 }
413
414 if (CheckProcName(name, &parent, &lastName) != 0) {
415 return;
416 }
417
418 spin_lock(&procfsLock);
419
420 pn = ProcFindNode(parent, lastName);
421 if (pn == NULL) {
422 PRINT_ERR("Error:name '%s' not found!\n", name);
423 spin_unlock(&procfsLock);
424 return;
425 }
426 ProcDetachNode(pn);
427
428 spin_unlock(&procfsLock);
429
431 ProcFreeEntry(pn);
432}
spinlock_t procfsLock
static int CheckProcName(const char *name, struct ProcDirEntry **parent, const char **lastName)
检查 proc名称有效性
Definition: proc_file.c:166
static void ProcDetachNode(struct ProcDirEntry *pn)
Definition: proc_file.c:298
static struct ProcDirEntry * ProcFindNode(struct ProcDirEntry *parent, const char *name)
Definition: proc_file.c:70
bool procfsInit
Definition: proc_file.c:44
static void RemoveProcEntryTravalsal(struct ProcDirEntry *pn)
Definition: proc_file.c:394
void ProcFreeEntry(struct ProcDirEntry *pn)
释放
Definition: proc_file.c:388
struct ProcDirEntry * subdir
当前目录项的关系项
Definition: proc_fs.h:108
函数调用图: