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

Kernel: Fixed fdc read/write problem

Fixed an issue with operator precedence in calls to `send_byte()`, in
which a value of `1` was being sent to the function. This had the
nasty side-effect of selecting the slave drive if the value of
`head` was equal to one. A read/write would fail in the case, as
it would attempt to read from the slave drive (not good).

I've also added a seek to the top of the read/write code, which seems
to have fixed an issue with Linux not detecting the disk images after
they have been unmounted from Serenity. This isn't specified in the
datasheet, but a few other drivers have it so we should too :^)
This commit is contained in:
Jesse Buhagiar 2019-10-21 01:04:08 +11:00 committed by Andreas Kling
parent 98c86e5109
commit c12d153894
2 changed files with 49 additions and 17 deletions

View file

@ -101,7 +101,7 @@ class FloppyDiskDevice final : public IRQHandler
AK_MAKE_ETERNAL
static constexpr u8 SECTORS_PER_CYLINDER = 18;
static constexpr u8 CCYLINDERS_PER_HEAD = 80;
static constexpr u8 CYLINDERS_PER_HEAD = 80;
static constexpr u16 BYTES_PER_SECTOR = 512;
public:
@ -158,9 +158,9 @@ private:
virtual const char* class_name() const override;
// Helper functions
inline u16 lba2cylinder(u16 lba) const { return lba / (2 * SECTORS_PER_CYLINDER); } // Convert an LBA into a cylinder value
inline u16 lba2head(u16 lba) const { return ((lba / SECTORS_PER_CYLINDER) % 2); } // Convert an LBA into a head value
inline u16 lba2sector(u16 lba) const { return ((lba % SECTORS_PER_CYLINDER) + 1); } // Convert an LBA into a sector value
inline u16 lba2head(u16 lba) const { return (lba % (SECTORS_PER_CYLINDER * 2)) / SECTORS_PER_CYLINDER; } // Convert an LBA into a head value
inline u16 lba2cylinder(u16 lba) const { return lba / (2 * SECTORS_PER_CYLINDER); } // Convert an LBA into a cylinder value
inline u16 lba2sector(u16 lba) const { return ((lba % SECTORS_PER_CYLINDER) + 1); } // Convert an LBA into a sector value
void initialize();
bool read_sectors_with_dma(u16, u16, u8*);