RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ File POSIX API 的协作图:

宏定义

#define AT_FDCWD   (-100)
 

函数

int open (const char *file, int flags,...)
 
 RTM_EXPORT (open)
 
int openat (int dirfd, const char *path, int flag,...)
 
int utimensat (int __fd, const char *__path, const struct timespec __times[2], int __flags)
 
int creat (const char *path, mode_t mode)
 
 RTM_EXPORT (creat)
 
int close (int fd)
 
 RTM_EXPORT (close)
 
ssize_t read (int fd, void *buf, size_t len)
 
 RTM_EXPORT (read)
 
ssize_t write (int fd, const void *buf, size_t len)
 
 RTM_EXPORT (write)
 
off_t lseek (int fd, off_t offset, int whence)
 
 RTM_EXPORT (lseek)
 
int rename (const char *old_file, const char *new_file)
 
 RTM_EXPORT (rename)
 
int unlink (const char *pathname)
 
 RTM_EXPORT (unlink)
 
int stat (const char *file, struct stat *buf)
 
 RTM_EXPORT (stat)
 
int fstat (int fildes, struct stat *buf)
 
 RTM_EXPORT (fstat)
 
int fsync (int fildes)
 
 RTM_EXPORT (fsync)
 
int fcntl (int fildes, int cmd,...)
 
 RTM_EXPORT (fcntl)
 
int ioctl (int fildes, int cmd,...)
 
 RTM_EXPORT (ioctl)
 
int ftruncate (int fd, off_t length)
 
 RTM_EXPORT (ftruncate)
 
int statfs (const char *path, struct statfs *buf)
 
 RTM_EXPORT (statfs)
 
int fstatfs (int fildes, struct statfs *buf)
 
 RTM_EXPORT (fstatfs)
 
int mkdir (const char *path, mode_t mode)
 
 RTM_EXPORT (mkdir)
 
 FINSH_FUNCTION_EXPORT (mkdir, create a directory)
 
int rmdir (const char *pathname)
 
 RTM_EXPORT (rmdir)
 
DIR * opendir (const char *name)
 
 RTM_EXPORT (opendir)
 
struct dirent * readdir (DIR *d)
 
 RTM_EXPORT (readdir)
 
long telldir (DIR *d)
 
 RTM_EXPORT (telldir)
 
void seekdir (DIR *d, long offset)
 
 RTM_EXPORT (seekdir)
 
void rewinddir (DIR *d)
 
 RTM_EXPORT (rewinddir)
 
int closedir (DIR *d)
 
 RTM_EXPORT (closedir)
 
int access (const char *path, int amode)
 
void setcwd (char *buf)
 
 RTM_EXPORT (setcwd)
 
char * getcwd (char *buf, size_t size)
 
 RTM_EXPORT (getcwd)
 
ssize_t pread (int fd, void *buf, size_t len, off_t offset)
 
 RTM_EXPORT (pread)
 
ssize_t pwrite (int fd, const void *buf, size_t len, off_t offset)
 
 RTM_EXPORT (pwrite)
 

详细描述

宏定义说明

◆ AT_FDCWD

#define AT_FDCWD   (-100)

在文件 dfs_posix.c92 行定义.

函数说明

◆ open()

int open ( const char * file,
int flags,
... )

this function is a POSIX compliant version, which will open a file and return a file descriptor according specified flags.

参数
filethe path name of file.
flagsthe file open flags. Common values include:
  • Access modes (mutually exclusive):
    • O_RDONLY: Open for read-only access.
    • O_WRONLY: Open for write-only access.
    • O_RDWR: Open for both reading and writing.
  • File status flags (can be combined with bitwise OR |):
    • O_CREAT: Create the file if it does not exist. Requires a mode argument.
    • O_TRUNC: Truncate the file to zero length if it already exists.
    • O_APPEND: Append writes to the end of the file.
    • O_EXCL: Ensure that O_CREAT creates the file exclusively.
    • Other platform-specific flags
返回
the non-negative integer on successful open, others for failed.

在文件 dfs_posix.c48 行定义.

49{
50 int fd, result;
51 struct dfs_file *df = RT_NULL;
52 mode_t mode = 0;
53
54 if (file == NULL)
55 {
56 rt_set_errno(-EBADF);
57 return -1;
58 }
59
60 if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE)
61 {
62 va_list ap;
63 va_start(ap, flags);
64 mode = va_arg(ap, mode_t);
65 va_end(ap);
66 }
67
68 fd = fd_new();
69 if (fd >= 0)
70 {
71 df = fd_get(fd);
72 }
73 else
74 {
75 rt_set_errno(-RT_ERROR);
76 return RT_NULL;
77 }
78
79 result = dfs_file_open(df, file, flags, mode);
80 if (result < 0)
81 {
82 fd_release(fd);
83 rt_set_errno(result);
84 return -1;
85 }
86
87 return fd;
88}
int dfs_file_open(struct dfs_file *file, const char *path, int oflags, mode_t mode)
int fd_new(void)
定义 dfs.c:345
struct dfs_file * fd_get(int fd)
定义 dfs.c:367
void fd_release(int fd)
定义 dfs.c:359
#define RT_NULL
uint32_t flags
uint16_t mode

引用了 dfs_file_open(), fd_get(), fd_new(), fd_release(), dfs_file::flags, dfs_file::mode , 以及 RT_NULL.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [1/28]

RTM_EXPORT ( open )

引用了 open().

+ 函数调用图:

◆ openat()

int openat ( int dirfd,
const char * path,
int flag,
... )

Opens a file relative to a directory file descriptor.

