|
rt_err_t | dfs_file_lock (void) |
|
void | dfs_file_unlock (void) |
|
int | dfs_init (void) |
|
struct dfs_file * | dfs_file_create (void) |
|
void | dfs_file_destroy (struct dfs_file *file) |
|
void | fdt_fd_release (struct dfs_fdtable *fdt, int fd) |
|
int | fdt_fd_associate_file (struct dfs_fdtable *fdt, int fd, struct dfs_file *file) |
|
int | fd_new (void) |
|
struct dfs_file * | fd_get (int fd) |
|
struct dfs_fdtable * | dfs_fdtable_get (void) |
|
struct dfs_fdtable * | dfs_fdtable_get_global (void) |
|
int | dfs_fdtable_dup (struct dfs_fdtable *fdt_dst, struct dfs_fdtable *fdt_src, int fd_src) |
|
int | dfs_fdtable_drop_fd (struct dfs_fdtable *fdt, int fd) |
|
int | dfs_dup (int oldfd, int startfd) |
|
int | dfs_dup_to (int oldfd, struct dfs_fdtable *fdtab) |
|
int | dfs_dup_from (int oldfd, struct dfs_fdtable *fdtab) |
|
int | sys_dup (int oldfd) |
|
rt_err_t | sys_dup2 (int oldfd, int newfd) |
|
const char * | dfs_subdir (const char *directory, const char *filename) |
|
char * | dfs_normalize_path (const char *directory, const char *filename) |
|
int | list_fd (void) |
|
int | dfs_fd_dump (int argc, char **argv) |
|
DFS is a virtual file system in RT-Thread RTOS.
The DFS (Device Virtual File System) is a vfs file system of RT-Thread RTOS, which is focused on embedded device. VFS is an abstraction layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way.
Figure 4: Device Virtual File System Architecture
The DFS specifies an interface between the kernel and a concrete file system. Therefore, it is easy to add support for new file system types to the kernel simply by fulfilling the interface.
◆ dfs_file_lock()
rt_err_t dfs_file_lock |
( |
void |
| ) |
|
Lock the file descriptor table mutex.
- Returns
- rt_err_t RT_EOK if lock acquired successfully, -RT_ENOSYS if filesystem not initialized, -RT_EBUSY if mutex is already locked (retries until acquired)
- Note
- This function will block indefinitely until the lock is acquired. Should not be called from interrupt service routines.
◆ dfs_file_unlock()
void dfs_file_unlock |
( |
void |
| ) |
|
Unlock the file descriptor table mutex.
- Note
- This function releases the lock acquired by dfs_file_lock(). Should be called in the same context as the corresponding lock. Should not be called from interrupt service routines.
◆ dfs_init()
this function will initialize device file system.
◆ dfs_file_create()
struct dfs_file* dfs_file_create |
( |
void |
| ) |
|
Create and initialize a new file descriptor structure.
- Returns
- struct dfs_file* Pointer to the newly created file descriptor structure, NULL if memory allocation failed
◆ dfs_file_destroy()
void dfs_file_destroy |
( |
struct dfs_file * |
file | ) |
|
Destroy and free a file descriptor structure.
- Parameters
-
[in] | file | Pointer to the file descriptor structure to be destroyed |
◆ fdt_fd_release()
void fdt_fd_release |
( |
struct dfs_fdtable * |
fdt, |
|
|
int |
fd |
|
) |
| |
Release a file descriptor from the file descriptor table.
- Parameters
-
[in,out] | fdt | Pointer to the file descriptor table |
[in] | fd | The file descriptor to be released |
◆ fdt_fd_associate_file()
int fdt_fd_associate_file |
( |
struct dfs_fdtable * |
fdt, |
|
|
int |
fd, |
|
|
struct dfs_file * |
file |
|
) |
| |
Associate a file structure with a file descriptor in the file descriptor table.
- Parameters
-
[in,out] | fdt | Pointer to the file descriptor table |
[in] | fd | The file descriptor to associate with |
[in] | file | Pointer to the file structure to associate |
- Returns
- int The file descriptor if successful (>= 0), -1 if association failed (invalid parameters or fd already in use), -RT_ENOSYS if filesystem lock failed
◆ fd_new()
Allocate a new file descriptor in current process's file descriptor table.
- Returns
- int The allocated file descriptor index if successful (>= 0), -1 if allocation failed
◆ fd_get()
struct dfs_file* fd_get |
( |
int |
fd | ) |
|
Get file structure by file descriptor from current process's fd table.
- Parameters
-
[in] | fd | The file descriptor to lookup |
- Returns
- struct dfs_file* Pointer to the file structure if found, NULL if invalid fd or file not found
◆ dfs_fdtable_get()
struct dfs_fdtable* dfs_fdtable_get |
( |
void |
| ) |
|
This function will get the file descriptor table of current process.
◆ dfs_fdtable_get_global()
struct dfs_fdtable* dfs_fdtable_get_global |
( |
void |
| ) |
|
Get the global file descriptor table.
- Returns
- struct dfs_fdtable* Pointer to the global file descriptor table
◆ dfs_fdtable_dup()
int dfs_fdtable_dup |
( |
struct dfs_fdtable * |
fdt_dst, |
|
|
struct dfs_fdtable * |
fdt_src, |
|
|
int |
fd_src |
|
) |
| |
Dup the specified fd_src from fdt_src to fdt_dst.
- Parameters
-
[out] | fdt_dst | is the fd table for destination, if empty, use global (_fdtab). |
[in] | fdt_src | is the fd table for source, if empty, use global (_fdtab). |
[in] | fd_src | is the fd in the designate fdt_src table. |
- Returns
- -1 on failed or the allocated file descriptor.
◆ dfs_fdtable_drop_fd()
int dfs_fdtable_drop_fd |
( |
struct dfs_fdtable * |
fdt, |
|
|
int |
fd |
|
) |
| |
drop fd from the fd table.
- Parameters
-
fdt | is the fd table, if empty, use global (_fdtab). |
fd | is the fd in the designate fd table. |
- Returns
- -1 on failed the drop file descriptor.
◆ dfs_dup()
int dfs_dup |
( |
int |
oldfd, |
|
|
int |
startfd |
|
) |
| |
Duplicate a file descriptor in the current process's file descriptor table.
- Parameters
-
[in] | oldfd | The file descriptor to duplicate |
[in] | startfd | The starting index to search for an available file descriptor slot |
- Returns
- int The new file descriptor if successful (>=0), -1 if failed (invalid fd or allocation failed), -RT_ENOSYS if filesystem lock failed
◆ dfs_dup_to()
int dfs_dup_to |
( |
int |
oldfd, |
|
|
struct dfs_fdtable * |
fdtab |
|
) |
| |
Duplicate a file descriptor from current process to target file descriptor table.
- Parameters
-
[in] | oldfd | is the fd in current process. |
[in,out] | fdtab | is the fd table to dup, if empty, use global (_fdtab). |
- Returns
- -1 on failed or the allocated file descriptor.
◆ dfs_dup_from()
int dfs_dup_from |
( |
int |
oldfd, |
|
|
struct dfs_fdtable * |
fdtab |
|
) |
| |
Duplicate a file descriptor from source table to current process.
- Parameters
-
[in] | oldfd | is the fd in the designate fd table. |
[in,out] | fdtab | is the fd table for oldfd, if empty, use global (_fdtab). |
- Returns
- -1 on failed or the allocated file descriptor.
◆ sys_dup()
System call to duplicate a file descriptor.
- Parameters
-
[in] | oldfd | The file descriptor to duplicate |
- Returns
- sysret_t/int The new file descriptor if successful (>=0), negative error code if failed
◆ sys_dup2()
rt_err_t sys_dup2 |
( |
int |
oldfd, |
|
|
int |
newfd |
|
) |
| |
System call to duplicate a file descriptor to a specific descriptor number.
- Parameters
-
[in] | oldfd | The file descriptor to duplicate |
[in] | newfd | The desired file descriptor number |
- Returns
- rt_err_t The new file descriptor number if successful (>=0), -RT_ENOSYS if filesystem lock failed, -1 if operation failed (invalid descriptors or allocation failed)
◆ dfs_subdir()
const char* dfs_subdir |
( |
const char * |
directory, |
|
|
const char * |
filename |
|
) |
| |
Get the subdirectory path relative to a parent directory.
- Parameters
-
[in] | directory | The parent directory path |
[in] | filename | The full path including parent directory and subpath |
- Returns
- const char* Pointer to the subdirectory portion of filename, NULL if paths are identical or invalid
◆ dfs_normalize_path()
char* dfs_normalize_path |
( |
const char * |
directory, |
|
|
const char * |
filename |
|
) |
| |
Normalize a path by combining directory and filename into an absolute path.
- Parameters
-
[in] | directory | The parent directory path (NULL means use working directory) |
[in] | filename | The filename or relative path to be normalized |
- Returns
- char* The normalized absolute path (must be freed by caller), NULL if path is invalid or memory allocation fails
- Note
- This function will:
- Handle working directory when directory is NULL
- Join directory and filename with proper separators
- Resolve . and .. in paths
- Remove redundant slashes
- Ensure path starts with /
- Allocate memory for the returned path string
◆ list_fd()
List all open file descriptors in the current process.
- Returns
- int 0 on success, -1 if failed to get file descriptor table
◆ dfs_fd_dump()
int dfs_fd_dump |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Dump all file descriptors information in the global file descriptor table.
- Parameters
-
[in] | argc | Number of command line arguments (unused) |
[in] | argv | Array of command line arguments (unused) |
- Returns
- int 0 on success, -RT_ENOSYS if failed to acquire file system lock