• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
OpenForRead(const unsigned char * data,size_t size)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 
MakeRealName(void)29 void DiskIO::MakeRealName(void) {
30     realFilename = userFilename;
31 }
32 
OpenForRead(void)33 int DiskIO::OpenForRead(void) {
34     return 1;
35 }
36 
OpenForWrite(void)37 int DiskIO::OpenForWrite(void) {
38     return 1;
39 }
40 
Close(void)41 void DiskIO::Close(void) {
42 }
43 
GetBlockSize(void)44 int DiskIO::GetBlockSize(void) {
45     return 512;
46 }
47 
GetPhysBlockSize(void)48 int DiskIO::GetPhysBlockSize(void) {
49     return 512;
50 }
51 
GetNumHeads(void)52 uint32_t DiskIO::GetNumHeads(void) {
53     return 255;
54 }
55 
GetNumSecsPerTrack(void)56 uint32_t DiskIO::GetNumSecsPerTrack(void) {
57     return 63;
58 }
59 
DiskSync(void)60 int DiskIO::DiskSync(void) {
61     return 1;
62 }
63 
Seek(uint64_t sector)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 
Read(void * buffer,int numBytes)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 
Write(void *,int)80 int DiskIO::Write(void*, int) {
81     return 0;
82 }
83 
DiskSize(int *)84 uint64_t DiskIO::DiskSize(int *) {
85     return this->size / GetBlockSize();
86 }
87