]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commit
mount/VFS: remove all auto-format paths; add mkfs; fix persistfs and flags
authorTulio A M Mendes <[email protected]>
Wed, 20 May 2026 17:06:48 +0000 (14:06 -0300)
committerTulio A M Mendes <[email protected]>
Wed, 20 May 2026 17:06:48 +0000 (14:06 -0300)
commit69feee53abb461e82669a1736866e772fc6e1a8e
tree4d3f7b57b93cf0ba04f4f96acf394fd7d97d415b
parent321fca7caf016135d6b4b1a7f30534cc4ca8cafa
mount/VFS: remove all auto-format paths; add mkfs; fix persistfs and flags

Patch A (CRITICAL): diskfs_create_root() no longer auto-formats on
missing superblock.  Any error from diskfs_super_load() (ENODEV,
EINVAL, EIO) now returns NULL immediately.  g_ready is only set when
the superblock is valid.  This eliminates all destructive mount paths.

Patch B: Added 'mkfs diskfs /dev/hdX' kconsole command for explicit
diskfs formatting.  Added diskfs_mkfs() public API that wraps
diskfs_format().  This is the ONLY way to create a new diskfs
filesystem.  Battery/smoke tests now pre-format disk images with a
minimal diskfs superblock (magic+version+next_free_lba+root_inode)
at LBA 2 before QEMU launch.

Patch C (CRITICAL): persistfs_create_root() now calls diskfs_probe()
before diskfs_create_root().  If the drive does not contain a valid
diskfs superblock, the diskfs initialization is skipped entirely.
This prevents persistfs from triggering diskfs_format() on a FAT/ext2
disk via the indirect path: boot detects ext2 -> mounts /disk as ext2
-> init_mount_fs(persistfs) -> persistfs_create_root() -> [was]
diskfs_create_root() -> diskfs_format() -> corrupts ext2 superblock.

Patch D: init_mount_fs() now accepts unsigned long flags parameter
and passes it to vfs_mount_full().  sys_mount passes mount_flags
through to init_mount_fs.  Boot-internal callers pass flags=0.
This allows mount -o ro,nodev,noexec to work for disk-based FS.

Patch E: mount CLI improvements — unknown -o options now cause error
exit (not just warning).  Added nosuid, nodev, noexec option parsing.
show_mounts() now returns error code when /proc/mounts is unavailable.

Patch F: Updated all test disk images to use create_diskfs_disk
helper that stamps a minimal diskfs superblock.  Updated Makefile
run/test-gdb targets similarly.  Updated fstab comment.
12 files changed:
Makefile
include/diskfs.h
include/kernel/init.h
rootfs/etc/fstab
src/kernel/diskfs.c
src/kernel/init.c
src/kernel/kconsole.c
src/kernel/persistfs.c
src/kernel/syscall.c
tests/smoke_test.exp
tests/test_battery.exp
user/cmds/mount/mount.c