From: Tulio A M Mendes Date: Tue, 26 May 2026 02:20:43 +0000 (-0300) Subject: vfs: add cwd check to umount to prevent filesystem in use X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=f2973bc857311d667f3cfd3e41e93726cef3387a;p=AdrOS.git vfs: add cwd check to umount to prevent filesystem in use Added busy check in vfs_umount_nolock to reject unmount if any process has its current working directory (cwd) within the mount being unmounted. Implementation details: - Iterates over ready_queue_head under sched_lock - Uses path_is_mountpoint_prefix to check if cwd is within mount - Returns -EBUSY if any process has cwd in the mount - Note: root directory check not implemented (root not stored as path in process struct) This prevents crashes when processes attempt to access files after their cwd filesystem has been unmounted. Test results: - Smoke test: 123/123 PASS - Zero regressions --- diff --git a/src/kernel/fs.c b/src/kernel/fs.c index e75db37a..493d4679 100644 --- a/src/kernel/fs.c +++ b/src/kernel/fs.c @@ -180,6 +180,26 @@ int vfs_umount_nolock(const char* mountpoint) { } } + /* Busy check: reject if any process has cwd or root in this mount */ + extern struct process* ready_queue_head; + extern spinlock_t sched_lock; + + uintptr_t sched_fl = spin_lock_irqsave(&sched_lock); + struct process* p = ready_queue_head; + while (p) { + /* Check if cwd is within this mount */ + if (p->cwd[0] && path_is_mountpoint_prefix(mp, p->cwd)) { + spin_unlock_irqrestore(&sched_lock, sched_fl); + return -EBUSY; + } + /* Check if root is within this mount (if different from cwd) */ + /* Note: root is not stored as a path in current process struct, + * so we only check cwd for now. A full implementation would require + * storing root as a path or implementing vfs_getpath. */ + p = p->rq_next; + } + spin_unlock_irqrestore(&sched_lock, sched_fl); + /* Release the block device */ if (g_mounts[idx].bdev) { blockdev_release(g_mounts[idx].bdev);