Newer
Older
tree-os / src / kernel / drivers / pci / hardDrive / ata.c
#include <alloc.h>
#include <ata.h>
#include <stdio.h>

void addIdentifyData(HardDrive *hardDrive, AtaIdentifyData *data) {
    hardDrive->model = malloc(41);
    for (int i = 0; i < 40; i += 2) {
        hardDrive->model[i] = data->model[i + 1];
        hardDrive->model[i + 1] = data->model[i];
    }
    hardDrive->model[40] = 0;
    if (data->CommandSetActive.BigLba) {
        hardDrive->sectorCount = *((uint32_t *)data->Max48BitLBA);
    } else {
        hardDrive->sectorCount = data->ObsoleteWord62;
    }
    hardDrive->sectorSize = 512;
    if (data->PhysicalLogicalSectorSize.LogicalSectorLongerThan256Words) {
        hardDrive->sectorSize = ((uint32_t)data->WordsPerLogicalSector[0] |
                                 (uint32_t)data->WordsPerLogicalSector[1] << 16)
                                << 1;
    }
    printf("sector count: %i, sector size: %i\nmodel: %s\n",
           hardDrive->sectorCount, hardDrive->sectorSize, hardDrive->model);
}