Esempio n. 1
0
    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)
Esempio n. 2
0
    def decstat(self, fcall, enclen=0):
        fcall.stat = []
        if enclen:
            totsz = self.dec2()
        while len(self.bytes):
            size = self.dec2()
            b = self.bytes
            self.bytes = b[0:size]

            stat = py9p.Dir(self.dotu)
            stat.type = self.dec2()     # type
            stat.dev = self.dec4()      # dev
            stat.qid = self.decQ()      # qid
            stat.mode = self.dec4()     # mode
            stat.atime = self.dec4()    # atime
            stat.mtime = self.dec4()    # mtime
            stat.length = self.dec8()   # length
            stat.name = self.decS()     # name  
            stat.uid = self.decS()      # uid
            stat.gid = self.decS()      # gid
            stat.muid = self.decS()     # muid
            if self.dotu:
                stat.extension = self.decS()
                stat.uidnum = self.dec4()
                stat.gidnum = self.dec4()
                stat.muidnum = self.dec4()
            fcall.stat.append(stat)
            self.bytes = b[size:]
Esempio n. 3
0
 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])
Esempio n. 4
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)
Esempio n. 5
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)