Skip to content

Commit e9452ee

Browse files
GorrayLimysterywolf
authored andcommitted
[documentation][dfs]add some comments to dfs posix APIs for supplement.
1 parent 03a9729 commit e9452ee

File tree

2 files changed

+99
-19
lines changed

2 files changed

+99
-19
lines changed

components/dfs/dfs_v1/src/dfs_posix.c

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2024 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -28,7 +28,17 @@
2828
* return a file descriptor according specified flags.
2929
*
3030
* @param file the path name of file.
31-
* @param flags the file open flags.
31+
* @param flags the file open flags. Common values include:
32+
* - Access modes (mutually exclusive):
33+
* - `O_RDONLY`: Open for read-only access.
34+
* - `O_WRONLY`: Open for write-only access.
35+
* - `O_RDWR`: Open for both reading and writing.
36+
* - File status flags (can be combined with bitwise OR `|`):
37+
* - `O_CREAT`: Create the file if it does not exist. Requires a `mode` argument.
38+
* - `O_TRUNC`: Truncate the file to zero length if it already exists.
39+
* - `O_APPEND`: Append writes to the end of the file.
40+
* - `O_EXCL`: Ensure that `O_CREAT` creates the file exclusively.
41+
* - Other platform-specific flags
3242
*
3343
* @return the non-negative integer on successful open, others for failed.
3444
*/
@@ -65,6 +75,22 @@ RTM_EXPORT(open);
6575
#ifndef AT_FDCWD
6676
#define AT_FDCWD (-100)
6777
#endif
78+
79+
/**
80+
* @brief Opens a file relative to a directory file descriptor.
81+
*
82+
* @param dirfd The file descriptor of the directory to base the relative path on.
83+
* @param pathname The path to the file to be opened, relative to the directory specified by `dirfd`.
84+
* Can be an absolute path (in which case `dirfd` is ignored).
85+
* @param flags File access and status flags (e.g., `O_RDONLY`, `O_WRONLY`, `O_CREAT`).
86+
*
87+
* @return On success, returns a new file descriptor for the opened file.
88+
* On failure, returns `-1` and sets `errno` to indicate the error.
89+
*
90+
* @note When using relative paths, ensure `dirfd` is a valid directory descriptor.
91+
* When `pathname` is absolute, the `dirfd` argument is ignored.
92+
*
93+
*/
6894
int openat(int dirfd, const char *path, int flag, ...)
6995
{
7096
struct dfs_file *d;
@@ -241,14 +267,22 @@ ssize_t write(int fd, const void *buf, size_t len)
241267
RTM_EXPORT(write);
242268

243269
/**
244-
* this function is a POSIX compliant version, which will seek the offset for
270+
* this function is a POSIX compliant version, which will Reposition the file offset for
245271
* an open file descriptor.
246272
*
273+
* The `lseek` function sets the file offset for the file descriptor `fd`
274+
* to a new value, determined by the `offset` and `whence` parameters.
275+
* It can be used to seek to specific positions in a file for reading or writing.
276+
*
247277
* @param fd the file descriptor.
248-
* @param offset the offset to be seeked.
249-
* @param whence the directory of seek.
278+
* @param offset The offset, in bytes, to set the file position.
279+
* The meaning of `offset` depends on the value of `whence`.
280+
* @param whence the directive of seek. It can be one of:
281+
* - `SEEK_SET`: Set the offset to `offset` bytes from the beginning of the file.
282+
* - `SEEK_CUR`: Set the offset to its current location plus `offset` bytes.
283+
* - `SEEK_END`: Set the offset to the size of the file plus `offset` bytes.
250284
*
251-
* @return the current read/write position in the file, or -1 on failed.
285+
* @return the resulting read/write position in the file, or -1 on failed.
252286
*/
253287
off_t lseek(int fd, off_t offset, int whence)
254288
{
@@ -436,9 +470,15 @@ RTM_EXPORT(fsync);
436470
* control functions on devices.
437471
*
438472
* @param fildes the file description
439-
* @param cmd the specified command
473+
* @param cmd the specified command, Common values include:
474+
* - `F_DUPFD`: Duplicate a file descriptor.
475+
* - `F_GETFD`: Get the file descriptor flags.
476+
* - `F_SETFD`: Set the file descriptor flags.
477+
* - `F_GETFL`: Get the file status flags.
478+
* - `F_SETFL`: Set the file status flags.
440479
* @param ... represents the additional information that is needed by this
441-
* specific device to perform the requested function.
480+
* specific device to perform the requested function. For example:
481+
* - When `cmd` is `F_SETFL`, an additional integer argument specifies the new status flags.
442482
*
443483
* @return 0 on successful completion. Otherwise, -1 shall be returned and errno
444484
* set to indicate the error.
@@ -595,7 +635,7 @@ RTM_EXPORT(fstatfs);
595635
* this function is a POSIX compliant version, which will make a directory
596636
*
597637
* @param path the directory path to be made.
598-
* @param mode
638+
* @param mode The permission mode for the new directory (unused here, can be set to 0).
599639
*
600640
* @return 0 on successful, others on failed.
601641
*/

components/dfs/dfs_v2/src/dfs_posix.c

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2024 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -31,7 +31,17 @@
3131
* return a file descriptor according specified flags.
3232
*
3333
* @param file the path name of file.
34-
* @param flags the file open flags.
34+
* @param flags the file open flags. Common values include:
35+
* - Access modes (mutually exclusive):
36+
* - `O_RDONLY`: Open for read-only access.
37+
* - `O_WRONLY`: Open for write-only access.
38+
* - `O_RDWR`: Open for both reading and writing.
39+
* - File status flags (can be combined with bitwise OR `|`):
40+
* - `O_CREAT`: Create the file if it does not exist. Requires a `mode` argument.
41+
* - `O_TRUNC`: Truncate the file to zero length if it already exists.
42+
* - `O_APPEND`: Append writes to the end of the file.
43+
* - `O_EXCL`: Ensure that `O_CREAT` creates the file exclusively.
44+
* - Other platform-specific flags
3545
*
3646
* @return the non-negative integer on successful open, others for failed.
3747
*/
@@ -81,6 +91,22 @@ RTM_EXPORT(open);
8191
#ifndef AT_FDCWD
8292
#define AT_FDCWD (-100)
8393
#endif
94+
95+
/**
96+
* @brief Opens a file relative to a directory file descriptor.
97+
*
98+
* @param dirfd The file descriptor of the directory to base the relative path on.
99+
* @param pathname The path to the file to be opened, relative to the directory specified by `dirfd`.
100+
* Can be an absolute path (in which case `dirfd` is ignored).
101+
* @param flags File access and status flags (e.g., `O_RDONLY`, `O_WRONLY`, `O_CREAT`).
102+
*
103+
* @return On success, returns a new file descriptor for the opened file.
104+
* On failure, returns `-1` and sets `errno` to indicate the error.
105+
*
106+
* @note When using relative paths, ensure `dirfd` is a valid directory descriptor.
107+
* When `pathname` is absolute, the `dirfd` argument is ignored.
108+
*
109+
*/
84110
int openat(int dirfd, const char *path, int flag, ...)
85111
{
86112
struct dfs_file *d;
@@ -171,7 +197,7 @@ int utimensat(int __fd, const char *__path, const struct timespec __times[2], in
171197
}
172198
}
173199

174-
//update time
200+
/*update time*/
175201
attr.ia_valid = ATTR_ATIME_SET | ATTR_MTIME_SET;
176202
time(&current_time);
177203
if (UTIME_NOW == __times[0].tv_nsec)
@@ -374,14 +400,22 @@ ssize_t write(int fd, const void *buf, size_t len)
374400
RTM_EXPORT(write);
375401

376402
/**
377-
* this function is a POSIX compliant version, which will seek the offset for
403+
* this function is a POSIX compliant version, which will Reposition the file offset for
378404
* an open file descriptor.
379405
*
406+
* The `lseek` function sets the file offset for the file descriptor `fd`
407+
* to a new value, determined by the `offset` and `whence` parameters.
408+
* It can be used to seek to specific positions in a file for reading or writing.
409+
*
380410
* @param fd the file descriptor.
381-
* @param offset the offset to be seeked.
382-
* @param whence the directory of seek.
411+
* @param offset The offset, in bytes, to set the file position.
412+
* The meaning of `offset` depends on the value of `whence`.
413+
* @param whence the directive of seek. It can be one of:
414+
* - `SEEK_SET`: Set the offset to `offset` bytes from the beginning of the file.
415+
* - `SEEK_CUR`: Set the offset to its current location plus `offset` bytes.
416+
* - `SEEK_END`: Set the offset to the size of the file plus `offset` bytes.
383417
*
384-
* @return the current read/write position in the file, or -1 on failed.
418+
* @return the resulting read/write position in the file, or -1 on failed.
385419
*/
386420
off_t lseek(int fd, off_t offset, int whence)
387421
{
@@ -581,9 +615,15 @@ RTM_EXPORT(fsync);
581615
* control functions on devices.
582616
*
583617
* @param fildes the file description
584-
* @param cmd the specified command
618+
* @param cmd the specified command, Common values include:
619+
* - `F_DUPFD`: Duplicate a file descriptor.
620+
* - `F_GETFD`: Get the file descriptor flags.
621+
* - `F_SETFD`: Set the file descriptor flags.
622+
* - `F_GETFL`: Get the file status flags.
623+
* - `F_SETFL`: Set the file status flags.
585624
* @param ... represents the additional information that is needed by this
586-
* specific device to perform the requested function.
625+
* specific device to perform the requested function. For example:
626+
* - When `cmd` is `F_SETFL`, an additional integer argument specifies the new status flags.
587627
*
588628
* @return 0 on successful completion. Otherwise, -1 shall be returned and errno
589629
* set to indicate the error.
@@ -765,7 +805,7 @@ RTM_EXPORT(fstatfs);
765805
* this function is a POSIX compliant version, which will make a directory
766806
*
767807
* @param path the directory path to be made.
768-
* @param mode
808+
* @param mode The permission mode for the new directory (unused here, can be set to 0).
769809
*
770810
* @return 0 on successful, others on failed.
771811
*/

0 commit comments

Comments
 (0)