Exemplo n.º 1
0
    def do_requestlock(self, line):
	pathcomps = self.ncl.get_pathcomps_rel(line)
	putrootfhop = self.ncl.putrootfh_op()
	lookupops = self.ncl.lookup_path(pathcomps)
	operations = [putrootfhop] + lookupops

	getfhop = self.ncl.getfh_op()
	operations.append(getfhop)

	stateid = stateid4(ncl, self.seqid, "FIXME")
	lock_type = READ_LT
	offset = 0
	length = pow(2, 64) - 1

	lock_owner = lock_owner4(ncl, ncl.clientid, "FIXME")
	open_to_lock_owner = open_to_lock_owner4(ncl, self.seqid, stateid, self.seqid, lock_owner)
	locker_me = locker4(ncl, TRUE, open_to_lock_owner)
	lockop = self.ncl.lock_op(lock_type, FALSE, offset,
				  length, locker=locker_me)
	operations.append(lockop)

	res = self.ncl.compound(operations)
	self.seqid = self.seqid + 1
	try:
	    nfs4lib.check_result(res)
	except nfs4lib.BadCompoundRes, r:
	    print "Error retrieving lock response:", r
	    return
Exemplo n.º 2
0
def create_dir(ncl, curdir, newdir):
    operations = [ncl.putrootfh_op()] + ncl.lookup_path(curdir)
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, newdir)
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)
Exemplo n.º 3
0
def clean_dir(directory):
    fh = ncl.do_getfh(directory)
    entries = ncl.do_readdir(fh)
    names = [entry.name for entry in entries]

    for name in names:
        lookup_dir_ops = ncl.lookup_path(directory)
        operations = [ncl.putrootfh_op()] + lookup_dir_ops
        operations.append(ncl.remove_op(name))
        res = ncl.compound(operations)

        if res.status == NFS4ERR_NOTEMPTY:
            # Recursive deletion
            clean_dir(directory + [name])
            # Remove dir itself
            lookup_dir_ops = ncl.lookup_path(directory)
            operations = [ncl.putrootfh_op()] + lookup_dir_ops
            operations.append(ncl.remove_op(name))
            res = ncl.compound(operations)
            nfs4lib.check_result(res)
        elif not res.status == NFS4_OK:
            raise "Cannot clean directory %s" % directory

    # Verify that all files were removed
    entries = ncl.do_readdir(fh)
    if entries:
        raise "Cannot clean directory %s" % directory
Exemplo n.º 4
0
def create_dir(ncl, curdir, create_dir):
    operations = [ncl.putrootfh_op()] + ncl.lookup_path(curdir)
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, create_dir)
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)
Exemplo n.º 5
0
def clean_dir(directory):
    fh = ncl.do_getfh(directory)
    entries = ncl.do_readdir(fh)
    names = [entry.name for entry in entries]

    for name in names:
        lookup_dir_ops = ncl.lookup_path(directory)
        operations = [ncl.putrootfh_op()] + lookup_dir_ops
        operations.append(ncl.remove_op(name))
        res = ncl.compound(operations)

        if res.status == NFS4ERR_NOTEMPTY:
            # Recursive deletion
            clean_dir(directory + [name])
            # Remove dir itself
            lookup_dir_ops = ncl.lookup_path(directory)
            operations = [ncl.putrootfh_op()] + lookup_dir_ops
            operations.append(ncl.remove_op(name))
            res = ncl.compound(operations)
            nfs4lib.check_result(res)
        elif not res.status == NFS4_OK:
            raise "Cannot clean directory %s" % directory

    # Verify that all files were removed
    entries = ncl.do_readdir(fh)
    if entries:
        raise "Cannot clean directory %s" % directory
