From: Tulio A M Mendes Date: Tue, 17 Feb 2026 07:47:48 +0000 (-0300) Subject: fix: mount command -t option argument parsing X-Git-Url: https://projects.tadryanom.me/docs/POSIX_ROADMAP.md?a=commitdiff_plain;h=e75c5ebe19660b60fd145d564b798d1f97980c82;p=AdrOS.git fix: mount command -t option argument parsing The mount command parsed device=argv[1] and mountpoint=argv[2] BEFORE scanning for -t, so 'mount -t fat /dev/hdb /test' set device='-t' and mountpoint='fat' instead of the correct values. Rewrote argument parsing to scan for -t first, then collect remaining positional arguments as device and mountpoint. Added usage message for missing arguments. --- diff --git a/user/mount.c b/user/mount.c index 42cb54a..fba0bf5 100644 --- a/user/mount.c +++ b/user/mount.c @@ -22,22 +22,32 @@ static void show_mounts(void) { } int main(int argc, char** argv) { - if (argc < 3) { + if (argc < 2) { show_mounts(); return 0; } - const char* device = argv[1]; - const char* mountpoint = argv[2]; const char* fstype = "diskfs"; + const char* device = NULL; + const char* mountpoint = NULL; - /* Parse -t fstype option */ - for (int i = 1; i < argc - 2; i++) { + /* Parse options first, then collect positional args */ + int i; + for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-t") == 0 && i + 1 < argc) { fstype = argv[++i]; + } else if (!device) { + device = argv[i]; + } else if (!mountpoint) { + mountpoint = argv[i]; } } + if (!device || !mountpoint) { + fprintf(stderr, "usage: mount [-t fstype] device mountpoint\n"); + return 1; + } + int rc = __syscall_ret(_syscall3(SYS_MOUNT, (int)device, (int)mountpoint, (int)fstype)); if (rc < 0) { fprintf(stderr, "mount: mounting %s on %s failed: %d\n", device, mountpoint, rc);