Esempio n. 1
0
 def op_readdir(self, op):
     # We ignore dircount hint
     print "  CURRENT FILEHANDLE %s" % repr(self.curr_fh)
     print "  COOKIEVERF: %s, %s" % ( repr(op.opreaddir.cookieverf), repr(op.opreaddir.cookie))
     print "  DIRCOUNT: %d MAXCOUNT: %d" % ( op.opreaddir.dircount, op.opreaddir.maxcount)
     print "  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opreaddir.attr_request)]
     if not self.curr_fh:
         return simple_error(NFS4ERR_NOFILEHANDLE)
     if self.curr_fh.get_type() != NF4DIR:
         return simple_error(NFS4ERR_NOTDIR)
     if op.opreaddir.cookie in [1,2]:
         return simple_error(NFS4ERR_BAD_COOKIE)
     if op.opreaddir.maxcount == 0:
         return simple_error(NFS4ERR_TOOSMALL)
     zeroverf = '\x00\x00\x00\x00\x00\x00\x00\x00'
     if op.opreaddir.cookie == 0 and op.opreaddir.cookieverf != zeroverf:
         return simple_error(NFS4ERR_BAD_COOKIE)
     try:
         verifier = self.curr_fh.getdirverf()
         if op.opreaddir.cookie != 0:
             if op.opreaddir.cookieverf != verifier:
                 return simple_error(NFS4ERR_NOT_SAME)
         try:
             dirlist = self.curr_fh.read_dir(op.opreaddir.cookie)
         except IndexError:
             return simple_error(NFS4ERR_BAD_COOKIE)
         attrs = nfs4lib.bitmap2list(op.opreaddir.attr_request)
         entries = []
         bytecnt = 0
         packer = nfs4lib.FancyNFS4Packer()
         for entry in dirlist:
             # Get file attributes
             try:
                 attrvals = entry.fh.get_attributes(attrs)
             except NFS4Error:
                 if FATTR4_RDATTR_ERROR not in attrs: raise
                 attrvals = entry.fh.get_attributes([FATTR4_RDATTR_ERROR])
             entry.attr = attrvals
             # Compute size of XDR encoding
             e4 = entry4(entry.cookie, entry.name, entry.attr, [])
             packer.reset()
             packer.pack_entry4(e4)
             # Make sure returned value not too big
             bytecnt += len(packer.get_buffer())
             if bytecnt > op.opreaddir.maxcount - 16:
                 break
             # Add file to returned entries
             entries.insert(0,entry)
         if (not entries) and dirlist:
             return simple_error(NFS4ERR_TOOSMALL)
         # Encode entries as linked list
         e4 = []
         for entry in entries:
             e4 = [entry4(entry.cookie, entry.name, entry.attr, nextentry=e4)]
         if len(entries) < len(dirlist):
             d4 = dirlist4(e4, eof=0)
         else:
             d4 = dirlist4(e4, eof=1)
     except NFS4Error, e:
         return simple_error(e.code)
Esempio n. 2
0
 def op_getattr(self, op):
     print "  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opgetattr.attr_request)]
     try:
         if not self.curr_fh:
             return simple_error(NFS4ERR_NOFILEHANDLE)
         attrs = nfs4lib.bitmap2list(op.opgetattr.attr_request)
         attrvals = self.curr_fh.get_attributes(attrs)
     except NFS4Error, e:
         return simple_error(e.code)