Exemplo n.º 6
0
    def do_create(self, line):
        args = line.split()
        if len(args) < 2:
            print "create <type> <name> <arguments>"
            return

        (type, objname) = line.split(None, 3)[:2]
        if type == "link":
            if len(args) < 3:
                print "create link <name> <target>"
                return
            else:
                linkdata = args[2]
            objtype = createtype4(self.ncl, type=NF4LNK, linkdata=linkdata)
        elif type == "block":
            if len(args) < 4:
                print "create block <name> major minor"
                return
            major = int(args[2])
            minor = int(args[3])
            devdata = specdata4(self.ncl, major, minor)
            objtype = createtype4(self.ncl, type=NF4BLK, devdata=devdata)
        elif type == "char":
            if len(args) < 4:
                print "create char <name> major minor"
                return
            major = int(args[2])
            minor = int(args[3])
            devdata = specdata4(self.ncl, major, minor)
            objtype = createtype4(self.ncl, type=NF4CHR, devdata=devdata)
        elif type == "socket":
            objtype = createtype4(self.ncl, type=NF4SOCK)
        elif type == "fifo":
            objtype = createtype4(self.ncl, type=NF4FIFO)
        elif type == "dir":
            objtype = createtype4(self.ncl, type=NF4DIR)
        else:
            print "unknown type"
            return

        pathcomps = self.ncl.get_pathcomps_rel(objname)
        dircomps = pathcomps[:-1]
        lookupops = self.ncl.lookup_path(dircomps)
        operations = [self.ncl.putrootfh_op()] + lookupops

        # CREATE
        createop = self.ncl.create(objtype, pathcomps[-1])
        operations.append(createop)

        try:
            res = self.ncl.compound(operations)
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "create failed:", r
            return
Exemplo n.º 7
0
    def do_create(self, line):
        args = line.split()
        if len(args) < 2:
            print "create <type> <name> <arguments>"
            return

        (type, objname) = line.split(None, 3)[:2]
        if type == "link":
            if len(args) < 3:
                print "create link <name> <target>"
                return
            else:
                linkdata = args[2]
            objtype = createtype4(self.ncl, type=NF4LNK, linkdata=linkdata)
        elif type == "block":
            if len(args) < 4:
                print "create block <name> major minor"
                return
            major = int(args[2])
            minor = int(args[3])
            devdata = specdata4(self.ncl, major, minor)
            objtype = createtype4(self.ncl, type=NF4BLK, devdata=devdata)
        elif type == "char":
            if len(args) < 4:
                print "create char <name> major minor"
                return
            major = int(args[2])
            minor = int(args[3])
            devdata = specdata4(self.ncl, major, minor)
            objtype = createtype4(self.ncl, type=NF4CHR, devdata=devdata)
        elif type == "socket":
            objtype = createtype4(self.ncl, type=NF4SOCK)
        elif type == "fifo":
            objtype = createtype4(self.ncl, type=NF4FIFO)
        elif type == "dir":
            objtype = createtype4(self.ncl, type=NF4DIR)
        else:
            print "unknown type"
            return

        pathcomps = self.ncl.get_pathcomps_rel(objname)
        dircomps = pathcomps[:-1]
        lookupops = self.ncl.lookup_path(dircomps)
        operations = [self.ncl.putrootfh_op()] + lookupops

        # CREATE
        createop = self.ncl.create(objtype, pathcomps[-1])
        operations.append(createop)

        try:
            res = self.ncl.compound(operations)
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "create failed:", r
            return
Exemplo n.º 8
0
    def do_readlink(self, line):
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops
        
        readlinkop = self.ncl.readlink_op()
        operations.append(readlinkop)

        res = self.ncl.compound(operations)
        try:
              nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
              print "Error reading link data:", r
              return
Exemplo n.º 9
0
    def do_dir(self, line):
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops

        getfhop = self.ncl.getfh_op()
        operations.append(getfhop)

        res = self.ncl.compound(operations)
        try:
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "Cannot list directory:", r
            return
Exemplo n.º 10
0
    def do_unlock(self, line):
	pathcomps = self.ncl.get_pathcomps_rel(line)
	putrootfhop = self.ncl.putrootfh_op()
	lookupops = self.ncl.lookup_path(pathcomps)
	operations = [putrootfhop] + lookupops

	getfhop = self.ncl.getfh_op()
	operations.append(getfhop)

	res = self.ncl.compound(operations)
	try:
	    nfs4lib.check_result(res)
	except nfs4lib.BadCompoundRes, r:
	    print "Error getting filehandle:", r
	    return
Exemplo n.º 11
0
    def do_readlink(self, line):
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops
        
        readlinkop = self.ncl.readlink_op()
        operations.append(readlinkop)

        res = self.ncl.compound(operations)
        try:
	    nfs4lib.check_result(res)
	except nfs4lib.BadCompoundRes, r:
	    print "Error reading link data:", r
	    return
