blob: 78d1dbf1a5e082d6dbca77e8e6ee53a65c4f980b (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* storage.h
Storage subsystem management.
Lays out our datafiles on disk, manages disk space.
*/
#pragma once
#pragma pack(push)
#pragma pack(1)
class Record;
class DeletedRecord;
class Extent;
class BtreeBucket;
class JSObj;
class PhysicalDataFile;
class Bucket;
class DiskLoc {
int fileNo; /* this will be volume, file #, etc. */
int ofs;
public:
enum { NullOfs = -1 };
int a() const { return fileNo; }
DiskLoc(int a, int b) : fileNo(a), ofs(b) {
assert(ofs!=0);
}
DiskLoc() { fileNo = -1; ofs = NullOfs; }
DiskLoc(const DiskLoc& l) { fileNo=l.fileNo; ofs=l.ofs; }
bool isNull() const { return ofs == NullOfs; }
void Null() { fileNo = -1; ofs = NullOfs; }
void assertOk() { assert(!isNull()); }
string toString() const {
if( isNull() )
return "null";
stringstream ss;
ss << hex << fileNo << ':' << ofs;
return ss.str();
}
int& GETOFS() { return ofs; }
int getOfs() const { return ofs; }
void set(int a, int b) { fileNo=a; ofs=b; }
void setOfs(int _fileNo, int _ofs) {
fileNo = _fileNo;
ofs = _ofs;
}
void inc(int amt) {
assert( !isNull() );
ofs += amt;
}
bool sameFile(DiskLoc b) { return fileNo == b.fileNo; }
bool operator==(const DiskLoc& b) const { return fileNo==b.fileNo && ofs == b.ofs; }
bool operator!=(const DiskLoc& b) const { return !(*this==b); }
const DiskLoc& operator=(const DiskLoc& b) {
fileNo=b.fileNo; ofs = b.ofs;
assert(ofs!=0);
return *this;
}
int compare(const DiskLoc& b) const {
int x = fileNo - b.fileNo;
if( x )
return x;
if( ofs == b.ofs ) return 0;
return ofs < b.ofs ? -1 : 1;
}
bool operator<(const DiskLoc& b) const {
if( fileNo == b.fileNo )
return ofs < b.ofs;
return fileNo < b.fileNo;
}
JSObj obj() const;
Record* rec() const;
DeletedRecord* drec() const;
Extent* ext() const;
BtreeBucket* btree() const;
Bucket* bucket() const;
PhysicalDataFile& pdf() const;
};
#pragma pack(pop)
|