Skip to content

Commit 1c97a36

Browse files
committed
feat: add support for dfs remount functionality
This patch introduces a remount feature for the DFS (Distributed File System), allowing for the modification of mount parameters without unmounting the filesystem. This was necessary to enhance flexibility and improve system management by enabling dynamic adjustments to filesystem settings. Changes: - Defined new constants for remount flags in `dfs_fs.h`. - Added the `dfs_remount()` function in `dfs_fs.c` to handle remount operations. - Introduced a check for unsupported flags and handle error conditions such as invalid paths or non-directory targets. - Updated the `dfs_mnt` structure in `dfs_mnt.h` to include a read-only flag (`MNT_RDONLY`). - The `dfs_remount()` function allows changing the read-only status of a mounted filesystem. The remount functionality helps modify certain mount flags (like `MS_RDONLY`) without requiring an unmount, providing more control over mounted filesystems in the system. Signed-off-by: Shell <[email protected]>
1 parent f7b34c0 commit 1c97a36

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

components/dfs/dfs_v2/include/dfs_fs.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ extern "C"
2020
{
2121
#endif
2222

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+
2355
/* file system partition table */
2456
struct dfs_partition
2557
{
@@ -87,6 +119,7 @@ int dfs_unregister(struct dfs_filesystem_type *fs);
87119
int dfs_register(struct dfs_filesystem_type *fs);
88120
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
89121

122+
int dfs_remount(const char *path, rt_ubase_t flags, void *data);
90123
int dfs_mount(const char *device_name,
91124
const char *path,
92125
const char *filesystemtype,

components/dfs/dfs_v2/include/dfs_mnt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct dfs_mnt
3939
#define MNT_IS_UMOUNT 0x8 /* the mnt is unmount */
4040
#define MNT_IS_LOCKED 0x10 /* the mnt is locked */
4141
#define MNT_FORCE 0x20 /* the mnt force unmount */
42+
#define MNT_RDONLY 0x80 /* the mnt is read only */
4243

4344
rt_atomic_t ref_count; /* reference count */
4445

components/dfs/dfs_v2/src/dfs_fs.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,55 @@ int dfs_unregister(struct dfs_filesystem_type *fs)
9595
return ret;
9696
}
9797

98+
#define REMNT_UNSUPP_FLAGS (~(MS_REMOUNT | MS_RMT_MASK))
99+
int dfs_remount(const char *path, rt_ubase_t flags, void *data)
100+
{
101+
int rc = 0;
102+
char *fullpath = RT_NULL;
103+
struct dfs_mnt *mnt = RT_NULL;
104+
105+
if (flags & REMNT_UNSUPP_FLAGS)
106+
{
107+
return -EINVAL;
108+
}
109+
110+
fullpath = dfs_normalize_path(RT_NULL, path);
111+
if (!fullpath)
112+
{
113+
rc = -ENOENT;
114+
}
115+
else
116+
{
117+
DLOG(msg, "dfs", "mnt", DLOG_MSG, "mnt = dfs_mnt_lookup(%s)", fullpath);
118+
mnt = dfs_mnt_lookup(fullpath);
119+
if (mnt)
120+
{
121+
dfs_lock();
122+
if (flags & MS_RDONLY)
123+
{
124+
mnt->flags |= MNT_RDONLY;
125+
}
126+
dfs_unlock();
127+
}
128+
else
129+
{
130+
struct stat buf = {0};
131+
if (dfs_file_stat(fullpath, &buf) == 0 && S_ISBLK(buf.st_mode))
132+
{
133+
/* path was not already mounted on target */
134+
rc = -EINVAL;
135+
}
136+
else
137+
{
138+
/* path is not a directory */
139+
rc = -ENOTDIR;
140+
}
141+
}
142+
}
143+
144+
return rc;
145+
}
146+
98147
/*
99148
* parent(mount path)
100149
* mnt_parent <- - - - - - - +

0 commit comments

Comments
 (0)