参数
dirfdThe file descriptor of the directory to base the relative path on.
pathThe path to the file to be opened, relative to the directory specified by dirfd. Can be an absolute path (in which case dirfd is ignored).
flagFile access and status flags (e.g., O_RDONLY, O_WRONLY, O_CREAT).
返回
On success, returns a new file descriptor for the opened file. On failure, returns -1 and sets errno to indicate the error.
注解
When using relative paths, ensure dirfd is a valid directory descriptor. When pathname is absolute, the dirfd argument is ignored.

在文件 dfs_posix.c110 行定义.

111{
112 struct dfs_file *d;
113 char *fullpath;
114 int fd;
115
116 if (!path)
117 {
118 rt_set_errno(-EBADF);
119 return -1;
120 }
121
122 fullpath = (char*)path;
123
124 if (path[0] != '/')
125 {
126 if (dirfd != AT_FDCWD)
127 {
128 d = fd_get(dirfd);
129 if (!d || !d->vnode)
130 {
131 rt_set_errno(-EBADF);
132 return -1;
133 }
134
135 fullpath = dfs_dentry_full_path(d->dentry);
136 if (!fullpath)
137 {
138 rt_set_errno(-ENOMEM);
139 return -1;
140 }
141 }
142 }
143
144 fd = open(fullpath, flag, 0);
145
146 if (fullpath != path)
147 {
148 rt_free(fullpath);
149 }
150
151 return fd;
152}
char * dfs_dentry_full_path(struct dfs_dentry *dentry)
#define AT_FDCWD
int open(const char *file, int flags,...)
rt_weak void rt_free(void *ptr)
This function will release the previously allocated memory block by rt_malloc. The released memory bl...
struct dfs_vnode * vnode
struct dfs_dentry * dentry

引用了 AT_FDCWD, dfs_file::dentry, dfs_dentry_full_path(), fd_get(), open(), rt_free() , 以及 dfs_file::vnode.

+ 函数调用图:

◆ utimensat()

int utimensat ( int __fd,
const char * __path,
const struct timespec __times[2],
int __flags )

在文件 dfs_posix.c154 行定义.

155{
156 int ret;
157 struct stat buffer;
158 struct dfs_file *d;
159 char *fullpath;
160 struct dfs_attr attr;
161 time_t current_time;
162 char *link_fn = (char *)rt_malloc(DFS_PATH_MAX);
163 int err;
164
165 if (__path == NULL)
166 {
167 return -EFAULT;
168 }
169
170 if (__path[0] == '/' || __fd == AT_FDCWD)
171 {
172 if (stat(__path, &buffer) < 0)
173 {
174 return -ENOENT;
175 }
176 else
177 {
178 fullpath = (char*)__path;
179 }
180 }
181 else
182 {
183 if (__fd != AT_FDCWD)
184 {
185 d = fd_get(__fd);
186 if (!d || !d->vnode)
187 {
188 return -EBADF;
189 }
190
191 fullpath = dfs_dentry_full_path(d->dentry);
192 if (!fullpath)
193 {
194 rt_set_errno(-ENOMEM);
195 return -1;
196 }
197 }
198 }
199
200 /*update time*/
202 time(&current_time);
203 if (UTIME_NOW == __times[0].tv_nsec)
204 {
205 attr.ia_atime.tv_sec = current_time;
206 }
207 else if (UTIME_OMIT != __times[0].tv_nsec)
208 {
209 attr.ia_atime.tv_sec = __times[0].tv_sec;
210 }
211 else
212 {
213 attr.ia_valid &= ~ATTR_ATIME_SET;
214 }
215
216 if (UTIME_NOW == __times[1].tv_nsec)
217 {
218 attr.ia_mtime.tv_sec = current_time;
219 }
220 else if (UTIME_OMIT == __times[1].tv_nsec)
221 {
222 attr.ia_mtime.tv_sec = __times[1].tv_sec;
223 }
224 else
225 {
226 attr.ia_valid &= ~ATTR_MTIME_SET;
227 }
228
229 if (dfs_file_lstat(fullpath, &buffer) == 0)
230 {
231 if (S_ISLNK(buffer.st_mode) && (__flags != AT_SYMLINK_NOFOLLOW))
232 {
233 if (link_fn)
234 {
235 err = dfs_file_readlink(fullpath, link_fn, DFS_PATH_MAX);
236 if (err < 0)
237 {
238 rt_free(link_fn);
239 return -ENOENT;
240 }
241 else
242 {
243 fullpath = link_fn;
244 if (dfs_file_stat(fullpath, &buffer) != 0)
245 {
246 rt_free(link_fn);
247 return -ENOENT;
248 }
249 }
250 }
251
252 }
253 }
254 attr.st_mode = buffer.st_mode;
255 ret = dfs_file_setattr(fullpath, &attr);
256 rt_free(link_fn);
257
258 return ret;
259}
#define ATTR_MTIME_SET
定义 dfs.h:37
#define ATTR_ATIME_SET
定义 dfs.h:33
#define UTIME_OMIT
定义 dfs.h:57
#define UTIME_NOW
定义 dfs.h:53
#define AT_SYMLINK_NOFOLLOW
定义 dfs.h:49
#define DFS_PATH_MAX
定义 dfs.h:72
int dfs_file_lstat(const char *path, struct stat *buf)
int dfs_file_setattr(const char *path, struct dfs_attr *attr)
int dfs_file_readlink(const char *path, char *buf, int bufsize)
int dfs_file_stat(const char *path, struct stat *buf)
int stat(const char *file, struct stat *buf)
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
unsigned int ia_valid

