From 8d6b92a2dc30ef734e9e1b86d1192d74c31b854c Mon Sep 17 00:00:00 2001 From: Steven Kang Date: Sat, 12 Aug 2023 18:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20umount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fs/fsyscall.c | 19 ++++++++++++++++++- src/kernel/ramdisk.c | 1 + src/kernel/test.c | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/fs/fsyscall.c b/src/fs/fsyscall.c index c3363861..3103363e 100644 --- a/src/fs/fsyscall.c +++ b/src/fs/fsyscall.c @@ -638,12 +638,14 @@ int sys_umount(char *target) goto rollback; } + // 如果传入不是块设备文件,而且不是设备根目录 if (!ISBLK(inode->mode) && (inode->super->iroot != inode)) { ret = -ENOTBLK; goto rollback; } + // 系统根目录不允许释放 if (inode == get_root_inode()) { ret = -EBUSY; @@ -669,6 +671,19 @@ int sys_umount(char *target) LOGK("warning super block mount = 0\n"); } + // 根目录引用还有其他人使用根目录 + if (super->iroot->count > 2) + { + ret = -EBUSY; + goto rollback; + } + + if (super->iroot->count == 2 && inode->super->iroot != inode) + { + ret = -EBUSY; + goto rollback; + } + if (list_size(&super->inode_list) > 1) { ret = -EBUSY; @@ -681,11 +696,13 @@ int sys_umount(char *target) super->imount->mount = 0; iput(super->imount); super->imount = NULL; + super->count--; + assert(super->count == 1); ret = EOK; rollback: - put_super(super); iput(inode); + put_super(super); return ret; } diff --git a/src/kernel/ramdisk.c b/src/kernel/ramdisk.c index 580100c6..de2b6dcd 100644 --- a/src/kernel/ramdisk.c +++ b/src/kernel/ramdisk.c @@ -66,6 +66,7 @@ void ramdisk_init() ramdisk_t *ramdisk = &ramdisks[i]; ramdisk->start = (u8 *)(KERNEL_RAMDISK_MEM + size * i); ramdisk->size = size; + memset(ramdisk->start, 0, ramdisk->size); sprintf(name, "md%c", i + 'a'); device_install(DEV_BLOCK, DEV_RAMDISK, ramdisk, name, 0, ramdisk_ioctl, ramdisk_read, ramdisk_write); diff --git a/src/kernel/test.c b/src/kernel/test.c index aab489db..7a567e42 100644 --- a/src/kernel/test.c +++ b/src/kernel/test.c @@ -131,7 +131,7 @@ err_t sys_test() { // test_sendrecv(); // test_connect(); - test_server(); + // test_server(); return EOK; }