blob: 31291132f10398c7421fd29aa8ee233c08919993 [file] [log] [blame]
Jeff Sharkey83fdc992020-10-13 19:50:30 -06001/*
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
18using namespace std;
19
20int 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
29void DiskIO::MakeRealName(void) {
30 realFilename = userFilename;
31}
32
33int DiskIO::OpenForRead(void) {
34 return 1;
35}
36
37int DiskIO::OpenForWrite(void) {
38 return 1;
39}
40
41void DiskIO::Close(void) {
42}
43
44int DiskIO::GetBlockSize(void) {
45 return 512;
46}
47
48int DiskIO::GetPhysBlockSize(void) {
49 return 512;
50}
51
52uint32_t DiskIO::GetNumHeads(void) {
53 return 255;
54}
55
56uint32_t DiskIO::GetNumSecsPerTrack(void) {
57 return 63;
58}
59
60int DiskIO::DiskSync(void) {
61 return 1;
62}
63
64int 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
74int 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
80int DiskIO::Write(void*, int) {
81 return 0;
82}
83
84uint64_t DiskIO::DiskSize(int *) {
85 return this->size / GetBlockSize();
86}