引用了 AT_FDCWD, AT_SYMLINK_NOFOLLOW, ATTR_ATIME_SET, ATTR_MTIME_SET, dfs_file::dentry, dfs_dentry_full_path(), dfs_file_lstat(), dfs_file_readlink(), dfs_file_setattr(), dfs_file_stat(), DFS_PATH_MAX, fd_get(), dfs_attr::ia_atime, dfs_attr::ia_mtime, dfs_attr::ia_valid, rt_free(), rt_malloc(), dfs_attr::st_mode, stat(), UTIME_NOW, UTIME_OMIT , 以及 dfs_file::vnode.

+ 函数调用图:

◆ creat()

int creat ( const char * path,
mode_t mode )

this function is a POSIX compliant version, which will create a new file or rewrite an existing one

参数
paththe path name of file.
modethe file permission bits to be used in creating the file (not used, can be 0)
返回
the non-negative integer on successful open, others for failed.

在文件 dfs_posix.c270 行定义.

271{
272 return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
273}

引用了 open().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [2/28]

RTM_EXPORT ( creat )

引用了 creat().

+ 函数调用图:

◆ close()

int close ( int fd)

this function is a POSIX compliant version, which will close the open file descriptor.

参数
fdthe file descriptor.
返回
0 on successful, -1 on failed.

在文件 dfs_posix.c284 行定义.

285{
286 int result;
287 struct dfs_file *file;
288
289 file = fd_get(fd);
290 if (file == NULL)
291 {
292 rt_set_errno(-EBADF);
293
294 return -1;
295 }
296
297 result = dfs_file_close(file);
298 if (result < 0)
299 {
300 rt_set_errno(result);
301
302 return -1;
303 }
304
305 fd_release(fd);
306
307 return 0;
308}
int dfs_file_close(struct dfs_file *file)

引用了 dfs_file_close(), fd_get() , 以及 fd_release().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [3/28]

RTM_EXPORT ( close )

引用了 close() , 以及 read().

+ 函数调用图:

◆ read()

ssize_t read ( int fd,
void * buf,
size_t len )

this function is a POSIX compliant version, which will read specified data buffer length for an open file descriptor.

参数
fdthe file descriptor.
bufthe buffer to save the read data.
lenthe maximal length of data buffer
返回
the actual read data buffer length. If the returned value is 0, it may be reach the end of file, please check errno.

在文件 dfs_posix.c325 行定义.

327{
328 ssize_t result;
329 struct dfs_file *file;
330
331 if (buf == NULL)
332 {
333 rt_set_errno(-EBADF);
334 return -1;
335 }
336
337 file = fd_get(fd);
338 if (file == NULL)
339 {
340 rt_set_errno(-EBADF);
341
342 return -1;
343 }
344
345 result = dfs_file_read(file, buf, len);
346 if (result < 0)
347 {
348 rt_set_errno(result);
349
350 return -1;
351 }
352
353 return result;
354}
ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len)

引用了 dfs_file_read() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [4/28]

RTM_EXPORT ( read )

引用了 read() , 以及 write().

+ 函数调用图:

◆ write()

ssize_t write ( int fd,
const void * buf,
size_t len )

this function is a POSIX compliant version, which will write specified data buffer length for an open file descriptor.

参数
fdthe file descriptor
bufthe data buffer to be written.
lenthe data buffer length.
返回
the actual written data buffer length.

在文件 dfs_posix.c370 行定义.

372{
373 ssize_t result;
374 struct dfs_file *file;
375
376 if (buf == NULL)
377 {
378 rt_set_errno(-EBADF);
379 return -1;
380 }
381
382 file = fd_get(fd);
383 if (file == NULL)
384 {
385 rt_set_errno(-EBADF);
386
387 return -1;
388 }
389
390 result = dfs_file_write(file, buf, len);
391 if (result < 0)
392 {
393 rt_set_errno(result);
394
395 return -1;
396 }
397
398 return result;
399}
ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len)

引用了 dfs_file_write() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [5/28]

RTM_EXPORT ( write )

引用了 write().

+ 函数调用图:

◆ lseek()

off_t lseek ( int fd,
off_t offset,
int whence )

this function is a POSIX compliant version, which will Reposition the file offset for an open file descriptor.

The lseek function sets the file offset for the file descriptor fd to a new value, determined by the offset and whence parameters. It can be used to seek to specific positions in a file for reading or writing.

参数
fdthe file descriptor.
offsetThe offset, in bytes, to set the file position. The meaning of offset depends on the value of whence.
whencethe directive of seek. It can be one of:
  • SEEK_SET: Set the offset to offset bytes from the beginning of the file.
  • SEEK_CUR: Set the offset to its current location plus offset bytes.
  • SEEK_END: Set the offset to the size of the file plus offset bytes.
返回
the resulting read/write position in the file, or -1 on failed.

在文件 dfs_posix.c420 行定义.

421{
422 off_t result;
423 struct dfs_file *file;
424
425 file = fd_get(fd);
426 if (file == NULL)
427 {
428 rt_set_errno(-EBADF);
429
430 return -1;
431 }
432
433 result = dfs_file_lseek(file, offset, whence);
434 if (result < 0)
435 {
436 rt_set_errno(-EPERM);
437
438 return -1;
439 }
440
441 return result;
442}
off_t dfs_file_lseek(struct dfs_file *file, off_t offset, int wherece)

引用了 dfs_file_lseek() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [6/28]

RTM_EXPORT ( lseek )

引用了 lseek().

+ 函数调用图:

◆ rename()

int rename ( const char * old_file,
const char * new_file )

this function is a POSIX compliant version, which will rename old file name to new file name.

参数
old_filethe old file name.
new_filethe new file name.
返回
0 on successful, -1 on failed.

