aboutsummaryrefslogtreecommitdiff
path: root/src/myriadfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/myriadfs.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/myriadfs.cpp b/src/myriadfs.cpp
new file mode 100644
index 0000000..af60c08
--- /dev/null
+++ b/src/myriadfs.cpp
@@ -0,0 +1,78 @@
1#include "bu/myriadfs.h"
2#include "bu/myriadstream.h"
3
4#include <string.h>
5#include <unistd.h>
6
7namespace Bu { subExceptionDef( MyriadFsException ) }
8
9#define Myriad_Fs_MAGIC_CODE ((char *)"\xa7\x18\x8b\x39")
10
11Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) :
12 rStore( rStore ),
13 mStore( rStore, iBlockSize )
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 }
73}
74
75Bu::MyriadFs::~MyriadFs()
76{
77}
78