Exemplo n.º 12
0
    def do_dir(self, line):
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops

        getfhop = self.ncl.getfh_op()
        operations.append(getfhop)

        res = self.ncl.compound(operations)
        try:
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "Cannot list directory:", r
            return
Exemplo n.º 13
0
def create_leading_paths(ncl, prefix):
    # Get root fh
    fh = ncl.do_getfh([])
    for thisdir in prefix:
        try:
            fh = ncl.do_lookup(fh, thisdir)
        except nfs4lib.BadCompoundRes, e:
            if e.errcode == NFS4ERR_NOENT:
                # Create dir
                print "Creating directory", thisdir
                objtype = createtype4(ncl, type=NF4DIR)
                createop = ncl.create(objtype, thisdir)
                res = ncl.compound([ncl.putfh_op(fh), createop, ncl.getfh_op()])
                nfs4lib.check_result(res)
                fh = res.resarray[-1].arm.arm.object
            else:
                raise
        else:
            print "Directory", thisdir, "exists"
Exemplo n.º 14
0
    def do_access(self, line):
        if not line:
            print "access <filename>"
            return

        allrights = ACCESS4_DELETE + ACCESS4_EXECUTE + ACCESS4_EXTEND + ACCESS4_LOOKUP \
                    + ACCESS4_MODIFY + ACCESS4_READ
        
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops
        
        # ACCESS
        operations.append(self.ncl.access_op(allrights))
        res = self.ncl.compound(operations)
        try:
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "access failed:", r
            return
Exemplo n.º 15
0
    def do_access(self, line):
        if not line:
            print "access <filename>"
            return

        allrights = ACCESS4_DELETE + ACCESS4_EXECUTE + ACCESS4_EXTEND + ACCESS4_LOOKUP \
                    + ACCESS4_MODIFY + ACCESS4_READ
        
        pathcomps = self.ncl.get_pathcomps_rel(line)
        putrootfhop = self.ncl.putrootfh_op()
        lookupops = self.ncl.lookup_path(pathcomps)
        operations = [putrootfhop] + lookupops
        
        # ACCESS
        operations.append(self.ncl.access_op(allrights))
        res = self.ncl.compound(operations)
        try:
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "access failed:", r
            return
Exemplo n.º 16
0
    def do_rmdir(self, line):
        """Remove directory"""

        # Make sure the object to remove is a directory
        pathcomps = self.ncl.get_pathcomps_rel(line)
        ftype = self.ncl.get_ftype(pathcomps)
        if ftype != NF4DIR:
            print "%s is not a directory (try rm instead)" % line
            return

        dircomps = pathcomps[:-1]
        lookupops = self.ncl.lookup_path(dircomps)
        operations = [self.ncl.putrootfh_op()] + lookupops

        objname = pathcomps[-1]
        operations.append(self.ncl.remove_op(objname))

        try:
            res = self.ncl.compound(operations)
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "remove failed:", r
            return
Exemplo n.º 17
0
    def do_rmdir(self, line):
        """Remove directory"""

        # Make sure the object to remove is a directory
        pathcomps = self.ncl.get_pathcomps_rel(line)
        ftype = self.ncl.get_ftype(pathcomps)
        if ftype != NF4DIR:
            print "%s is not a directory (try rm instead)" % line
            return

        dircomps = pathcomps[:-1]
        lookupops = self.ncl.lookup_path(dircomps)
        operations = [self.ncl.putrootfh_op()] + lookupops

        objname = pathcomps[-1]
        operations.append(self.ncl.remove_op(objname))

        try:
            res = self.ncl.compound(operations)
            nfs4lib.check_result(res)
        except nfs4lib.BadCompoundRes, r:
            print "remove failed:", r
            return
Exemplo n.º 18
0
def main(ncl, unix_prefix):
    ncl.init_connection()
    prefix = nfs4lib.unixpath2comps(unix_prefix)
    putrootfhop = ncl.putrootfh_op()

    lookup_treeroot = [putrootfhop] + ncl.lookup_path(prefix)
    lookup_dev = lookup_treeroot + ncl.lookup_path(["dev"])
    lookup_doc = lookup_treeroot + ncl.lookup_path(["doc"])
    lookup_src = lookup_treeroot + ncl.lookup_path(["src"])
    lookup_tmp = lookup_treeroot + ncl.lookup_path(["tmp"])
    lookup_private = lookup_treeroot + ncl.lookup_path(["private"])

    print "Creating path", unix_prefix
    create_leading_paths(ncl, prefix)

    print "Clearing", unix_prefix
    clean_dir(prefix)

    print "Creating /dev"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "dev")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/floppy"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4LNK, linkdata="fd0")
    createop = ncl.create(objtype, "floppy")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/fd0"
    operations = lookup_dev[:]
    devdata = specdata4(ncl, 2, 0)
    objtype = createtype4(ncl, type=NF4BLK, devdata=devdata)
    createop = ncl.create(objtype, "fd0")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/ttyS0"
    operations = lookup_dev[:]
    devdata = specdata4(ncl, 4, 64)
    objtype = createtype4(ncl, type=NF4CHR, devdata=devdata)
    createop = ncl.create(objtype, "ttyS0")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/log"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4SOCK)
    createop = ncl.create(objtype, "log")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/initctl"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4FIFO)
    createop = ncl.create(objtype, "initctl")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /doc"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "doc")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /doc/README"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "doc/README"), "w")
    data ="""\
    Welcome to this NFS4 server.
    Enjoy.
    """
    remote.write(data)
    remote.close()

    print "Creating directory doc/porting"
    operations = lookup_doc[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "porting")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating doc/porting/TODO"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "doc/porting/TODO"), "w")
    data ="""\
    Need to work on DNIX support...
    Enjoy.
    """
    remote.write(data)
    remote.close()

    print "Creating src"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "src")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating src/hello.c"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "src/hello.c"), "w")
    data = """\
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        printf("Hello world!\\n");
        exit(0);
    }
    """
    remote.write(data)
    remote.close()

    print "Creating tmp"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "tmp")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating tmp/gazonk"
    operations = lookup_tmp[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "gazonk")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating tmp/gazonk/foo.c"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "tmp/gazonk/foo.c"), "w")
    data = """\
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        printf("Hello world!\\n");
        exit(0);
    }
    """
    remote.write(data)
    remote.close()

    print "Creating directory private"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "private")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating private/info.txt"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "private/info.txt"), "w")
    remote.write("Personal data.\n")
    remote.close()

    print "Changing UNIX permissions of private dir to 0000"
    operations = lookup_private[:]
    stateid = stateid4(ncl, 0, "")
    attrmask = nfs4lib.list2attrmask([FATTR4_MODE])
    dummy_ncl = nfs4lib.DummyNcl()
    dummy_ncl.packer.pack_uint(0000)
    attr_vals = dummy_ncl.packer.get_buffer()
    obj_attributes = fattr4(ncl, attrmask, attr_vals)
    operations.append(ncl.setattr_op(stateid, obj_attributes))

    res = ncl.compound(operations)
    if res.status == NFS4ERR_ATTRNOTSUPP:
        print "UNIX mode attribute not supported"
    else:
        nfs4lib.check_result(res)

    print "Creating symlink src/doc -> ../doc"
    operations = lookup_src[:]
    objtype = createtype4(ncl, type=NF4LNK, linkdata="../doc")
    createop = ncl.create(objtype, "doc")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)
