Skip to content

Commit

Permalink
🐛 umount
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenBaby committed Aug 12, 2023
1 parent 2955b7d commit 8d6b92a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/fs/fsyscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/kernel/ramdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ err_t sys_test()
{
// test_sendrecv();
// test_connect();
test_server();
// test_server();

return EOK;
}

0 comments on commit 8d6b92a

Please sign in to comment.