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

浏览源代码.

函数

struct ProcDirEntryOpenProcFile (const char *fileName, int flags,...)
 open a proc node 更多...
 
int ReadProcFile (struct ProcDirEntry *pde, void *buf, size_t len)
 read a proc node 更多...
 
int WriteProcFile (struct ProcDirEntry *pde, const void *buf, size_t len)
 write a proc node 更多...
 
loff_t LseekProcFile (struct ProcDirEntry *pde, loff_t offset, int whence)
 File migration 更多...
 
int LseekDirProcFile (struct ProcDirEntry *pde, off_t *pos, int whence)
 directory migration 更多...
 
int CloseProcFile (struct ProcDirEntry *pde)
 close a proc node 更多...
 
struct ProcDirEntryGetProcRootEntry (void)
 
int ProcOpen (struct ProcFile *procFile)
 打开 pro 更多...
 

函数说明

◆ CloseProcFile()

int CloseProcFile ( struct ProcDirEntry pde)

close a proc node

Description:
This API is used to close the node by pde
注意
  • None.
参数
pde[IN] Type #struct ProcDirEntry * pointer of the node structure to be closed
返回值
#-1close failed
#0close successfully
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_open

在文件 proc_file.c663 行定义.

664{
665 int result = 0;
666
667 if (pde == NULL) {
668 return -EPERM;
669 }
670 pde->pf->fPos = 0;
671 atomic_set(&pde->count, 1);
672 if (S_ISDIR(pde->mode)) {
673 pde->pdirCurrent = pde->subdir;
674 }
675
676 if ((pde->procFileOps != NULL) && (pde->procFileOps->release != NULL)) {
677 result = pde->procFileOps->release((struct Vnode *)pde, pde->pf);
678 }
679 LosBufRelease(pde->pf->sbuf);
680 pde->pf->sbuf = NULL;
681
682 if (pde->parent == NULL) {
683 FreeProcEntry(pde);
684 }
685 return result;
686}
int LosBufRelease(struct SeqBuf *seqBuf)
释放 seq buf
Definition: los_seq_buf.c:145
static void FreeProcEntry(struct ProcDirEntry *entry)
释放proc
Definition: proc_file.c:376
struct ProcFile * pf
proc文件指针
Definition: proc_fs.h:107
struct ProcDirEntry * subdir
当前目录项的关系项
Definition: proc_fs.h:108
struct ProcDirEntry * pdirCurrent
当前目录
Definition: proc_fs.h:113
atomic_t count
Definition: proc_fs.h:110
const struct ProcFileOperations * procFileOps
驱动程序,每个 /proc 下目录的驱动程序都不一样
Definition: proc_fs.h:106
struct ProcDirEntry * parent
Definition: proc_fs.h:108
mode_t mode
模式(读|写...)
Definition: proc_fs.h:104
loff_t fPos
文件操作偏移位
Definition: proc_fs.h:128
struct SeqBuf * sbuf
序列号BUF
Definition: proc_fs.h:125
int(* release)(struct Vnode *vnode, struct ProcFile *pf)
Definition: proc_fs.h:93
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
函数调用图:
这是这个函数的调用关系图:

◆ GetProcRootEntry()

struct ProcDirEntry * GetProcRootEntry ( void  )

在文件 proc_file.c688 行定义.

689{
690 return &g_procRootDirEntry;
691}
static struct ProcDirEntry g_procRootDirEntry
Definition: proc_file.c:50
这是这个函数的调用关系图:

◆ LseekDirProcFile()

int LseekDirProcFile ( struct ProcDirEntry pde,
off_t *  pos,
int  whence 
)

directory migration

Description:
This API is used to set the proc directory migration
注意
  • Only allow SEEK_SET to zero.
参数
pde[IN] Type #struct ProcDirEntry * pointer of the node structure to be deviated
pos[IN] Type #off_t * the number of deviation
whence[IN] Type int the begin of deviation
返回值
#EINVALdeviation failed
#ENOERRdeviation successfully
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_open

在文件 proc_file.c652 行定义.

653{
654 /* Only allow SEEK_SET to zero */
655 if ((whence != SEEK_SET) || (*pos != 0)) {
656 return EINVAL;
657 }
658 pde->pdirCurrent = pde->subdir;
659 pde->pf->fPos = 0;
660 return ENOERR;
661}

◆ LseekProcFile()

loff_t LseekProcFile ( struct ProcDirEntry pde,
loff_t  offset,
int  whence 
)

File migration

Description:
This API is used to set the proc file migration
注意
  • None.
参数
pde[IN] Type #struct ProcDirEntry * pointer of the node structure to be deviation
offset[IN] Type #loff_t the number of deviation
whence[IN] Type int the begin of deviation
返回值
#<0deviation failed
#>=0deviation successfully
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_open

File migration

在文件 proc_file.c622 行定义.

623{
624 if (pde == NULL || pde->pf == NULL) {
625 return PROC_ERROR;
626 }
627
628 struct ProcFile *procFile = pde->pf;
629
630 loff_t result = -EINVAL;
631
632 switch (whence) {
633 case SEEK_CUR:
634 result = procFile->fPos + offset;
635 break;
636
637 case SEEK_SET:
638 result = offset;
639 break;
640
641 default:
642 break;
643 }
644
645 if (result >= 0) {
646 procFile->fPos = result;
647 }
648
649 return result;
650}
Proc文件结构体,对标 FILE 结构体
Definition: proc_fs.h:121

