mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-24 04:04:49 -04:00
Cleanup
This commit is contained in:
parent
225ae71b9e
commit
d2ee3b1c6d
@ -30,8 +30,8 @@ void detect_disks();
|
|||||||
uint8_t number_of_disks();
|
uint8_t number_of_disks();
|
||||||
drive_descriptor& drive(uint8_t disk);
|
drive_descriptor& drive(uint8_t disk);
|
||||||
|
|
||||||
bool read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination);
|
size_t read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination, size_t& read);
|
||||||
bool write_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* source);
|
size_t write_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, const void* source, size_t& written);
|
||||||
|
|
||||||
struct ata_driver : devfs::dev_driver {
|
struct ata_driver : devfs::dev_driver {
|
||||||
size_t read(void* data, char* buffer, size_t count, size_t offset, size_t& read);
|
size_t read(void* data, char* buffer, size_t count, size_t offset, size_t& read);
|
||||||
|
@ -43,9 +43,6 @@ void detect_disks();
|
|||||||
disk_descriptor& disk_by_index(uint64_t index);
|
disk_descriptor& disk_by_index(uint64_t index);
|
||||||
disk_descriptor& disk_by_uuid(uint64_t uuid);
|
disk_descriptor& disk_by_uuid(uint64_t uuid);
|
||||||
|
|
||||||
//bool read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination);
|
|
||||||
//bool write_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination);
|
|
||||||
|
|
||||||
std::unique_heap_array<partition_descriptor> partitions(disk_descriptor& disk);
|
std::unique_heap_array<partition_descriptor> partitions(disk_descriptor& disk);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -372,18 +372,7 @@ size_t ata::ata_driver::read(void* data, char* destination, size_t count, size_t
|
|||||||
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
||||||
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
||||||
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(destination);
|
return ata::read_sectors(*disk, start, sectors, destination, read);
|
||||||
|
|
||||||
for(size_t i = 0; i < sectors; ++i){
|
|
||||||
if(!read_write_sector(*disk, start + i, buffer, true)){
|
|
||||||
return std::ERROR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += BLOCK_SIZE;
|
|
||||||
read += BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ata::ata_driver::write(void* data, const char* source, size_t count, size_t offset, size_t& written){
|
size_t ata::ata_driver::write(void* data, const char* source, size_t count, size_t offset, size_t& written){
|
||||||
@ -403,18 +392,7 @@ size_t ata::ata_driver::write(void* data, const char* source, size_t count, size
|
|||||||
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
auto descriptor = reinterpret_cast<disks::disk_descriptor*>(data);
|
||||||
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
auto disk = reinterpret_cast<ata::drive_descriptor*>(descriptor->descriptor);
|
||||||
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(const_cast<char*>(source));
|
return ata::write_sectors(*disk, start, sectors, source, written);
|
||||||
|
|
||||||
for(size_t i = 0; i < sectors; ++i){
|
|
||||||
if(!read_write_sector(*disk, start + i, buffer, false)){
|
|
||||||
return std::ERROR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += BLOCK_SIZE;
|
|
||||||
written += BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ata::ata_part_driver::read(void* data, char* destination, size_t count, size_t offset, size_t& read){
|
size_t ata::ata_part_driver::read(void* data, char* destination, size_t count, size_t offset, size_t& read){
|
||||||
@ -437,18 +415,7 @@ size_t ata::ata_part_driver::read(void* data, char* destination, size_t count, s
|
|||||||
|
|
||||||
start += part_descriptor->start;
|
start += part_descriptor->start;
|
||||||
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(destination);
|
return ata::read_sectors(*disk, start, sectors, destination, read);
|
||||||
|
|
||||||
for(size_t i = 0; i < sectors; ++i){
|
|
||||||
if(!read_write_sector(*disk, start + i, buffer, true)){
|
|
||||||
return std::ERROR_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += BLOCK_SIZE;
|
|
||||||
read += BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ata::ata_part_driver::write(void* data, const char* source, size_t count, size_t offset, size_t& written){
|
size_t ata::ata_part_driver::write(void* data, const char* source, size_t count, size_t offset, size_t& written){
|
||||||
@ -471,10 +438,29 @@ size_t ata::ata_part_driver::write(void* data, const char* source, size_t count,
|
|||||||
|
|
||||||
start += part_descriptor->start;
|
start += part_descriptor->start;
|
||||||
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(const_cast<char*>(source));
|
return ata::write_sectors(*disk, start, sectors, source, written);
|
||||||
|
}
|
||||||
|
|
||||||
for(size_t i = 0; i < sectors; ++i){
|
size_t ata::read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination, size_t& read){
|
||||||
if(!read_write_sector(*disk, start + i, buffer, false)){
|
auto buffer = reinterpret_cast<uint8_t*>(destination);
|
||||||
|
|
||||||
|
for(size_t i = 0; i < count; ++i){
|
||||||
|
if(!read_write_sector(drive, start + i, buffer, true)){
|
||||||
|
return std::ERROR_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer += BLOCK_SIZE;
|
||||||
|
read += BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ata::write_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, const void* source, size_t& written){
|
||||||
|
auto buffer = reinterpret_cast<uint8_t*>(const_cast<void*>(source));
|
||||||
|
|
||||||
|
for(size_t i = 0; i < count; ++i){
|
||||||
|
if(!read_write_sector(drive, start + i, buffer, false)){
|
||||||
return std::ERROR_FAILED;
|
return std::ERROR_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,31 +470,3 @@ size_t ata::ata_part_driver::write(void* data, const char* source, size_t count,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ata::read_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* destination){
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(destination);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < count; ++i){
|
|
||||||
if(!read_write_sector(drive, start + i, buffer, true)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += BLOCK_SIZE;;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ata::write_sectors(drive_descriptor& drive, uint64_t start, uint8_t count, void* source){
|
|
||||||
auto buffer = reinterpret_cast<uint8_t*>(source);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < count; ++i){
|
|
||||||
if(!read_write_sector(drive, start + i, buffer, false)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer += BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
@ -104,30 +104,11 @@ disks::disk_descriptor& disks::disk_by_uuid(uint64_t uuid){
|
|||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*bool disks::read_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination){
|
|
||||||
switch(disk.type){
|
|
||||||
case disk_type::ATA:
|
|
||||||
return ata::read_sectors(*static_cast<ata::drive_descriptor*>(disk.descriptor), start, count, destination);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool disks::write_sectors(const disk_descriptor& disk, uint64_t start, uint8_t count, void* destination){
|
|
||||||
switch(disk.type){
|
|
||||||
case disk_type::ATA:
|
|
||||||
return ata::write_sectors(*static_cast<ata::drive_descriptor*>(disk.descriptor), start, count, destination);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
std::unique_heap_array<disks::partition_descriptor> disks::partitions(disk_descriptor& disk){
|
std::unique_heap_array<disks::partition_descriptor> disks::partitions(disk_descriptor& disk){
|
||||||
std::unique_ptr<boot_record_t> boot_record(new boot_record_t());
|
std::unique_ptr<boot_record_t> boot_record(new boot_record_t());
|
||||||
|
|
||||||
if(!ata::read_sectors(*static_cast<ata::drive_descriptor*>(disk.descriptor), 0, 1, boot_record.get())){
|
size_t read;
|
||||||
|
if(ata::read_sectors(*static_cast<ata::drive_descriptor*>(disk.descriptor), 0, 1, boot_record.get(), read) > 0){
|
||||||
k_print_line("Read Boot Record failed");
|
k_print_line("Read Boot Record failed");
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user