Import 2.1.118
[davej-history.git] / fs / nfs / mount_clnt.c
blob81da8f9968ddbd4e9528631ff6c3ba262a419bdd
1 /*
2 * linux/fs/nfs/mount_clnt.c
4 * MOUNT client to support NFSroot.
6 * Copyright (C) 1997, Olaf Kirch <okir@monad.swb.de>
7 */
9 #include <linux/types.h>
10 #include <linux/socket.h>
11 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/uio.h>
14 #include <linux/net.h>
15 #include <linux/in.h>
16 #include <linux/inet.h>
17 #include <linux/sunrpc/clnt.h>
18 #include <linux/sunrpc/xprt.h>
19 #include <linux/sunrpc/sched.h>
20 #include <linux/nfs_fs.h>
22 #ifdef RPC_DEBUG
23 # define NFSDBG_FACILITY NFSDBG_ROOT
24 #endif
27 #define MOUNT_PROGRAM 100005
28 #define MOUNT_VERSION 1
29 #define MOUNT_MNT 1
30 #define MOUNT_UMNT 3
33 static struct rpc_clnt * mnt_create(char *, struct sockaddr_in *);
34 extern struct rpc_program mnt_program;
36 struct mnt_fhstatus {
37 unsigned int status;
38 struct nfs_fh * fh;
42 * Obtain an NFS file handle for the given host and path
44 int
45 nfs_mount(struct sockaddr_in *addr, char *path, struct nfs_fh *fh)
47 struct rpc_clnt *mnt_clnt;
48 struct mnt_fhstatus result = { 0, fh };
49 char hostname[32];
50 int status;
52 dprintk("NFS: nfs_mount(%08x:%s)\n",
53 (unsigned)ntohl(addr->sin_addr.s_addr), path);
55 strcpy(hostname, in_ntoa(addr->sin_addr.s_addr));
56 if (!(mnt_clnt = mnt_create(hostname, addr)))
57 return -EACCES;
59 status = rpc_call(mnt_clnt, NFS_MNTPROC_MNT, path, &result, 0);
60 return status < 0? status : (result.status? -EACCES : 0);
63 static struct rpc_clnt *
64 mnt_create(char *hostname, struct sockaddr_in *srvaddr)
66 struct rpc_xprt *xprt;
67 struct rpc_clnt *clnt;
69 if (!(xprt = xprt_create_proto(IPPROTO_UDP, srvaddr, NULL)))
70 return NULL;
72 clnt = rpc_create_client(xprt, hostname,
73 &mnt_program, NFS_MNT_VERSION,
74 RPC_AUTH_NULL);
75 if (!clnt) {
76 xprt_destroy(xprt);
77 } else {
78 clnt->cl_softrtry = 1;
79 clnt->cl_chatty = 1;
80 clnt->cl_oneshot = 1;
82 return clnt;
86 * XDR encode/decode functions for MOUNT
88 static int
89 xdr_error(struct rpc_rqst *req, u32 *p, void *dummy)
91 return -EIO;
94 static int
95 xdr_encode_dirpath(struct rpc_rqst *req, u32 *p, const char *path)
97 p = xdr_encode_string(p, path);
99 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
100 return 0;
103 static int
104 xdr_decode_fhstatus(struct rpc_rqst *req, u32 *p, struct mnt_fhstatus *res)
106 if ((res->status = ntohl(*p++)) == 0)
107 memcpy(res->fh, p, sizeof(*res->fh));
108 return 0;
111 #define MNT_dirpath_sz (1 + 256)
112 #define MNT_fhstatus_sz (1 + 8)
114 static struct rpc_procinfo mnt_procedures[2] = {
115 { "mnt_null",
116 (kxdrproc_t) xdr_error,
117 (kxdrproc_t) xdr_error, 0, 0 },
118 { "mnt_mount",
119 (kxdrproc_t) xdr_encode_dirpath,
120 (kxdrproc_t) xdr_decode_fhstatus,
121 MNT_dirpath_sz, MNT_fhstatus_sz },
124 static struct rpc_version mnt_version1 = {
125 1, 2, mnt_procedures
128 static struct rpc_version * mnt_version[] = {
129 NULL,
130 &mnt_version1,
133 static struct rpc_stat mnt_stats;
135 struct rpc_program mnt_program = {
136 "mount",
137 NFS_MNT_PROGRAM,
138 sizeof(mnt_version)/sizeof(mnt_version[0]),
139 mnt_version,
140 &mnt_stats,