Jeff Sharkey | 83fdc99 | 2020-10-13 19:50:30 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <algorithm> |
| 15 | |
| 16 | #include "diskio.h" |
| 17 | |
| 18 | using namespace std; |
| 19 | |
| 20 | int DiskIO::OpenForRead(const unsigned char* data, size_t size) { |
| 21 | this->data = data; |
| 22 | this->size = size; |
| 23 | this->off = 0; |
| 24 | this->isOpen = 1; |
| 25 | this->openForWrite = 0; |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | void DiskIO::MakeRealName(void) { |
| 30 | realFilename = userFilename; |
| 31 | } |
| 32 | |
| 33 | int DiskIO::OpenForRead(void) { |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | int DiskIO::OpenForWrite(void) { |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | void DiskIO::Close(void) { |
| 42 | } |
| 43 | |
| 44 | int DiskIO::GetBlockSize(void) { |
| 45 | return 512; |
| 46 | } |
| 47 | |
| 48 | int DiskIO::GetPhysBlockSize(void) { |
| 49 | return 512; |
| 50 | } |
| 51 | |
| 52 | uint32_t DiskIO::GetNumHeads(void) { |
| 53 | return 255; |
| 54 | } |
| 55 | |
| 56 | uint32_t DiskIO::GetNumSecsPerTrack(void) { |
| 57 | return 63; |
| 58 | } |
| 59 | |
| 60 | int DiskIO::DiskSync(void) { |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | int DiskIO::Seek(uint64_t sector) { |
| 65 | off_t off = sector * GetBlockSize(); |
| 66 | if (off >= this->size) { |
| 67 | return 0; |
| 68 | } else { |
| 69 | this->off = off; |
| 70 | return 1; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | int DiskIO::Read(void* buffer, int numBytes) { |
| 75 | int actualBytes = std::min(static_cast<int>(this->size - this->off), numBytes); |
| 76 | memcpy(buffer, this->data + this->off, actualBytes); |
| 77 | return actualBytes; |
| 78 | } |
| 79 | |
| 80 | int DiskIO::Write(void*, int) { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | uint64_t DiskIO::DiskSize(int *) { |
| 85 | return this->size / GetBlockSize(); |
| 86 | } |