- FS
- Overview
- Summary
- Files
- Data Structures
- Macros
- Typedefs
- Functions
- Details
- Macro Definition Documentation
- FTW_DP
- Function Documentation
- alphasort()
- basename()
- chmod()
- closedir()
- creat()
- dirname()
- fallocate()
- fcntl()
- fstat()
- ftw()
- glob()
- globfree()
- ioctl()
- lstat()
- mkdir()
- mkdirat()
- mkfifo()
- mount()
- nftw()
- open()
- opendir()
- readdir()
- readdir_r()
- rewinddir()
- scandir()
- seekdir()
- stat()
- statfs()
- statvfs()
- telldir()
- umask()
- umount()
- umount2()
- utime()
FS
Overview
Provides functions for file system, include file operations, directory operations and so on.
Since:
1.0
Version:
1.0
Summary
Files
Data Structures
Defines the file tree walker (FTW). |
|
Macros
fallocate64 fallocate |
Pre-allocates space to a file. See fallocate. |
Unreadable directory. Its subdirectories will not be traversed. |
|
The data of the stat structure cannot be obtained. The possible cause is that the permission is incorrect. |
|
FTW_DP 6 |
|
Symbolic links that are not traversed. If not set, symbolic links are traversed by default. |
|
chdir is called to go to the directory before reading the directory. |
|
All subdirectories will be traversed before the directory itself. |
|
Append a slash (/) to each path, which corresponds to a directory. |
|
In the pglob parameter of the glob() function, reserve a string that has a length of pglob->gl_offs and ends with \0 at the beginning of the string list in pglob->pathv. That is, the newly matched string is appended to a position where the distance from the beginning of pglob->pathv is the length of pglob->gl_offs. |
|
Append the results of this call to the results returned by a previous call to glob(). |
|
Carry out tilde expansion. If a tilde (~) is the only character in the pattern, or an initial tilde is followed immediately by a slash (/), then the home directory of the caller is substituted for the tilde. |
|
Similar to GLOB_TILDE. The difference is that if the username is invalid, or the home directory cannot be determined, glob() returns GLOB_NOMATCH to indicate an error. |
|
Typedefs
Functions
struct dirent |
|
readdir_r (DIR restrict dirp, struct dirent *restrict entry, struct dirent __restrict result) |
|
scandir (const char dir, struct dirent namelist, int(sel)(const struct dirent ), int(compar)(const struct dirent , const struct dirent )) |
|
Sets the position of the next readdir call in the directory stream. |
|
Obtains the current position in the specified directory stream. |
|
creat (const char path, mode_t mode) |
|
open (const char path, int oflags,…) |
|
fallocate (int fd, int mode, off_t offset, off_t len) |
|
fcntl (int fd, int cmd,…) |
|
ftw (const char path, int(fn)(const char file, const struct stat sb, int flag), int depth) |
|
nftw (const char path, int(fn)(const char file, const struct stat sb, int flag, struct FTW s), int fd_limit, int flags) |
|
glob (const char __restrict pattern, int flags, int(errfunc)(const char , int), glob_t restrict pglob) |
|
Frees allocated memory from a call to glob(). |
|
dirname (char path) |
|
basename (char path) |
Obtains a file name (excluding the directory) in a specified path. |
ioctl (int fd, int cmd,…) |
|
mount (const char source, const char target, const char filesystemtype, unsigned long mountflags, const void data) |
|
umount (const char target) |
|
umount2 (const char target, int flags) |
|
lstat (const char __restrict path, struct stat restrict buf) |
|
mkdir (const char pathname, mode_t mode) |
|
mkfifo (const char name, mode_t mode) |
Creates a named pipe to implement inter-process communication. |
mkdirat (int fd, const char pathname, mode_t mode) |
|
chmod (const char pathname, mode_t mode) |
|
umask (mode_t mode) |
|
statfs (const char path, struct statfs buf) |
Obtains file system information of a file in a specified path. |
statvfs (const char *restrict path, struct statvfs __restrict buf) |
|
Details
Macro Definition Documentation
FTW_DP
#define FTW_DP 6
Description:
@briefDirectory. All subdirectories in this directory have been traversed.
Function Documentation
alphasort()
int alphasort (const struct [dirent]($api-api-SmartVision-Devices-dirent.md) ** a, const struct [dirent]($api-api-SmartVision-Devices-dirent.md) ** b )
Description:
Sorts the directory entries in alphabetical order.
This function is used to sort the two directory entries passed through the input parameters in alphabetical order. Generally, these parameters are passed in scandir as its last parameter.
Parameters:
a | Indicates the pointer to directory entry a. |
a | Indicates the pointer to directory entry b. |
Returns:
Returns an integer greater than, equal to, or less than 0, respectively, based on whether the name of the directory entry to which a points is lexically greater than, equal to, or less than the directory.
basename()
char* basename (char * path)
Description:
Obtains a file name (excluding the directory) in a specified path.
Parameters:
path | Indicates the pointer to the path. |
Returns:
Returns the file name if the operation is successful; returns NULL otherwise.
chmod()
int chmod (const char * pathname, mode_t mode )
Description:
Modifies permissions for a file.
Parameters:
pathname | Indicates the pointer to the path of the file. |
mode | Indicates the new file permission. |
Attention:
This function can be used only in the JFFS2 file system.
Returns:
Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table otherwise.
The permission bit of the file mode does not allow the requested access, or the search permission is denied on the path prefix directory. |
|
The path name length is greater than the value of NAME_MAX. |
|
A component of the path prefix is the name of an existing file. The file is neither a directory nor a symbolic link of a directory. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
closedir()
int closedir ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) * dirp)
Description:
Closes a specified directory.
Parameters:
dirp | Indicates the pointer to the structure representing the directory to close. |
Returns:
Returns 0 if the directory is successfully closed; returns -1 and sets errno to the following value otherwise.
creat()
int creat (const char * path, mode_t mode )
Description:
Creates a file or rewrites an existing file.
Parameters:
path | Indicates the pointer to the name of the file to create or rewrite. |
mode | Indicates permissions on the file. |
Returns:
Returns 0 if the file is created or rewritten successfully; returns -1 and sets errno to a value in the following table otherwise.
The length of path is greater than the value of NAME_MAX. |
|
All file descriptors that can be used by the process are opened. |
|
The file structure corresponding to the file descriptor cannot be obtained. |
|
A hardware error occurs at the low-level disk I/O layer. As a result, the physical drive cannot work. |
|
The number of opened files in the system has reached the maximum. |
|
A component of the path prefix is the name of an existing file and is not a directory. |
|
The operation is rejected according to the file sharing policy. |
|
dirname()
char* dirname (char * path)
Description:
Obtains a directory name in a specified path.
Parameters:
path | Indicates the pointer to the path. |
Returns:
Returns the directory name if the operation is successful; returns NULL otherwise.
fallocate()
int fallocate (int fd, int mode, off_t offset, off_t len )
Description:
Pre-allocates space to a file.
Parameters:
Attention:
This function can be used only in the FAT file system.
Returns:
Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table otherwise.
The value of len or offset is less than 0 or greater than that of INT_MAX, or the value of mode is not FALLOC_FL_KEEP_SIZE. |
|
fd is not a valid file descriptor, or the basic file system does not support this operation. |
|
An I/O error occurs when data is read from or written to the file system. |
|
The operation is rejected according to the file sharing policy. |
fcntl()
int fcntl (int fd, int cmd, ... )
Description:
Manipulates a specified file descriptor.
Parameters:
fd | Indicates the file descriptor. |
cmd | Indicates the command used to manipulate the file descriptor. |
Obtain the status of the file specified by fd. (fd is a file or sockets are available.) |
|
Set the file descriptor status. (fd is a file or sockets are available.) |
Returns:
Returns the value depending on cmd if the operation is successful; returns -1 and sets errno to a value in the following table otherwise.
Too many segment locks open, lock table is full, or a remote locking protocol failed. |
|
Attempt to clear the O_APPEND flag on a file that has the append-only attribute set. |
fstat()
int fstat (int fd, struct [stat]($api-api-SmartVision-Devices-stat.md) * buf )
Description:
Obtains file status information.
Parameters:
fd | Indicates the file descriptor. |
buf | Indicates the pointer to a stat structure into which file information is placed. |
Returns:
Returns 0 if file information is obtained successfully; returns -1 and sets errno to a value in the following table otherwise.
A component of path does not name an existing file or path is an empty string. |
|
The path name length is greater than the value of NAME_MAX. |
|
Search permission is denied on a component of the path prefix. |
|
An I/O error occurs when data is read from or written to the file system. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
The operation is rejected according to the file sharing policy. |
|
ftw()
int ftw (const char * path, int(*)(const char *file, const struct [stat]($api-api-SmartVision-Devices-stat.md) *sb, int flag) fn, int depth )
Description:
Traverses a file tree.
This function is used to traverse a file tree for search.
Parameters:
path | Indicates the pointer to the file directory to traverse. |
fn | Indicates the pointer to the function to be called for the found entry. For the fn function, file identifies the path of the file relative to path, and sb indicates the pointer to the stat structure. flag indicates the flag. The values of flag are as follows: |
depth | Indicates the number of files that can be opened during traversal. |
Unreadable directory. Its subdirectories will not be traversed. |
|
The data of the stat structure cannot be obtained. The possible cause is that the permission is incorrect. |
Returns:
Returns 0 if the tree is traversed; returns the value that is returned by the fn() function if the traversal is interrupted; returns -1 if an error occurs.
glob()
int glob (const char *__restrict pattern, int flags, int(*)(const char *, int) errfunc, [glob_t]($api-api-SmartVision-Devices-glob_t.md) *__restrict pglob )
Description:
Searches for path names that meet a specified pattern.
Parameters:
pattern | Indicates the pattern you want to match. |
flags | Indicates the matching mode. |
errfunc | Indicates the pointer to the error processing callback function. If errfunc is not a null pointer, errfunc() is called when an error occurs (opendir(), readdir(), or stat() fails) during the search. If the function returns a non-zero value or GLOB_ERR is set, glob() terminates the entire search process. |
pglob | Indicates the pointer to the address storing the matched path names. |
Returns:
Returns 0 on successful completion; returns GLOB_NOSPACE for running out of memory; returns GLOB_ABORTED for a read error; returns GLOB_NOMATCH for no match found.
globfree()
void globfree ([glob_t]($api-api-SmartVision-Devices-glob_t.md) * pglob)
Description:
Frees allocated memory from a call to glob().
Parameters:
pglob | Indicates the pointer to the address of memory dynamically allocated for a glob call. |
ioctl()
int ioctl (int fd, int cmd, ... )
Description:
Manipulates a device.
This function is used to perform specified operations on an input device file descriptor.
Parameters:
fd | Indicates the file descriptor of the device (file-related file descriptors are not supported). |
cmd | Indicates the operation instruction for the device. You can define it based on the specific device. |
Returns:
Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table otherwise.
lstat()
int lstat (const char *__restrict path, struct [stat]($api-api-SmartVision-Devices-stat.md) *__restrict buf )
Description:
Obtains file information.
Parameters:
path | Indicates the file path. |
buf | Indicates the pointer to a stat structure into which file information is placed. |
Returns:
Returns 0 if file information is obtained successfully; returns -1 and sets errno to a value in the following table otherwise.
A component of path does not name an existing file or path is an empty string. |
|
The path name length is greater than the value of NAME_MAX. |
|
The permission bit of the file mode does not allow the requested access, or the search permission is denied on the path prefix component. |
|
An I/O error occurs when data is read from or written to the file system. |
|
The number of opened files in the system has reached the maximum. |
|
A component of the path prefix is the name of an existing file. The file is neither a directory nor a symbolic link of a directory. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
The operation is rejected according to the file sharing policy. |
|
mkdir()
int mkdir (const char * pathname, mode_t mode )
Description:
Creates a directory.
Parameters:
pathname | Indicates the pointer to the name of the directory to create. |
mode | Indicates the directory permission. |
Attention:
This function can NOT be used in the PROC file system.
Returns:
Returns 0 if the directory is created successfully; returns -1 and sets errno to a value in the following table otherwise.
The permission bit of the file mode does not allow the requested access, or the search permission is denied on the path prefix directory. |
|
The path name length is greater than the value of NAME_MAX. |
|
An I/O error occurs when data is read from or written to the file system. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
The operation is rejected according to the file sharing policy. |
|
mkdirat()
int mkdirat (int fd, const char * pathname, mode_t mode )
Description:
Creates a directory.
Parameters:
Attention:
This function can NOT be used in the PROC file system.
Returns:
Returns 0 if the directory is created successfully; returns -1 and sets errno to a value in the following table otherwise.
The permission bit of the file mode does not allow the requested access, or the search permission is denied on the path prefix directory. |
|
The path name length is greater than the value of NAME_MAX. |
|
An I/O error occurs when data is read from or written to the file system. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
The operation is rejected according to the file sharing policy. |
|
mkfifo()
int mkfifo (const char * name, mode_t mode )
Description:
Creates a named pipe to implement inter-process communication.
Parameters:
name | Indicates the pointer to the name of the pipe to create. |
mode | Not supported. |
Attention:
Permission control is not supported. The number of pipes that can be created is not limited. Pipes can be created only in the /dev directory.
Returns:
Returns 0 if the pipe is created successfully; returns -1 and sets errno to a value in the following table otherwise.
Invalid input parameter (for example, empty address, file name too long or the file is not in the /dev directory). |
|
mount()
int mount (const char * source, const char * target, const char * filesystemtype, unsigned long mountflags, const void * data )
Description:
Mounts a file system.
Mounts a device (referenced by a file system name) to a specified directory.
Parameters:
source | Indicates the pointer to the device to mount. |
target | Indicates the pointer to the path of the mount point. |
filesystemtype | Indicates the pointer to the file system type. |
mountflags | Indicates the mounting flag. |
data | Indicates the pointer to the mounting data. |
Returns:
Returns 0 if the mounting is successful; returns -1 and sets errno to a value in the following table otherwise.
One of the pointer parameters points outside the user address space. |
|
The path name length is greater than the value of MAXPATHLEN. |
|
nftw()
int nftw (const char * path, int(*)(const char *file, const struct [stat]($api-api-SmartVision-Devices-stat.md) *sb, int flag, struct [FTW]($api-api-SmartVision-Devices-FTW.md) *s) fn, int fd_limit, int flags )
Description:
Traverses a file tree.
This function is used to traverse a file tree. It has a similar effect to ftw except that it takes an additional parameter flags.
Parameters:
path | Indicates the pointer to the file directory to traverse. |
fn | Indicates the pointer to the function to be called for the found entry. For the fn function, file identifies the path of the file relative to path, and sb indicates the pointer to the stat structure. flag indicates the flag. The values of flag are as follows: The fourth argument of fn() is a pointer to a FTW structure. |
fd_limit | Indicates the number of files that can be opened during traversal. |
flags | Indicates the traversal action. It is a bitwise inclusive-OR of zero or more of the following flags: |
Unreadable directory. Its subdirectories will not be traversed. |
|
The data of the stat structure cannot be obtained. The possible cause is that the permission is incorrect. |
|
Returns:
Returns 0 if the tree is traversed; returns the value that is returned by the fn() function if the traversal is interrupted; returns -1 if an error occurs.
open()
int open (const char * path, int oflags, ... )
Description:
Opens a file.
Parameters:
path | Indicates the pointer to the name of the file to open. |
oflags | Indicates the file access mode. Available values are as follows: |
If set, the file offset will be set to the end of the file prior to each write. |
|
If the file is opened successfully with O_WRONLY or O_RDWR, its length is truncated to 0. |
|
Used together with O_CREAT. This function fails if the file exists. |
|
This flag must be added for opening a directory. Otherwise, the directory fails to be opened. |
Attention:
This function can NOT be used in the PROC file system to create a file. This function is used to open a file. If the file does not exist, this function creates a file and opens it.
Returns:
Returns the file descriptor if the file is opened successfully; returns -1 and sets errno to a value in the following table otherwise.
Search permission is denied on a component of the path prefix. |
|
The length of path is greater than the value of NAME_MAX. |
|
The O_CREAT flag is not set and the named file does not exist. |
|
Inode is invalid, not a normal character driver, or not a mount point. |
|
The file structure corresponding to the file descriptor cannot be obtained. |
|
A hardware error occurs at the low-level disk I/O layer. As a result, the physical drive cannot work. |
|
The named file resides on a read-only file system, and either O_WRONLY, O_RDWR, O_CREAT (if file does not exist), or O_TRUNC is set in the oflags parameter. |
|
The directory or file system that would contain the new file cannot be expanded, the file does not exist, and O_CREAT is specified. |
|
The number of opened files in the system has reached the maximum. |
|
The named file is a directory, and oflags includes O_WRONLY, O_RDWR, or O_CREAT without O_DIRECTORY. |
|
A component of the path prefix names an existing file that is not a directory. |
|
The operation is rejected according to the file sharing policy. |
|
opendir()
[DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849)* opendir (const char * dirname)
Description:
Opens a specified directory.
Parameters:
dirname | Indicates the pointer to the name of directory to open. |
Returns:
Returns the pointer to the DIR structure representing the directory if it is opened successfully; returns NULL and sets errno to a value in the following table otherwise.
The length of the path name string is longer than the value of NAME_MAX. |
|
readdir()
struct [dirent]($api-api-SmartVision-Devices-dirent.md)* readdir ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) * dirp)
Description:
Reads a specified directory.
Parameters:
dirp | Indicates the pointer to the directory structure. |
Returns:
Returns the pointer to the dirent structure representing the directory if it is read successfully; returns NULL if reaching the end of the directory stream or the directory fails to be read. If the directory fails to be read, the corresponding error code is returned.
The path name length is greater than the value of NAME_MAX. |
|
readdir_r()
int readdir_r ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) *__restrict dirp, struct [dirent]($api-api-SmartVision-Devices-dirent.md) *__restrict entry, struct [dirent]($api-api-SmartVision-Devices-dirent.md) **__restrict result )
Description:
Reads a specified directory (thread-safe version).
Parameters:
dirp | Indicates the pointer to the directory structure. |
entry | Indicates the entry read from the dirp stream. |
result | Indicates the pointer to the returned buffer. |
Returns:
Returns 0. If the directory fails to be read, errno is sets to a value in the following table.
The path name length is greater than the value of NAME_MAX. |
|
rewinddir()
void rewinddir ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) * dirp)
Description:
Resets a directory stream read position.
This function is used to change the current read position of the specified directory stream to the original read position (that is, the start position after the directory stream is opened by opendir).
Parameters:
dirp | Indicates the pointer to the directory stream whose read position needs to be reset. |
scandir()
int scandir (const char * dir, struct [dirent]($api-api-SmartVision-Devices-dirent.md) *** namelist, int(*)(const struct [dirent]($api-api-SmartVision-Devices-dirent.md) *) sel, int(*)(const struct [dirent]($api-api-SmartVision-Devices-dirent.md) **, const struct [dirent]($api-api-SmartVision-Devices-dirent.md) **) compar )
Description:
Scans directory to find the target entries.
Parameters:
Returns:
Returns the number of entries copied to the namelist array if the scanning is successful; returns -1 and sets errno to a value in the following table otherwise.
The length of the path name string is greater than the value of NAME_MAX. |
|
seekdir()
void seekdir ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) * dirp, long offset )
Description:
Sets the position of the next readdir call in the directory stream.
Parameters:
dirp | Indicates the pointer to the directory stream in which the position of the next readdir call needs to be set. |
offset | Indicates the offset of the position relative to the current position. |
stat()
int [stat]($api-api-SmartVision-Devices-stat.md) (const char *__restrict path, struct [stat]($api-api-SmartVision-Devices-stat.md) *__restrict buf )
Description:
Obtains file information.
Parameters:
path | Indicates the file path. |
buf | Indicates the pointer to a stat structure into which file information is placed. |
Returns:
Returns 0 if file information is obtained successfully; returns -1 and sets errno to a value in the following table otherwise.
A component of path does not name an existing file or path is an empty string. |
|
The path name length is greater than the value of NAME_MAX. |
|
The permission bit of the file mode does not allow the requested access, or the search permission is denied on the path prefix component. |
|
An I/O error occurs when data is read from or written to the file system. |
|
The number of opened files in the system has reached the maximum. |
|
A component of the path prefix is the name of an existing file. The file is neither a directory nor a symbolic link of a directory. |
|
Operation not permitted or access denied because the access is prohibited or the directory is full. |
|
The operation is rejected according to the file sharing policy. |
|
statfs()
int statfs (const char * path, struct statfs * buf )
Description:
Obtains file system information of a file in a specified path.
Parameters:
path | Indicates the pointer to the name of the target file. |
buf | Indicates the pointer to a statfs structure that stores the information about the file system. |
Returns:
Returns 0 if the operation is successful; returns -1 and sets errno to a value in the following table if the operation fails.
Search permission is denied on a component of the path prefix. |
|
statvfs()
int [statvfs]($api-api-SmartVision-Devices-statvfs.md) (const char *__restrict path, struct [statvfs]($api-api-SmartVision-Devices-statvfs.md) *__restrict buf )
Description:
Obtains the file system information.
Parameters:
path | Indicates the pointer to the path name of the file. |
buf | Indicates the pointer to the statvfs structure that stores the obtained file system information. |
Returns:
Returns 0 if the file system information is obtained successfully; returns -1 and sets errno to a value in the following table otherwise.
Search permission is denied on a component of the path prefix. |
|
telldir()
long telldir ([DIR]($api-api-SmartVision-Devices-FS.md#ga0ebe68390948c14bb9d82987adbfc849) * dirp)
Description:
Obtains the current position in the specified directory stream.
Parameters:
dirp | Indicates the pointer to the directory stream. |
Returns:
Returns the current position in the directory stream if the operation is successful; returns -1 and sets errno to the value in the following table otherwise.
umask()
mode_t umask (mode_t mode)
Description:
Sets umask for a process.
This function sets the umask of the current process file and returns the previous value of the umask. umask is used to turn off permission bits corresponding to in the mode parameter.
Parameters:
mode | Used to specify the umask value of a process. |
Returns:
Returns the previous value of the umask. This function call always succeeds.
umount()
int umount (const char * target)
Description:
Unmounts a file system.
Parameters:
target | Indicates the pointer to the path of the file system to unmount. |
Returns:
Returns 0 if the file system is unmounted successfully; returns -1 and sets errno to a value in the following table otherwise.
umount2()
int umount2 (const char * target, int flags )
Description:
Unmounts a file system.
This function is used to unmount a file system. Currently, the value of flags can only be 0. In this case, this function is the same as umount().
Parameters:
target | Indicates the pointer to the path of the file system to unmount. |
flags | Indicates the control flag. (Currently, the value of flags can only be 0. In this case, this function is the same as umount().) |
Returns:
Returns 0 if the file system is unmounted successfully; returns -1 and sets errno to a value in the following table otherwise.
utime()
int utime (const char * filename, const struct [utimbuf]($api-api-SmartVision-Devices-utimbuf.md) * times )
Description:
Sets the access time and modification time of a file.
Parameters:
Returns:
Returns 0 if the access time and modification time are set successfully; returns -1 and sets errno to a value in the following table otherwise.
The length of the component in the path name is greater than the value of NAME_MAX. |
|