first commit for chrg

This commit is contained in:
wmano
2025-08-16 22:58:22 +08:00
commit 52a3ed5862
2306 changed files with 1021208 additions and 0 deletions
@@ -0,0 +1,151 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2005-02-22 Bernard The first version.
* 2023-05-05 Bernard change to dfs v2.0
*/
#ifndef __DFS_H__
#define __DFS_H__
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "../../libc/compilers/common/include/dirent.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <rtatomic.h>
#include <rtdevice.h>
#ifndef ATTR_MODE_SET
#define ATTR_MODE_SET (1 << 6)
#endif
#ifndef ATTR_ATIME_SET
#define ATTR_ATIME_SET (1 << 7)
#endif
#ifndef ATTR_MTIME_SET
#define ATTR_MTIME_SET (1 << 8)
#endif
#ifndef ATTR_UID_SET
#define ATTR_UID_SET (1 << 9)
#endif
#ifndef ATTR_GID_SET
#define ATTR_GID_SET (1 << 10)
#endif
#ifndef AT_SYMLINK_NOFOLLOW
#define AT_SYMLINK_NOFOLLOW 0x100
#endif
#ifndef UTIME_NOW
#define UTIME_NOW 0x3fffffff
#endif
#ifndef UTIME_OMIT
#define UTIME_OMIT 0x3ffffffe
#endif
#ifndef DFS_FD_MAX
#define DFS_FD_MAX 16
#endif
/*
* skip stdin/stdout/stderr normally
*/
#ifndef DFS_STDIO_OFFSET
#define DFS_STDIO_OFFSET 3
#endif
#ifndef DFS_PATH_MAX
#define DFS_PATH_MAX 4096
#endif
#ifndef SECTOR_SIZE
#define SECTOR_SIZE 512
#endif
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
/* File flags */
#define DFS_F_FREAD 0x01
#define DFS_F_FWRITE 0x02
#ifdef __cplusplus
extern "C" {
#endif
rt_inline int dfs_fflags(int oflags)
{
int rw = oflags & O_ACCMODE;
oflags &= ~O_ACCMODE;
return (rw + 1) | oflags;
}
rt_inline int dfs_oflags(int fflags)
{
int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
return (rw - 1) | fflags;
}
struct dfs_fdtable
{
uint32_t maxfd;
struct dfs_file **fds;
};
/* Initialization of dfs */
int dfs_init(void);
char *dfs_normalize_path(const char *directory, const char *filename);
const char *dfs_subdir(const char *directory, const char *filename);
rt_err_t dfs_lock(void);
void dfs_unlock(void);
rt_err_t dfs_file_lock(void);
void dfs_file_unlock(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 *fdtab, int fd);
#ifdef DFS_USING_POSIX
/* FD APIs */
int fdt_fd_new(struct dfs_fdtable *fdt);
struct dfs_file *fdt_get_file(struct dfs_fdtable* fdt, int fd);
void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
int fd_new(void);
int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
struct dfs_file *fd_get(int fd);
void fd_release(int fd);
void fd_init(struct dfs_file *fd);
struct dfs_fdtable *dfs_fdtable_get(void);
struct dfs_fdtable *dfs_fdtable_get_global(void);
int dfs_dup(int oldfd, int startfd);
#endif /* DFS_USING_POSIX */
struct dfs_file* dfs_file_create(void);
void dfs_file_destroy(struct dfs_file *file);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 Bernard Implement dentry in dfs v2.0
*/
#ifndef __DFS_DENTRY_H__
#define __DFS_DENTRY_H__
#include "dfs_file.h"
#include "dfs_fs.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct dfs_mnt;
struct dfs_vnode;
struct dfs_dentry
{
rt_list_t hashlist;
uint32_t flags;
#define DENTRY_IS_MOUNTED 0x1 /* dentry is mounted */
#define DENTRY_IS_ALLOCED 0x2 /* dentry is allocated */
#define DENTRY_IS_ADDHASH 0x4 /* dentry was added into hash table */
#define DENTRY_IS_OPENED 0x8 /* dentry was opened. */
char *pathname; /* the pathname under mounted file sytem */
struct dfs_vnode *vnode; /* the vnode of this dentry */
struct dfs_mnt *mnt; /* which mounted file system does this dentry belong to */
rt_atomic_t ref_count; /* the reference count */
};
struct dfs_dentry *dfs_dentry_create(struct dfs_mnt *mnt, char *fullpath);
struct dfs_dentry *dfs_dentry_create_rela(struct dfs_mnt *mnt, char *rela_path);
struct dfs_dentry *dfs_dentry_unref(struct dfs_dentry *dentry);
struct dfs_dentry *dfs_dentry_ref(struct dfs_dentry *dentry);
void dfs_dentry_insert(struct dfs_dentry *dentry);
struct dfs_dentry *dfs_dentry_lookup(struct dfs_mnt *mnt, const char *path, uint32_t flags);
/* get full path of a dentry */
char* dfs_dentry_full_path(struct dfs_dentry* dentry);
/* get pathname (with mnt path) of a dentry */
char* dfs_dentry_pathname(struct dfs_dentry* dentry);
/* get full path crc32 */
uint32_t dfs_dentry_full_path_crc32(struct dfs_dentry* dentry);
int dfs_dentry_init(void);
#ifdef __cplusplus
}
#endif
#endif /*__DFS_DENTRY_H__*/
@@ -0,0 +1,204 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2005-01-26 Bernard The first version.
* 2023-05-05 Bernard Change to dfs v2.0
*/
#ifndef __DFS_FILE_H__
#define __DFS_FILE_H__
#include <dfs.h>
#include <dfs_fs.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define STDIN_FILENO 0 /* standard input file descriptor */
#define STDOUT_FILENO 1 /* standard output file descriptor */
#define STDERR_FILENO 2 /* standard error file descriptor */
struct dfs_file;
struct dfs_vnode;
struct dfs_dentry;
struct dfs_attr;
struct rt_pollreq;
struct dirent;
struct lwp_avl_struct;
struct file_lock;
struct dfs_aspace;
struct dfs_file_ops
{
int (*open)(struct dfs_file *file);
int (*close)(struct dfs_file *file);
int (*ioctl)(struct dfs_file *file, int cmd, void *arg);
ssize_t (*read)(struct dfs_file *file, void *buf, size_t count, off_t *pos);
ssize_t (*write)(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
int (*flush)(struct dfs_file *file);
off_t (*lseek)(struct dfs_file *file, off_t offset, int wherece);
int (*truncate)(struct dfs_file *file, off_t offset);
int (*getdents)(struct dfs_file *file, struct dirent *dirp, uint32_t count);
int (*poll)(struct dfs_file *file, struct rt_pollreq *req);
int (*mmap)(struct dfs_file *file, struct lwp_avl_struct *mmap);
int (*lock)(struct dfs_file *file, struct file_lock *flock);
int (*flock)(struct dfs_file *file, int, struct file_lock *flock);
};
struct dfs_vnode
{
uint32_t flags;
uint32_t mode;
int type; /* node type */
rt_atomic_t ref_count; /* reference count */
struct dfs_mnt *mnt; /* which mounted file system does this vnode belong to */
size_t size;
uint32_t nlink;
const struct dfs_file_ops *fops;
unsigned int uid;
unsigned int gid;
struct timespec atime;
struct timespec mtime;
struct timespec ctime;
struct dfs_aspace *aspace;
struct rt_mutex lock;
void *data; /* private data of this file system */
};
/* file descriptor */
#define DFS_FD_MAGIC 0xfdfd
struct dfs_file
{
uint16_t magic;
uint16_t mode;
uint32_t flags;
rt_atomic_t ref_count;
off_t fpos;
struct rt_mutex pos_lock;
const struct dfs_file_ops *fops;
struct dfs_dentry *dentry; /* dentry of this file */
struct dfs_vnode *vnode; /* vnode of this file */
void *mmap_context; /* used by mmap routine */
void *data;
};
#define DFS_FILE_POS(dfs_file) ((dfs_file)->fpos)
/* file is open for reading */
#define FMODE_READ 0x1
/* file is open for writing */
#define FMODE_WRITE 0x2
/* file is seekable */
#define FMODE_LSEEK 0x4
/* file can be accessed using pread */
#define FMODE_PREAD 0x8
/* file can be accessed using pwrite */
#define FMODE_PWRITE 0x10
/* File is opened for execution with sys_execve / sys_uselib */
#define FMODE_EXEC 0x20
/* File is opened with O_NDELAY (only set for block devices) */
#define FMODE_NDELAY 0x40
/* File is opened with O_EXCL (only set for block devices) */
#define FMODE_EXCL 0x80
/* dfs_vnode.c */
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops);
struct dfs_vnode *dfs_vnode_create(void);
int dfs_vnode_destroy(struct dfs_vnode* vnode);
struct dfs_vnode *dfs_vnode_ref(struct dfs_vnode *vnode);
void dfs_vnode_unref(struct dfs_vnode *vnode);
/*dfs_file.c*/
#ifdef RT_USING_SMART
struct dfs_mmap2_args
{
void *addr;
size_t length;
int prot;
int flags;
off_t pgoffset;
size_t min_align_size;
struct rt_lwp *lwp;
void *ret;
};
#endif
void dfs_file_init(struct dfs_file *file);
void dfs_file_deinit(struct dfs_file *file);
int dfs_file_open(struct dfs_file *file, const char *path, int flags, mode_t mode);
int dfs_file_close(struct dfs_file *file);
off_t dfs_file_get_fpos(struct dfs_file *file);
void dfs_file_set_fpos(struct dfs_file *file, off_t fpos);
ssize_t dfs_file_pread(struct dfs_file *file, void *buf, size_t len, off_t offset);
ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len);
ssize_t dfs_file_pwrite(struct dfs_file *file, const void *buf, size_t len, off_t offset);
ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len);
off_t generic_dfs_lseek(struct dfs_file *file, off_t offset, int whence);
off_t dfs_file_lseek(struct dfs_file *file, off_t offset, int wherece);
int dfs_file_stat(const char *path, struct stat *buf);
int dfs_file_lstat(const char *path, struct stat *buf);
int dfs_file_setattr(const char *path, struct dfs_attr *attr);
int dfs_file_fstat(struct dfs_file *file, struct stat *buf);
int dfs_file_ioctl(struct dfs_file *file, int cmd, void *args);
int dfs_file_fcntl(int fd, int cmd, unsigned long arg);
int dfs_file_fsync(struct dfs_file *file);
int dfs_file_unlink(const char *path);
int dfs_file_link(const char *oldname, const char *newname);
int dfs_file_symlink(const char *oldname, const char *name);
int dfs_file_readlink(const char *path, char *buf, int bufsize);
int dfs_file_rename(const char *old_file, const char *new_file);
int dfs_file_ftruncate(struct dfs_file *file, off_t length);
int dfs_file_getdents(struct dfs_file *file, struct dirent *dirp, size_t nbytes);
int dfs_file_mkdir(const char *path, mode_t mode);
int dfs_file_rmdir(const char *pathname);
int dfs_file_isdir(const char *path);
int dfs_file_access(const char *path, mode_t mode);
int dfs_file_chdir(const char *path);
char *dfs_file_getcwd(char *buf, size_t size);
#ifdef RT_USING_SMART
int dfs_file_mmap2(struct dfs_file *file, struct dfs_mmap2_args *mmap2);
int dfs_file_mmap(struct dfs_file *file, struct dfs_mmap2_args *mmap2);
#endif
/* 0x5254 is just a magic number to make these relatively unique ("RT") */
#define RT_FIOFTRUNCATE 0x52540000U
#define RT_FIOGETADDR 0x52540001U
#define RT_FIOMMAP2 0x52540002U
/* dfs_file_realpath mode */
#define DFS_REALPATH_EXCEPT_LAST 0
#define DFS_REALPATH_EXCEPT_NONE 1
#define DFS_REALPATH_ONLY_LAST 3
char *dfs_file_realpath(struct dfs_mnt **mnt, const char *fullpath, int mode);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,141 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2005-02-22 Bernard The first version.
* 2023-05-05 Bernard Change to dfs v2.0
*/
#ifndef __DFS_FS_H__
#define __DFS_FS_H__
#include <dfs.h>
#include <dfs_file.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define MS_RDONLY 1
#define MS_NOSUID 2
#define MS_NODEV 4
#define MS_NOEXEC 8
#define MS_SYNCHRONOUS 16
#define MS_REMOUNT 32
#define MS_MANDLOCK 64
#define MS_DIRSYNC 128
#define MS_NOATIME 1024
#define MS_NODIRATIME 2048
#define MS_BIND 4096
#define MS_MOVE 8192
#define MS_REC 16384
#define MS_SILENT 32768
#define MS_POSIXACL (1<<16)
#define MS_UNBINDABLE (1<<17)
#define MS_PRIVATE (1<<18)
#define MS_SLAVE (1<<19)
#define MS_SHARED (1<<20)
#define MS_RELATIME (1<<21)
#define MS_KERNMOUNT (1<<22)
#define MS_I_VERSION (1<<23)
#define MS_STRICTATIME (1<<24)
#define MS_LAZYTIME (1<<25)
#define MS_NOREMOTELOCK (1<<27)
#define MS_NOSEC (1<<28)
#define MS_BORN (1<<29)
#define MS_ACTIVE (1<<30)
#define MS_NOUSER (1U<<31)
#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)
/* file system partition table */
struct dfs_partition
{
uint8_t type; /* file system type */
off_t offset; /* partition start offset */
size_t size; /* partition size */
rt_sem_t lock;
};
struct dfs_attr
{
unsigned int ia_valid;
uid_t st_uid;
gid_t st_gid;
mode_t st_mode;
struct timespec ia_atime;
struct timespec ia_mtime;
};
struct dfs_mnt;
struct dfs_dentry;
struct dfs_vnode;
struct statfs;
struct dfs_filesystem_ops
{
const char *name;
uint32_t flags;
#define FS_NEED_DEVICE 0x1
const struct dfs_file_ops *default_fops;
int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
int (*umount)(struct dfs_mnt *mnt);
int (*mkfs)(rt_device_t devid, const char *fs_name);
int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
int (*unlink)(struct dfs_dentry *dentry);
int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/
int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
int (*stat)(struct dfs_dentry *dentry, struct stat *buf);
int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);
int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);
struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);
struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
int (*free_vnode)(struct dfs_vnode* vnode);
};
struct dfs_filesystem_type
{
const struct dfs_filesystem_ops *fs_ops;
struct dfs_filesystem_type *next;
};
struct dfs_filesystem_type *dfs_filesystems(void);
int dfs_unregister(struct dfs_filesystem_type *fs);
int dfs_register(struct dfs_filesystem_type *fs);
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
int dfs_remount(const char *path, rt_ubase_t flags, void *data);
int dfs_mount(const char *device_name,
const char *path,
const char *filesystemtype,
unsigned long rwflag,
const void *data);
int dfs_umount(const char *specialfile, int flags);
int dfs_unmount(const char *specialfile);
int dfs_is_mounted(struct dfs_mnt *mnt);
int dfs_mkfs(const char *fs_name, const char *device_name);
int dfs_statfs(const char *path, struct statfs *buffer);
int dfs_filesystem_get_partition(struct dfs_partition *part,
uint8_t *buf,
uint32_t pindex);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 Bernard Implement dentry in dfs v2.0
*/
#ifndef DFS_MNT_H__
#define DFS_MNT_H__
#include <rtservice.h>
#include <rtthread.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct dfs_mnt;
struct dfs_dentry;
struct dfs_filesystem_ops;
struct dfs_mnt
{
struct dfs_mnt *parent; /* the parent mounted file system */
rt_list_t sibling; /* the sibling node for mounted list */
rt_list_t child; /* the child node for mounted list */
char *fullpath; /* the fullpath of this mounted file system */
int flags; /* the falgs of this mounted file system */
#define MNT_IS_ALLOCED 0x1 /* the mnt struct is allocated */
#define MNT_IS_ADDLIST 0x2 /* the mnt struct is added into list */
#define MNT_IS_MOUNTED 0x4 /* the mnt struct is mounted */
#define MNT_IS_UMOUNT 0x8 /* the mnt is unmount */
#define MNT_IS_LOCKED 0x10 /* the mnt is locked */
#define MNT_FORCE 0x20 /* the mnt force unmount */
#define MNT_LAZY_UMNT 0x40 /* the mnt has pending umount */
#define MNT_RDONLY 0x80 /* the mnt is read only */
rt_atomic_t ref_count; /* reference count */
rt_device_t dev_id; /* the mounted device id */
const struct dfs_filesystem_ops *fs_ops;
void *data;
};
struct dfs_mnt *dfs_mnt_create(const char *path);
int dfs_mnt_destroy(struct dfs_mnt* mnt);
int dfs_mnt_list(struct dfs_mnt* mnt);
int dfs_mnt_insert(struct dfs_mnt* mnt, struct dfs_mnt* child);
struct dfs_mnt *dfs_mnt_dev_lookup(rt_device_t dev_id);
struct dfs_mnt *dfs_mnt_lookup(const char *path);
const char *dfs_mnt_get_mounted_path(struct rt_device *device);
struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt);
int dfs_mnt_unref(struct dfs_mnt* mnt);
int dfs_mnt_umount(struct dfs_mnt *mnt, int flags);
int dfs_mnt_setflags(struct dfs_mnt *mnt, int flags);
rt_bool_t dfs_mnt_has_child_mnt(struct dfs_mnt *mnt, const char* fullpath);
int dfs_mnt_foreach(struct dfs_mnt* (*func)(struct dfs_mnt *mnt, void *parameter), void *parameter);
int dfs_mnt_umount_iter(rt_bool_t (*filter)(struct dfs_mnt *mnt, void *parameter), void *parameter);
typedef void (*dfs_mnt_umnt_cb_t)(struct dfs_mnt *mnt);
RT_OBJECT_HOOKLIST_DECLARE(dfs_mnt_umnt_cb_t, dfs_mnt_umnt);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,134 @@
/*
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 RTT Implement dentry in dfs v2.0
*/
#ifndef DFS_PAGE_CACHE_H__
#define DFS_PAGE_CACHE_H__
#include <rtthread.h>
#ifdef RT_USING_PAGECACHE
#include <dfs_file.h>
#include <avl.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct rt_varea;
struct rt_aspace;
struct dfs_vnode;
struct dfs_dentry;
struct dfs_aspace;
/* Memory mapping structure for page cache */
struct dfs_mmap
{
rt_list_t mmap_node; /* List node for address space's mmap list */
struct rt_aspace *aspace; /* Address space this mapping belongs to */
void *vaddr; /* Virtual address where the page is mapped */
};
/* Page structure for file system page cache */
struct dfs_page
{
rt_list_t space_node; /* Node for address space's page list */
rt_list_t dirty_node; /* Node for dirty page list */
struct util_avl_struct avl_node; /* Node for AVL tree in address space */
rt_list_t mmap_head; /* Head of memory mappings list */
rt_atomic_t ref_count; /* Reference count for this page */
void *page; /* Pointer to physical page data */
off_t fpos; /* File position this page represents */
size_t size; /* Total size of the page */
size_t len; /* Valid data length in the page */
int is_dirty; /* Dirty flag indicating if page needs writeback */
rt_tick_t tick_ms; /* Last access timestamp */
struct dfs_aspace *aspace; /* Address space this page belongs to */
};
/* Address space operations interface */
struct dfs_aspace_ops
{
ssize_t (*read)(struct dfs_file *file, struct dfs_page *page); /* Read operation for page cache */
ssize_t (*write)(struct dfs_page *page); /* Write operation for page cache */
};
/* Address space structure for page cache management */
struct dfs_aspace
{
rt_list_t hash_node, cache_node; /* Nodes for hash table and cache lists */
char *fullpath, *pathname; /* Full path and relative path strings */
struct dfs_mnt *mnt; /* Mount point this space belongs to */
rt_list_t list_active, list_inactive; /* Active and inactive page lists */
rt_list_t list_dirty; /* Dirty page list */
size_t pages_count; /* Total pages in this space */
struct util_avl_root avl_root; /* AVL tree root for page lookup */
struct dfs_page *avl_page; /* Current AVL tree page */
rt_bool_t is_active; /* Active/inactive status flag */
struct rt_mutex lock; /* Mutex for thread safety */
rt_atomic_t ref_count; /* Reference counter */
struct dfs_vnode *vnode; /* Associated vnode */
const struct dfs_aspace_ops *ops; /* Operations interface */
};
#ifndef RT_PAGECACHE_HASH_NR
#define RT_PAGECACHE_HASH_NR 1024
#endif
/* Global page cache management structure */
struct dfs_pcache
{
rt_list_t head[RT_PAGECACHE_HASH_NR]; /* Hash table buckets for address spaces */
rt_list_t list_active, list_inactive; /* Active and inactive space lists */
rt_atomic_t pages_count; /* Total cached pages count */
struct rt_mutex lock; /* Global lock for thread safety */
struct rt_messagequeue *mqueue; /* Message queue for sending GC/WB command.*/
rt_tick_t last_time_wb; /* Last writeback timestamp */
};
struct dfs_aspace *dfs_aspace_create(struct dfs_dentry *dentry, struct dfs_vnode *vnode, const struct dfs_aspace_ops *ops);
int dfs_aspace_destroy(struct dfs_aspace *aspace);
int dfs_aspace_read(struct dfs_file *file, void *buf, size_t count, off_t *pos);
int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos);
int dfs_aspace_flush(struct dfs_aspace *aspace);
int dfs_aspace_clean(struct dfs_aspace *aspace);
void *dfs_aspace_mmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
int dfs_aspace_unmap(struct dfs_file *file, struct rt_varea *varea);
int dfs_aspace_page_unmap(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
int dfs_aspace_page_dirty(struct dfs_file *file, struct rt_varea *varea, void *vaddr);
off_t dfs_aspace_fpos(struct rt_varea *varea, void *vaddr);
void *dfs_aspace_vaddr(struct rt_varea *varea, off_t fpos);
int dfs_aspace_mmap_read(struct dfs_file *file, struct rt_varea *varea, void *data);
int dfs_aspace_mmap_write(struct dfs_file *file, struct rt_varea *varea, void *data);
void dfs_pcache_release(size_t count);
void dfs_pcache_unmount(struct dfs_mnt *mnt);
void dfs_pcache_clean(struct dfs_mnt *mnt);
#ifdef __cplusplus
}
#endif
#endif
#endif
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-05-27 Yi.qiu The first version.
* 2010-07-18 Bernard add stat and statfs structure definitions.
* 2011-05-16 Yi.qiu Change parameter name of rename, "new" is C++ key word.
* 2017-12-27 Bernard Add fcntl API.
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
*/
#ifndef __DFS_POSIX_H__
#define __DFS_POSIX_H__
#include <fcntl.h>
#include <errno.h>
#include <dfs.h>
#include <dfs_file.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __DFS_SEQ_FILE_H__
#define __DFS_SEQ_FILE_H__
#include <dfs.h>
#include <dfs_fs.h>
struct dfs_seq_ops;
/**
* Sequence file control structure
*/
struct dfs_seq_file
{
char *buf; /* Data buffer pointer */
size_t size; /* Total buffer size in bytes */
size_t from; /* Start offset of valid data in buffer */
size_t count; /* Length of valid data in buffer */
size_t pad_until; /* Padding target position for alignment */
off_t index; /* Current item index in sequence */
off_t read_pos; /* Current read position in file */
struct rt_mutex lock; /* Mutex for thread safety */
const struct dfs_seq_ops *ops; /* Operation function table */
const struct dfs_file *file; /* Associated file object */
void *data; /* Private data pointer */
};
/**
* Sequence file operations structure
*/
struct dfs_seq_ops
{
void *(*start)(struct dfs_seq_file *seq, off_t *index); /* Start sequence traversal */
void (*stop)(struct dfs_seq_file *seq, void *data); /* Stop sequence traversal */
void *(*next)(struct dfs_seq_file *seq, void *data, off_t *index); /* Get next item in sequence */
int (*show)(struct dfs_seq_file *seq, void *data); /* Show current item */
};
/**
* check if the buffer is full
*/
static inline rt_bool_t dfs_seq_is_full(struct dfs_seq_file *seq)
{
return seq->count == seq->size;
}
/**
* set padding width size
*/
static inline void dfs_seq_setwidth(struct dfs_seq_file *seq, size_t size)
{
seq->pad_until = seq->count + size;
}
int dfs_seq_open(struct dfs_file *file, const struct dfs_seq_ops *ops);
ssize_t dfs_seq_read(struct dfs_file *file, void *buf, size_t size, off_t *pos);
off_t dfs_seq_lseek(struct dfs_file *file, off_t offset, int whence);
int dfs_seq_release(struct dfs_file *file);
int dfs_seq_write(struct dfs_seq_file *seq, const void *data, size_t len);
void dfs_seq_vprintf(struct dfs_seq_file *seq, const char *fmt, va_list args);
void dfs_seq_printf(struct dfs_seq_file *seq, const char *fmt, ...);
void dfs_seq_putc(struct dfs_seq_file *seq, char c);
void dfs_seq_puts(struct dfs_seq_file *seq, const char *s);
void dfs_seq_pad(struct dfs_seq_file *seq, char c);
#endif
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __DFS_VFS_H__
#define __DFS_VFS_H__
#include "dfs_file.h"
#include "dfs_fs.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct dfs_vfs_node
{
rt_list_t subnode; /* file subnode list */
rt_list_t sibling; /* file sibling list */
};
rt_inline void dfs_vfs_init_node(struct dfs_vfs_node *node)
{
rt_list_init(&node->subnode);
rt_list_init(&node->sibling);
}
rt_inline void dfs_vfs_append_node(struct dfs_vfs_node *dir, struct dfs_vfs_node *node)
{
rt_list_insert_after(&(dir->subnode), &(node->sibling));
}
rt_inline void dfs_vfs_remove_node(struct dfs_vfs_node *node)
{
rt_list_remove(&(node->sibling));
}
#define dfs_vfs_for_each_subnode(node, tmp, dir, member) \
rt_list_for_each_entry_safe(node, tmp, &dir->member.subnode, member.sibling)
#ifdef __cplusplus
}
#endif
#endif /*__DFS_VFS_H__*/