diff options
Diffstat (limited to '')
-rw-r--r-- | src/myriadfs.cpp | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp index bb72cd5..af60c08 100644 --- a/src/myriadfs.cpp +++ b/src/myriadfs.cpp | |||
@@ -1,7 +1,75 @@ | |||
1 | #include "myriadfs.h" | 1 | #include "bu/myriadfs.h" |
2 | #include "bu/myriadstream.h" | ||
2 | 3 | ||
3 | Bu::MyriadFs::MyriadFs() | 4 | #include <string.h> |
5 | #include <unistd.h> | ||
6 | |||
7 | namespace Bu { subExceptionDef( MyriadFsException ) } | ||
8 | |||
9 | #define Myriad_Fs_MAGIC_CODE ((char *)"\xa7\x18\x8b\x39") | ||
10 | |||
11 | Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : | ||
12 | rStore( rStore ), | ||
13 | mStore( rStore, iBlockSize ) | ||
4 | { | 14 | { |
15 | if( mStore.hasStream( 1 ) ) | ||
16 | { | ||
17 | // Check to see if this is a MyriadFs stream. | ||
18 | Bu::MyriadStream ms = mStore.openStream( 1 ); | ||
19 | char sMagic[4]; | ||
20 | if( ms.read( sMagic, 4 ) < 4 ) | ||
21 | throw MyriadFsException("The provided stream does not appear to be " | ||
22 | "a MyriadFs stream."); | ||
23 | if( ::strncmp( sMagic, Myriad_Fs_MAGIC_CODE, 4 ) ) | ||
24 | throw MyriadFsException("The provided stream does not appear to be " | ||
25 | "a MyriadFs stream."); | ||
26 | |||
27 | int8_t iVer; | ||
28 | } | ||
29 | else | ||
30 | { | ||
31 | // Create initial header stream | ||
32 | { | ||
33 | mStore.createStream( 1 ); | ||
34 | Bu::MyriadStream ms = mStore.openStream( 1 ); | ||
35 | ms.write( Myriad_Fs_MAGIC_CODE, 4 ); | ||
36 | int8_t iVer = 1; | ||
37 | int32_t iTmp = 1; | ||
38 | ms.write( &iVer, 1 ); | ||
39 | ms.write( &iBlockSize, 4 ); | ||
40 | ms.write( &iTmp, 4 ); // iNumNodes | ||
41 | iTmp = 0; | ||
42 | ms.write( &iTmp, 4 ); // iInode | ||
43 | ms.write( &iTmp, 0 ); // iPosition | ||
44 | } | ||
45 | |||
46 | // Create initial inode stream, with one root node. | ||
47 | { | ||
48 | mStore.createStream( 2 ); | ||
49 | Bu::MyriadStream ms = mStore.openStream( 2 ); | ||
50 | int32_t iUser = 0, iGroup = 0; | ||
51 | #ifndef WIN32 | ||
52 | iUser = getuid(); | ||
53 | iGroup = getgid(); | ||
54 | #endif | ||
55 | int32_t iTmp32 = 0; | ||
56 | int16_t iTmp16 = 0; | ||
57 | ms.write( &iUser, 4 ); | ||
58 | ms.write( &iGroup, 4 ); | ||
59 | ms.write( &iTmp16, 2 ); | ||
60 | ms.write( &iTmp16, 2 ); | ||
61 | iTmp32 = 3; | ||
62 | ms.write( &iTmp32, 4 ); | ||
63 | iTmp32 = 0; | ||
64 | ms.write( &iTmp32, 4 ); | ||
65 | ms.write( &iTmp16, 2 ); | ||
66 | } | ||
67 | |||
68 | // Create inode 0's storage stream. | ||
69 | { | ||
70 | mStore.createStream( 3 ); | ||
71 | } | ||
72 | } | ||
5 | } | 73 | } |
6 | 74 | ||
7 | Bu::MyriadFs::~MyriadFs() | 75 | Bu::MyriadFs::~MyriadFs() |