Skip to content

Commit 0fd5016

Browse files
committed
新增 procfs, 重写 mount 系统调用, 修改文件系统注册逻辑.
取消 modfs pipefs tmpfs 的内核主动性挂载 (由用户态 mount 命令挂载) 修复 modfs 的偏移计算读取问题.
1 parent 0f5a01e commit 0fd5016

File tree

23 files changed

+352
-85
lines changed

23 files changed

+352
-85
lines changed

assets/readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Welcome to CoolPotOS. This file is a test description.
22
All source code of this operating system is licensed under the MIT open-source license.
3+
4+
open-source: https://github.com/plos-clan/CoolPotOS
5+
website: https://cpos.plos-clan.org

module/all_include/fs_subsystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct vfs_node { // vfs节点
104104

105105
errno_t vfs_mkdir(const char *name);
106106
errno_t vfs_mkfile(const char *name);
107-
int vfs_regist(const char *name, vfs_callback_t callback);
107+
int vfs_regist(const char *name, vfs_callback_t callback, int register_id);
108108
vfs_node_t vfs_child_append(vfs_node_t parent, const char *name, void *handle);
109109
vfs_node_t vfs_node_alloc(vfs_node_t parent, const char *name);
110110
errno_t vfs_close(vfs_node_t node);

module/extfs/ext.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int ext_mkdir(void *parent, const char *name, vfs_node_t node) {
306306
return ret;
307307
}
308308

309-
int ext_delete(void *parent, vfs_node_t node) {
309+
errno_t ext_delete(void *parent, vfs_node_t node) {
310310
spin_lock(rwlock);
311311

312312
char *path = vfs_get_fullpath(node);
@@ -366,7 +366,7 @@ static struct vfs_callback callbacks = {
366366
.mkfile = ext_mkfile,
367367
.link = ext_link,
368368
.symlink = ext_symlink,
369-
.delete = (vfs_del_t)ext_delete,
369+
.delete = ext_delete,
370370
.rename = (vfs_rename_t)ext_rename,
371371
.map = (vfs_mapfile_t)ext_map,
372372
.stat = ext_stat,
@@ -376,7 +376,7 @@ static struct vfs_callback callbacks = {
376376
};
377377

378378
__attribute__((used)) __attribute__((visibility("default"))) int dlmain(void) {
379-
ext_fsid = vfs_regist("extfs", &callbacks);
379+
ext_fsid = vfs_regist("extfs", &callbacks, 0);
380380
if (ext_fsid == -1) {
381381
printk("Cannot register extfs file system.\n");
382382
return -EFAULT;

src/x86_64/boot/limine_req.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ LIMINE_REQUEST struct limine_rsdp_request rsdp_request = {.id = LIMINE_RSDP_REQU
4646
LIMINE_REQUEST struct limine_framebuffer_request framebuffer_request = {
4747
.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0};
4848

49+
LIMINE_REQUEST struct limine_executable_cmdline_request cmdline_request = {
50+
.id = LIMINE_EXECUTABLE_CMDLINE_REQUEST,
51+
};
52+
53+
char *get_kernel_cmdline() {
54+
return cmdline_request.response->cmdline;
55+
}
56+
4957
const char *get_bootloader_name() {
5058
struct limine_bootloader_info_response *limine_bootloader_request = info_request.response;
5159

src/x86_64/driver/pty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ static struct vfs_callback pts_callbacks = {
519519
};
520520

521521
static void setup_ptmx_device() {
522-
ptmx_fsid = vfs_regist("ptyfs_master", &ptmx_callbacks);
523-
pts_fsid = vfs_regist("ptyfs_slave", &pts_callbacks);
522+
ptmx_fsid = vfs_regist("ptyfs_master", &ptmx_callbacks, 0);
523+
pts_fsid = vfs_regist("ptyfs_slave", &pts_callbacks, 0);
524524
ptmx_list_head = malloc(sizeof(struct llist_header));
525525
llist_init_head(ptmx_list_head);
526526
if (ptmx_fsid == VFS_STATUS_FAILED) {

src/x86_64/fs/cpio/cpfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void cpfs_open(void *parent, const char *name, vfs_node_t node) {
3636
node->handle = pos;
3737
node->fsid = cpfs_id;
3838
node->type = pos->is_dir ? file_dir : file_none;
39+
node->size = pos->is_dir ? 0 : pos->size;
3940
if (pos->is_symlink) node->type |= file_symlink;
4041
node->refcount = 1;
4142
return;
@@ -220,5 +221,5 @@ static struct vfs_callback cpfs_callbacks = {
220221
};
221222

222223
void cpfs_setup() {
223-
cpfs_id = vfs_regist("cpfs", &cpfs_callbacks);
224+
cpfs_id = vfs_regist("cpfs", &cpfs_callbacks, CPFS_REGISTER_ID);
224225
}

src/x86_64/fs/devfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static struct vfs_callback devfs_callbacks = {
210210
};
211211

212212
void devfs_setup() {
213-
devfs_id = vfs_regist("devfs", &devfs_callbacks);
213+
devfs_id = vfs_regist("devfs", &devfs_callbacks, DEVFS_REGISTER_ID);
214214
vfs_mkdir("/dev");
215215
vfs_node_t dev = vfs_open("/dev");
216216
if (dev == NULL) {

src/x86_64/fs/fatfs/fatfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,6 @@ static struct vfs_callback fatfs_callbacks = {
333333
};
334334

335335
void fatfs_init() {
336-
fatfs_id = vfs_regist("fatfs", &fatfs_callbacks);
336+
fatfs_id = vfs_regist("fatfs", &fatfs_callbacks, 0);
337337
if (fatfs_id == VFS_STATUS_FAILED) { kerror("Failed to register fat filesystem\n"); }
338338
}

src/x86_64/fs/iso9660.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ void iso9660_open(void *parent, const char *name, vfs_node_t node) {
328328
l9660_dir *c_dir = (l9660_dir *)malloc(sizeof(l9660_dir));
329329
l9660_file *c_file = (l9660_file *)malloc(sizeof(l9660_file));
330330
l9660_status status;
331-
file_t new = (file_t)malloc(sizeof(struct file));
332-
status = l9660_openat(c_file, p_dir, name);
331+
file_t new = (file_t)malloc(sizeof(struct file));
332+
status = l9660_openat(c_file, p_dir, name);
333333

334334
if (status != L9660_OK) {
335335
status = l9660_opendirat(c_dir, p_dir, name);
@@ -427,5 +427,5 @@ static struct vfs_callback iso_callbacks = {
427427
};
428428

429429
void iso9660_regist() {
430-
iso9660_id = vfs_regist("iso9660", &iso_callbacks);
430+
iso9660_id = vfs_regist("iso9660", &iso_callbacks, 0);
431431
}

src/x86_64/fs/modfs.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ static int modfs_mount(const char *handle, vfs_node_t node) {
3030
}
3131
node->fsid = modfs_id;
3232
modfs_root = node;
33+
for (int i = 0; i < module_count; i++) {
34+
vfs_child_append(modfs_root, module_ls[i].module_name, NULL);
35+
rbtree_sp_insert(mod_rbtree, module_ls[i].module_name, (void *)&module_ls[i]);
36+
}
3337
return VFS_STATUS_SUCCESS;
3438
}
3539

@@ -56,7 +60,7 @@ static size_t modfs_read(void *file, void *addr, size_t offset, size_t size) {
5660
cp_module_t *mod = (cp_module_t *)file;
5761
if (offset > mod->size) { return VFS_STATUS_FAILED; }
5862
void *buffer = mod->data + offset;
59-
memcpy(addr, buffer, (mod->size - offset) > size ? size : mod->size - offset);
63+
memcpy(addr, buffer, (size + offset) > mod->size ? size : mod->size - offset);
6064
return size;
6165
}
6266

@@ -103,20 +107,5 @@ static struct vfs_callback modfs_callbacks = {
103107
};
104108

105109
void modfs_setup() {
106-
modfs_id = vfs_regist("modfs", &modfs_callbacks);
107-
vfs_mkdir("/mod");
108-
vfs_node_t mod = vfs_open("/mod");
109-
if (mod == NULL) {
110-
kerror("'mod' handle is null.");
111-
return;
112-
}
113-
if (vfs_mount((const char *)MODFS_REGISTER_ID, mod) == VFS_STATUS_FAILED) {
114-
kerror("Cannot mount module file system.");
115-
return;
116-
}
117-
118-
for (int i = 0; i < module_count; i++) {
119-
vfs_child_append(modfs_root, module_ls[i].module_name, NULL);
120-
rbtree_sp_insert(mod_rbtree, module_ls[i].module_name, (void *)&module_ls[i]);
121-
}
110+
modfs_id = vfs_regist("modfs", &modfs_callbacks, MODFS_REGISTER_ID);
122111
}

0 commit comments

Comments
 (0)