1 /*
2  * Copyright (c) 2006-2023, 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  * 2023-05-05     Bernard      Change to dfs v2.0
10  */
11 
12 #ifndef __DFS_FS_H__
13 #define __DFS_FS_H__
14 
15 #include <dfs.h>
16 #include <dfs_file.h>
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #define MS_RDONLY      1
24 #define MS_NOSUID      2
25 #define MS_NODEV       4
26 #define MS_NOEXEC      8
27 #define MS_SYNCHRONOUS 16
28 #define MS_REMOUNT     32
29 #define MS_MANDLOCK    64
30 #define MS_DIRSYNC     128
31 #define MS_NOATIME     1024
32 #define MS_NODIRATIME  2048
33 #define MS_BIND        4096
34 #define MS_MOVE        8192
35 #define MS_REC         16384
36 #define MS_SILENT      32768
37 #define MS_POSIXACL    (1<<16)
38 #define MS_UNBINDABLE  (1<<17)
39 #define MS_PRIVATE     (1<<18)
40 #define MS_SLAVE       (1<<19)
41 #define MS_SHARED      (1<<20)
42 #define MS_RELATIME    (1<<21)
43 #define MS_KERNMOUNT   (1<<22)
44 #define MS_I_VERSION   (1<<23)
45 #define MS_STRICTATIME (1<<24)
46 #define MS_LAZYTIME    (1<<25)
47 #define MS_NOREMOTELOCK (1<<27)
48 #define MS_NOSEC       (1<<28)
49 #define MS_BORN        (1<<29)
50 #define MS_ACTIVE      (1<<30)
51 #define MS_NOUSER      (1U<<31)
52 
53 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)
54 
55 /* file system partition table */
56 struct dfs_partition
57 {
58     uint8_t type; /* file system type */
59     off_t offset; /* partition start offset */
60     size_t size;  /* partition size */
61     rt_sem_t lock;
62 };
63 
64 struct dfs_attr
65 {
66     unsigned int ia_valid;
67     uid_t st_uid;
68     gid_t st_gid;
69     mode_t st_mode;
70     struct timespec ia_atime;
71     struct timespec ia_mtime;
72 };
73 
74 struct dfs_mnt;
75 struct dfs_dentry;
76 struct dfs_vnode;
77 
78 struct statfs;
79 
80 struct dfs_filesystem_ops
81 {
82     const char *name;
83     uint32_t flags;
84 #define FS_NEED_DEVICE 0x1
85 
86     const struct dfs_file_ops *default_fops;
87 
88     int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
89     int (*umount)(struct dfs_mnt *mnt);
90 
91     int (*mkfs)(rt_device_t devid, const char *fs_name);
92 
93     int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
94     int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
95     int (*unlink)(struct dfs_dentry *dentry);
96     int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/
97 
98     int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
99     int (*stat)(struct dfs_dentry *dentry, struct stat *buf);
100 
101     int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);
102 
103     int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);
104 
105     struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);
106 
107     struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
108     int (*free_vnode)(struct dfs_vnode* vnode);
109 };
110 
111 struct dfs_filesystem_type
112 {
113     const struct dfs_filesystem_ops *fs_ops;
114     struct dfs_filesystem_type *next;
115 };
116 
117 struct dfs_filesystem_type *dfs_filesystems(void);
118 int dfs_unregister(struct dfs_filesystem_type *fs);
119 int dfs_register(struct dfs_filesystem_type *fs);
120 const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
121 
122 int dfs_remount(const char *path, rt_ubase_t flags, void *data);
123 int dfs_mount(const char *device_name,
124             const char *path,
125             const char *filesystemtype,
126             unsigned long rwflag,
127             const void *data);
128 int dfs_umount(const char *specialfile, int flags);
129 int dfs_unmount(const char *specialfile);
130 int dfs_is_mounted(struct dfs_mnt *mnt);
131 int dfs_mkfs(const char *fs_name, const char *device_name);
132 int dfs_statfs(const char *path, struct statfs *buffer);
133 int dfs_filesystem_get_partition(struct dfs_partition *part,
134                                 uint8_t *buf,
135                                 uint32_t pindex);
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif
142