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

浏览源代码.

函数

static ssize_t file_fallocate (struct file *filep, int mode, off_t offset, off_t len)
 
int fallocate (int fd, int mode, off_t offset, off_t len)
 

函数说明

◆ fallocate()

int fallocate ( int  fd,
int  mode,
off_t  offset,
off_t  len 
)

在文件 vfs_fallocate.c105 行定义.

106{
107#if CONFIG_NFILE_DESCRIPTORS > 0
108 struct file *filep = NULL;
109#endif
110
111/* Did we get a valid file descriptor? */
112
113#if CONFIG_NFILE_DESCRIPTORS > 0
114 if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
115#endif
116 {
117 set_errno(EBADF);
118 return VFS_ERROR;
119 }
120
121#if CONFIG_NFILE_DESCRIPTORS > 0
122
123 /* The descriptor is in the right range to be a file descriptor... write to the file. */
124
125 int ret = fs_getfilep(fd, &filep);
126 if (ret < 0) {
127 /* The errno value has already been set */
128 return VFS_ERROR;
129 }
130
131 if (filep->f_oflags & O_DIRECTORY) {
132 set_errno(EBADF);
133 return VFS_ERROR;
134 }
135
136 /* Perform the fallocate operation using the file descriptor as an index */
137 return file_fallocate(filep, mode, offset, len);
138#endif
139}
int f_oflags
static ssize_t file_fallocate(struct file *filep, int mode, off_t offset, off_t len)
Definition: vfs_fallocate.c:49
函数调用图:
这是这个函数的调用关系图:

◆ file_fallocate()

static ssize_t file_fallocate ( struct file filep,
int  mode,
off_t  offset,
off_t  len 
)
static

在文件 vfs_fallocate.c49 行定义.

50{
51 int ret;
52
53 if (len <= 0) {
54 ret = EINVAL;
55 goto errout;
56 }
57
58 /* Was this file opened for write access? */
59
60 if (((unsigned int)(filep->f_oflags) & O_ACCMODE) == O_RDONLY) {
61 ret = -EACCES;
62 goto errout;
63 }
64
65 if (!filep->ops || !filep->ops->fallocate) {
66 ret = -EBADF;
67 goto errout;
68 }
69
70 /* Yes, then let the driver perform the fallocate */
71
72 ret = filep->ops->fallocate(filep, mode, offset, len);
73 if (ret < 0) {
74 goto errout;
75 }
76
77 return ret;
78
79errout:
80 set_errno(-ret);
81 return VFS_ERROR;
82}
这是这个函数的调用关系图: