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