-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisk_io.cpp
More file actions
executable file
·39 lines (30 loc) · 838 Bytes
/
disk_io.cpp
File metadata and controls
executable file
·39 lines (30 loc) · 838 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
29
30
31
32
33
34
35
36
37
38
39
#include "merge.h"
#include "dbtproj.h"
#include <fstream>
//Only for generator
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
unsigned int block_id;
void init_block_id() {
block_id = 0;
}
void readBlock(std::istream& input, unsigned int offset, bool seq, block_t *buffer, unsigned int spot)
{
//The seq boolean indicates whether we read sequentially or with an offset.
if(!seq) {
input.seekg(offset, input.beg);
}
input.read((char *) &buffer[spot], sizeof(block_t));
}
void readMultipleBlocks(std::istream& input, block_t *buffer, unsigned int blocks)
{
input.read((char *) buffer, sizeof(block_t)*blocks);
}
void writeBlock(std::ofstream& output, block_t *block)
{
block->blockid = block_id;
block_id++;
output.write((char *) block, sizeof(block_t));
}