aboutsummaryrefslogtreecommitdiff
path: root/src/extra
diff options
context:
space:
mode:
Diffstat (limited to 'src/extra')
-rw-r--r--src/extra/myriadfs.cpp500
1 files changed, 250 insertions, 250 deletions
diff --git a/src/extra/myriadfs.cpp b/src/extra/myriadfs.cpp
index 867a595..6dc3ff4 100644
--- a/src/extra/myriadfs.cpp
+++ b/src/extra/myriadfs.cpp
@@ -28,307 +28,307 @@ int64_t iNextFileId = 0;
28#define TRACE 28#define TRACE
29 29
30extern "C" { 30extern "C" {
31 static int myriadfs_getattr( const char *sPath, struct stat *stbuf ) 31 static int myriadfs_getattr( const char *sPath, struct stat *stbuf )
32 { 32 {
33#ifdef TRACE 33#ifdef TRACE
34 printf("myriadfs_getattr(\"%s\", ... );\n", sPath ); 34 printf("myriadfs_getattr(\"%s\", ... );\n", sPath );
35#endif 35#endif
36 try 36 try
37 { 37 {
38 Bu::MyriadFs::Stat st; 38 Bu::MyriadFs::Stat st;
39 pFs->stat( sPath, st ); 39 pFs->stat( sPath, st );
40 stbuf->st_ino = st.iNode; 40 stbuf->st_ino = st.iNode;
41 stbuf->st_mode = st.uPerms; 41 stbuf->st_mode = st.uPerms;
42 stbuf->st_nlink = st.iLinks; 42 stbuf->st_nlink = st.iLinks;
43 stbuf->st_uid = st.iUser; 43 stbuf->st_uid = st.iUser;
44 stbuf->st_gid = st.iGroup; 44 stbuf->st_gid = st.iGroup;
45 stbuf->st_rdev = Bu::MyriadFs::devToSys( st.uDev ); 45 stbuf->st_rdev = Bu::MyriadFs::devToSys( st.uDev );
46 stbuf->st_size = st.iSize; 46 stbuf->st_size = st.iSize;
47 stbuf->st_blocks = 8; 47 stbuf->st_blocks = 8;
48 stbuf->st_atime = st.iATime; 48 stbuf->st_atime = st.iATime;
49 stbuf->st_mtime = st.iMTime; 49 stbuf->st_mtime = st.iMTime;
50 stbuf->st_ctime = st.iCTime; 50 stbuf->st_ctime = st.iCTime;
51 return 0; 51 return 0;
52 } 52 }
53 catch(...) 53 catch(...)
54 { 54 {
55 return -ENOENT; 55 return -ENOENT;
56 } 56 }
57 } 57 }
58 58
59 static int myriadfs_readdir( const char *sPath, void *buf, 59 static int myriadfs_readdir( const char *sPath, void *buf,
60 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi ) 60 fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi )
61 { 61 {
62#ifdef TRACE 62#ifdef TRACE
63 printf("myriadfs_readdir(\"%s\", ... );\n", sPath ); 63 printf("myriadfs_readdir(\"%s\", ... );\n", sPath );
64#endif 64#endif
65 Bu::MyriadFs::Dir lDir = pFs->readDir( sPath ); 65 Bu::MyriadFs::Dir lDir = pFs->readDir( sPath );
66 filler( buf, ".", NULL, 0 ); 66 filler( buf, ".", NULL, 0 );
67 filler( buf, "..", NULL, 0 ); 67 filler( buf, "..", NULL, 0 );
68 for( Bu::MyriadFs::Dir::iterator i = lDir.begin(); i; i++ ) 68 for( Bu::MyriadFs::Dir::iterator i = lDir.begin(); i; i++ )
69 { 69 {
70 filler( buf, (*i).sName.getStr(), NULL, 0 ); 70 filler( buf, (*i).sName.getStr(), NULL, 0 );
71 } 71 }
72 72
73 return 0; 73 return 0;
74 } 74 }
75 75
76 static int myriadfs_mkdir( const char *sPath, mode_t uMode ) 76 static int myriadfs_mkdir( const char *sPath, mode_t uMode )
77 { 77 {
78#ifdef TRACE 78#ifdef TRACE
79 printf("myriadfs_mkdir(\"%s\", 0%o );\n", sPath, uMode ); 79 printf("myriadfs_mkdir(\"%s\", 0%o );\n", sPath, uMode );
80#endif 80#endif
81 pFs->mkDir( sPath, uMode ); 81 pFs->mkDir( sPath, uMode );
82 return 0; 82 return 0;
83 } 83 }
84 84
85 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi ) 85 static int myriadfs_open( const char *sPath, struct fuse_file_info *fi )
86 { 86 {
87#ifdef TRACE 87#ifdef TRACE
88 printf("myriadfs_open(\"%s\", ... );\n", sPath ); 88 printf("myriadfs_open(\"%s\", ... );\n", sPath );
89#endif 89#endif
90 try 90 try
91 { 91 {
92 Bu::MyriadStream ms = pFs->open( sPath, 0 ); 92 Bu::MyriadStream ms = pFs->open( sPath, 0 );
93 fi->fh = iNextFileId; 93 fi->fh = iNextFileId;
94 hOpenFiles.insert( iNextFileId++, ms ); 94 hOpenFiles.insert( iNextFileId++, ms );
95// printf("File '%s' opened, %d files open now.\n", 95// printf("File '%s' opened, %d files open now.\n",
96// sPath, hOpenFiles.getSize() ); 96// sPath, hOpenFiles.getSize() );
97 return 0; 97 return 0;
98 } 98 }
99 catch(...) 99 catch(...)
100 { 100 {
101 return -EACCES; 101 return -EACCES;
102 } 102 }
103 } 103 }
104 104
105 static int myriadfs_read( const char *sPath, char *buf, size_t iSize, 105 static int myriadfs_read( const char *sPath, char *buf, size_t iSize,
106 off_t iOffset, struct fuse_file_info *fi ) 106 off_t iOffset, struct fuse_file_info *fi )
107 { 107 {
108#ifdef TRACE 108#ifdef TRACE
109 printf("myriadfs_read(\"%s\", ..., %d, %d, ... );\n", sPath, iSize, 109 printf("myriadfs_read(\"%s\", ..., %d, %d, ... );\n", sPath, iSize,
110 iOffset ); 110 iOffset );
111#endif 111#endif
112 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh ); 112 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
113 ms.setPos( iOffset ); 113 ms.setPos( iOffset );
114 return ms.read( buf, iSize ); 114 return ms.read( buf, iSize );
115 } 115 }
116 116
117 static int myriadfs_write( const char *sPath, const char *buf, size_t iSize, 117 static int myriadfs_write( const char *sPath, const char *buf, size_t iSize,
118 off_t iOffset, struct fuse_file_info *fi ) 118 off_t iOffset, struct fuse_file_info *fi )
119 { 119 {
120#ifdef TRACE 120#ifdef TRACE
121 printf("myriadfs_write(\"%s\", ..., %d, %d, ... );\n", sPath, iSize, 121 printf("myriadfs_write(\"%s\", ..., %d, %d, ... );\n", sPath, iSize,
122 iOffset ); 122 iOffset );
123#endif 123#endif
124 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh ); 124 Bu::MyriadStream &ms = hOpenFiles.get( fi->fh );
125 ms.setPos( iOffset ); 125 ms.setPos( iOffset );
126 return ms.write( buf, iSize ); 126 return ms.write( buf, iSize );
127 } 127 }
128 128
129 static int myriadfs_create( const char *sPath, mode_t uPerms, 129 static int myriadfs_create( const char *sPath, mode_t uPerms,
130 struct fuse_file_info *fi ) 130 struct fuse_file_info *fi )
131 { 131 {
132#ifdef TRACE 132#ifdef TRACE
133 printf("myriadfs_create(\"%s\", 0%o, ... );\n", sPath, uPerms ); 133 printf("myriadfs_create(\"%s\", 0%o, ... );\n", sPath, uPerms );
134#endif 134#endif
135 try 135 try
136 { 136 {
137 Bu::MyriadStream ms = pFs->open( sPath, 0, uPerms ); 137 Bu::MyriadStream ms = pFs->open( sPath, 0, uPerms );
138 fi->fh = iNextFileId; 138 fi->fh = iNextFileId;
139 hOpenFiles.insert( iNextFileId++, ms ); 139 hOpenFiles.insert( iNextFileId++, ms );
140// printf("File '%s' created, %d files open now.\n", 140// printf("File '%s' created, %d files open now.\n",
141// sPath, hOpenFiles.getSize() ); 141// sPath, hOpenFiles.getSize() );
142 return 0; 142 return 0;
143 } 143 }
144 catch(...) 144 catch(...)
145 { 145 {
146 return -EACCES; 146 return -EACCES;
147 } 147 }
148 } 148 }
149 149
150 static int myriadfs_mknod( const char *sPath, mode_t uPerms, dev_t Dev ) 150 static int myriadfs_mknod( const char *sPath, mode_t uPerms, dev_t Dev )
151 { 151 {
152#ifdef TRACE 152#ifdef TRACE
153 printf("myriadfs_mknod(\"%s\", 0%o, %x );\n", sPath, uPerms, Dev ); 153 printf("myriadfs_mknod(\"%s\", 0%o, %x );\n", sPath, uPerms, Dev );
154#endif 154#endif
155 try 155 try
156 { 156 {
157 pFs->create( sPath, uPerms, Bu::MyriadFs::sysToDev( Dev ) ); 157 pFs->create( sPath, uPerms, Bu::MyriadFs::sysToDev( Dev ) );
158 return 0; 158 return 0;
159 } 159 }
160 catch(...) 160 catch(...)
161 { 161 {
162 return -EACCES; 162 return -EACCES;
163 } 163 }
164 } 164 }
165 165
166 static int myriadfs_release( const char *sPath, struct fuse_file_info *fi ) 166 static int myriadfs_release( const char *sPath, struct fuse_file_info *fi )
167 { 167 {
168#ifdef TRACE 168#ifdef TRACE
169 printf("myriadfs_release(\"%s\", ... );\n", sPath ); 169 printf("myriadfs_release(\"%s\", ... );\n", sPath );
170#endif 170#endif
171 hOpenFiles.erase( fi->fh ); 171 hOpenFiles.erase( fi->fh );
172// printf("File '%s' released, %d files open now.\n", 172// printf("File '%s' released, %d files open now.\n",
173// sPath, hOpenFiles.getSize() ); 173// sPath, hOpenFiles.getSize() );
174 174
175 return 0; 175 return 0;
176 } 176 }
177 177
178 static int myriadfs_utimens( const char *sPath, 178 static int myriadfs_utimens( const char *sPath,
179 const struct timespec tv[2] ) 179 const struct timespec tv[2] )
180 { 180 {
181#ifdef TRACE 181#ifdef TRACE
182 printf("myriadfs_utimens(\"%s\", ... );\n", sPath ); 182 printf("myriadfs_utimens(\"%s\", ... );\n", sPath );
183#endif 183#endif
184 try 184 try
185 { 185 {
186 pFs->setTimes( sPath, tv[0].tv_sec, tv[1].tv_sec ); 186 pFs->setTimes( sPath, tv[0].tv_sec, tv[1].tv_sec );
187 } 187 }
188 catch(...) 188 catch(...)
189 { 189 {
190 return -EACCES; 190 return -EACCES;
191 } 191 }
192 return 0; 192 return 0;
193 } 193 }
194 194
195 static int myriadfs_unlink( const char *sPath ) 195 static int myriadfs_unlink( const char *sPath )
196 { 196 {
197#ifdef TRACE 197#ifdef TRACE
198 printf("myriadfs_unlink(\"%s\");\n", sPath ); 198 printf("myriadfs_unlink(\"%s\");\n", sPath );
199#endif 199#endif
200 try 200 try
201 { 201 {
202 pFs->unlink( sPath ); 202 pFs->unlink( sPath );
203 } 203 }
204 catch( Bu::MyriadFsException &e ) 204 catch( Bu::MyriadFsException &e )
205 { 205 {
206 printf("MyriadFsException: %s\n", e.what() ); 206 printf("MyriadFsException: %s\n", e.what() );
207 return -EACCES; 207 return -EACCES;
208 } 208 }
209 return 0; 209 return 0;
210 } 210 }
211 211
212 static int myriadfs_symlink( const char *sTarget, const char *sPath ) 212 static int myriadfs_symlink( const char *sTarget, const char *sPath )
213 { 213 {
214#ifdef TRACE 214#ifdef TRACE
215 printf("myriadfs_symlink(\"%s\", \"%s\");\n", sTarget, sPath ); 215 printf("myriadfs_symlink(\"%s\", \"%s\");\n", sTarget, sPath );
216#endif 216#endif
217 try 217 try
218 { 218 {
219 pFs->mkSymLink( sTarget, sPath ); 219 pFs->mkSymLink( sTarget, sPath );
220 } 220 }
221 catch( Bu::MyriadFsException &e ) 221 catch( Bu::MyriadFsException &e )
222 { 222 {
223 printf("MyriadFsException: %s\n", e.what() ); 223 printf("MyriadFsException: %s\n", e.what() );
224 return -EACCES; 224 return -EACCES;
225 } 225 }
226 return 0; 226 return 0;
227 } 227 }
228 228
229 static int myriadfs_readlink( const char *sPath, char *sOut, size_t s ) 229 static int myriadfs_readlink( const char *sPath, char *sOut, size_t s )
230 { 230 {
231#ifdef TRACE 231#ifdef TRACE
232 printf("myriadfs_readlink(\"%s\", ... );\n", sPath ); 232 printf("myriadfs_readlink(\"%s\", ... );\n", sPath );
233#endif 233#endif
234 try 234 try
235 { 235 {
236 Bu::String sTrg = pFs->readSymLink( sPath ); 236 Bu::String sTrg = pFs->readSymLink( sPath );
237 size_t iLen = (s-1>sTrg.getSize())?(sTrg.getSize()):(s-1); 237 size_t iLen = (s-1>sTrg.getSize())?(sTrg.getSize()):(s-1);
238 memcpy( sOut, sTrg.getStr(), iLen ); 238 memcpy( sOut, sTrg.getStr(), iLen );
239 sOut[iLen] = '\0'; 239 sOut[iLen] = '\0';
240 } 240 }
241 catch( Bu::MyriadFsException &e ) 241 catch( Bu::MyriadFsException &e )
242 { 242 {
243 printf("MyriadFsException: %s\n", e.what() ); 243 printf("MyriadFsException: %s\n", e.what() );
244 return -EACCES; 244 return -EACCES;
245 } 245 }
246 return 0; 246 return 0;
247 } 247 }
248 248
249 static int myriadfs_truncate( const char *sPath, off_t iSize ) 249 static int myriadfs_truncate( const char *sPath, off_t iSize )
250 { 250 {
251#ifdef TRACE 251#ifdef TRACE
252 printf("myriadfs_truncate(\"%s\", %d );\n", sPath, iSize ); 252 printf("myriadfs_truncate(\"%s\", %d );\n", sPath, iSize );
253#endif 253#endif
254 254
255 try 255 try
256 { 256 {
257 pFs->setFileSize( sPath, iSize ); 257 pFs->setFileSize( sPath, iSize );
258 } 258 }
259 catch( Bu::MyriadFsException &e ) 259 catch( Bu::MyriadFsException &e )
260 { 260 {
261 printf("MyriadFsException: %s\n", e.what() ); 261 printf("MyriadFsException: %s\n", e.what() );
262 return -ENOENT; 262 return -ENOENT;
263 } 263 }
264 return 0; 264 return 0;
265 } 265 }
266 266
267 static int myriadfs_link( const char *sTarget, const char *sPath ) 267 static int myriadfs_link( const char *sTarget, const char *sPath )
268 { 268 {
269#ifdef TRACE 269#ifdef TRACE
270 printf("myriadfs_link(\"%s\", \"%s\");\n", sTarget, sPath ); 270 printf("myriadfs_link(\"%s\", \"%s\");\n", sTarget, sPath );
271#endif 271#endif
272 272
273 try 273 try
274 { 274 {
275 pFs->mkHardLink( sTarget, sPath ); 275 pFs->mkHardLink( sTarget, sPath );
276 } 276 }
277 catch( Bu::MyriadFsException &e ) 277 catch( Bu::MyriadFsException &e )
278 { 278 {
279 printf("MyriadFsException: %s\n", e.what() ); 279 printf("MyriadFsException: %s\n", e.what() );
280 return -EACCES; 280 return -EACCES;
281 } 281 }
282 return 0; 282 return 0;
283 } 283 }
284 284
285 static int myriadfs_rename( const char *sFrom, const char *sTo ) 285 static int myriadfs_rename( const char *sFrom, const char *sTo )
286 { 286 {
287#ifdef TRACE 287#ifdef TRACE
288 printf("myriadfs_rename(\"%s\", \"%s\");\n", sFrom, sTo ); 288 printf("myriadfs_rename(\"%s\", \"%s\");\n", sFrom, sTo );
289#endif 289#endif
290 290
291 try 291 try
292 { 292 {
293 pFs->rename( sFrom, sTo ); 293 pFs->rename( sFrom, sTo );
294 } 294 }
295 catch( Bu::MyriadFsException &e ) 295 catch( Bu::MyriadFsException &e )
296 { 296 {
297 printf("MyriadFsException: %s\n", e.what() ); 297 printf("MyriadFsException: %s\n", e.what() );
298 return -EACCES; 298 return -EACCES;
299 } 299 }
300 return 0; 300 return 0;
301 } 301 }
302 302
303 static struct fuse_operations myriadfs_oper; 303 static struct fuse_operations myriadfs_oper;
304 304
305 int main( int argc, char *argv[] ) 305 int main( int argc, char *argv[] )
306 { 306 {
307 pF = new Bu::File("store.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create ); 307 pF = new Bu::File("store.myr", Bu::File::Read|Bu::File::Write|Bu::File::Create );
308 pFs = new Bu::MyriadFs( *pF, 512 ); 308 pFs = new Bu::MyriadFs( *pF, 512 );
309 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 ); 309 memset( &myriadfs_oper, sizeof(myriadfs_oper), 0 );
310 myriadfs_oper.getattr = myriadfs_getattr; 310 myriadfs_oper.getattr = myriadfs_getattr;
311 myriadfs_oper.readdir = myriadfs_readdir; 311 myriadfs_oper.readdir = myriadfs_readdir;
312 myriadfs_oper.mkdir = myriadfs_mkdir; 312 myriadfs_oper.mkdir = myriadfs_mkdir;
313 myriadfs_oper.open = myriadfs_open; 313 myriadfs_oper.open = myriadfs_open;
314 myriadfs_oper.read = myriadfs_read; 314 myriadfs_oper.read = myriadfs_read;
315 myriadfs_oper.write = myriadfs_write; 315 myriadfs_oper.write = myriadfs_write;
316 myriadfs_oper.create = myriadfs_create; 316 myriadfs_oper.create = myriadfs_create;
317 myriadfs_oper.mknod = myriadfs_mknod; 317 myriadfs_oper.mknod = myriadfs_mknod;
318 myriadfs_oper.release = myriadfs_release; 318 myriadfs_oper.release = myriadfs_release;
319 myriadfs_oper.utimens = myriadfs_utimens; 319 myriadfs_oper.utimens = myriadfs_utimens;
320 myriadfs_oper.unlink = myriadfs_unlink; 320 myriadfs_oper.unlink = myriadfs_unlink;
321 myriadfs_oper.rmdir = myriadfs_unlink; 321 myriadfs_oper.rmdir = myriadfs_unlink;
322 myriadfs_oper.symlink = myriadfs_symlink; 322 myriadfs_oper.symlink = myriadfs_symlink;
323 myriadfs_oper.readlink = myriadfs_readlink; 323 myriadfs_oper.readlink = myriadfs_readlink;
324 myriadfs_oper.truncate = myriadfs_truncate; 324 myriadfs_oper.truncate = myriadfs_truncate;
325 myriadfs_oper.link = myriadfs_link; 325 myriadfs_oper.link = myriadfs_link;
326 myriadfs_oper.rename = myriadfs_rename; 326 myriadfs_oper.rename = myriadfs_rename;
327 printf("Starting fuse_main.\n"); 327 printf("Starting fuse_main.\n");
328 int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL ); 328 int iRet = fuse_main( argc, argv, &myriadfs_oper, NULL );
329 printf("Done with fuse_main.\n"); 329 printf("Done with fuse_main.\n");
330 delete pFs; 330 delete pFs;
331 delete pF; 331 delete pF;
332 return iRet; 332 return iRet;
333 } 333 }
334} 334}