diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-01-10 21:04:17 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-01-10 21:04:17 +0000 |
| commit | 2ba3f84ab559da02a11aa000b3cecb3b3668af61 (patch) | |
| tree | 266f450b512f607ec54d54af4fa8c13fdbe7ef91 /src/myriadfs.cpp | |
| parent | ea18007633b31901f2ae275cc0576c3f7ce99fc9 (diff) | |
| parent | 3611f253f6fdfa4954d374ab85ddaa7f799c130c (diff) | |
| download | libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.gz libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.bz2 libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.tar.xz libbu++-2ba3f84ab559da02a11aa000b3cecb3b3668af61.zip | |
Merged in the core branch. This is a major update that fixes many things, and
changes many others, including source files that were deleted and renamed.
Before doing this update, I reccomend a full clean, or even a fresh checkout.
Things to note, most outstanding about this update:
- Bu::Socket was changed to Bu::TcpSocket and the default mode is blocking.
- All templatized container classes are SharedCore now, which is good, but
SharedCore is inherently non-reentrant safe. However, all SharedCore classes
have a "clone" function that return a non-shared copy of the object, safe for
passing into a reentrant safe function accessing shared memory.
Diffstat (limited to 'src/myriadfs.cpp')
| -rw-r--r-- | src/myriadfs.cpp | 78 |
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 | |||
| 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 ) | ||
| 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 | |||
| 75 | Bu::MyriadFs::~MyriadFs() | ||
| 76 | { | ||
| 77 | } | ||
| 78 | |||