note: the old and new file name must be belong to a same file system.

在文件 dfs_posix.c456 行定义.

457{
458 int result;
459
460 if (old_file == NULL || new_file == NULL)
461 {
462 rt_set_errno(-EBADF);
463 return -1;
464 }
465
466 result = dfs_file_rename(old_file, new_file);
467 if (result < 0)
468 {
469 rt_set_errno(result);
470
471 return -1;
472 }
473
474 return 0;
475}
int dfs_file_rename(const char *old_file, const char *new_file)

引用了 dfs_file_rename().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [7/28]

RTM_EXPORT ( rename )

引用了 rename().

+ 函数调用图:

◆ unlink()

int unlink ( const char * pathname)

this function is a POSIX compliant version, which will unlink (remove) a specified path file from file system.

参数
pathnamethe specified path name to be unlinked.
返回
0 on successful, -1 on failed.

在文件 dfs_posix.c486 行定义.

487{
488 int result;
489 struct stat stat;
490
491 if (pathname == NULL)
492 {
493 rt_set_errno(-EBADF);
494 return -1;
495 }
496
497 result = dfs_file_lstat(pathname, &stat);
498 if (result == 0 && S_ISDIR(stat.st_mode))
499 {
500 rt_set_errno(-RT_ERROR);
501
502 return -1;
503 }
504
505 result = dfs_file_unlink(pathname);
506 if (result < 0)
507 {
508 rt_set_errno(result);
509
510 return -1;
511 }
512
513 return 0;
514}
int dfs_file_unlink(const char *path)

引用了 dfs_file_lstat(), dfs_file_unlink() , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [8/28]

RTM_EXPORT ( unlink )

引用了 unlink().

+ 函数调用图:

◆ stat()

int stat ( const char * file,
struct stat * buf )

this function is a POSIX compliant version, which will get file information.

参数
filethe file name
bufthe data buffer to save stat description.
返回
0 on successful, -1 on failed.

在文件 dfs_posix.c526 行定义.

527{
528 int result;
529
530 if (file == NULL || buf == NULL)
531 {
532 rt_set_errno(EBADF);
533 return -1;
534 }
535
536 result = dfs_file_stat(file, buf);
537 if (result < 0)
538 {
539 rt_set_errno(-result);
540 }
541
542 return result;
543}

引用了 dfs_file_stat() , 以及 stat().

+ 函数调用图:

◆ RTM_EXPORT() [9/28]

RTM_EXPORT ( stat )

引用了 stat().

+ 函数调用图:

◆ fstat()

int fstat ( int fildes,
struct stat * buf )

this function is a POSIX compliant version, which will get file status.

参数
fildesthe file description
bufthe data buffer to save stat description.
返回
0 on successful, -1 on failed.

在文件 dfs_posix.c554 行定义.

555{
556 int ret = -1;
557 struct dfs_file *file;
558
559 if (buf == NULL)
560 {
561 rt_set_errno(-EBADF);
562 return -1;
563 }
564
565 /* get the fd */
566 file = fd_get(fildes);
567 if (file == NULL)
568 {
569 rt_set_errno(-EBADF);
570
571 return -1;
572 }
573
574 if (dfs_is_mounted(file->dentry->mnt) == 0)
575 {
576 ret = file->dentry->mnt->fs_ops->stat(file->dentry, buf);
577 }
578
579 return ret;
580}
int dfs_is_mounted(struct dfs_mnt *mnt)
struct dfs_mnt * mnt
int(* stat)(struct dfs_dentry *dentry, struct stat *buf)
const struct dfs_filesystem_ops * fs_ops

引用了 dfs_file::dentry, dfs_is_mounted(), fd_get(), dfs_mnt::fs_ops, dfs_dentry::mnt, dfs_filesystem_ops::stat , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [10/28]

RTM_EXPORT ( fstat )

引用了 fstat().

+ 函数调用图:

◆ fsync()

int fsync ( int fildes)

this function is a POSIX compliant version, which shall request that all data for the open file descriptor named by fildes is to be transferred to the storage device associated with the file described by fildes.

参数
fildesthe file description
返回
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

在文件 dfs_posix.c594 行定义.

595{
596 int ret;
597 struct dfs_file *file;
598
599 file = fd_get(fildes);
600 if (file == NULL)
601 {
602 rt_set_errno(-EBADF);
603
604 return -1;
605 }
606
607 ret = dfs_file_fsync(file);
608
609 return ret;
610}
int dfs_file_fsync(struct dfs_file *file)

引用了 dfs_file_fsync() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [11/28]

RTM_EXPORT ( fsync )

引用了 fsync().

+ 函数调用图:

◆ fcntl()

int fcntl ( int fildes,
int cmd,
... )

this function is a POSIX compliant version, which shall perform a variety of control functions on devices.

参数
fildesthe file description
cmdthe specified command, Common values include:
  • F_DUPFD: Duplicate a file descriptor.
  • F_GETFD: Get the file descriptor flags.
  • F_SETFD: Set the file descriptor flags.
  • F_GETFL: Get the file status flags.
  • F_SETFL: Set the file status flags.
...represents the additional information that is needed by this specific device to perform the requested function. For example:
  • When cmd is F_SETFL, an additional integer argument specifies the new status flags.
返回
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

在文件 dfs_posix.c631 行定义.

