2 * In-kernel MOUNT protocol client
4 * Copyright (C) 1997, Olaf Kirch <okir@monad.swb.de>
7 #include <linux/types.h>
8 #include <linux/socket.h>
9 #include <linux/kernel.h>
10 #include <linux/errno.h>
11 #include <linux/uio.h>
12 #include <linux/net.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sunrpc/sched.h>
16 #include <linux/nfs_fs.h>
20 # define NFSDBG_FACILITY NFSDBG_MOUNT
23 static struct rpc_program mnt_program;
31 * nfs_mount - Obtain an NFS file handle for the given host and path
32 * @info: pointer to mount request arguments
34 * Uses default timeout parameters specified by underlying transport.
36 int nfs_mount(struct nfs_mount_request *info)
38 struct mnt_fhstatus result = {
41 struct rpc_message msg = {
42 .rpc_argp = info->dirpath,
45 struct rpc_create_args args = {
46 .protocol = info->protocol,
48 .addrsize = info->salen,
49 .servername = info->hostname,
50 .program = &mnt_program,
51 .version = info->version,
52 .authflavor = RPC_AUTH_UNIX,
55 struct rpc_clnt *mnt_clnt;
58 dprintk("NFS: sending MNT request for %s:%s\n",
59 (info->hostname ? info->hostname : "server"),
62 mnt_clnt = rpc_create(&args);
66 if (info->version == NFS_MNT3_VERSION)
67 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC3_MNT];
69 msg.rpc_proc = &mnt_clnt->cl_procinfo[MNTPROC_MNT];
71 status = rpc_call_sync(mnt_clnt, &msg, 0);
72 rpc_shutdown_client(mnt_clnt);
76 if (result.status != 0)
79 dprintk("NFS: MNT request succeeded\n");
86 status = PTR_ERR(mnt_clnt);
87 dprintk("NFS: failed to create RPC client, status=%d\n", status);
91 dprintk("NFS: failed to start MNT request, status=%d\n", status);
95 dprintk("NFS: MNT server returned result %d\n", result.status);
96 status = nfs_stat_to_errno(result.status);
101 * XDR encode/decode functions for MOUNT
103 static int xdr_encode_dirpath(struct rpc_rqst *req, __be32 *p,
106 p = xdr_encode_string(p, path);
108 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
112 static int xdr_decode_fhstatus(struct rpc_rqst *req, __be32 *p,
113 struct mnt_fhstatus *res)
115 struct nfs_fh *fh = res->fh;
117 if ((res->status = ntohl(*p++)) == 0) {
118 fh->size = NFS2_FHSIZE;
119 memcpy(fh->data, p, NFS2_FHSIZE);
124 static int xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p,
125 struct mnt_fhstatus *res)
127 struct nfs_fh *fh = res->fh;
130 if ((res->status = ntohl(*p++)) == 0) {
132 if (size <= NFS3_FHSIZE && size != 0) {
134 memcpy(fh->data, p, size);
136 res->status = -EBADHANDLE;
141 #define MNT_dirpath_sz (1 + 256)
142 #define MNT_fhstatus_sz (1 + 8)
143 #define MNT_fhstatus3_sz (1 + 16)
145 static struct rpc_procinfo mnt_procedures[] = {
147 .p_proc = MNTPROC_MNT,
148 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
149 .p_decode = (kxdrproc_t) xdr_decode_fhstatus,
150 .p_arglen = MNT_dirpath_sz,
151 .p_replen = MNT_fhstatus_sz,
152 .p_statidx = MNTPROC_MNT,
157 static struct rpc_procinfo mnt3_procedures[] = {
159 .p_proc = MOUNTPROC3_MNT,
160 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
161 .p_decode = (kxdrproc_t) xdr_decode_fhstatus3,
162 .p_arglen = MNT_dirpath_sz,
163 .p_replen = MNT_fhstatus3_sz,
164 .p_statidx = MOUNTPROC3_MNT,
170 static struct rpc_version mnt_version1 = {
173 .procs = mnt_procedures,
176 static struct rpc_version mnt_version3 = {
179 .procs = mnt3_procedures,
182 static struct rpc_version *mnt_version[] = {
189 static struct rpc_stat mnt_stats;
191 static struct rpc_program mnt_program = {
193 .number = NFS_MNT_PROGRAM,
194 .nrvers = ARRAY_SIZE(mnt_version),
195 .version = mnt_version,