From 9af80a223128dd465aabdd311fdf529e97b40e13 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 20 Feb 2011 07:19:44 +0000 Subject: Well, unlink, mkHardLink, setFileSize, and more are freshly implemented, as is rename, but there seems to be a problem, rename uses mkHardLink, and if the target exists, hey, it adds another one...not quite ideal... --- src/tools/myriadfs.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 8 deletions(-) (limited to 'src/tools') diff --git a/src/tools/myriadfs.cpp b/src/tools/myriadfs.cpp index 8db59d7..3e4599b 100644 --- a/src/tools/myriadfs.cpp +++ b/src/tools/myriadfs.cpp @@ -24,9 +24,14 @@ typedef Bu::Hash FileHash; FileHash hOpenFiles; int64_t iNextFileId = 0; +#define TRACE + extern "C" { static int myriadfs_getattr( const char *sPath, struct stat *stbuf ) { +#ifdef TRACE + printf("myriadfs_getattr(\"%s\", ... );\n", sPath ); +#endif try { Bu::MyriadFs::Stat st; @@ -53,6 +58,9 @@ extern "C" { static int myriadfs_readdir( const char *sPath, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_readdir(\"%s\", ... );\n", sPath ); +#endif Bu::MyriadFs::Dir lDir = pFs->readDir( sPath ); filler( buf, ".", NULL, 0 ); filler( buf, "..", NULL, 0 ); @@ -66,19 +74,25 @@ extern "C" { static int myriadfs_mkdir( const char *sPath, mode_t uMode ) { +#ifdef TRACE + printf("myriadfs_mkdir(\"%s\", 0%o );\n", sPath, uMode ); +#endif pFs->mkDir( sPath, uMode ); return 0; } static int myriadfs_open( const char *sPath, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_open(\"%s\", ... );\n", sPath ); +#endif try { Bu::MyriadStream ms = pFs->open( sPath, 0 ); fi->fh = iNextFileId; hOpenFiles.insert( iNextFileId++, ms ); - printf("File '%s' opened, %d files open now.\n", - sPath, hOpenFiles.getSize() ); +// printf("File '%s' opened, %d files open now.\n", +// sPath, hOpenFiles.getSize() ); return 0; } catch(...) @@ -90,6 +104,10 @@ extern "C" { static int myriadfs_read( const char *sPath, char *buf, size_t iSize, off_t iOffset, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_read(\"%s\", ..., %d, %d, ... );\n", sPath, iSize, + iOffset ); +#endif Bu::MyriadStream &ms = hOpenFiles.get( fi->fh ); ms.setPos( iOffset ); return ms.read( buf, iSize ); @@ -98,6 +116,10 @@ extern "C" { static int myriadfs_write( const char *sPath, const char *buf, size_t iSize, off_t iOffset, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_write(\"%s\", ..., %d, %d, ... );\n", sPath, iSize, + iOffset ); +#endif Bu::MyriadStream &ms = hOpenFiles.get( fi->fh ); ms.setPos( iOffset ); return ms.write( buf, iSize ); @@ -106,13 +128,16 @@ extern "C" { static int myriadfs_create( const char *sPath, mode_t uPerms, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_create(\"%s\", 0%o, ... );\n", sPath, uPerms ); +#endif try { Bu::MyriadStream ms = pFs->open( sPath, 0, uPerms ); fi->fh = iNextFileId; hOpenFiles.insert( iNextFileId++, ms ); - printf("File '%s' created, %d files open now.\n", - sPath, hOpenFiles.getSize() ); +// printf("File '%s' created, %d files open now.\n", +// sPath, hOpenFiles.getSize() ); return 0; } catch(...) @@ -123,6 +148,9 @@ extern "C" { static int myriadfs_mknod( const char *sPath, mode_t uPerms, dev_t Dev ) { +#ifdef TRACE + printf("myriadfs_mknod(\"%s\", 0%o, %x );\n", sPath, uPerms, Dev ); +#endif try { pFs->create( sPath, uPerms, Bu::MyriadFs::sysToDev( Dev ) ); @@ -136,9 +164,12 @@ extern "C" { static int myriadfs_release( const char *sPath, struct fuse_file_info *fi ) { +#ifdef TRACE + printf("myriadfs_release(\"%s\", ... );\n", sPath ); +#endif hOpenFiles.erase( fi->fh ); - printf("File '%s' released, %d files open now.\n", - sPath, hOpenFiles.getSize() ); +// printf("File '%s' released, %d files open now.\n", +// sPath, hOpenFiles.getSize() ); return 0; } @@ -146,6 +177,9 @@ extern "C" { static int myriadfs_utimens( const char *sPath, const struct timespec tv[2] ) { +#ifdef TRACE + printf("myriadfs_utimens(\"%s\", ... );\n", sPath ); +#endif try { pFs->setTimes( sPath, tv[0].tv_sec, tv[1].tv_sec ); @@ -159,6 +193,9 @@ extern "C" { static int myriadfs_unlink( const char *sPath ) { +#ifdef TRACE + printf("myriadfs_unlink(\"%s\");\n", sPath ); +#endif try { pFs->unlink( sPath ); @@ -173,10 +210,12 @@ extern "C" { static int myriadfs_symlink( const char *sTarget, const char *sPath ) { +#ifdef TRACE + printf("myriadfs_symlink(\"%s\", \"%s\");\n", sTarget, sPath ); +#endif try { - printf("Path = '%s', Target = '%s'\n", sPath, sTarget ); - pFs->mkSymLink( sPath, sTarget ); + pFs->mkSymLink( sTarget, sPath ); } catch( Bu::MyriadFsException &e ) { @@ -188,6 +227,9 @@ extern "C" { static int myriadfs_readlink( const char *sPath, char *sOut, size_t s ) { +#ifdef TRACE + printf("myriadfs_readlink(\"%s\", ... );\n", sPath ); +#endif try { Bu::String sTrg = pFs->readSymLink( sPath ); @@ -203,6 +245,60 @@ extern "C" { return 0; } + static int myriadfs_truncate( const char *sPath, off_t iSize ) + { +#ifdef TRACE + printf("myriadfs_truncate(\"%s\", %d );\n", sPath, iSize ); +#endif + + try + { + pFs->setFileSize( sPath, iSize ); + } + catch( Bu::MyriadFsException &e ) + { + printf("MyriadFsException: %s\n", e.what() ); + return -ENOENT; + } + return 0; + } + + static int myriadfs_link( const char *sTarget, const char *sPath ) + { +#ifdef TRACE + printf("myriadfs_link(\"%s\", \"%s\");\n", sTarget, sPath ); +#endif + + try + { + pFs->mkHardLink( sTarget, sPath ); + } + catch( Bu::MyriadFsException &e ) + { + printf("MyriadFsException: %s\n", e.what() ); + return -EACCES; + } + return 0; + } + + static int myriadfs_rename( const char *sFrom, const char *sTo ) + { +#ifdef TRACE + printf("myriadfs_rename(\"%s\", \"%s\");\n", sFrom, sTo ); +#endif + + try + { + pFs->rename( sFrom, sTo ); + } + catch( Bu::MyriadFsException &e ) + { + printf("MyriadFsException: %s\n", e.what() ); + return -EACCES; + } + return 0; + } + static struct fuse_operations myriadfs_oper; int main( int argc, char *argv[] ) @@ -224,6 +320,9 @@ extern "C" { myriadfs_oper.rmdir = myriadfs_unlink; myriadfs_oper.symlink = myriadfs_symlink; myriadfs_oper.readlink = myriadfs_readlink; + myriadfs_oper.truncate = myriadfs_truncate; + myriadfs_oper.link = myriadfs_link; + myriadfs_oper.rename = myriadfs_rename; printf("Starting fuse_main.\n"); int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL ); printf("Done with fuse_main.\n"); -- cgit v1.2.3