From 2545d1f2a82bc7c23abc0034958b169f9fffe613 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 19 Nov 2010 23:48:03 +0000 Subject: MyriadFs is starting out...but the FUSE system is...akward at best. --- src/file.cpp | 1 - src/myriad.h | 2 +- src/myriadfs.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/myriadfs.h | 20 ++++++++++++-- src/tools/myriadfs.cpp | 38 ++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 src/tools/myriadfs.cpp (limited to 'src') diff --git a/src/file.cpp b/src/file.cpp index 0566ee8..008b88e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -11,7 +11,6 @@ #include #include #include -#include // for mkstemp #include #include "bu/config.h" diff --git a/src/myriad.h b/src/myriad.h index 79c3cda..ed0ef53 100644 --- a/src/myriad.h +++ b/src/myriad.h @@ -46,7 +46,7 @@ namespace Bu * Header format is as follows: * * MMMMvBssssSSSS* - * M = Magic number (FFC399BD) + * M = Magic number (0AD3FA84) * v = version number * B = Bits per int * s = Blocksize in bytes 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 @@ -#include "myriadfs.h" +#include "bu/myriadfs.h" +#include "bu/myriadstream.h" -Bu::MyriadFs::MyriadFs() +#include +#include + +namespace Bu { subExceptionDef( MyriadFsException ) } + +#define Myriad_Fs_MAGIC_CODE ((char *)"\xa7\x18\x8b\x39") + +Bu::MyriadFs::MyriadFs( Bu::Stream &rStore, int iBlockSize ) : + rStore( rStore ), + mStore( rStore, iBlockSize ) { + if( mStore.hasStream( 1 ) ) + { + // Check to see if this is a MyriadFs stream. + Bu::MyriadStream ms = mStore.openStream( 1 ); + char sMagic[4]; + if( ms.read( sMagic, 4 ) < 4 ) + throw MyriadFsException("The provided stream does not appear to be " + "a MyriadFs stream."); + if( ::strncmp( sMagic, Myriad_Fs_MAGIC_CODE, 4 ) ) + throw MyriadFsException("The provided stream does not appear to be " + "a MyriadFs stream."); + + int8_t iVer; + } + else + { + // Create initial header stream + { + mStore.createStream( 1 ); + Bu::MyriadStream ms = mStore.openStream( 1 ); + ms.write( Myriad_Fs_MAGIC_CODE, 4 ); + int8_t iVer = 1; + int32_t iTmp = 1; + ms.write( &iVer, 1 ); + ms.write( &iBlockSize, 4 ); + ms.write( &iTmp, 4 ); // iNumNodes + iTmp = 0; + ms.write( &iTmp, 4 ); // iInode + ms.write( &iTmp, 0 ); // iPosition + } + + // Create initial inode stream, with one root node. + { + mStore.createStream( 2 ); + Bu::MyriadStream ms = mStore.openStream( 2 ); + int32_t iUser = 0, iGroup = 0; +#ifndef WIN32 + iUser = getuid(); + iGroup = getgid(); +#endif + int32_t iTmp32 = 0; + int16_t iTmp16 = 0; + ms.write( &iUser, 4 ); + ms.write( &iGroup, 4 ); + ms.write( &iTmp16, 2 ); + ms.write( &iTmp16, 2 ); + iTmp32 = 3; + ms.write( &iTmp32, 4 ); + iTmp32 = 0; + ms.write( &iTmp32, 4 ); + ms.write( &iTmp16, 2 ); + } + + // Create inode 0's storage stream. + { + mStore.createStream( 3 ); + } + } } Bu::MyriadFs::~MyriadFs() diff --git a/src/myriadfs.h b/src/myriadfs.h index 687584b..42a3493 100644 --- a/src/myriadfs.h +++ b/src/myriadfs.h @@ -1,13 +1,20 @@ #ifndef MYRIAD_FS_H #define MYRIAD_FS_H +#include "bu/myriad.h" + namespace Bu { + class Stream; + + subExceptionDecl( MyriadFsException ); + /** * A POSIX compliant, node based filesystem built on top of Myriad. * + * A header is placed into stream 1. * Header format: - * int32_t iMagicHeader + * int32_t iMagicHeader (A7188B39) * int8_t iVersion (1) * int32_t iNodeSize * int32_t iNumNodes @@ -17,6 +24,11 @@ namespace Bu * int32_t iInode * int32_t iPosition * + * The node headers or inode structures have a base size of 22 bytes. + * Everything else in the block is used for the name. I.e. if you have + * a blocksize of 512 bytes then you wind up with a max name size of + * 512-22=490 characters, or a blocksize of 256 gives you 234 chraacters + * as a max. The node headers are all stored in stream 2. * Basic node header format: * int32_t iUser * int32_t iGroup @@ -30,8 +42,12 @@ namespace Bu class MyriadFs { public: - MyriadFs(); + MyriadFs( Bu::Stream &rStore, int iBlockSize=512 ); virtual ~MyriadFs(); + + private: + Bu::Stream &rStore; + Bu::Myriad mStore; }; }; diff --git a/src/tools/myriadfs.cpp b/src/tools/myriadfs.cpp new file mode 100644 index 0000000..66955a5 --- /dev/null +++ b/src/tools/myriadfs.cpp @@ -0,0 +1,38 @@ +#define FUSE_USE_VERSION 26 + +#include + +#include + +extern "C" { + static int myriadfs_getattr( const char *sPath, struct stat *stbuf ) + { + + } + + static int myriadfs_readdir( const char *sPath, void *buf, + fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) + { + } + + static int myriadfs_open( const char *sPath, struct fuse_file_info *fi ) + { + } + + static int myriadfs_read( const char *sPath, char *buf, size_t iSize, + off_t iOffset, struct fuse_file_info *fi ) + { + } + + static struct fuse_operations myriadfs_oper; + + int main( int argc, char *argv[] ) + { + memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 ); + myriadfs_oper.getattr = myriadfs_getattr; + myriadfs_oper.readdir = myriadfs_readdir; + myriadfs_oper.open = myriadfs_open; + myriadfs_oper.read = myriadfs_read; + return fuse_main( argc, argv, &myriadfs_oper, NULL ); + } +} -- cgit v1.2.3