632{
633 int ret = -1;
634 struct dfs_file *file;
635
636 file = fd_get(fildes);
637 if (file)
638 {
639 void *arg;
640 va_list ap;
641
642 va_start(ap, cmd);
643 arg = va_arg(ap, void *);
644 va_end(ap);
645
646 ret = dfs_file_ioctl(file, cmd, arg);
647 if (ret < 0)
648 {
649 ret = dfs_file_fcntl(fildes, cmd, (unsigned long)arg);
650 }
651 }
652 else
653 {
654 ret = -EBADF;
655 }
656
657 if (ret < 0)
658 {
659 rt_set_errno(ret);
660 ret = -1;
661 }
662
663 return ret;
664}
int dfs_file_ioctl(struct dfs_file *file, int cmd, void *args)
int dfs_file_fcntl(int fd, int cmd, unsigned long arg)

引用了 dfs_file_fcntl(), dfs_file_ioctl() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [12/28]

RTM_EXPORT ( fcntl )

引用了 fcntl().

+ 函数调用图:

◆ ioctl()

int ioctl ( int fildes,
int cmd,
... )

this function is a POSIX compliant version, which shall perform a variety of control functions on devices.

参数
fildesthe file description
cmdthe specified command
...represents the additional information that is needed by this specific device to perform the requested function.
返回
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

在文件 dfs_posix.c679 行定义.

680{
681 void *arg;
682 va_list ap;
683
684 va_start(ap, cmd);
685 arg = va_arg(ap, void *);
686 va_end(ap);
687
688 /* we use fcntl for this API. */
689 return fcntl(fildes, cmd, arg);
690}
int fcntl(int fildes, int cmd,...)

引用了 fcntl().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [13/28]

RTM_EXPORT ( ioctl )

引用了 ioctl().

+ 函数调用图:

◆ ftruncate()

int ftruncate ( int fd,
off_t length )

this function is a POSIX compliant version, which cause the regular file referenced by fd to be truncated to a size of precisely length bytes.

参数
fdthe file descriptor.
lengththe length to be truncated.
返回
Upon successful completion, ftruncate() shall return 0; otherwise, -1 shall be returned and errno set to indicate the error.

在文件 dfs_posix.c703 行定义.

704{
705 int result;
706 struct dfs_file *file;
707
708 file = fd_get(fd);
709 if (file == NULL)
710 {
711 rt_set_errno(-EBADF);
712
713 return -1;
714 }
715
716 if (length < 0)
717 {
718 rt_set_errno(-EINVAL);
719
720 return -1;
721 }
722
723 result = dfs_file_ftruncate(file, length);
724 if (result < 0)
725 {
726 rt_set_errno(result);
727
728 return -1;
729 }
730
731 return 0;
732}
int dfs_file_ftruncate(struct dfs_file *file, off_t length)

引用了 dfs_file_ftruncate() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [14/28]

RTM_EXPORT ( ftruncate )

引用了 ftruncate().

+ 函数调用图:

◆ statfs()

int statfs ( const char * path,
struct statfs * buf )

this function is a POSIX compliant version, which will return the information about a mounted file system.

参数
paththe path which mounted file system.
bufthe buffer to save the returned information.
返回
0 on successful, others on failed.

在文件 dfs_posix.c744 行定义.

745{
746 int result;
747
748 if (path == NULL || buf == NULL)
749 {
750 rt_set_errno(-EBADF);
751 return -1;
752 }
753
754 result = dfs_statfs(path, buf);
755 if (result < 0)
756 {
757 rt_set_errno(result);
758
759 return -1;
760 }
761
762 return result;
763}
int dfs_statfs(const char *path, struct statfs *buffer)

引用了 dfs_statfs() , 以及 statfs().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [15/28]

RTM_EXPORT ( statfs )

引用了 statfs().

+ 函数调用图:

◆ fstatfs()

int fstatfs ( int fildes,
struct statfs * buf )

this function is a POSIX compliant version, which will return the information about a mounted file system.

参数
fildesthe file description.
bufthe buffer to save the returned information.
返回
0 on successful, others on failed.

在文件 dfs_posix.c775 行定义.

776{
777 int ret = -1;
778 struct dfs_file *file;
779
780 if (buf == NULL)
781 {
782 rt_set_errno(-EBADF);
783 return -1;
784 }
785
786 /* get the fd */
787 file = fd_get(fildes);
788 if (file == NULL)
789 {
790 rt_set_errno(-EBADF);
791
792 return -1;
793 }
794
795 if (dfs_is_mounted(file->dentry->mnt) == 0)
796 {
797 ret = file->dentry->mnt->fs_ops->statfs(file->dentry->mnt, buf);
798 }
799
800 return ret;
801}
int(* statfs)(struct dfs_mnt *mnt, struct statfs *buf)

引用了 dfs_file::dentry, dfs_is_mounted(), fd_get(), dfs_mnt::fs_ops, dfs_dentry::mnt, dfs_filesystem_ops::statfs , 以及 statfs().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [16/28]

RTM_EXPORT ( fstatfs )

引用了 fstatfs().

+ 函数调用图:

◆ mkdir()

int mkdir ( const char * path,
mode_t mode )

this function is a POSIX compliant version, which will make a directory

参数
paththe directory path to be made.
modeThe permission mode for the new directory (unused here, can be set to 0).
返回
0 on successful, others on failed.

在文件 dfs_posix.c812 行定义.

813{
814 int result;
815 struct stat stat;
816 struct dfs_file file;
817
818 if (path == NULL)
819 {
820 rt_set_errno(-EBADF);
821 return -1;
822 }
823
824 if (path && dfs_file_lstat(path, &stat) == 0)
825 {
826 rt_set_errno(-EEXIST);
827 return -1;
828 }
829
830 dfs_file_init(&file);
831
832 result = dfs_file_open(&file, path, O_DIRECTORY | O_CREAT, mode);
833 if (result >= 0)
834 {
835 dfs_file_close(&file);
836 result = 0;
837 }
838 else
839 {
840 rt_set_errno(result);
841 result = -1;
842 }
843
844 dfs_file_deinit(&file);
845
846 return result;
847}
void dfs_file_init(struct dfs_file *file)
void dfs_file_deinit(struct dfs_file *file)

