mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
mount: Separate mounting by line into a new function
This commit is contained in:
parent
6453f74642
commit
e04155475d
1 changed files with 37 additions and 31 deletions
|
@ -64,26 +64,16 @@ static int get_source_fd(StringView source)
|
|||
return fd_or_error.release_value();
|
||||
}
|
||||
|
||||
static ErrorOr<void> mount_all()
|
||||
static bool mount_by_line(String const& line)
|
||||
{
|
||||
// Mount all filesystems listed in /etc/fstab.
|
||||
dbgln("Mounting all filesystems...");
|
||||
|
||||
auto fstab = TRY(Core::File::open("/etc/fstab", Core::OpenMode::ReadOnly));
|
||||
|
||||
bool all_ok = true;
|
||||
while (fstab->can_read_line()) {
|
||||
auto line = fstab->read_line();
|
||||
|
||||
// Skip comments and blank lines.
|
||||
if (line.is_empty() || line.starts_with("#"))
|
||||
continue;
|
||||
return true;
|
||||
|
||||
Vector<String> parts = line.split('\t');
|
||||
if (parts.size() < 3) {
|
||||
warnln("Invalid fstab entry: {}", line);
|
||||
all_ok = false;
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mountpoint = parts[1];
|
||||
|
@ -92,7 +82,7 @@ static ErrorOr<void> mount_all()
|
|||
|
||||
if (mountpoint == "/") {
|
||||
dbgln("Skipping mounting root");
|
||||
continue;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto filename = parts[0];
|
||||
|
@ -104,9 +94,25 @@ static ErrorOr<void> mount_all()
|
|||
auto error_or_void = Core::System::mount(fd, mountpoint, fstype, flags);
|
||||
if (error_or_void.is_error()) {
|
||||
warnln("Failed to mount {} (FD: {}) ({}) on {}: {}", filename, fd, fstype, mountpoint, strerror(errno));
|
||||
all_ok = false;
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static ErrorOr<void> mount_all()
|
||||
{
|
||||
// Mount all filesystems listed in /etc/fstab.
|
||||
dbgln("Mounting all filesystems...");
|
||||
|
||||
auto fstab = TRY(Core::File::open("/etc/fstab", Core::OpenMode::ReadOnly));
|
||||
|
||||
bool all_ok = true;
|
||||
while (fstab->can_read_line()) {
|
||||
auto line = fstab->read_line();
|
||||
|
||||
if (!mount_by_line(line))
|
||||
all_ok = false;
|
||||
}
|
||||
|
||||
if (all_ok)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue