1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:27:35 +00:00

Kernel: mount system call (#396)

It is now possible to mount ext2 `DiskDevice` devices under Serenity on
any folder in the root filesystem. Currently any user can do this with
any permissions. There's a fair amount of assumptions made here too,
that might not be too good, but can be worked on in the future. This is
a good start to allow more dynamic operation under the OS itself.

It is also currently impossible to unmount and such, and devices will
fail to mount in Linux as the FS 'needs to be cleaned'. I'll work on
getting `umount` done ASAP to rectify this (as well as working on less
assumption-making in the mount syscall. We don't want to just be able
to mount DiskDevices!). This could probably be fixed with some `-t`
flag or something similar.
This commit is contained in:
Jesse 2019-08-02 23:18:47 +10:00 committed by Andreas Kling
parent 3f91d2d0cc
commit 401c87a0cc
17 changed files with 123 additions and 14 deletions

View file

@ -25,6 +25,7 @@ public:
uid_t gid() const { return m_gid; }
virtual bool is_device() const override { return true; }
virtual bool is_disk_device() const { return false; }
protected:
Device(unsigned major, unsigned minor);

View file

@ -1,6 +1,7 @@
#include <Kernel/Devices/DiskDevice.h>
DiskDevice::DiskDevice()
DiskDevice::DiskDevice(int major, int minor)
: BlockDevice(major, minor)
{
}

View file

@ -2,11 +2,12 @@
#include <AK/RefCounted.h>
#include <AK/Types.h>
#include <Kernel/Devices/BlockDevice.h>
// FIXME: Support 64-bit DiskOffset
typedef u32 DiskOffset;
class DiskDevice : public RefCounted<DiskDevice> {
class DiskDevice : public BlockDevice {
public:
virtual ~DiskDevice();
@ -20,6 +21,8 @@ public:
virtual bool read_blocks(unsigned index, u16 count, u8*) = 0;
virtual bool write_blocks(unsigned index, u16 count, const u8*) = 0;
virtual bool is_disk_device() const override { return true; };
protected:
DiskDevice();
DiskDevice(int major, int minor);
};

View file

@ -8,7 +8,8 @@ NonnullRefPtr<DiskPartition> DiskPartition::create(NonnullRefPtr<DiskDevice> dev
}
DiskPartition::DiskPartition(NonnullRefPtr<DiskDevice> device, unsigned block_offset)
: m_device(move(device))
: DiskDevice(100, 0)
, m_device(move(device))
, m_block_offset(block_offset)
{
}

View file

@ -14,6 +14,12 @@ public:
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
// ^BlockDevice
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; }
virtual bool can_read(FileDescription&) const override { return true; }
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; }
virtual bool can_write(FileDescription&) const override { return true; }
private:
virtual const char* class_name() const override;

View file

@ -84,6 +84,7 @@ const char* FloppyDiskDevice::class_name() const
FloppyDiskDevice::FloppyDiskDevice(FloppyDiskDevice::DriveType type)
: IRQHandler(IRQ_FLOPPY_DRIVE)
, DiskDevice(89, (type == FloppyDiskDevice::DriveType::Master) ? 0 : 1)
, m_io_base_addr((type == FloppyDiskDevice::DriveType::Master) ? 0x3F0 : 0x370)
{
initialize();

View file

@ -132,7 +132,7 @@ private:
};
public:
static NonnullRefPtr<FloppyDiskDevice> create(DriveType type);
static NonnullRefPtr<FloppyDiskDevice> create(DriveType);
virtual ~FloppyDiskDevice() override;
// ^DiskDevice
@ -142,6 +142,12 @@ public:
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
// ^BlockDevice
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; }
virtual bool can_read(FileDescription&) const override { return true; }
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; }
virtual bool can_write(FileDescription&) const override { return true; }
protected:
explicit FloppyDiskDevice(DriveType);

View file

@ -236,11 +236,12 @@ void PATAChannel::detect_disks()
heads,
spt);
int major = (m_channel_number == 0) ? 3 : 4;
if (i == 0) {
m_master = PATADiskDevice::create(*this, PATADiskDevice::DriveType::Master);
m_master = PATADiskDevice::create(*this, PATADiskDevice::DriveType::Master, major, 0);
m_master->set_drive_geometry(cyls, heads, spt);
} else {
m_slave = PATADiskDevice::create(*this, PATADiskDevice::DriveType::Slave);
m_slave = PATADiskDevice::create(*this, PATADiskDevice::DriveType::Slave, major, 1);
m_slave->set_drive_geometry(cyls, heads, spt);
}
}

View file

@ -78,13 +78,14 @@
#define ATA_REG_ALTSTATUS 0x0C
#define ATA_REG_DEVADDRESS 0x0D
NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(PATAChannel& channel, DriveType type)
NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(PATAChannel& channel, DriveType type, int major, int minor)
{
return adopt(*new PATADiskDevice(channel, type));
return adopt(*new PATADiskDevice(channel, type, major, minor));
}
PATADiskDevice::PATADiskDevice(PATAChannel& channel, DriveType type)
: m_drive_type(type)
PATADiskDevice::PATADiskDevice(PATAChannel& channel, DriveType type, int major, int minor)
: DiskDevice(major, minor)
, m_drive_type(type)
, m_channel(channel)
{
}

View file

@ -26,7 +26,7 @@ public:
};
public:
static NonnullRefPtr<PATADiskDevice> create(PATAChannel&, DriveType);
static NonnullRefPtr<PATADiskDevice> create(PATAChannel&, DriveType, int major, int minor);
virtual ~PATADiskDevice() override;
// ^DiskDevice
@ -38,8 +38,14 @@ public:
void set_drive_geometry(u16, u16, u16);
// ^BlockDevice
virtual ssize_t read(FileDescription&, u8*, ssize_t) override { return 0; }
virtual bool can_read(FileDescription&) const override { return true; }
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override { return 0; }
virtual bool can_write(FileDescription&) const override { return true; }
protected:
explicit PATADiskDevice(PATAChannel&, DriveType);
explicit PATADiskDevice(PATAChannel&, DriveType, int, int);
private:
// ^DiskDevice