1 /* 2 * Copyright (c) 2006-2021, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2005-02-22 Bernard The first version. 9 */ 10 11 #ifndef __DFS_FS_H__ 12 #define __DFS_FS_H__ 13 14 #include <dfs.h> 15 #include <sys/types.h> 16 #include <sys/errno.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 /* Pre-declaration */ 23 struct dfs_filesystem; 24 struct dfs_file; 25 26 /* File system operations */ 27 struct dfs_filesystem_ops 28 { 29 char *name; 30 uint32_t flags; /* flags for file system operations */ 31 32 /* operations for file */ 33 const struct dfs_file_ops *fops; 34 35 /* mount and unmount file system */ 36 int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data); 37 int (*unmount) (struct dfs_filesystem *fs); 38 39 /* make a file system */ 40 int (*mkfs) (rt_device_t dev_id, const char *fs_name); 41 int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf); 42 43 int (*unlink) (struct dfs_filesystem *fs, const char *pathname); 44 int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf); 45 int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath); 46 }; 47 48 /* Mounted file system */ 49 struct dfs_filesystem 50 { 51 rt_device_t dev_id; /* Attached device */ 52 53 char *path; /* File system mount point */ 54 const struct dfs_filesystem_ops *ops; /* Operations for file system type */ 55 56 void *data; /* Specific file system data */ 57 }; 58 59 /* file system partition table */ 60 struct dfs_partition 61 { 62 uint8_t type; /* file system type */ 63 off_t offset; /* partition start offset */ 64 size_t size; /* partition size */ 65 rt_sem_t lock; 66 }; 67 68 /* mount table */ 69 struct dfs_mount_tbl 70 { 71 const char *device_name; 72 const char *path; 73 const char *filesystemtype; 74 unsigned long rwflag; 75 const void *data; 76 }; 77 78 int dfs_register(const struct dfs_filesystem_ops *ops); 79 struct dfs_filesystem *dfs_filesystem_lookup(const char *path); 80 const char *dfs_filesystem_get_mounted_path(struct rt_device *device); 81 82 int dfs_filesystem_get_partition(struct dfs_partition *part, 83 uint8_t *buf, 84 uint32_t pindex); 85 86 int dfs_mount(const char *device_name, 87 const char *path, 88 const char *filesystemtype, 89 unsigned long rwflag, 90 const void *data); 91 int dfs_unmount(const char *specialfile); 92 93 int dfs_mkfs(const char *fs_name, const char *device_name); 94 int dfs_statfs(const char *path, struct statfs *buffer); 95 int dfs_mount_device(rt_device_t dev); 96 int dfs_unmount_device(rt_device_t dev); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 102 #endif 103