mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
a3a2226bb5
Read operations are enabled by default, but you must set DISKWRITE=1 in makeflags before write operations are permitted. This protects against accidentally corrupting the existing filesystems on the system.
88 lines
2 KiB
C++
88 lines
2 KiB
C++
/******************************************************************************
|
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
|
|
|
This file is part of Sortix.
|
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
terms of the GNU General Public License as published by the Free Software
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
version.
|
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with Sortix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
ata.cpp
|
|
Allowes access to block devices over ATA PIO.
|
|
|
|
******************************************************************************/
|
|
|
|
#ifndef SORTIX_ATA_H
|
|
#define SORTIX_ATA_H
|
|
|
|
namespace Sortix
|
|
{
|
|
class ATABus;
|
|
class ATADrive;
|
|
|
|
class ATABus
|
|
{
|
|
public:
|
|
ATABus(uint16_t portoffset, uint16_t altport);
|
|
~ATABus();
|
|
|
|
public:
|
|
ATADrive* Instatiate(unsigned driveid);
|
|
bool SelectDrive(unsigned driveid);
|
|
|
|
private:
|
|
unsigned curdriveid;
|
|
uint16_t iobase;
|
|
uint16_t altport;
|
|
|
|
};
|
|
|
|
class ATADrive
|
|
{
|
|
public:
|
|
off_t GetSectorSize();
|
|
off_t GetNumSectors();
|
|
off_t GetSize() { return GetSectorSize() * GetNumSectors(); }
|
|
bool ReadSector(off_t sector, uint8_t* dest);
|
|
bool WriteSector(off_t sector, const uint8_t* src);
|
|
size_t Read(off_t byteoffset, uint8_t* dest, size_t numbytes);
|
|
size_t Write(off_t byteoffset, const uint8_t* src, size_t numbytes);
|
|
|
|
public:
|
|
ATADrive(ATABus* bus, unsigned driveid, uint16_t portoffset, uint16_t altport);
|
|
~ATADrive();
|
|
|
|
private:
|
|
void Initialize();
|
|
bool PrepareIO(bool write, off_t sector);
|
|
|
|
private:
|
|
unsigned driveid;
|
|
uint16_t meta[256];
|
|
uint16_t iobase;
|
|
uint16_t altport;
|
|
ATABus* bus;
|
|
bool lba48;
|
|
size_t sectorsize;
|
|
off_t numsectors;
|
|
|
|
};
|
|
|
|
namespace ATA
|
|
{
|
|
void Init();
|
|
ATABus* CreateBus(uint16_t portoffset, uint16_t altport);
|
|
}
|
|
}
|
|
|
|
#endif
|