This repository has been archived by the owner on Aug 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Entry.h
284 lines (185 loc) · 5.66 KB
/
Entry.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#ifndef __DIRECTORY_H__
#define __DIRECTORY_H__
#include <vector>
#include <stdint.h>
#include "DateTime.h"
namespace ProFUSE {
class BlockDevice;
class Bitmap;
class FileEntry;
class Volume;
class Buffer;
enum Access {
DestroyEnabled = 0x80,
RenameEnabled = 0x40,
BackupNeeded = 0x20,
Invisible = 0x04,
WriteEnabled = 0x02,
ReadEnabled = 0x01
};
enum StorageType {
DeletedFile = 0x00,
SeedlingFile = 0x01,
SaplingFile = 0x02,
TreeFile = 0x03,
PascalFile = 0x04,
ExtendedFile = 0x05,
DirectoryFile = 0x0d,
DirectoryHeader = 0x0e,
VolumeHeader = 0x0f
};
class Entry {
public:
virtual ~Entry();
virtual void write(Buffer *) = 0;
unsigned storageType() const { return _storageType; }
unsigned nameLength() const { return _nameLength; }
const char *name() const { return _name; }
const char *namei() const { return _namei; }
unsigned caseFlag() const { return _caseFlag; }
void setName(const char *name);
// returns strlen() on success, 0 on failure.
static unsigned ValidName(const char *);
unsigned block() const { return _address / 512; }
unsigned offset() const { return _address % 512; }
unsigned address() const { return _address; }
unsigned index() const { return _index; }
Volume *volume() { return _volume; }
protected:
Entry(unsigned storageType, const char *name);
Entry(const void *bp);
void setStorageType(unsigned type)
{ _storageType = type; }
void setAddress(unsigned address)
{ _address = address; }
void setIndex(unsigned index)
{ _index = index; }
void setVolume(Volume *v)
{ _volume = v; }
private:
unsigned _address;
unsigned _index;
Volume *_volume;
unsigned _storageType;
unsigned _nameLength;
char _namei[15+1]; // insensitive, ie, uppercase.
char _name[15+1];
unsigned _caseFlag;
};
class Directory : public Entry {
public:
enum {
OffsetCreation = 0x18,
OffsetVersion = 0x1c,
OffsetMinVersion = 0x1d,
OffsetAccess = 0x1e,
OffsetEntryLength = 0x1f,
OffsetEntriesPerBlock = 0x20,
OffsetFileCount = 0x21
};
virtual ~Directory();
DateTime creation() const { return _creation; }
unsigned access() const { return _access; }
unsigned entryLength() const { return _entryLength; }
unsigned entriesPerBlock() const { return _entriesPerBlock; }
unsigned fileCount() const { return _fileCount; }
unsigned version() const { return _version; }
unsigned minVersion() const { return _minVersion; }
void setAccess(unsigned access);
protected:
Directory(unsigned type, const char *name);
Directory(const void *bp);
std::vector<FileEntry *> _children;
std::vector<unsigned> _entryBlocks;
void loadChildren(BlockDevice *, unsigned block);
private:
DateTime _creation;
unsigned _version;
unsigned _minVersion;
unsigned _access;
unsigned _entryLength; // always 0x27
unsigned _entriesPerBlock; //always 0x0d
unsigned _fileCount;
};
class VolumeDirectory: public Directory {
public:
enum {
OffsetLastMod = 0x12,
OffsetFileNameCaseFlag = 0x16,
OffsetBitmapPointer = 0x23,
OffsetTotalBlocks = 0x25
};
static VolumeDirectory *Create(const char *name, BlockDevice *device);
static VolumeDirectory *Create(BlockDevice *);
virtual ~VolumeDirectory();
unsigned bitmapPointer() const { return _bitmapPointer; }
unsigned totalBlocks() const { return _totalBlocks; }
// bitmap stuff...
int allocBlock();
void freeBlock(unsigned block);
virtual void write(Buffer *);
BlockDevice *device() const { return _device; }
private:
VolumeDirectory(const char *name, BlockDevice *device);
VolumeDirectory(BlockDevice *device, const void *bp);
Bitmap *_bitmap;
BlockDevice *_device;
DateTime _modification;
unsigned _totalBlocks;
unsigned _bitmapPointer;
// inode / free inode list?
};
class SubDirectory : public Directory {
public:
enum {
OffsetPasswordEnabled = 0x10,
OffsetParentPointer = 0x23,
OffsetParentEntryNumber = 0x25,
OffsetParentEntryLength = 0x26
};
SubDirectory(FileEntry *);
private:
unsigned _parentPointer;
unsigned _parentEntryNumber;
unsigned _parentEntryLength;
};
class FileEntry : public Entry {
public:
enum {
OffsetFileType = 0x10,
OffsetKeyPointer = 0x11,
OffsetBlocksUsed = 0x13,
OffsetEOF = 0x15,
OffsetCreation = 0x18,
OffsetVersion = 0x1c,
OffsetMinVersion = 0x1d,
OffsetFileNameCaseFlag = 0x1c,
OffsetAccess = 0x1e,
OffsetAuxType = 0x1f,
OffsetLastMod = 0x21,
OffsetHeaderPointer = 0x25
};
unsigned fileType() const { return _fileType; }
unsigned auxType() const { return _auxType; }
unsigned blocksUsed() const { return _blocksUsed; }
unsigned eof() const { return _eof; }
unsigned access() const { return _access; }
DateTime creation() const { return _creation; }
DateTime modification() const { return _modification; }
private:
void *acquirePointer();
void releasePointer();
unsigned _fileType;
unsigned _keyPointer;
unsigned _blocksUsed;
unsigned _eof;
DateTime _creation;
//version
//min version
unsigned _access;
unsigned _auxType;
DateTime _modification;
unsigned _headerPointer;
};
}
#endif