1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

Kernel: Some improvements to the mount syscall

- You must now have superuser privileges to use mount().
- We now verify that the mount point is a valid path first, before
  trying to find a filesystem on the specified device.
- Convert some dbgprintf() to dbg().
This commit is contained in:
Andreas Kling 2019-08-02 19:03:50 +02:00
parent c76668644b
commit 31de5dee26
3 changed files with 33 additions and 19 deletions

View file

@ -2729,16 +2729,26 @@ int Process::sys$reboot()
int Process::sys$mount(const char* device, const char* mountpoint)
{
dbgprintf("mount: device = %s mountpoint = %s\n", device, mountpoint);
if (!is_superuser())
return -EPERM;
if (!validate_read_str(device) || !validate_read_str(mountpoint))
return -EFAULT;
dbg() << "mount: device " << device << " @ " << mountpoint;
auto custody_or_error = VFS::the().resolve_path(mountpoint, current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
auto& mountpoint_custody = custody_or_error.value();
// Let's do a stat to get some information about the device..
// Let's use lstat so we can convert devname into a major/minor device pair!
struct stat st;
int rc = sys$stat(device, &st);
if (rc < 0) {
dbgprintf("mount: call to sys$stat failed!\n");
dbg() << "mount: call to sys$stat failed!";
return -ENODEV;
}
@ -2748,7 +2758,7 @@ int Process::sys$mount(const char* device, const char* mountpoint)
auto* dev = VFS::the().get_device(major, minor);
auto* disk_device = static_cast<DiskDevice*>(dev);
dbgprintf("mount: attempting to mount %d,%d to %s...\n", major, minor, mountpoint);
dbg() << "mount: attempting to mount device (" << major << "," << minor << ") on " << mountpoint;
// Do a quick check to make sure we're not passing nullptr to Ext2FS::create!
if (dev == nullptr)
@ -2757,15 +2767,14 @@ int Process::sys$mount(const char* device, const char* mountpoint)
// We currently only support ext2. Sorry :^)
auto ext2fs = Ext2FS::create(*disk_device);
if (!ext2fs->initialize()) {
dbgprintf("mount: failed to create ext2fs!\n");
dbg() << "mount: could not find ext2 filesystem on " << device;
return -ENODEV; // Hmmm, this doesn't seem quite right....
}
// Let's mount the volume now
VFS::the().mount(ext2fs, mountpoint);
dbgprintf("mount: successfully mounted ext2 volume on %s to %s!\n", device, mountpoint);
return ESUCCESS;
auto result = VFS::the().mount(ext2fs, mountpoint_custody);
dbg() << "mount: successfully mounted " << device << " on " << mountpoint;
return result;
}
ProcessTracer& Process::ensure_tracer()