引用了 dfs_file_close(), dfs_file_deinit(), dfs_file_init(), dfs_file_lstat(), dfs_file_open(), dfs_file::mode , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [17/28]

RTM_EXPORT ( mkdir )

引用了 mkdir().

+ 函数调用图:

◆ FINSH_FUNCTION_EXPORT()

FINSH_FUNCTION_EXPORT ( mkdir ,
create a directory )

引用了 mkdir().

+ 函数调用图:

◆ rmdir()

int rmdir ( const char * pathname)

this function is a POSIX compliant version, which will remove a directory.

参数
pathnamethe path name to be removed.
返回
0 on successful, others on failed.

在文件 dfs_posix.c862 行定义.

863{
864 int result;
865 DIR *dir = RT_NULL;
866 struct stat stat;
867
868 if (!pathname)
869 {
870 rt_set_errno(-EPERM);
871 return -1;
872 }
873
874 dir = opendir(pathname);
875 if (dir)
876 {
877 struct dirent *dirent;
878
879 while (1)
880 {
881 dirent = readdir(dir);
882 if (dirent == RT_NULL)
883 break;
884 if (rt_strcmp(".", dirent->d_name) != 0 &&
885 rt_strcmp("..", dirent->d_name) != 0)
886 {
887 break;
888 }
889 }
890
891 closedir(dir);
892
893 if (dirent)
894 {
895 rt_set_errno(-EPERM);
896 return -1;
897 }
898 }
899
900 if (dfs_file_lstat(pathname, &stat) == 0)
901 {
902 if (S_ISLNK(stat.st_mode))
903 {
904 rt_set_errno(-EPERM);
905 return -1;
906 }
907 }
908
909 result = dfs_file_unlink(pathname);
910 if (result < 0)
911 {
912 rt_set_errno(result);
913
914 return -1;
915 }
916
917 return 0;
918}
int closedir(DIR *d)
struct dirent * readdir(DIR *d)
DIR * opendir(const char *name)

引用了 closedir(), dfs_file_lstat(), dfs_file_unlink(), opendir(), readdir(), RT_NULL , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [18/28]

RTM_EXPORT ( rmdir )

引用了 rmdir().

+ 函数调用图:

◆ opendir()

DIR * opendir ( const char * name)

this function is a POSIX compliant version, which will open a directory.

参数
namethe path name to be open.
返回
the DIR pointer of directory, NULL on open directory failed.

在文件 dfs_posix.c928 行定义.

929{
930 DIR *t = RT_NULL;
931 int fd, result;
932 struct dfs_file *file = RT_NULL;
933
934 if (!name || dfs_file_isdir(name) != 0)
935 {
936 rt_set_errno(-RT_ERROR);
937 return RT_NULL;
938 }
939
940 fd = fd_new();
941 if (fd >= 0)
942 {
943 file = fd_get(fd);
944 }
945 else
946 {
947 rt_set_errno(-RT_ERROR);
948 return RT_NULL;
949 }
950
951 result = dfs_file_open(file, name, O_RDONLY | O_DIRECTORY, 0);
952 if (result >= 0)
953 {
954 /* open successfully */
955 t = (DIR *) rt_malloc(sizeof(DIR));
956 if (t == NULL)
957 {
958 dfs_file_close(file);
959 fd_release(fd);
960 }
961 else
962 {
963 rt_memset(t, 0, sizeof(DIR));
964
965 t->fd = fd;
966 }
967
968 return t;
969 }
970
971 fd_release(fd);
972 rt_set_errno(result);
973
974 return NULL;
975}
int dfs_file_isdir(const char *path)

引用了 dfs_file_close(), dfs_file_isdir(), dfs_file_open(), fd_get(), fd_new(), fd_release(), rt_malloc() , 以及 RT_NULL.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [19/28]

RTM_EXPORT ( opendir )

引用了 opendir().

+ 函数调用图:

◆ readdir()

struct dirent * readdir ( DIR * d)

this function is a POSIX compliant version, which will return a pointer to a dirent structure representing the next directory entry in the directory stream.

参数
dthe directory stream pointer.
返回
the next directory entry, NULL on the end of directory or failed.

在文件 dfs_posix.c987 行定义.

988{
989 int result;
990 struct dirent *dirent = NULL;
991
992 if (d == NULL)
993 {
994 rt_set_errno(-EBADF);
995 return NULL;
996 }
997
998 do
999 {
1000 if (d->num)
1001 {
1002 struct dirent *dirent_ptr;
1003 dirent_ptr = (struct dirent *)&d->buf[d->cur];
1004 d->cur += dirent_ptr->d_reclen;
1005 }
1006
1007 if (!d->num || d->cur >= d->num)
1008 {
1009 /* get a new entry */
1010 result = dfs_file_getdents(fd_get(d->fd),
1011 (struct dirent *)d->buf,
1012 sizeof(d->buf) - 1);
1013 if (result <= 0)
1014 {
1015 rt_set_errno(result);
1016
1017 return NULL;
1018 }
1019
1020 d->num = result;
1021 d->cur = 0; /* current entry index */
1022 }
1023
1024 dirent = (struct dirent *)(d->buf + d->cur);
1025 if (rt_strcmp(".", dirent->d_name) != 0 &&
1026 rt_strcmp("..", dirent->d_name) != 0)
1027 {
1028 break;
1029 }
1030 } while (dirent);
1031
1032 return dirent;
1033}
int dfs_file_getdents(struct dfs_file *file, struct dirent *dirp, size_t nbytes)