◆ OpenProcFile()

struct ProcDirEntry * OpenProcFile ( const char *  fileName,
int  flags,
  ... 
)

open a proc node

Description:
This API is used to open the node by 'fileName' and flags,
注意
  • None.
参数
fileName[IN] Type #const char * the fileName of the node to be opened
flags[IN] Type int the flags of open's node
返回值
#NULLopen failed
#NOTNULL open successfully
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_close

在文件 proc_file.c553 行定义.

554{
555 unsigned int intSave;
556 struct ProcDirEntry *pn = ProcFindEntry(fileName);
557 if (pn == NULL) {
558 return NULL;
559 }
560
561 SCHEDULER_LOCK(intSave);
562 if (S_ISREG(pn->mode) && (pn->count != 1)) {
563 SCHEDULER_UNLOCK(intSave);
564 return NULL;
565 }
566
567 pn->flags = (unsigned int)(pn->flags) | (unsigned int)flags;
568 atomic_set(&pn->count, PROC_INUSE);
569 SCHEDULER_UNLOCK(intSave);
570 if (ProcOpen(pn->pf) != OK) {
571 return NULL;
572 }
573 if (S_ISREG(pn->mode) && (pn->procFileOps != NULL) && (pn->procFileOps->open != NULL)) {
574 (void)pn->procFileOps->open((struct Vnode *)pn, pn->pf);
575 }
576 if (S_ISDIR(pn->mode)) {
577 pn->pdirCurrent = pn->subdir;
578 pn->pf->fPos = 0;
579 }
580
581 return pn;
582}
int ProcOpen(struct ProcFile *procFile)
打开 pro
Definition: proc_file.c:503
struct ProcDirEntry * ProcFindEntry(const char *path)
Definition: proc_file.c:95
proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ? 操作 /proc的 真正结构体
Definition: proc_fs.h:101
int flags
标签
Definition: proc_fs.h:105
int(* open)(struct Vnode *vnode, struct ProcFile *pf)
Definition: proc_fs.h:92
ARG_NUM_3 int
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:
这是这个函数的调用关系图:

◆ ProcOpen()

int ProcOpen ( struct ProcFile procFile)

打开 pro

在文件 proc_file.c503 行定义.

504{
505 if (procFile == NULL) {
506 return PROC_ERROR;
507 }
508 if (procFile->sbuf != NULL) {
509 return OK;
510 }
511
512 struct SeqBuf *buf = LosBufCreat();//创建一个 seq buf
513 if (buf == NULL) {
514 return PROC_ERROR;
515 }
516 procFile->sbuf = buf;
517 return OK;
518}
struct SeqBuf * LosBufCreat(void)
创建seq buf
Definition: los_seq_buf.c:76
char * buf
Definition: los_seq_buf.h:49
函数调用图:
这是这个函数的调用关系图:

◆ ReadProcFile()

int ReadProcFile ( struct ProcDirEntry pde,
void buf,
size_t  len 
)

read a proc node

Description:
This API is used to read the node by pde
注意
  • None.
参数
pde[IN] Type #struct ProcDirEntry * pointer of the node structure to be read
buf[IN] Type void * user-provided to save the data
len[IN] Type size_t the length of want to read
返回值
#-1read failed
#>0Number of bytes read success
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_open

在文件 proc_file.c584 行定义.

585{
586 int result = -EPERM;
587
588 if (pde == NULL) {
589 return result;
590 }
591 if (S_ISREG(pde->mode)) {
592 if ((pde->procFileOps != NULL) && (pde->procFileOps->read != NULL)) {
593 result = ProcRead(pde, (char *)buf, len);
594 }
595 } else if (S_ISDIR(pde->mode)) {
596 result = GetNextDir(pde, buf, len);
597 }
598 return result;
599}
static int GetNextDir(struct ProcDirEntry *pn, void *buf, size_t len)
Definition: proc_file.c:484
static int ProcRead(struct ProcDirEntry *pde, char *buf, size_t len)
Definition: proc_file.c:520
int(* read)(struct SeqBuf *m, void *v)
Definition: proc_fs.h:94
函数调用图:
这是这个函数的调用关系图:

◆ WriteProcFile()

int WriteProcFile ( struct ProcDirEntry pde,
const void buf,
size_t  len 
)

write a proc node

Description:
This API is used to write the node by pde
注意
  • None.
参数
pde[IN] Type #struct ProcDirEntry * pointer of the node structure to be written
buf[IN] Type #const void * data to write
len[IN] Type size_t length of data to write
返回值
#-1write failed
#>0Number of bytes write successfully
Dependency:
  • proc_fs.h: the header file that contains the API declaration.
参见
proc_open

write a proc node

在文件 proc_file.c601 行定义.

602{
603 int result = -EPERM;
604
605 if (pde == NULL) {
606 return result;
607 }
608
609 if (S_ISDIR(pde->mode)) {
610 return -EISDIR;
611 }
612
613 spin_lock(&procfsLock);
614 if ((pde->procFileOps != NULL) && (pde->procFileOps->write != NULL)) {
615 result = pde->procFileOps->write(pde->pf, (const char *)buf, len, &(pde->pf->fPos));
616 }
617 spin_unlock(&procfsLock);
618
619 return result;
620}
spinlock_t procfsLock
ssize_t(* write)(struct ProcFile *pf, const char *buf, size_t count, loff_t *ppos)
Definition: proc_fs.h:91
这是这个函数的调用关系图: