# NFS RPC client -- RFC 1094
# XXX This is not yet complete.
# XXX Only GETATTR, SETTTR, LOOKUP and READDIR are supported.
# (See mountclient.py for some hints on how to write RPC clients in
from rpc import UDPClient, TCPClient
from mountclient import FHSIZE, MountPacker, MountUnpacker
# (...many error values...)
class NFSPacker(MountPacker):
def pack_sattrargs(self, sa):
self.pack_sattr(attributes)
def pack_sattr(self, sa):
mode, uid, gid, size, atime, mtime = sa
def pack_diropargs(self, da):
def pack_readdirargs(self, ra):
def pack_timeval(self, tv):
class NFSUnpacker(MountUnpacker):
def unpack_readdirres(self):
status = self.unpack_enum()
entries = self.unpack_list(self.unpack_entry)
fileid = self.unpack_uint()
name = self.unpack_string()
cookie = self.unpack_uint()
return (fileid, name, cookie)
def unpack_diropres(self):
status = self.unpack_enum()
fh = self.unpack_fhandle()
def unpack_attrstat(self):
status = self.unpack_enum()
attributes = self.unpack_fattr()
return status, attributes
type = self.unpack_enum()
mode = self.unpack_uint()
nlink = self.unpack_uint()
size = self.unpack_uint()
blocksize = self.unpack_uint()
rdev = self.unpack_uint()
blocks = self.unpack_uint()
fsid = self.unpack_uint()
fileid = self.unpack_uint()
atime = self.unpack_timeval()
mtime = self.unpack_timeval()
ctime = self.unpack_timeval()
return (type, mode, nlink, uid, gid, size, blocksize, \
rdev, blocks, fsid, fileid, atime, mtime, ctime)
def unpack_timeval(self):
secs = self.unpack_uint()
usecs = self.unpack_uint()
class NFSClient(UDPClient):
def __init__(self, host):
UDPClient.__init__(self, host, NFS_PROGRAM, NFS_VERSION)
self.packer = NFSPacker()
self.unpacker = NFSUnpacker('')
self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
return self.make_call(1, fh, \
self.packer.pack_fhandle, \
self.unpacker.unpack_attrstat)
return self.make_call(2, sa, \
self.packer.pack_sattrargs, \
self.unpacker.unpack_attrstat)
return self.make_call(4, da, \
self.packer.pack_diropargs, \
self.unpacker.unpack_diropres)
return self.make_call(16, ra, \
self.packer.pack_readdirargs, \
self.unpacker.unpack_readdirres)
# Shorthand to get the entire contents of a directory
(status, rest) = self.Readdir(ra)
for fileid, name, cookie in entries:
list.append((fileid, name))
if eof or last_cookie is None:
ra = (ra[0], last_cookie, ra[2])
if sys.argv[1:]: host = sys.argv[1]
if sys.argv[2:]: filesys = sys.argv[2]
from mountclient import UDPMountClient, TCPMountClient
mcl = TCPMountClient(host)
attrstat = ncl.Getattr(fh)
for item in list: print item