-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreadSector.cpp
More file actions
41 lines (40 loc) · 1.31 KB
/
readSector.cpp
File metadata and controls
41 lines (40 loc) · 1.31 KB
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
#include "filesystem.h"
void FileSystem::readSector(int sector_no, char *buf) const {
/*
objective: to read a sector from disk
input:
sector_no = sector number to read
buf = char buffer to read into
return: None
effect: None
sector data is printed if it exists & it is not reserved
sector data is also set into *buf
*/
int status = getStatus(sector_no);
if (status == RESERVED) {
std::cout << "It is a reserved sector." << std::endl;
} else if (status == NOT_FOUND) {
std::cout << "Sector does not exist." << std::endl;
return;
}
std::ifstream fin;
fin.open(kDiskTitle, std::ios::binary | std::ios::in);
int byteOffset = sector_no*kSectorSize;
fin.seekg(byteOffset);
fin.read(buf, kSectorSize);
fin.close();
// std::cout << "Reading contents of sector #" <<
// sector_no << ", bytes = [" <<
// byteOffset << ", " << (byteOffset + kSectorSize - 1) <<
// "] in disk." << std::endl;
// if (status == RESERVED) {
// for (int i = 0; i < kSectorSize; i++) {
// std::cout << static_cast<int>(buf[i]);
// }
// } else {
// for (int i = 0; i < kSectorSize; i++) {
// std::cout << buf[i];
// }
// }
// std::cout << std::endl;
}