int read(u64 fd, u64 buf, u64 off, u64 len) { u64 j=0; off = off>>9; len = (len+0x1ff)>>9; while(len>0x80) { //0x80sectors=0x10000=64KB ahciread(0, buf+j*0x10000, off+j*0x80, 0x80); j++; len -= 0x80; } ahciread(0, buf+j*0x10000, off+j*0x80, len); return len; }
// addr - destination // count - bytes to read // offset - start byte (offset from start of disk) void readbytes(uchar *addr, ulong count, ulong offset) { uchar *eaddr; uint lba; eaddr = addr + count; addr -= offset % SECTSIZE; lba = offset/SECTSIZE; for (; addr < eaddr; addr += SECTSIZE, lba++) { if (has_ahci) { ahciread(addr, lba, 1); } else { ideread(addr, lba, 1); } } }