引用了 dfs_file_getdents() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [20/28]

RTM_EXPORT ( readdir )

引用了 readdir().

+ 函数调用图:

◆ telldir()

long telldir ( DIR * d)

this function is a POSIX compliant version, which will return current location in directory stream.

参数
dthe directory stream pointer.
返回
the current location in directory stream.

在文件 dfs_posix.c1044 行定义.

1045{
1046 struct dfs_file *file;
1047 long result;
1048
1049 if (d == NULL)
1050 {
1051 rt_set_errno(-EBADF);
1052 return -1;
1053 }
1054
1055 file = fd_get(d->fd);
1056 if (file == NULL)
1057 {
1058 rt_set_errno(-EBADF);
1059
1060 return 0;
1061 }
1062
1063 result = file->fpos - d->num + d->cur;
1064
1065 return result;
1066}

引用了 fd_get() , 以及 dfs_file::fpos.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [21/28]

RTM_EXPORT ( telldir )

引用了 telldir().

+ 函数调用图:

◆ seekdir()

void seekdir ( DIR * d,
long offset )

this function is a POSIX compliant version, which will set position of next directory structure in the directory stream.

参数
dthe directory stream.
offsetthe offset in directory stream.

在文件 dfs_posix.c1076 行定义.

1077{
1078 struct dfs_file *file;
1079
1080 if (d == NULL)
1081 {
1082 rt_set_errno(-EBADF);
1083 return;
1084 }
1085
1086 file = fd_get(d->fd);
1087 if (file == NULL)
1088 {
1089 rt_set_errno(-EBADF);
1090
1091 return;
1092 }
1093
1094 if (d && d->fd > 0)
1095 {
1096 if (file->fpos > offset)
1097 {
1098 /* seek to the offset position of directory */
1099 if (dfs_file_lseek(fd_get(d->fd), 0, SEEK_SET) >= 0)
1100 d->num = d->cur = 0;
1101 }
1102
1103 while(file->fpos < offset)
1104 {
1105 if (!readdir(d))
1106 {
1107 break;
1108 }
1109 }
1110 }
1111}

引用了 dfs_file_lseek(), fd_get(), dfs_file::fpos , 以及 readdir().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [22/28]

RTM_EXPORT ( seekdir )

引用了 seekdir().

+ 函数调用图:

◆ rewinddir()

void rewinddir ( DIR * d)

this function is a POSIX compliant version, which will reset directory stream.

参数
dthe directory stream.

在文件 dfs_posix.c1120 行定义.

1121{
1122 if (d && d->fd > 0)
1123 {
1124 /* seek to the beginning of directory */
1125 if (dfs_file_lseek(fd_get(d->fd), 0, SEEK_SET) >= 0)
1126 d->num = d->cur = 0;
1127 }
1128}

引用了 dfs_file_lseek() , 以及 fd_get().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [23/28]

RTM_EXPORT ( rewinddir )

引用了 rewinddir().

+ 函数调用图:

◆ closedir()

int closedir ( DIR * d)

this function is a POSIX compliant version, which will close a directory stream.

参数
dthe directory stream.
返回
0 on successful, -1 on failed.

在文件 dfs_posix.c1139 行定义.

1140{
1141 int result;
1142 struct dfs_file *file;
1143
1144 if (d == NULL)
1145 {
1146 rt_set_errno(-EBADF);
1147 return -1;
1148 }
1149
1150 file = fd_get(d->fd);
1151 if (file == NULL)
1152 {
1153 rt_set_errno(-EBADF);
1154 return -1;
1155 }
1156
1157 result = dfs_file_close(file);
1158 if (result < 0)
1159 {
1160 rt_set_errno(result);
1161
1162 return -1;
1163 }
1164 else
1165 {
1166 fd_release(d->fd);
1167 rt_free(d);
1168 }
1169
1170 return 0;
1171}

引用了 dfs_file_close(), fd_get(), fd_release() , 以及 rt_free().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [24/28]

RTM_EXPORT ( closedir )

引用了 closedir() , 以及 working_directory.

+ 函数调用图:

◆ access()

int access ( const char * path,
int amode )

this function is a POSIX compliant version, which shall check the file named by the pathname pointed to by the path argument for accessibility according to the bit pattern contained in amode.

参数
paththe specified file/dir path.
amodethe value is either the bitwise-inclusive OR of the access permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).

在文件 dfs_posix.c1258 行定义.

1259{
1260 struct stat st;
1261
1262 if (path == NULL)
1263 {
1264 rt_set_errno(-EINVAL);
1265 return -1;
1266 }
1267
1268 if (stat(path, &st) < 0)
1269 {
1270 rt_set_errno(-ENOENT);
1271 return -1;
1272 }
1273
1274 if (amode == F_OK)
1275 {
1276 return 0;
1277 }
1278
1279 if ((amode & R_OK) && !(st.st_mode & S_IRUSR))
1280 {
1281 rt_set_errno(-EACCES);
1282 return -1;
1283 }
1284
1285 if ((amode & W_OK) && !(st.st_mode & S_IWUSR))
1286 {
1287 rt_set_errno(-EACCES);
1288 return -1;
1289 }
1290
1291 if ((amode & X_OK) && !(st.st_mode & S_IXUSR))
1292 {
1293 rt_set_errno(-EACCES);
1294 return -1;
1295 }
1296
1297 return 0;
1298}

引用了 stat().

+ 函数调用图:

◆ setcwd()

void setcwd ( char * buf)