Exemplo n.º 19
0
def main(ncl, unix_prefix):
    ncl.init_connection()
    prefix = nfs4lib.unixpath2comps(unix_prefix)
    putrootfhop = ncl.putrootfh_op()

    lookup_treeroot = [putrootfhop] + ncl.lookup_path(prefix)
    lookup_dev = lookup_treeroot + ncl.lookup_path(["dev"])
    lookup_doc = lookup_treeroot + ncl.lookup_path(["doc"])
    lookup_src = lookup_treeroot + ncl.lookup_path(["src"])
    lookup_tmp = lookup_treeroot + ncl.lookup_path(["tmp"])
    lookup_private = lookup_treeroot + ncl.lookup_path(["private"])

    print "Creating path", unix_prefix
    create_leading_paths(ncl, prefix)

    print "Clearing", unix_prefix
    clean_dir(prefix)

    print "Creating /dev"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "dev")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/floppy"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4LNK, linkdata="fd0")
    createop = ncl.create(objtype, "floppy")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/fd0"
    operations = lookup_dev[:]
    devdata = specdata4(ncl, 2, 0)
    objtype = createtype4(ncl, type=NF4BLK, devdata=devdata)
    createop = ncl.create(objtype, "fd0")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/ttyS0"
    operations = lookup_dev[:]
    devdata = specdata4(ncl, 4, 64)
    objtype = createtype4(ncl, type=NF4CHR, devdata=devdata)
    createop = ncl.create(objtype, "ttyS0")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/log"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4SOCK)
    createop = ncl.create(objtype, "log")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /dev/initctl"
    operations = lookup_dev[:]
    objtype = createtype4(ncl, type=NF4FIFO)
    createop = ncl.create(objtype, "initctl")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /doc"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "doc")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating /doc/README"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "doc/README"), "w")
    data = """\
    Welcome to this NFS4 server.
    Enjoy.
    """
    remote.write(data)
    remote.close()

    print "Creating directory doc/porting"
    operations = lookup_doc[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "porting")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating doc/porting/TODO"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "doc/porting/TODO"), "w")
    data = """\
    Need to work on DNIX support...
    Enjoy.
    """
    remote.write(data)
    remote.close()

    print "Creating src"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "src")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating src/hello.c"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "src/hello.c"), "w")
    data = """\
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        printf("Hello world!\\n");
        exit(0);
    }
    """
    remote.write(data)
    remote.close()

    print "Creating tmp"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "tmp")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating tmp/gazonk"
    operations = lookup_tmp[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "gazonk")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating tmp/gazonk/foo.c"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "tmp/gazonk/foo.c"), "w")
    data = """\
    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
        printf("Hello world!\\n");
        exit(0);
    }
    """
    remote.write(data)
    remote.close()

    print "Creating directory private"
    operations = lookup_treeroot[:]
    objtype = createtype4(ncl, type=NF4DIR)
    createop = ncl.create(objtype, "private")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)

    print "Creating private/info.txt"
    remote = nfs4lib.NFS4OpenFile(ncl)
    remote.open(os.path.join(unix_prefix, "private/info.txt"), "w")
    remote.write("Personal data.\n")
    remote.close()

    print "Changing UNIX permissions of private dir to 0000"
    operations = lookup_private[:]
    stateid = stateid4(ncl, 0, "")
    attrmask = nfs4lib.list2attrmask([FATTR4_MODE])
    dummy_ncl = nfs4lib.DummyNcl()
    dummy_ncl.packer.pack_uint(0000)
    attr_vals = dummy_ncl.packer.get_buffer()
    obj_attributes = fattr4(ncl, attrmask, attr_vals)
    operations.append(ncl.setattr_op(stateid, obj_attributes))

    res = ncl.compound(operations)
    if res.status == NFS4ERR_ATTRNOTSUPP:
        print "UNIX mode attribute not supported"
    else:
        nfs4lib.check_result(res)

    print "Creating symlink src/doc -> ../doc"
    operations = lookup_src[:]
    objtype = createtype4(ncl, type=NF4LNK, linkdata="../doc")
    createop = ncl.create(objtype, "doc")
    operations.append(createop)
    res = ncl.compound(operations)
    nfs4lib.check_result(res)
Exemplo n.º 20
0
	fh = res.resarray[-1].arm.arm.object

	if not self.locks.has_key(fh):
	    print "Lock not found in client-side locking table."
	    return

	putfhop = self.ncl.putfh_op(fh)
	lock_data = self.locks[fh][0]
	unlockop = self.ncl.locku_op(lock_data.locktype, lock_data.stateid.seqid,
				     lock_data.stateid, lock_data.offset,
				     lock_data.length)
	operations = [putfhop, unlockop]

	res = self.ncl.compound(operations)
	try:
	    nfs4lib.check_result(res)
	except nfs4lib.BadCompoundRes, r:
	    print "Error unlocking file:", r
	    return

	# Delete lock from local lock table
	self.release_lock(fh, lock_data)

    def do_version(self, unused_line):
        print "nfs4client.py version", VERSION

    do_ls = do_dir

    do_exit = do_EOF

    do_quit = do_EOF