def __init__(self): self.start = int(time.time()) rootdir = py9p.Dir(0) # not dotu rootdir.children = [] rootdir.type = 0 rootdir.dev = 0 rootdir.mode = 0755 rootdir.atime = rootdir.mtime = int(time.time()) rootdir.length = 0 rootdir.name = '/' rootdir.uid = rootdir.gid = rootdir.muid = os.environ['USER'] rootdir.qid = py9p.Qid(py9p.QTDIR, 0, py9p.hash8(rootdir.name)) rootdir.parent = rootdir self.root = rootdir # / is its own parent, just so we don't fall off the edge of the earth # two files in '/' f = copy.copy(rootdir) f.name = 'sample1' f.qid = py9p.Qid(0, 0, py9p.hash8(f.name)) f.length = 1024 f.parent = rootdir self.root.children.append(f) f = copy.copy(f) f.name = 'sample2' f.length = 8192 f.qid = py9p.Qid(0, 0, py9p.hash8(f.name)) self.root.children.append(f) self.files[self.root.qid.path] = self.root for x in self.root.children: self.files[x.qid.path] = x
def readlink(self, tfid, path): if py9p.hash8(path) in self.dircache: return self.dircache[py9p.hash8(path)].extension self.client._walk(self.client.ROOT, tfid, filter(None, path.split("/"))) self.client._open(tfid, py9p.OREAD) ret = self.client._read(tfid, 0, self.msize) self.client._clunk(tfid) return ret.data
def write(self, tfid, path, buf, offset, f): if py9p.hash8(path) in self.dircache: del self.dircache[py9p.hash8(path)] size = len(buf) for i in range((size + f.iounit - 1) / f.iounit): start = i * f.iounit length = start + f.iounit self.client._write(f.fid, offset + start, buf[start:length]) return size
def _getattr(self, tfid, path): if py9p.hash8(path) in self.dircache: return fStat(self.dircache[py9p.hash8(path)]) self.client._walk(self.client.ROOT, tfid, filter(None, path.split("/"))) ret = self.client._stat(tfid).stat[0] s = fStat(ret) self.client._clunk(tfid) self.dircache[py9p.hash8(path)] = ret return s
def pathtodir(self, f): '''Stat-to-dir conversion''' s = _os(os.lstat, f) u = uidname(s.st_uid) g = gidname(s.st_gid) res = s.st_mode & 0777 type = 0 ext = "" if stat.S_ISDIR(s.st_mode): type = type | py9p.QTDIR res = res | py9p.DMDIR qid = py9p.Qid(type, 0, py9p.hash8(f)) if self.dotu: if stat.S_ISLNK(s.st_mode): ext = os.readlink(f) ext = os.path.join(os.path.dirname(f), ext) elif stat.S_ISCHR(s.st_mode): ext = "c %d %d" % (os.major(s.st_rdev), os.minor(s.st_rdev)) elif stat.S_ISBLK(s.st_mode): ext = "b %d %d" % (os.major(s.st_rdev), os.minor(s.st_rdev)) else: ext = "" return py9p.Dir(1, 0, s.st_dev, qid, res, int(s.st_atime), int(s.st_mtime), s.st_size, os.path.basename(f), u, gidname(s.st_gid), u, ext, s.st_uid, s.st_gid, s.st_uid) else: return py9p.Dir(0, 0, s.st_dev, qid, res, int(s.st_atime), int(s.st_mtime), s.st_size, os.path.basename(f), u, g, u)
def __init__(self): rootdir = py9p.Dir(0) # not dotu rootdir.children = [] rootdir.type = 0 rootdir.dev = 0 rootdir.mode = 0755 | py9p.DMDIR rootdir.atime = rootdir.mtime = int(time.time()) rootdir.length = 0 rootdir.name = '/' rootdir.uid = rootdir.gid = rootdir.muid = os.environ['USER'] rootdir.qid = py9p.Qid(py9p.QTDIR, 0, py9p.hash8(rootdir.name)) rootdir.parent = rootdir self.root = rootdir self.root.qid.file_obj = rootdir for bar in bars: print('Processing bar:', bar) for socket_name, socket in bar.sockets.items(): print('Processing socket:', socket_name) nd = self._make_file(socket_name, self.root) self.root.children.append(nd) qid_to_socket[nd.qid] = (socket_name, socket)
def __init__(self,name,parent,qtype=0,storage=None): py9p.Dir.__init__(self,True) self.parent = parent self.storage = storage or parent.storage self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(self.absolute_name())) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = {} self.static_children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE self.children["."] = self self.children[".."] = self.parent self.special_names = [".",".."] else: self.mode = DEFAULT_FILE_MODE self.data = StringIO() self.special_names = [] self.storage.register(self) self.child_map = {} self.subst_map = {}
def __init__(self, name, parent, qtype=0, storage=None): py9p.Dir.__init__(self, True) self.parent = parent self.storage = storage or parent.storage self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(self.absolute_name())) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = {} self.static_children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE self.children["."] = self self.children[".."] = self.parent self.special_names = [".", ".."] else: self.mode = DEFAULT_FILE_MODE self.data = StringIO() self.special_names = [] self.storage.register(self) self.child_map = {} self.subst_map = {}
def rename(self, tfid, path, dest): # the most complicated routine :| # 9p protocol has no "rename" neither "move" call # in the meaning of Linux vfs, it can only change # the name of an entry w/o moving it from dir to # dir, which can be done with wstat() for i in (path, dest): if py9p.hash8(i) in self.dircache: del self.dircache[py9p.hash8(i)] # if we can use wstat(): if path.split("/")[:-1] == dest.split("/")[:-1]: return self._wstat(path, newname=dest.split("/")[-1]) # it is not simple rename, fall back to copy/delete: # # get source and destination source = self._getattr(path) destination = self._getattr(dest) # abort on EIO if -errno.EIO in (source, destination): return -errno.EIO # create the destination file if destination == -errno.ENOENT: self.mknod(dest, source.st_mode, 0) if source.st_mode & stat.S_IFDIR: # move all the content to the new directory for i in self._readdir(path, 0): self.rename( "/".join((path, i.name)), "/".join((dest, i.name))) else: # open both files sf = self.open(path, os.O_RDONLY) df = self.open(dest, os.O_WRONLY | os.O_TRUNC) # copy the content for i in range((source.st_size + self.msize - 1) / self.msize): block = self.read(path, self.msize, i * self.msize, sf) self.write(dest, block, i * self.msize, df) # close files self.release(path, 0, sf) self.release(dest, 0, df) # remove the source self.unlink(path)
def __init__(self): self.dotu = 0 self.cancreate = 0 self.root = py9p.Dir(0) self.root.qid = py9p.Qid(py9p.QTDIR, 0, py9p.hash8('/')) self.root.localpath = '/' self.root.children = [] self.files[self.root.qid.path] = self.root for db in self.myexec("show databases"): self.root.children.append(db[0])
def pathtodir(self, f): '''Stat-to-dir conversion''' s = [] if f in self.myexec("show databases"): type = py9p.QTDIR res = py9p.DMDIR else: type = py9p.QTFILE res = 0770 qid = py9p.Qid(type, 0, py9p.hash8(f)) return py9p.Dir(1, 0, type, qid, res, 0, 0, 0, basename(f), 0, 0, 0)
def _wstat(self, tfid, path, uid=py9p.ERRUNDEF, gid=py9p.ERRUNDEF, mode=py9p.ERRUNDEF, newname=None): self.client._walk(self.client.ROOT, tfid, filter(None, path.split("/"))) if self.dotu: stats = [py9p.Dir( dotu=1, type=0, dev=0, qid=py9p.Qid(0, 0, py9p.hash8(path)), mode=mode, atime=int(time.time()), mtime=int(time.time()), length=py9p.ERRUNDEF, name=newname or path.split("/")[-1], uid="", gid="", muid="", extension="", uidnum=uid, gidnum=gid, muidnum=py9p.ERRUNDEF), ] else: stats = [py9p.Dir( dotu=0, type=0, dev=0, qid=py9p.Qid(0, 0, py9p.hash8(path)), mode=mode, atime=int(time.time()), mtime=int(time.time()), length=py9p.ERRUNDEF, name=newname or path.split("/")[-1], uid=pwd.getpwuid(uid).pw_name, gid=grp.getgrgid(gid).gr_name, muid=""), ] self.client._wstat(tfid, stats) self.client._clunk(tfid)
def readdir(self, path, offset): self._interval = 1 self._reconnect_event.set() dirs = self._readdir(path, offset) if not isinstance(dirs, list): dirs = [] if path == "/": path = "" for i in dirs: self.dircache[py9p.hash8("/".join((path, i.name)))] = i yield fuse.Direntry(i.name)
def _make_file(self, name, parent=None): newdir = py9p.Dir(0) # not dotu newdir.children = [] newdir.type = 0 newdir.dev = 0 newdir.mode = 0220 newdir.atime = newdir.mtime = int(time.time()) newdir.length = 0 newdir.name = name newdir.uid = newdir.gid = newdir.muid = os.environ['USER'] newdir.qid = py9p.Qid(0, 0, py9p.hash8(newdir.name)) if parent: newdir.parent = parent else: newdir.parent = newdir newdir.qid.file_obj = newdir return newdir
def __init__(self, name, qtype=0, parent=None): py9p.Dir.__init__(self, True) self.parent = parent self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(name)) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE else: self.mode = DEFAULT_FILE_MODE self.data = StringIO()
def __init__(self,name,qtype=0,parent=None): py9p.Dir.__init__(self,True) self.parent = parent self.name = name # # DMDIR = 0x80000000 # QTDIR = 0x80 # self.qid = py9p.Qid((qtype >> 24) & py9p.QTDIR, 0, py9p.hash8(name)) self.type = 0 self.dev = 0 self.atime = self.mtime = int(time.time()) self.uidnum = self.muidnum = os.getuid() self.gidnum = os.getgid() self.uid = self.muid = pwd.getpwuid(self.uidnum).pw_name self.gid = grp.getgrgid(self.gidnum).gr_name self.children = [] self.writelock = False if self.qid.type & py9p.QTDIR: self.mode = py9p.DMDIR | DEFAULT_DIR_MODE else: self.mode = DEFAULT_FILE_MODE self.data = StringIO()