]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
vfs: implement cwd busy check via mount refcount
authorTulio A M Mendes <[email protected]>
Tue, 26 May 2026 03:08:21 +0000 (00:08 -0300)
committerTulio A M Mendes <[email protected]>
Wed, 3 Jun 2026 04:02:35 +0000 (01:02 -0300)
commit3492da2b0609781e878cc6e96f922a98f8e902ad
treecb3b0e57208eb2dba418bd2acafd50e977c3975b
parent62a90ada9646dd30c3e306d66e5e7a48010ac302
vfs: implement cwd busy check via mount refcount

Implemented mount refcount-based busy check for umount to prevent
filesystem unmount when processes have cwd inside the mount.

Implementation uses mount refcount approach (same as Linux/BSD):
- Added vfs_mount_ref_by_path() and vfs_mount_unref_by_path()
- Functions use longest prefix match to find most specific mount
- chdir() updates refcounts (unref old cwd, ref new cwd)
- Process creation increments refcount for initial cwd
- Process exit decrements refcount for cwd
- vfs_umount_nolock() rejects if refcount > 0

This approach is O(1) for the check, avoids storing root as path
string (which caused struct alignment issues), and matches how
commercial OSes handle mount busy detection.

Test I20 (umount cwd) validates the implementation:
- Mounts tmpfs to /tmp/mnt_cwd
- Changes cwd into mount
- Verifies umount fails with -EBUSY
- Changes cwd back to /
- Verifies umount succeeds

Test results: 124/124 PASS
include/fs.h
src/kernel/fs.c
src/kernel/scheduler.c
src/kernel/syscall.c