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

浏览源代码.

函数

ssize_t file_fallocate64 (struct file *filep, int mode, off64_t offset, off64_t len)
 
int fallocate64 (int fd, int mode, off64_t offset, off64_t len)
 

函数说明

◆ fallocate64()

int fallocate64 ( int  fd,
int  mode,
off64_t  offset,
off64_t  len 
)

在文件 vfs_fallocate64.c108 行定义.

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

◆ file_fallocate64()

ssize_t file_fallocate64 ( struct file filep,
int  mode,
off64_t  offset,
off64_t  len 
)

在文件 vfs_fallocate64.c49 行定义.

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