| 189 | } |
| 190 | |
| 191 | int Port::ReadDiskBlock(uint64_t lba, uint32_t count, void* _buffer){ |
| 192 | uint64_t blockCount = ((count + (blocksize - 1)) / blocksize); |
| 193 | uint8_t* buffer = reinterpret_cast<uint8_t*>(_buffer); |
| 194 | |
| 195 | //Log::Info("LBA: %x, count: %u, blcount: %u", lba, count, blockCount); |
| 196 | |
| 197 | unsigned buf = AcquireBuffer(); |
| 198 | if(buf >= 8){ |
| 199 | return 4; // Should not happen |
| 200 | } |
| 201 | |
| 202 | while(blockCount >= 8 && count){ |
| 203 | int size = 512 * 8; |
| 204 | if(size > count) size = count; |
| 205 | |
| 206 | if(!size) break; |
| 207 | |
| 208 | if(Access(lba, 8, physBuffers[buf], 0)){ // LBA, 8 blocks, read |
| 209 | return 1; // Error Reading Sectors |
| 210 | } |
| 211 | |
| 212 | memcpy(buffer, buffers[buf], size); |
| 213 | |
| 214 | buffer += size; |
| 215 | lba += 8; |
| 216 | blockCount -= 8; |
| 217 | count -= size; |
| 218 | } |
| 219 | |
| 220 | while(blockCount >= 2 && count){ |
| 221 | int size = 512 << 1; |
| 222 | if(size > count) size = count; |
| 223 | |
| 224 | if(!size) break; |
| 225 | |
| 226 | if(Access(lba, 2, physBuffers[buf], 0)){ // LBA, 2 blocks, read |
| 227 | ReleaseBuffer(buf); |
| 228 | return 1; // Error Reading Sectors |
| 229 | } |
| 230 | |
| 231 | memcpy(buffer, buffers[buf], size); |
| 232 | |
| 233 | buffer += size; |
| 234 | lba += 2; |
| 235 | blockCount -= 2; |
| 236 | count -= size; |
| 237 | } |
| 238 | |
| 239 | while(blockCount && count){ |
| 240 | int size = 512; |
| 241 | if(size > count) size = count; |
| 242 | |
| 243 | if(!size) break; |
| 244 | |
| 245 | if(Access(lba, 1, physBuffers[buf], 0)){ // LBA, 1 block, read |
| 246 | ReleaseBuffer(buf); |
| 247 | return 1; // Error Reading Sectors |
| 248 | } |