1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 22:58:12 +00:00
serenity/Kernel/Devices/PATADiskDevice.h
Jesse 401c87a0cc 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.
2019-08-02 15:18:47 +02:00

68 lines
2.2 KiB
C++

//
// A Disk Device Connected to a PATA Channel
//
//
#pragma once
#include <AK/RefPtr.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/Devices/PATAChannel.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/Lock.h>
#include <Kernel/PCI.h>
#include <Kernel/VM/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h>
class PATADiskDevice final : public DiskDevice {
AK_MAKE_ETERNAL
public:
// Type of drive this IDEDiskDevice is on the ATA channel.
//
// Each PATA channel can contain only two devices, which (I think) are
// jumper selectable on the drive itself by shorting two pins.
enum class DriveType : u8 {
Master,
Slave
};
public:
static NonnullRefPtr<PATADiskDevice> create(PATAChannel&, DriveType, int major, int minor);
virtual ~PATADiskDevice() override;
// ^DiskDevice
virtual unsigned block_size() const override;
virtual bool read_block(unsigned index, u8*) const override;
virtual bool write_block(unsigned index, const u8*) override;
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
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, int, int);
private:
// ^DiskDevice
virtual const char* class_name() const override;
bool wait_for_irq();
bool read_sectors_with_dma(u32 lba, u16 count, u8*);
bool write_sectors_with_dma(u32 lba, u16 count, const u8*);
bool read_sectors(u32 lba, u16 count, u8* buffer);
bool write_sectors(u32 lba, u16 count, const u8* data);
bool is_slave() const;
Lock m_lock { "IDEDiskDevice" };
u16 m_cylinders { 0 };
u16 m_heads { 0 };
u16 m_sectors_per_track { 0 };
DriveType m_drive_type { DriveType::Master };
PATAChannel& m_channel;
};