Skip to content

Commit d5f8ee4

Browse files
committed
将 sys_mount 的 data 参数通过 vfs 传递进各文件系统实现.
1 parent 96f7bd3 commit d5f8ee4

File tree

16 files changed

+46
-38
lines changed

16 files changed

+46
-38
lines changed

module/all_include/fs_subsystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
typedef struct vfs_node *vfs_node_t;
3535

36-
typedef errno_t (*vfs_mount_t)(const char *src, vfs_node_t node);
36+
typedef errno_t (*vfs_mount_t)(const char *src, vfs_node_t node, void *data);
3737
typedef void (*vfs_unmount_t)(void *root);
3838

3939
typedef void (*vfs_open_t)(void *parent, const char *name, vfs_node_t node);

module/fatfs/fatfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool fatfs_close(file_t handle) {
137137
return true;
138138
}
139139

140-
errno_t fatfs_mount(const char *src, vfs_node_t node) {
140+
errno_t fatfs_mount(const char *src, vfs_node_t node, void *data) {
141141
int drive = alloc_number();
142142
drive_number_mapping[drive] = vfs_open(src);
143143
if (drive_number_mapping[drive] == NULL) return -ENODEV;

module/iso9660/iso9660.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,20 @@ bool iso9660_close(file_t handle) {
356356
return true;
357357
}
358358

359-
errno_t iso9660_mount(const char *src, vfs_node_t node) {
360-
vfs_node_t device = vfs_open(src);
359+
static errno_t iso9660_mount(const char *src, const vfs_node_t node, void *data) {
360+
const vfs_node_t device = vfs_open(src);
361361
if (device == NULL || device->type == file_dir) { return -1; }
362362
node->dev = device->rdev;
363-
l9660_fs *fs = (l9660_fs *)malloc(sizeof(l9660_fs));
364-
l9660_status status = l9660_openfs(fs, read_sector, device);
363+
l9660_fs *fs = malloc(sizeof(l9660_fs));
364+
const l9660_status status = l9660_openfs(fs, read_sector, device);
365365
if (status != L9660_OK) {
366366
free(fs);
367367
vfs_close(device);
368368
return -1;
369369
}
370-
l9660_dir *root_dir = (l9660_dir *)malloc(sizeof(l9660_dir));
370+
l9660_dir *root_dir = malloc(sizeof(l9660_dir));
371371
l9660_fs_open_root(root_dir, fs);
372-
file_t handle = (file_t)malloc(sizeof(struct file));
372+
const file_t handle = malloc(sizeof(struct file));
373373
handle->type = file_dir;
374374
handle->handle = (void *)root_dir;
375375
node->fsid = iso9660_id;
@@ -429,4 +429,4 @@ __attribute__((used)) __attribute__((visibility("default"))) int dlmain(void) {
429429
iso9660_id = vfs_regist("iso9660", &iso_callbacks, 0x9660, 0);
430430
if (iso9660_id == -EINVAL) { printk("Failed to register iso9660 filesystem\n"); }
431431
return EOK;
432-
}
432+
}

src/fs/cpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void cpio_init(void) {
104104
if (!init_ramfs) {
105105
return;
106106
}
107-
if (vfs_mount(NULL, "tmpfs", get_rootdir()) != EOK) {
107+
if (vfs_mount(NULL, "tmpfs", get_rootdir(), NULL) != EOK) {
108108
kerror("Cannot mount tmpfs to root_dir");
109109
return;
110110
}

src/fs/devtmpfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void load_drm_device(vfs_node_t node) {
8181
free(builder);
8282
}
8383

84-
errno_t devtmpfs_mount(const char *handle, vfs_node_t node) {
84+
errno_t devtmpfs_mount(const char *handle, vfs_node_t node, void *data) {
8585
node->fsid = dev_tmpfs_id;
8686
dtmp_handle_t *tmpfs_root = (dtmp_handle_t *)malloc(sizeof(dtmp_handle_t));
8787
tmpfs_root->type = dtp_file_dir;

src/fs/fssys.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,12 @@ syscall_(fcntl, int fd, int cmd, uint64_t arg) {
583583
}
584584

585585
syscall_(mount, char *dev_name, char *dir_name, char *type, uint64_t flags, void *data) {
586-
if (dir_name == NULL)
586+
if (dir_name == NULL) {
587587
return SYSCALL_FAULT_(EINVAL);
588+
}
588589

589590
char *ndir_name = vfs_cwd_path_build(dir_name);
590-
vfs_node_t dir = vfs_open((const char *)ndir_name);
591+
vfs_node_t dir = vfs_open(ndir_name);
591592
if (!dir) {
592593
free(ndir_name);
593594
return SYSCALL_FAULT_(ENOENT);
@@ -631,7 +632,7 @@ syscall_(mount, char *dev_name, char *dir_name, char *type, uint64_t flags, void
631632
char *ndev_name = vfs_cwd_path_build(dev_name);
632633
errno_t mret = EOK;
633634
mount:
634-
mret = vfs_mount((const char *)ndev_name, type, dir);
635+
mret = vfs_mount(ndev_name, type, dir, data);
635636
if (mret != EOK) {
636637
free(ndir_name);
637638
free(ndev_name);

src/fs/pipefs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int pipefs_poll(void *file, size_t events) {
306306
return out;
307307
}
308308

309-
int pipefs_mount(const char *handle, vfs_node_t node) {
309+
int pipefs_mount(const char *handle, vfs_node_t node, void *data) {
310310
if (pipefs_root != NULL)
311311
return -EBUSY;
312312
node->fsid = pipefs_id;

src/fs/procfs/proc_dpatch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "bootarg.h"
33
#include "fs/procfs.h"
44

5-
proc_handle_node_t *dispatch_array[256];
5+
static proc_handle_node_t *dispatch_array[256];
66
static size_t dp_index = 0;
77
extern vfs_node_t procfs_root;
88

@@ -19,12 +19,15 @@ size_t procfs_node_read(size_t len, size_t offset, size_t size, char *addr, char
1919

2020
static uint64_t hash_dp(const char *s) {
2121
uint64_t h = 0;
22-
while (*s)
22+
while (*s) {
2323
h = h * 131 + (unsigned char)*s++;
24+
}
2425
return h;
2526
}
2627

27-
static void create_procfs_handle(char *name, read_entry_t read_entry, stat_entry_t stat_entry) {
28+
static void create_procfs_handle(
29+
const char *name, const read_entry_t read_entry, const stat_entry_t stat_entry
30+
) {
2831
proc_handle_node_t *handle = malloc(sizeof(proc_handle_node_t));
2932
handle->name = strdup(name);
3033
handle->hash = hash_dp(handle->name);
@@ -33,9 +36,10 @@ static void create_procfs_handle(char *name, read_entry_t read_entry, stat_entry
3336
dispatch_array[dp_index++] = handle;
3437
}
3538

36-
static void create_procfs_node(char *name, read_entry_t read_entry, stat_entry_t stat_entry) {
39+
static void
40+
create_procfs_node(char *name, const read_entry_t read_entry, const stat_entry_t stat_entry) {
3741
create_procfs_handle(name, read_entry, stat_entry);
38-
vfs_node_t node = vfs_node_alloc(procfs_root, name);
42+
const vfs_node_t node = vfs_node_alloc(procfs_root, name);
3943
node->type = file_none;
4044
node->mode = 0700;
4145
proc_handle_t *handle0 = malloc(sizeof(proc_handle_t));

src/fs/procfs/procfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
static int procfs_id = 0;
1212
static int proc_self_id = 0;
1313
vfs_node_t procfs_root = NULL;
14-
spin_t procfs_oplock = SPIN_INIT;
14+
static spin_t procfs_oplock = SPIN_INIT;
1515

16-
errno_t procfs_mount(const char *src, vfs_node_t node) {
16+
errno_t procfs_mount(const char *src, vfs_node_t node, void *data) {
1717
procfs_root = node;
1818

1919
procfs_root->fsid = procfs_id;

src/fs/sockfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ static errno_t sockfs_free(void *handle) {
283283
return EOK;
284284
}
285285

286-
static int sockfs_mount(const char *handle, vfs_node_t node) {
287-
if (sockfs_root != NULL)
286+
static int sockfs_mount(const char *handle, vfs_node_t node, void *data) {
287+
if (sockfs_root != NULL) {
288288
return -EBUSY;
289+
}
289290
node->fsid = sockfs_id;
290291
sockfs_root = node;
291292
node->handle = calloc(1, sizeof(socket_specific_t));

0 commit comments

Comments
 (0)