-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.h
65 lines (55 loc) · 1.38 KB
/
disk.h
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
#ifndef TOYFS_FAKEDISK_H_
#define TOYFS_FAKEDISK_H_
#include <fstream>
#include <mutex>
#include <string>
class Disk
{
public:
// static attributes
static const int kNumOfSector = 128;
static const int kSectorSize = 64; // in byte
// static functions
/**
* @brief CreateDisk Create a fake disk.
*
* @param filePath File path.
* @return true if succeed.
*/
static bool CreateDisk(const std::string& filePath);
// constructors & destructor
explicit Disk(const std::string& diskFile);
~Disk();
// keep from copying
Disk(const Disk&) = delete;
Disk& operator=(const Disk&) = delete;
/**
* @brief isValid Whether is this disk valid or not.
*
* @return true if is valid.
*/
bool isValid();
/**
* @brief read Read data from disk.
*
* @param buf Buffer to store data.
* @param sector Start sector.
* @param length Number of bytes to read.
* @return true if succeeded.
*/
bool read(char* buf, int sector);
/**
* @brief write Write data to disk.
*
* @param buf Buffer to read data.
* @param sector Start sector.
* @param length Number of bytes to write.
* @return true if succeeded.
*/
bool write(char* buf, int sector);
bool sync();
private:
std::fstream m_ioFile;
std::mutex m_mutex;
};
#endif // TOYFS_FAKEDISK_H_