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 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