Beispiel #1
0
    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
Beispiel #2
0
 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)
Beispiel #3
0
 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
Beispiel #4
0
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
Beispiel #5
0
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)