-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwriteSector.cpp
More file actions
28 lines (27 loc) · 861 Bytes
/
writeSector.cpp
File metadata and controls
28 lines (27 loc) · 861 Bytes
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
#include "filesystem.h"
void FileSystem::writeSector(int sector_no, char* buf) {
/*
objective: to write data into a sector
input:
sector_no = sector number to write into
buf = buffer to write from (size = kSectorSize)
return: None
effect:
data is written into a sector if it is FREE OR BUSY (over-written)
else: nothing
*/
int status = getStatus(sector_no);
if (status == RESERVED) {
std::cout << "It is a reserved sector" << std::endl;
return;
} else if (status == NOT_FOUND) {
std::cout << "Sector does not exist." << std::endl;
return;
} else {
std::ofstream fp;
fp.open(kDiskTitle, std::ios::binary | std::ios::in | std::ios::out);
fp.seekp(sector_no*kSectorSize);
fp.write(buf, kSectorSize);
fp.close();
}
}