this function is a POSIX compliant version, which will set current working directory.

参数
bufthe current directory.

在文件 dfs_posix.c1306 行定义.

1307{
1308 if (buf == NULL)
1309 {
1310 rt_set_errno(-EBADF);
1311 return;
1312 }
1313
1314#ifdef DFS_USING_WORKDIR
1315 dfs_lock();
1316#ifdef RT_USING_SMART
1317 lwp_setcwd(buf);
1318#else
1319 rt_strncpy(working_directory, buf, DFS_PATH_MAX);
1320#endif
1321 dfs_unlock();
1322#else
1324#endif
1325
1326 return ;
1327}
rt_err_t dfs_lock(void)
定义 dfs.c:120
void dfs_unlock(void)
定义 dfs.c:137
char working_directory[]
#define NO_WORKING_DIR
#define rt_kprintf(...)

引用了 dfs_lock(), DFS_PATH_MAX, dfs_unlock(), NO_WORKING_DIR, rt_kprintf , 以及 working_directory.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [25/28]

RTM_EXPORT ( setcwd )

引用了 setcwd().

+ 函数调用图:

◆ getcwd()

char * getcwd ( char * buf,
size_t size )

this function is a POSIX compliant version, which will return current working directory.

参数
bufthe returned current directory.
sizethe buffer size.
返回
the returned current directory.

在文件 dfs_posix.c1339 行定义.

1340{
1341 if (buf == NULL)
1342 {
1343 rt_set_errno(-EBADF);
1344 return NULL;
1345 }
1346
1347#ifdef DFS_USING_WORKDIR
1348 char *dir_buf = RT_NULL;
1349
1350 dfs_lock();
1351
1352#ifdef RT_USING_SMART
1353 dir_buf = lwp_getcwd();
1354#else
1355 dir_buf = &working_directory[0];
1356#endif
1357
1358 /* copy to buf parameter */
1359 if (buf)
1360 {
1361 rt_strncpy(buf, dir_buf, size);
1362 }
1363
1364 dfs_unlock();
1365#else
1367#endif
1368
1369 return buf;
1370}

引用了 dfs_lock(), dfs_unlock(), NO_WORKING_DIR, rt_kprintf, RT_NULL , 以及 working_directory.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [26/28]

RTM_EXPORT ( getcwd )

引用了 getcwd().

+ 函数调用图:

◆ pread()

ssize_t pread ( int fd,
void * buf,
size_t len,
off_t offset )

this function is a POSIX compliant version, which will read specified data buffer length for an open file descriptor.

参数
fdthe file descriptor.
bufthe buffer to save the read data.
lenthe maximal length of data buffer
offsetthe file pos
返回
the actual read data buffer length. If the returned value is 0, it may be reach the end of file, please check errno.

在文件 dfs_posix.c1385 行定义.

1386{
1387 ssize_t result;
1388 off_t fpos;
1389 struct dfs_file *file;
1390
1391 if (buf == NULL)
1392 {
1393 rt_set_errno(-EBADF);
1394 return -1;
1395 }
1396
1397 file = fd_get(fd);
1398 if (file == NULL)
1399 {
1400 rt_set_errno(-EBADF);
1401
1402 return -1;
1403 }
1404
1405 /* fpos lock */
1406 fpos = dfs_file_get_fpos(file);
1407 result = dfs_file_pread(file, buf, len, offset);
1408 /* fpos unlock */
1409 dfs_file_set_fpos(file, fpos);
1410 if (result < 0)
1411 {
1412 rt_set_errno(result);
1413
1414 return -1;
1415 }
1416
1417 return result;
1418}
off_t dfs_file_get_fpos(struct dfs_file *file)
ssize_t dfs_file_pread(struct dfs_file *file, void *buf, size_t len, off_t offset)
void dfs_file_set_fpos(struct dfs_file *file, off_t fpos)

引用了 dfs_file_get_fpos(), dfs_file_pread(), dfs_file_set_fpos(), fd_get() , 以及 dfs_file::fpos.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [27/28]

RTM_EXPORT ( pread )

引用了 pread().

+ 函数调用图:

◆ pwrite()

ssize_t pwrite ( int fd,
const void * buf,
size_t len,
off_t offset )

this function is a POSIX compliant version, which will write specified data buffer length for an open file descriptor.

参数
fdthe file descriptor
bufthe data buffer to be written.
lenthe data buffer length.
offsetthe file pos
返回
the actual written data buffer length.

在文件 dfs_posix.c1432 行定义.

1433{
1434 ssize_t result;
1435 off_t fpos;
1436 struct dfs_file *file;
1437
1438 if (buf == NULL)
1439 {
1440 rt_set_errno(-EBADF);
1441 return -1;
1442 }
1443
1444 file = fd_get(fd);
1445 if (file == NULL)
1446 {
1447 rt_set_errno(-EBADF);
1448
1449 return -1;
1450 }
1451 /* fpos lock */
1452 fpos = dfs_file_get_fpos(file);
1453 result = dfs_file_pwrite(file, buf, len, offset);
1454 /* fpos unlock */
1455 dfs_file_set_fpos(file, fpos);
1456 if (result < 0)
1457 {
1458 rt_set_errno(result);
1459
1460 return -1;
1461 }
1462
1463 return result;
1464}
ssize_t dfs_file_pwrite(struct dfs_file *file, const void *buf, size_t len, off_t offset)

引用了 dfs_file_get_fpos(), dfs_file_pwrite(), dfs_file_set_fpos(), fd_get() , 以及 dfs_file::fpos.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [28/28]

RTM_EXPORT ( pwrite )

引用了 pwrite().

+ 函数调用图: