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
24 * Defined by RFC 1094, section A.3; and RFC 1813, section 5.1.4
26 #define MNTPATHLEN (1024)
31 #define encode_dirpath_sz (1 + XDR_QUADLEN(MNTPATHLEN))
34 * XDR argument and result sizes
36 #define MNT_enc_dirpath_sz encode_dirpath_sz
39 * Defined by RFC 1094, section A.5
46 MOUNTPROC_UMNTALL = 4,
51 * Defined by RFC 1813, section 5.2
58 MOUNTPROC3_UMNTALL = 4,
59 MOUNTPROC3_EXPORT = 5,
62 static struct rpc_program mnt_program;
70 * nfs_mount - Obtain an NFS file handle for the given host and path
71 * @info: pointer to mount request arguments
73 * Uses default timeout parameters specified by underlying transport.
75 int nfs_mount(struct nfs_mount_request *info)
77 struct mnt_fhstatus result = {
80 struct rpc_message msg = {
81 .rpc_argp = info->dirpath,
84 struct rpc_create_args args = {
85 .protocol = info->protocol,
87 .addrsize = info->salen,
88 .servername = info->hostname,
89 .program = &mnt_program,
90 .version = info->version,
91 .authflavor = RPC_AUTH_UNIX,
93 struct rpc_clnt *mnt_clnt;
96 dprintk("NFS: sending MNT request for %s:%s\n",
97 (info->hostname ? info->hostname : "server"),
100 if (info->noresvport)
101 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
103 mnt_clnt = rpc_create(&args);
104 if (IS_ERR(mnt_clnt))
107 if (info->version == NFS_MNT3_VERSION)
108 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC3_MNT];
110 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC_MNT];
112 status = rpc_call_sync(mnt_clnt, &msg, 0);
113 rpc_shutdown_client(mnt_clnt);
117 if (result.status != 0)
120 dprintk("NFS: MNT request succeeded\n");
127 status = PTR_ERR(mnt_clnt);
128 dprintk("NFS: failed to create RPC client, status=%d\n", status);
132 dprintk("NFS: failed to start MNT request, status=%d\n", status);
136 dprintk("NFS: MNT server returned result %d\n", result.status);
137 status = nfs_stat_to_errno(result.status);
142 * XDR encode/decode functions for MOUNT
144 static int xdr_encode_dirpath(struct rpc_rqst *req, __be32 *p,
147 p = xdr_encode_string(p, path);
149 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
153 static int encode_mntdirpath(struct xdr_stream *xdr, const char *pathname)
155 const u32 pathname_len = strlen(pathname);
158 if (unlikely(pathname_len > MNTPATHLEN))
161 p = xdr_reserve_space(xdr, sizeof(u32) + pathname_len);
162 if (unlikely(p == NULL))
164 xdr_encode_opaque(p, pathname, pathname_len);
169 static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p,
172 struct xdr_stream xdr;
174 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
175 return encode_mntdirpath(&xdr, dirpath);
178 static int xdr_decode_fhstatus(struct rpc_rqst *req, __be32 *p,
179 struct mnt_fhstatus *res)
181 struct nfs_fh *fh = res->fh;
183 if ((res->status = ntohl(*p++)) == 0) {
184 fh->size = NFS2_FHSIZE;
185 memcpy(fh->data, p, NFS2_FHSIZE);
190 static int xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p,
191 struct mnt_fhstatus *res)
193 struct nfs_fh *fh = res->fh;
196 if ((res->status = ntohl(*p++)) == 0) {
198 if (size <= NFS3_FHSIZE && size != 0) {
200 memcpy(fh->data, p, size);
202 res->status = -EBADHANDLE;
207 #define MNT_fhstatus_sz (1 + 8)
208 #define MNT_fhstatus3_sz (1 + 16)
210 static struct rpc_procinfo mnt_procedures[] = {
212 .p_proc = MOUNTPROC_MNT,
213 .p_encode = (kxdrproc_t)mnt_enc_dirpath,
214 .p_decode = (kxdrproc_t) xdr_decode_fhstatus,
215 .p_arglen = MNT_enc_dirpath_sz,
216 .p_replen = MNT_fhstatus_sz,
217 .p_statidx = MOUNTPROC_MNT,
222 static struct rpc_procinfo mnt3_procedures[] = {
224 .p_proc = MOUNTPROC3_MNT,
225 .p_encode = (kxdrproc_t)mnt_enc_dirpath,
226 .p_decode = (kxdrproc_t) xdr_decode_fhstatus3,
227 .p_arglen = MNT_enc_dirpath_sz,
228 .p_replen = MNT_fhstatus3_sz,
229 .p_statidx = MOUNTPROC3_MNT,
235 static struct rpc_version mnt_version1 = {
238 .procs = mnt_procedures,
241 static struct rpc_version mnt_version3 = {
244 .procs = mnt3_procedures,
247 static struct rpc_version *mnt_version[] = {
254 static struct rpc_stat mnt_stats;
256 static struct rpc_program mnt_program = {
258 .number = NFS_MNT_PROGRAM,
259 .nrvers = ARRAY_SIZE(mnt_version),
260 .version = mnt_version,