def __init__(self, *args, **kw): self.dirtree = CBFSDirtree() if not ('unittest' in kw and kw['unittest']): Fuse.__init__(self, *args, **kw) #print "args: " + str(sys.argv) #if '-c' in sys.argv: #i = sys.argv.index('-c') #if i>=len(sys.argv)-1: #raise Exception("Configuration file not specified!") #config = sys.argv[i+1] #else: #raise Exception("Configuration file not specified!") config = "cbfs.conf" self.chunkstore = ChunkStoreManager(self.dirtree, config) # passes complete dirtree to other classes (e.g. CBFSFilehandle) global dirtree dirtree = self.dirtree
class CBFS(Fuse): dirtree = None chunkstore = None def __init__(self, *args, **kw): self.dirtree = CBFSDirtree() if not ('unittest' in kw and kw['unittest']): Fuse.__init__(self, *args, **kw) #print "args: " + str(sys.argv) #if '-c' in sys.argv: #i = sys.argv.index('-c') #if i>=len(sys.argv)-1: #raise Exception("Configuration file not specified!") #config = sys.argv[i+1] #else: #raise Exception("Configuration file not specified!") config = "cbfs.conf" self.chunkstore = ChunkStoreManager(self.dirtree, config) # passes complete dirtree to other classes (e.g. CBFSFilehandle) global dirtree dirtree = self.dirtree def getattr(self, path): print "getattr(%s)" % path try: print "returning path:" s = self.dirtree.getnode(path).st s.printme() return s except: print "getattr: node not found" traceback.print_exc() return -errno.ENOENT def readdir(self, path, offset): print "readdir(%s, %s)" % (path, offset) try: dir = self.dirtree.getnode(path) except: print "dir not found" traceback.print_exc() yield -errno.ENOENT return if not isinstance(dir, CBFSDirectory): print "dir not a directory" yield -errno.ENOENT return yield fuse.Direntry(".") yield fuse.Direntry("..") for e in dir.entries: print "readdir: yielding %s" % dir.entries[e].name yield dir.entries[e] def readlink(self, path): print "readlink(%s)" % path try: dir = self.dirtree.getnode(path) except: traceback.print_exc() return -errno.ENOENT if not isinstance(dir, CBFSSymlink): return -errno.EACCES return dir.dest def unlink(self, path): print "unlink(%s)" % path try: dir = self.dirtree.getnode(path) if isinstance(dir, CBFSDirectory): return -errno.EACCES parent = dir.parent del(parent.entries[dir.name]) except: traceback.print_exc() return -errno.ENOENT def rmdir(self, path): print "rmdir(%s)" % path try: dir = self.dirtree.getnode(path) except: traceback.print_exc() return -errno.ENOENT if (not isinstance(dir, CBFSDirectory)) or len(dir.entries)>0: return -errno.EACCES parent = dir.parent print "parent: %s" % parent.name del(parent.entries[dir.name]) def symlink(self, target, name): print "symlink(%s, %s)" % (target, name) (dirname, sep, symname) = name.rpartition("/") try: dir = self.dirtree.getnode(dirname) if not isinstance(dir, CBFSDirectory): return -errno.EACCES dir.entries[symname] = CBFSSymlink(symname, dir, target) except: traceback.print_exc() return -errno.ENOENT def rename(self, path, path1): print "rename(%s, %s)" % (path, path1) (dirname1, sep, name1) = path.rpartition("/") (dirname2, sep, name2) = path1.rpartition("/") try: dir1 = self.dirtree.getnode(dirname1) dir2 = self.dirtree.getnode(dirname2) entry1 = dir1.entries[name1] except: traceback.print_exc() return -errno.ENOENT if name2 in dir2.entries: return -errno.EEXIST dir2.entries[name2] = entry1 entry1.name = name2; del(dir1.entries[name1]) #def link(self, path, path1): def chmod(self, path, mode): print "chmod(%s, %s)" % (path, mode) try: dir = self.dirtree.getnode(path) except: traceback.print_exc() return -errno.ENOENT dir.st.st_mode = mode def chown(self, path, user, group): print "chown(%s, %s, %s)" % (path, user, group) try: dir = self.dirtree.getnode(path) except: traceback.print_exc() return -errno.ENOENT if user>=0: dir.st.st_uid = user if group>=0: dir.st.st_gid = group def truncate(self, path, len): print "truncate(%s, %s)" % (path, len) fh = CBFSFilehandle(path, None) fh.truncate(len) def mknod(self, path, mode, dev): print "mknod(%s, %s, %s)" % (path, mode, dev) if not mode&stat.S_IFREG: return -errno.EOPNOTSUPP (dirname, sep, newfilename) = path.rpartition("/") try: dir = self.dirtree.getnode(dirname) except: traceback.print_exc() return -errno.ENOENT dir.entries[newfilename] = CBFSFile(newfilename, dir) def mkdir(self, path, mode): print "mkdir(%s, %s)" % (path, mode) (dirname, sep, newdirname) = path.rpartition("/") try: dir = self.dirtree.getnode(dirname) except: traceback.print_exc() return -errno.ENOENT if newdirname in dir.entries: return -errno.EEXIST dir.entries[newdirname] = CBFSDirectory(newdirname, dir) def utime(self, path, times): print "utime(%s, %s)" % (path, times) try: st = self.dirtree.getnode(path).st st.st_atime = times[0] st.st_mtime = times[1] except: print "utime: node not found (%s)!" % sys.exc_info()[0] traceback.print_exc() return -errno.ENOENT def access(self, path, mode): print "access(%s, %s): ******** not implemented!" % (path, mode) return def setattr(self, path, st): print "setattr(%s, %s): ******** not implemented!" % (path, st) print def statfs(self): print "statfs()" csstat = self.chunkstore.getSpaceStat() stat = fuse.StatVfs() stat.f_bsize = 1 stat.f_frsize = stat.f_bsize stat.f_blocks = csstat[1] stat.f_bfree = csstat[1]-csstat[0] stat.f_bavail = stat.f_bfree stat.f_files = csstat[0] stat.f_ffree = stat.f_bfree stat.f_favail = stat.f_bfree return stat def fsinit(self): print "fsinit()" global chunkstore chunkstore = self.chunkstore self.dirtree.chunkstore = self.chunkstore try: self.dirtree.load() except Exception, e: traceback.print_exc()