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

浏览源代码.

函数

static int FcntlDupFd (int procfd, int leastFd)
 
int VfsFcntl (int procfd, int cmd,...)
 

函数说明

◆ FcntlDupFd()

static int FcntlDupFd ( int  procfd,
int  leastFd 
)
static

在文件 vfs_fcntl.c43 行定义.

44{
45 int sysfd = GetAssociatedSystemFd(procfd);
46 if ((sysfd < 0) || (sysfd >= CONFIG_NFILE_DESCRIPTORS)) {
47 return -EBADF;
48 }
49
50 if (CheckProcessFd(leastFd) != OK) {
51 return -EINVAL;
52 }
53
54 int dupFd = AllocLowestProcessFd(leastFd);
55 if (dupFd < 0) {
56 return -EMFILE;
57 }
58
59 files_refer(sysfd);
60 AssociateSystemFd(dupFd, sysfd);
61
62 return dupFd;
63}
void files_refer(int fd)
int CheckProcessFd(int procFd)
Definition: vfs_procfd.c:122
int AllocLowestProcessFd(int minFd)
分配文件描述符,从3号开始
Definition: vfs_procfd.c:233
void AssociateSystemFd(int procFd, int sysFd)
参数进程FD和参数系统FD进行绑定(关联)
Definition: vfs_procfd.c:105
int GetAssociatedSystemFd(int procFd)
获取绑定的系统描述符
Definition: vfs_procfd.c:133
函数调用图:
这是这个函数的调用关系图:

◆ VfsFcntl()

int VfsFcntl ( int  fd,
int  cmd,
  ... 
)
Description:
The VfsFcntl function shall manipulate file descriptor.
返回值
#0On success.
#-1On failure with errno set.
CONTINE_NUTTX_FCNTLdoesn't support some cmds in VfsFcntl, needs to continue going through Nuttx vfs operation.
Dependency:
  • fs.h
参见
None

在文件 vfs_fcntl.c68 行定义.

69{
70 va_list ap;
71 int ret = 0;
72
73 va_start(ap, cmd);
74 switch (cmd) {
75 case F_DUPFD:
76 {
77 int arg = va_arg(ap, int);
78 ret = FcntlDupFd(procfd, arg);
79 }
80 break;
81 case F_GETFD:
82 {
83 bool isCloexec = CheckCloexecFlag(procfd);
84 ret = isCloexec ? FD_CLOEXEC : 0;
85 }
86 break;
87 case F_SETFD:
88 {
89 int oflags = va_arg(ap, int);
90 if (oflags & FD_CLOEXEC) {
91 SetCloexecFlag(procfd);
92 } else {
93 ClearCloexecFlag(procfd);
94 }
95 }
96 break;
97 default:
98 ret = CONTINE_NUTTX_FCNTL;
99 break;
100 }
101
102 va_end(ap);
103 return ret;
104}
void SetCloexecFlag(int procFd)
Definition: vfs_cloexec.c:62
bool CheckCloexecFlag(int procFd)
Definition: vfs_cloexec.c:75
void ClearCloexecFlag(int procFd)
Definition: vfs_cloexec.c:89
static int FcntlDupFd(int procfd, int leastFd)
Definition: vfs_fcntl.c:43
函数调用图:
这是这个函数的调用关系图: