mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 23:32:06 +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:
parent
c76668644b
commit
31de5dee26
3 changed files with 33 additions and 19 deletions
|
@ -36,21 +36,25 @@ InodeIdentifier VFS::root_inode_id() const
|
||||||
return m_root_inode->identifier();
|
return m_root_inode->identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
|
KResult VFS::mount(NonnullRefPtr<FS>&& file_system, Custody& mount_point)
|
||||||
|
{
|
||||||
|
auto& inode = mount_point.inode();
|
||||||
|
dbg() << "VFS: Mounting " << file_system->class_name() << " at " << mount_point.absolute_path() << " (inode: " << inode.identifier() << ")";
|
||||||
|
// FIXME: check that this is not already a mount point
|
||||||
|
auto mount = make<Mount>(mount_point, move(file_system));
|
||||||
|
m_mounts.append(move(mount));
|
||||||
|
mount_point.did_mount_on({});
|
||||||
|
return KSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
|
||||||
{
|
{
|
||||||
auto result = resolve_path(path, root_custody());
|
auto result = resolve_path(path, root_custody());
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
dbg() << "VFS: mount can't resolve mount point '" << path << "'";
|
dbg() << "VFS: mount can't resolve mount point '" << path << "'";
|
||||||
return false;
|
return result.error();
|
||||||
}
|
}
|
||||||
auto& inode = result.value()->inode();
|
return mount(move(file_system), result.value());
|
||||||
dbg() << "VFS: Mounting " << file_system->class_name() << " at " << path << " (inode: " << inode.identifier() << ")";
|
|
||||||
// FIXME: check that this is not already a mount point
|
|
||||||
auto mount = make<Mount>(*result.value(), move(file_system));
|
|
||||||
m_mounts.append(move(mount));
|
|
||||||
|
|
||||||
result.value()->did_mount_on({});
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
|
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
|
||||||
|
|
|
@ -57,7 +57,8 @@ public:
|
||||||
~VFS();
|
~VFS();
|
||||||
|
|
||||||
bool mount_root(NonnullRefPtr<FS>&&);
|
bool mount_root(NonnullRefPtr<FS>&&);
|
||||||
bool mount(NonnullRefPtr<FS>&&, StringView path);
|
KResult mount(NonnullRefPtr<FS>&&, StringView path);
|
||||||
|
KResult mount(NonnullRefPtr<FS>&&, Custody& mount_point);
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<FileDescription>> open(RefPtr<Device>&&, int options);
|
KResultOr<NonnullRefPtr<FileDescription>> open(RefPtr<Device>&&, int options);
|
||||||
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
||||||
|
|
|
@ -2729,16 +2729,26 @@ int Process::sys$reboot()
|
||||||
|
|
||||||
int Process::sys$mount(const char* device, const char* mountpoint)
|
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))
|
if (!validate_read_str(device) || !validate_read_str(mountpoint))
|
||||||
return -EFAULT;
|
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 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!
|
// Let's use lstat so we can convert devname into a major/minor device pair!
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int rc = sys$stat(device, &st);
|
int rc = sys$stat(device, &st);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
dbgprintf("mount: call to sys$stat failed!\n");
|
dbg() << "mount: call to sys$stat failed!";
|
||||||
return -ENODEV;
|
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* dev = VFS::the().get_device(major, minor);
|
||||||
auto* disk_device = static_cast<DiskDevice*>(dev);
|
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!
|
// Do a quick check to make sure we're not passing nullptr to Ext2FS::create!
|
||||||
if (dev == nullptr)
|
if (dev == nullptr)
|
||||||
|
@ -2757,15 +2767,14 @@ int Process::sys$mount(const char* device, const char* mountpoint)
|
||||||
// We currently only support ext2. Sorry :^)
|
// We currently only support ext2. Sorry :^)
|
||||||
auto ext2fs = Ext2FS::create(*disk_device);
|
auto ext2fs = Ext2FS::create(*disk_device);
|
||||||
if (!ext2fs->initialize()) {
|
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....
|
return -ENODEV; // Hmmm, this doesn't seem quite right....
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's mount the volume now
|
// Let's mount the volume now
|
||||||
VFS::the().mount(ext2fs, mountpoint);
|
auto result = VFS::the().mount(ext2fs, mountpoint_custody);
|
||||||
dbgprintf("mount: successfully mounted ext2 volume on %s to %s!\n", device, mountpoint);
|
dbg() << "mount: successfully mounted " << device << " on " << mountpoint;
|
||||||
|
return result;
|
||||||
return ESUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessTracer& Process::ensure_tracer()
|
ProcessTracer& Process::ensure_tracer()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue