aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-02-18 17:41:24 +0000
committerMike Buland <eichlan@xagasoft.com>2011-02-18 17:41:24 +0000
commit26bb069c535e3fd5b0e0fb28fb54a2a540b60a84 (patch)
tree9eab7637e5fa1d881c775a6f0611b74e385196f1 /src/tools
parent80c8dd155a164c186fd11e3e3f66e8f3cfdf19fe (diff)
downloadlibbu++-26bb069c535e3fd5b0e0fb28fb54a2a540b60a84.tar.gz
libbu++-26bb069c535e3fd5b0e0fb28fb54a2a540b60a84.tar.bz2
libbu++-26bb069c535e3fd5b0e0fb28fb54a2a540b60a84.tar.xz
libbu++-26bb069c535e3fd5b0e0fb28fb54a2a540b60a84.zip
Some Uuid tweaks, not much, just figuring out the format. MyriadFs is coming
along quite nicely. It looks like it works great for normal programs, but there need to be some tweaks made to a few things before it's working 100% via fuse. Also, the fuse module won't let you specify a file, a little odd.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/myriadfs.cpp124
1 files changed, 122 insertions, 2 deletions
diff --git a/src/tools/myriadfs.cpp b/src/tools/myriadfs.cpp
index 88db0c0..3956311 100644
--- a/src/tools/myriadfs.cpp
+++ b/src/tools/myriadfs.cpp
@@ -10,36 +10,156 @@
10#include <fuse.h> 10#include <fuse.h>
11 11
12#include <string.h> 12#include <string.h>
13#include <errno.h>
14
15#include <bu/file.h>
16#include <bu/myriadfs.h>
17#include <bu/myriadstream.h>
18#include <bu/hash.h>
19
20Bu::File *pF = NULL;
21Bu::MyriadFs *pFs = NULL;
22
23typedef Bu::Hash<int64_t, Bu::MyriadStream> FileHash;
24FileHash hOpenFiles;
25int64_t iNextFileId = 0;
13 26
14extern "C" { 27extern "C" {
15 static int myriadfs_getattr( const char *sPath, struct stat *stbuf ) 28 static int myriadfs_getattr( const char *sPath, struct stat *stbuf )
16 { 29 {
17 30 try
31 {
32 printf("myriadfs_getattr: Statting file: %s\n", sPath );
33 Bu::MyriadFs::Stat st;
34 pFs->stat( sPath, st );
35 stbuf->st_ino = st.iNode;
36 stbuf->st_mode = st.uPerms;
37 stbuf->st_nlink = st.iLinks;
38 stbuf->st_uid = st.iUser;
39 stbuf->st_gid = st.iGroup;
40 stbuf->st_rdev = Bu::MyriadFs::devToSys( st.uDev );
41 stbuf->st_size = st.iSize;
42 stbuf->st_blocks = 8;
43 stbuf->st_atime = st.iATime;
44 stbuf->st_mtime = st.iMTime;
45 stbuf->st_ctime = st.iCTime;
46 return 0;
47 }
48 catch(...)
49 {
50 return -ENOENT;
51 }
18 } 52 }
19 53
20 static int myriadfs_readdir( const char *sPath, void *buf, 54 static int myriadfs_readdir( const char *sPath, void *buf,
21 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) 55 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi )
22 { 56 {
57 fprintf( stderr, "Reading dir...\n");
58 Bu::MyriadFs::Dir lDir = pFs->readDir( sPath );
59 filler( buf, ".", NULL, 0 );
60 filler( buf, "..", NULL, 0 );
61 for( Bu::MyriadFs::Dir::iterator i = lDir.begin(); i; i++ )
62 {
63 fprintf( stderr, "Adding file: '%s'\n", (*i).sName.getStr() );
64 filler( buf, (*i).sName.getStr(), NULL, 0 );
65 }
66
67 return 0;
68 }
69
70 static int myriadfs_mkdir( const char *sPath, mode_t uMode )
71 {
72 pFs->mkDir( sPath, uMode );
73 return 0;
23 } 74 }
24 75
25 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi ) 76 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi )
26 { 77 {
78 try
79 {
80 Bu::MyriadStream ms = pFs->open( sPath, 0 );
81 fi->fh = iNextFileId;
82 hOpenFiles.insert( iNextFileId++, ms );
83 return 0;
84 }
85 catch(...)
86 {
87 return -EACCES;
88 }
27 } 89 }
28 90
29 static int myriadfs_read( const char *sPath, char *buf, size_t iSize, 91 static int myriadfs_read( const char *sPath, char *buf, size_t iSize,
30 off_t iOffset, struct fuse_file_info *fi ) 92 off_t iOffset, struct fuse_file_info *fi )
31 { 93 {
94 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
95 ms.setPos( iOffset );
96 return ms.read( buf, iSize );
97 }
98
99 static int myriadfs_write( const char *sPath, const char *buf, size_t iSize,
100 off_t iOffset, struct fuse_file_info *fi )
101 {
102 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
103 ms.setPos( iOffset );
104 return ms.write( buf, iSize );
105 }
106
107 static int myriadfs_create( const char *sPath, mode_t uPerms,
108 struct fuse_file_info *fi )
109 {
110 try
111 {
112 Bu::MyriadStream ms = pFs->open( sPath, 0 );
113 fi->fh = iNextFileId;
114 hOpenFiles.insert( iNextFileId++, ms );
115 return 0;
116 }
117 catch(...)
118 {
119 return -EACCES;
120 }
121 }
122
123 static int myriadfs_mknod( const char *sPath, mode_t uPerms, dev_t Dev )
124 {
125 try
126 {
127 pFs->create( sPath, uPerms, Bu::MyriadFs::sysToDev( Dev ) );
128 return 0;
129 }
130 catch(...)
131 {
132 return -EACCES;
133 }
134 }
135
136 static int myriadfs_release( const char *sPath, struct fuse_file_info *fi )
137 {
138 hOpenFiles.erase( fi->fh );
139
140 return 0;
32 } 141 }
33 142
34 static struct fuse_operations myriadfs_oper; 143 static struct fuse_operations myriadfs_oper;
35 144
36 int main( int argc, char *argv[] ) 145 int main( int argc, char *argv[] )
37 { 146 {
147 pF = new Bu::File("store.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create );
148 pFs = new Bu::MyriadFs( *pF, 512 );
38 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 ); 149 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 );
39 myriadfs_oper.getattr = myriadfs_getattr; 150 myriadfs_oper.getattr = myriadfs_getattr;
40 myriadfs_oper.readdir = myriadfs_readdir; 151 myriadfs_oper.readdir = myriadfs_readdir;
152 myriadfs_oper.mkdir = myriadfs_mkdir;
41 myriadfs_oper.open = myriadfs_open; 153 myriadfs_oper.open = myriadfs_open;
42 myriadfs_oper.read = myriadfs_read; 154 myriadfs_oper.read = myriadfs_read;
43 return fuse_main( argc, argv, &myriadfs_oper, NULL ); 155 myriadfs_oper.write = myriadfs_write;
156 myriadfs_oper.create = myriadfs_create;
157 myriadfs_oper.mknod = myriadfs_mknod;
158 printf("Starting fuse_main.\n");
159 int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL );
160 printf("Done with fuse_main.\n");
161 delete pFs;
162 delete pF;
163 return iRet;
44 } 164 }
45} 165}