1 /* 2 * Copyright (c) 2006-2018, 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 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* Pre-declaration */ 21 struct dfs_filesystem; 22 struct dfs_fd; 23 24 /* File system operations */ 25 struct dfs_filesystem_ops 26 { 27 char *name; 28 uint32_t flags; /* flags for file system operations */ 29 30 /* operations for file */ 31 const struct dfs_file_ops *fops; 32 33 /* mount and unmount file system */ 34 int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data); 35 int (*unmount) (struct dfs_filesystem *fs); 36 37 /* make a file system */ 38 int (*mkfs) (rt_device_t devid); 39 int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf); 40 41 int (*unlink) (struct dfs_filesystem *fs, const char *pathname); 42 int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf); 43 int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath); 44 }; 45 46 /* Mounted file system */ 47 struct dfs_filesystem 48 { 49 rt_device_t dev_id; /* Attached device */ 50 51 char *path; /* File system mount point */ 52 const struct dfs_filesystem_ops *ops; /* Operations for file system type */ 53 54 void *data; /* Specific file system data */ 55 }; 56 57 /* file system partition table */ 58 struct dfs_partition 59 { 60 uint8_t type; /* file system type */ 61 off_t offset; /* partition start offset */ 62 size_t size; /* partition size */ 63 rt_sem_t lock; 64 }; 65 66 /* mount table */ 67 struct dfs_mount_tbl 68 { 69 const char *device_name; 70 const char *path; 71 const char *filesystemtype; 72 unsigned long rwflag; 73 const void *data; 74 }; 75 76 int dfs_register(const struct dfs_filesystem_ops *ops); 77 struct dfs_filesystem *dfs_filesystem_lookup(const char *path); 78 const char* dfs_filesystem_get_mounted_path(struct rt_device* device); 79 80 int dfs_filesystem_get_partition(struct dfs_partition *part, 81 uint8_t *buf, 82 uint32_t pindex); 83 84 int dfs_mount(const char *device_name, 85 const char *path, 86 const char *filesystemtype, 87 unsigned long rwflag, 88 const void *data); 89 int dfs_unmount(const char *specialfile); 90 91 int dfs_mkfs(const char *fs_name, const char *device_name); 92 int dfs_statfs(const char *path, struct statfs *buffer); 93 94 #ifdef __cplusplus 95 } 96 #endif 97 98 #endif 99