def __init__(self): self.start = int(time.time()) rootdir = py9p.Dir(0) # not dotu rootdir.children = [] rootdir.type = 0 rootdir.dev = 0 rootdir.mode = 0o20000000755 rootdir.atime = rootdir.mtime = int(time.time()) rootdir.length = 0 rootdir.name = '/' rootdir.uid = rootdir.gid = rootdir.muid = bytes3(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 f.mode = 0o644 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)) f.mode = 0o644 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 create(self, srv, req, inode): new = self.storage.create(req.ifcall.name, inode, py9p.mode2stat(req.ifcall.perm)) if new.mode == stat.S_IFLNK: new.write(bytes(req.ifcall.extension.encode('utf-8'))) req.ofcall.qid = py9p.Qid((req.ifcall.perm >> 24) & py9p.QTDIR, 0, new.path) srv.respond(req, None)
def NinePFile(name, parent, byte_length): f = copy.copy(parent) f.name = name f.qid = py9p.Qid(0, 0, py9p.hash8(f.name)) f.length = byte_length f.parent = parent f.mode = 0o644 return f
def create(self, srv, req): # get parent f = self.files[req.fid.qid.path] if req.ifcall.perm & py9p.DMDIR: new = py9p.Dir(0, dev=0, type=0, mode=req.ifcall.perm, length=0, name=req.ifcall.name, qid=py9p.Qid(py9p.QTDIR, 0, py9p.hash8(req.ifcall.name)), uid=os.environ['USER'], gid=f.gid, muid=os.environ['USER'], parent=f) new.atime = new.mtime = int(time.time()) new.children = [] self.files[new.qid.path] = new f.children.append(new) req.ofcall.qid = new.qid else: new = py9p.Dir(0, dev=0, type=0, mode=req.ifcall.perm, length=0, name=req.ifcall.name, qid=py9p.Qid(0, 0, py9p.hash8(req.ifcall.name)), uid=os.environ['USER'], gid=f.gid, muid=os.environ['USER'], parent=f) new.atime = new.mtime = int(time.time()) self.files[new.qid.path] = new f.children.append(new) req.ofcall.qid = new.qid srv.respond(req, None)
def __init__(self): self.start = int(time.time()) rootdir = py9p.Dir(0) # not dotu rootdir.children = [] rootdir.type = 0 rootdir.dev = 0 rootdir.mode = 020000000755 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 self.files[self.root.qid.path] = self.root
def rootdir(): """Build a valid 9P Directory to serve as a root directory""" # Assumes the protocol version is .u/dotu 0; ie: This is legacy, not .u rdir = py9p.Dir() rdir.children = [] rdir.type = 0 rdir.dev = 0 rdir.mode = 0o20000000755 rdir.atime = rdir.mtime = int(time.time()) rdir.length = 0 rdir.name = '/' rdir.uid = rdir.gid = rdir.muid = bytes3(os.environ['USER']) rdir.qid = py9p.Qid(py9p.QTDIR, 0, py9p.hash8(rdir.name)) rdir.parent = rdir # / is its own parent, just so we don't fall off the edge of the earth return rdir
def walk(self, srv, req, fid=None): fd = fid or req.fid f = self.storage.checkout(fd.qid.path) self.storage.sync(f) for (i, k) in list(f.children.items()): if req.ifcall.wname[0] == i: qid = py9p.Qid((py9p.mode2plan(k.mode) >> 24) & py9p.QTDIR, 0, hash(k)) req.ofcall.wqid.append(qid) if len(req.ifcall.wname) > 1: req.ifcall.wname.pop(0) self.walk(srv, req, inode2dir(k)) else: srv.respond(req, None) return srv.respond(req, "file not found") return
def inode2dir(inode): return py9p.Dir(dotu=1, type=0, dev=0, qid=py9p.Qid((py9p.mode2plan(inode.mode) >> 24) & py9p.QTDIR, 0, inode.path), mode=py9p.mode2plan(inode.mode), atime=inode.atime, mtime=inode.mtime, length=inode.length, name=bytes(inode.name.encode('utf-8')), uid=bytes(inode.uid.encode('utf-8')), gid=bytes(inode.gid.encode('utf-8')), muid=bytes(inode.muid.encode('utf-8')), extension=inode.getvalue() if inode.mode == stat.S_IFLNK else b'', uidnum=inode.uidnum, gidnum=inode.gidnum, muidnum=inode.muidnum)