diff --git a/Base/usr/share/man/man8/mount.md b/Base/usr/share/man/man8/mount.md index eee65739c6c..5f927df657f 100644 --- a/Base/usr/share/man/man8/mount.md +++ b/Base/usr/share/man/man8/mount.md @@ -16,7 +16,7 @@ If invoked without any arguments, `mount` prints a list of all currently mounted filesystems. If invoked as `mount -a`, `mount` mounts all the filesystems configured in -`/etc/fstab`. This is normally done on system startup by +`/etc/fstab` and `/etc/fstab.d/*`. This is normally done on system startup by [`SystemServer`(7)](help://man/7/SystemServer). Otherwise, `mount` performs a single filesystem mount. Source should be a path @@ -36,6 +36,7 @@ Additionally, the name `defaults` is accepted and ignored. ## Files * `/etc/fstab` - read by `mount -a` on startup to find out which filesystems to mount. +* `/etc/fstab.d` - directory with drop-in additions to the normal `fstab` file, also read by `mount -a`. * `/proc/df` - read by `mount` to get information about mounted filesystems. ## Examples diff --git a/Userland/Utilities/mount.cpp b/Userland/Utilities/mount.cpp index efba1de970b..8479d7b5fb0 100644 --- a/Userland/Utilities/mount.cpp +++ b/Userland/Utilities/mount.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -115,6 +116,31 @@ static ErrorOr mount_all() all_ok = false; } + auto fstab_directory_iterator = Core::DirIterator("/etc/fstab.d", Core::DirIterator::SkipDots); + + if (fstab_directory_iterator.has_error() && fstab_directory_iterator.error() != ENOENT) { + dbgln("Failed to open /etc/fstab.d: {}", fstab_directory_iterator.error_string()); + } else if (!fstab_directory_iterator.has_error()) { + while (fstab_directory_iterator.has_next()) { + auto path = fstab_directory_iterator.next_full_path(); + auto file_or_error = Core::File::open(path, Core::OpenMode::ReadOnly); + + if (file_or_error.is_error()) { + dbgln("Failed to open '{}': {}", path, file_or_error.error()); + continue; + } + + auto file = file_or_error.release_value(); + + while (file->can_read_line()) { + auto line = file->read_line(); + + if (!mount_by_line(line)) + all_ok = false; + } + } + } + if (all_ok) return {}; else @@ -174,7 +200,7 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_positional_argument(mountpoint, "Mount point", "mountpoint", Core::ArgsParser::Required::No); args_parser.add_option(fs_type, "File system type", nullptr, 't', "fstype"); args_parser.add_option(options, "Mount options", nullptr, 'o', "options"); - args_parser.add_option(should_mount_all, "Mount all file systems listed in /etc/fstab", nullptr, 'a'); + args_parser.add_option(should_mount_all, "Mount all file systems listed in /etc/fstab and /etc/fstab.d/*", nullptr, 'a'); args_parser.parse(arguments); if (should_mount_all) {