-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceManager.cpp
45 lines (35 loc) · 955 Bytes
/
DeviceManager.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include "DeviceManager.h"
#include <Stdlib.h>
using namespace std;
const char* DeviceManager::DISK_FILE_NAME = "FileSystem.img";
DeviceManager::DeviceManager() {
fp = fopen(DISK_FILE_NAME, "rb+");
}
DeviceManager::~DeviceManager() {
if (fp) {
fclose(fp);
}
}
bool DeviceManager::IsExist() {
return fp != NULL;
}
void DeviceManager::Open() {
fp = fopen(DISK_FILE_NAME, "wb+");
if (fp == NULL) {
printf("´ò¿ª»òн¨Îļþ%sʧ°Ü£¡", DISK_FILE_NAME);
exit(ERROR_OPEN_FILE);
}
}
void DeviceManager::write(const void* buffer, unsigned int size, int offset, unsigned int origin) {
if (offset >= 0) {
fseek(fp, offset, origin);
}
fwrite(buffer, size, 1, fp);
}
void DeviceManager::read(void* buffer, unsigned int size, int offset, unsigned int origin) {
if (offset >= 0) {
fseek(fp, offset, origin);
}
fread(buffer, size, 1, fp);
}