Esempio n. 3
0
 def op_getattr(self, op):
     print("  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opgetattr.attr_request)])
     try:
         if not self.curr_fh:
             return simple_error(NFS4ERR_NOFILEHANDLE)
         attrs = nfs4lib.bitmap2list(op.opgetattr.attr_request)
         attrvals = self.curr_fh.get_attributes(attrs)
     except NFS4Error as e:
         return simple_error(e.code)
     garesok = GETATTR4resok(attrvals)
     return simple_error(NFS4_OK, garesok)
Esempio n. 4
0
def check_res(t, c, res, file, dict):
    modified = bitmap2list(res.resarray[-1].attrsset)
    for attr in modified:
        if attr not in dict:
            t.fail("attrsset contained %s, which was not requested" %
                   get_bitnumattr_dict()[attr])
    newdict = c.do_getattrdict(file, dict.keys())
    if newdict != dict:
        t.fail("Set attrs %s not equal to got attrs %s" % (dict, newdict))
Esempio n. 5
0
def check_res(t, c, res, file, dict):
    modified = bitmap2list(res.resarray[-1].attrsset)
    for attr in modified:
        if attr not in dict:
            t.fail("attrsset contained %s, which was not requested" %
                   get_bitnumattr_dict()[attr])
    newdict = c.do_getattrdict(file, dict.keys())
    if newdict != dict:
        t.fail("Set attrs %s not equal to got attrs %s" % (dict, newdict))
Esempio n. 6
0
 def op_readdir(self, op):
     # We ignore dircount hint
     print("  CURRENT FILEHANDLE %s" % repr(self.curr_fh))
     print("  COOKIEVERF: %s, %s" % ( repr(op.opreaddir.cookieverf), repr(op.opreaddir.cookie)))
     print("  DIRCOUNT: %d MAXCOUNT: %d" % ( op.opreaddir.dircount, op.opreaddir.maxcount))
     print("  ATTRMASK: %s" % [nfs4lib.get_attr_name(bit) for bit in nfs4lib.bitmap2list(op.opreaddir.attr_request)])
     if not self.curr_fh:
         return simple_error(NFS4ERR_NOFILEHANDLE)
     if self.curr_fh.get_type() != NF4DIR:
         return simple_error(NFS4ERR_NOTDIR)
     if op.opreaddir.cookie in [1,2]:
         return simple_error(NFS4ERR_BAD_COOKIE)
     if op.opreaddir.maxcount == 0:
         return simple_error(NFS4ERR_TOOSMALL)
     zeroverf = '\x00\x00\x00\x00\x00\x00\x00\x00'
     if op.opreaddir.cookie == 0 and op.opreaddir.cookieverf != zeroverf:
         return simple_error(NFS4ERR_BAD_COOKIE)
     try:
         verifier = self.curr_fh.getdirverf()
         if op.opreaddir.cookie != 0:
             if op.opreaddir.cookieverf != verifier:
                 return simple_error(NFS4ERR_NOT_SAME)
         try:
             dirlist = self.curr_fh.read_dir(op.opreaddir.cookie)
         except IndexError:
             return simple_error(NFS4ERR_BAD_COOKIE)
         attrs = nfs4lib.bitmap2list(op.opreaddir.attr_request)
         entries = []
         bytecnt = 0
         packer = nfs4lib.FancyNFS4Packer()
         for entry in dirlist:
             # Get file attributes
             try:
                 attrvals = entry.fh.get_attributes(attrs)
             except NFS4Error:
                 if FATTR4_RDATTR_ERROR not in attrs: raise
                 attrvals = entry.fh.get_attributes([FATTR4_RDATTR_ERROR])
             entry.attr = attrvals
             # Compute size of XDR encoding
             e4 = entry4(entry.cookie, entry.name, entry.attr, [])
             packer.reset()
             packer.pack_entry4(e4)
             # Make sure returned value not too big
             bytecnt += len(packer.get_buffer())
             if bytecnt > op.opreaddir.maxcount - 16:
                 break
             # Add file to returned entries
             entries.insert(0,entry)
         if (not entries) and dirlist:
             return simple_error(NFS4ERR_TOOSMALL)
         # Encode entries as linked list
         e4 = []
         for entry in entries:
             e4 = [entry4(entry.cookie, entry.name, entry.attr, nextentry=e4)]
         if len(entries) < len(dirlist):
             d4 = dirlist4(e4, eof=0)
         else:
             d4 = dirlist4(e4, eof=1)
     except NFS4Error as e:
         return simple_error(e.code)
     rdresok = READDIR4resok(cookieverf=verifier, reply=d4)
     return simple_error(NFS4_OK, rdresok)