Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * nfsmount.c -- Linux NFS mount |
| 4 | * Copyright (C) 1993 Rick Sladkey <jrs@world.std.com> |
| 5 | * |
Rob Landley | 7a260f0 | 2006-06-19 03:20:03 +0000 | [diff] [blame] | 6 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 7 | * |
| 8 | * Wed Feb 8 12:51:48 1995, biro@yggdrasil.com (Ross Biro): allow all port |
| 9 | * numbers to be specified on the command line. |
| 10 | * |
| 11 | * Fri, 8 Mar 1996 18:01:39, Swen Thuemmler <swen@uni-paderborn.de>: |
| 12 | * Omit the call to connect() for Linux version 1.3.11 or later. |
| 13 | * |
| 14 | * Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com> |
| 15 | * Implemented the "bg", "fg" and "retry" mount options for NFS. |
| 16 | * |
| 17 | * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> |
| 18 | * - added Native Language Support |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 19 | * |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 20 | * Modified by Olaf Kirch and Trond Myklebust for new NFS code, |
| 21 | * plus NFSv3 stuff. |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * nfsmount.c,v 1.1.1.1 1993/11/18 08:40:51 jrs Exp |
| 26 | */ |
| 27 | |
Rob Landley | 22d26fc | 2006-06-15 15:49:36 +0000 | [diff] [blame] | 28 | #include "busybox.h" |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 29 | #include <sys/utsname.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 30 | #undef TRUE |
| 31 | #undef FALSE |
| 32 | #include <rpc/rpc.h> |
| 33 | #include <rpc/pmap_prot.h> |
| 34 | #include <rpc/pmap_clnt.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 35 | #include "nfsmount.h" |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 36 | |
Rob Landley | 7b363fd | 2005-12-20 17:18:01 +0000 | [diff] [blame] | 37 | /* This is just a warning of a common mistake. Possibly this should be a |
Bernhard Reutner-Fischer | ed7bb62 | 2006-02-23 14:25:15 +0000 | [diff] [blame] | 38 | * uclibc faq entry rather than in busybox... */ |
Rob Landley | 7b363fd | 2005-12-20 17:18:01 +0000 | [diff] [blame] | 39 | #if ENABLE_FEATURE_MOUNT_NFS && defined(__UCLIBC__) && ! defined(__UCLIBC_HAS_RPC__) |
| 40 | #error "You need to build uClibc with UCLIBC_HAS_RPC for NFS support." |
| 41 | #endif |
| 42 | |
Eric Andersen | 80ff944 | 2002-12-11 04:04:26 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * NFS stats. The good thing with these values is that NFSv3 errors are |
| 46 | * a superset of NFSv2 errors (with the exception of NFSERR_WFLUSH which |
| 47 | * no-one uses anyway), so we can happily mix code as long as we make sure |
| 48 | * no NFSv3 errors are returned to NFSv2 clients. |
| 49 | * Error codes that have a `--' in the v2 column are not part of the |
| 50 | * standard, but seem to be widely used nevertheless. |
| 51 | */ |
| 52 | enum nfs_stat { |
| 53 | NFS_OK = 0, /* v2 v3 */ |
| 54 | NFSERR_PERM = 1, /* v2 v3 */ |
| 55 | NFSERR_NOENT = 2, /* v2 v3 */ |
| 56 | NFSERR_IO = 5, /* v2 v3 */ |
| 57 | NFSERR_NXIO = 6, /* v2 v3 */ |
| 58 | NFSERR_EAGAIN = 11, /* v2 v3 */ |
| 59 | NFSERR_ACCES = 13, /* v2 v3 */ |
| 60 | NFSERR_EXIST = 17, /* v2 v3 */ |
| 61 | NFSERR_XDEV = 18, /* v3 */ |
| 62 | NFSERR_NODEV = 19, /* v2 v3 */ |
| 63 | NFSERR_NOTDIR = 20, /* v2 v3 */ |
| 64 | NFSERR_ISDIR = 21, /* v2 v3 */ |
| 65 | NFSERR_INVAL = 22, /* v2 v3 that Sun forgot */ |
| 66 | NFSERR_FBIG = 27, /* v2 v3 */ |
| 67 | NFSERR_NOSPC = 28, /* v2 v3 */ |
| 68 | NFSERR_ROFS = 30, /* v2 v3 */ |
| 69 | NFSERR_MLINK = 31, /* v3 */ |
| 70 | NFSERR_OPNOTSUPP = 45, /* v2 v3 */ |
| 71 | NFSERR_NAMETOOLONG = 63, /* v2 v3 */ |
| 72 | NFSERR_NOTEMPTY = 66, /* v2 v3 */ |
| 73 | NFSERR_DQUOT = 69, /* v2 v3 */ |
| 74 | NFSERR_STALE = 70, /* v2 v3 */ |
| 75 | NFSERR_REMOTE = 71, /* v2 v3 */ |
| 76 | NFSERR_WFLUSH = 99, /* v2 */ |
| 77 | NFSERR_BADHANDLE = 10001, /* v3 */ |
| 78 | NFSERR_NOT_SYNC = 10002, /* v3 */ |
| 79 | NFSERR_BAD_COOKIE = 10003, /* v3 */ |
| 80 | NFSERR_NOTSUPP = 10004, /* v3 */ |
| 81 | NFSERR_TOOSMALL = 10005, /* v3 */ |
| 82 | NFSERR_SERVERFAULT = 10006, /* v3 */ |
| 83 | NFSERR_BADTYPE = 10007, /* v3 */ |
| 84 | NFSERR_JUKEBOX = 10008 /* v3 */ |
| 85 | }; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 86 | |
Eric Andersen | 80ff944 | 2002-12-11 04:04:26 +0000 | [diff] [blame] | 87 | #define NFS_PROGRAM 100003 |
| 88 | |
| 89 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 90 | enum { |
Glenn L McGrath | c52a97d | 2000-12-09 23:59:04 +0000 | [diff] [blame] | 91 | #ifndef NFS_FHSIZE |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 92 | NFS_FHSIZE = 32, |
Glenn L McGrath | c52a97d | 2000-12-09 23:59:04 +0000 | [diff] [blame] | 93 | #endif |
| 94 | #ifndef NFS_PORT |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 95 | NFS_PORT = 2049 |
Glenn L McGrath | c52a97d | 2000-12-09 23:59:04 +0000 | [diff] [blame] | 96 | #endif |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 97 | }; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 98 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 99 | /* Disable the nls stuff */ |
| 100 | # undef bindtextdomain |
| 101 | # define bindtextdomain(Domain, Directory) /* empty */ |
| 102 | # undef textdomain |
| 103 | # define textdomain(Domain) /* empty */ |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 104 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 105 | enum { |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 106 | S_QUOTA = 128, /* Quota initialized for file/directory/symlink */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 107 | }; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 108 | |
| 109 | |
| 110 | /* |
| 111 | * We want to be able to compile mount on old kernels in such a way |
| 112 | * that the binary will work well on more recent kernels. |
| 113 | * Thus, if necessary we teach nfsmount.c the structure of new fields |
| 114 | * that will come later. |
| 115 | * |
| 116 | * Moreover, the new kernel includes conflict with glibc includes |
| 117 | * so it is easiest to ignore the kernel altogether (at compile time). |
| 118 | */ |
| 119 | |
Mark Whitley | 8526067 | 2001-01-30 18:53:42 +0000 | [diff] [blame] | 120 | /* NOTE: Do not make this into a 'static const int' because the pre-processor |
| 121 | * needs to test this value in some #if statements. */ |
| 122 | #define NFS_MOUNT_VERSION 4 |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 123 | |
| 124 | struct nfs2_fh { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 125 | char data[32]; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 126 | }; |
| 127 | struct nfs3_fh { |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 128 | unsigned short size; |
| 129 | unsigned char data[64]; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | struct nfs_mount_data { |
| 133 | int version; /* 1 */ |
| 134 | int fd; /* 1 */ |
| 135 | struct nfs2_fh old_root; /* 1 */ |
| 136 | int flags; /* 1 */ |
| 137 | int rsize; /* 1 */ |
| 138 | int wsize; /* 1 */ |
| 139 | int timeo; /* 1 */ |
| 140 | int retrans; /* 1 */ |
| 141 | int acregmin; /* 1 */ |
| 142 | int acregmax; /* 1 */ |
| 143 | int acdirmin; /* 1 */ |
| 144 | int acdirmax; /* 1 */ |
| 145 | struct sockaddr_in addr; /* 1 */ |
| 146 | char hostname[256]; /* 1 */ |
| 147 | int namlen; /* 2 */ |
| 148 | unsigned int bsize; /* 3 */ |
| 149 | struct nfs3_fh root; /* 4 */ |
| 150 | }; |
| 151 | |
| 152 | /* bits in the flags field */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 153 | enum { |
| 154 | NFS_MOUNT_SOFT = 0x0001, /* 1 */ |
| 155 | NFS_MOUNT_INTR = 0x0002, /* 1 */ |
| 156 | NFS_MOUNT_SECURE = 0x0004, /* 1 */ |
| 157 | NFS_MOUNT_POSIX = 0x0008, /* 1 */ |
| 158 | NFS_MOUNT_NOCTO = 0x0010, /* 1 */ |
| 159 | NFS_MOUNT_NOAC = 0x0020, /* 1 */ |
| 160 | NFS_MOUNT_TCP = 0x0040, /* 2 */ |
| 161 | NFS_MOUNT_VER3 = 0x0080, /* 3 */ |
| 162 | NFS_MOUNT_KERBEROS = 0x0100, /* 3 */ |
| 163 | NFS_MOUNT_NONLM = 0x0200 /* 3 */ |
| 164 | }; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 165 | |
| 166 | |
| 167 | #define UTIL_LINUX_VERSION "2.10m" |
| 168 | #define util_linux_version "util-linux-2.10m" |
| 169 | |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 170 | #define HAVE_inet_aton |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 171 | #define HAVE_scsi_h |
| 172 | #define HAVE_blkpg_h |
| 173 | #define HAVE_kd_h |
| 174 | #define HAVE_termcap |
| 175 | #define HAVE_locale_h |
| 176 | #define HAVE_libintl_h |
| 177 | #define ENABLE_NLS |
| 178 | #define HAVE_langinfo_h |
| 179 | #define HAVE_progname |
| 180 | #define HAVE_openpty |
| 181 | #define HAVE_nanosleep |
| 182 | #define HAVE_personality |
| 183 | #define HAVE_tm_gmtoff |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 184 | |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 185 | static char *nfs_strerror(int status); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 186 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 187 | #define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 188 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 189 | enum { |
| 190 | EX_FAIL = 32, /* mount failure */ |
| 191 | EX_BG = 256 /* retry in background (internal only) */ |
| 192 | }; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 193 | |
| 194 | |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 195 | /* |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 196 | * nfs_mount_version according to the sources seen at compile time. |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 197 | */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 198 | static int nfs_mount_version; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 199 | |
| 200 | /* |
| 201 | * Unfortunately, the kernel prints annoying console messages |
| 202 | * in case of an unexpected nfs mount version (instead of |
| 203 | * just returning some error). Therefore we'll have to try |
| 204 | * and figure out what version the kernel expects. |
| 205 | * |
| 206 | * Variables: |
| 207 | * KERNEL_NFS_MOUNT_VERSION: kernel sources at compile time |
| 208 | * NFS_MOUNT_VERSION: these nfsmount sources at compile time |
| 209 | * nfs_mount_version: version this source and running kernel can handle |
| 210 | */ |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 211 | static void |
Mark Whitley | 065c7e7 | 2001-02-01 19:51:13 +0000 | [diff] [blame] | 212 | find_kernel_nfs_mount_version(void) |
| 213 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 214 | static int kernel_version = 0; |
| 215 | |
| 216 | if (kernel_version) |
| 217 | return; |
| 218 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 219 | nfs_mount_version = NFS_MOUNT_VERSION; /* default */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 220 | |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 221 | kernel_version = get_linux_version_code(); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 222 | if (kernel_version) { |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 223 | if (kernel_version < KERNEL_VERSION(2,1,32)) |
Mark Whitley | 065c7e7 | 2001-02-01 19:51:13 +0000 | [diff] [blame] | 224 | nfs_mount_version = 1; |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 225 | else if (kernel_version < KERNEL_VERSION(2,2,18) || |
| 226 | (kernel_version >= KERNEL_VERSION(2,3,0) && |
| 227 | kernel_version < KERNEL_VERSION(2,3,99))) |
Mark Whitley | 065c7e7 | 2001-02-01 19:51:13 +0000 | [diff] [blame] | 228 | nfs_mount_version = 3; |
| 229 | else |
| 230 | nfs_mount_version = 4; /* since 2.3.99pre4 */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 231 | } |
| 232 | if (nfs_mount_version > NFS_MOUNT_VERSION) |
Mark Whitley | 065c7e7 | 2001-02-01 19:51:13 +0000 | [diff] [blame] | 233 | nfs_mount_version = NFS_MOUNT_VERSION; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 236 | static struct pmap * |
| 237 | get_mountport(struct sockaddr_in *server_addr, |
| 238 | long unsigned prog, |
| 239 | long unsigned version, |
| 240 | long unsigned proto, |
| 241 | long unsigned port) |
| 242 | { |
| 243 | struct pmaplist *pmap; |
| 244 | static struct pmap p = {0, 0, 0, 0}; |
| 245 | |
| 246 | server_addr->sin_port = PMAPPORT; |
| 247 | pmap = pmap_getmaps(server_addr); |
| 248 | |
| 249 | if (version > MAX_NFSPROT) |
| 250 | version = MAX_NFSPROT; |
| 251 | if (!prog) |
| 252 | prog = MOUNTPROG; |
| 253 | p.pm_prog = prog; |
| 254 | p.pm_vers = version; |
| 255 | p.pm_prot = proto; |
| 256 | p.pm_port = port; |
| 257 | |
| 258 | while (pmap) { |
| 259 | if (pmap->pml_map.pm_prog != prog) |
| 260 | goto next; |
| 261 | if (!version && p.pm_vers > pmap->pml_map.pm_vers) |
| 262 | goto next; |
| 263 | if (version > 2 && pmap->pml_map.pm_vers != version) |
| 264 | goto next; |
| 265 | if (version && version <= 2 && pmap->pml_map.pm_vers > 2) |
| 266 | goto next; |
| 267 | if (pmap->pml_map.pm_vers > MAX_NFSPROT || |
| 268 | (proto && p.pm_prot && pmap->pml_map.pm_prot != proto) || |
| 269 | (port && pmap->pml_map.pm_port != port)) |
| 270 | goto next; |
| 271 | memcpy(&p, &pmap->pml_map, sizeof(p)); |
| 272 | next: |
| 273 | pmap = pmap->pml_next; |
| 274 | } |
| 275 | if (!p.pm_vers) |
| 276 | p.pm_vers = MOUNTVERS; |
| 277 | if (!p.pm_port) |
| 278 | p.pm_port = MOUNTPORT; |
| 279 | if (!p.pm_prot) |
| 280 | p.pm_prot = IPPROTO_TCP; |
| 281 | return &p; |
| 282 | } |
| 283 | |
| 284 | int nfsmount(const char *spec, const char *node, int *flags, |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 285 | char **mount_opts, int running_bg) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 286 | { |
| 287 | static char *prev_bg_host; |
| 288 | char hostdir[1024]; |
| 289 | CLIENT *mclient; |
| 290 | char *hostname; |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 291 | char *pathname; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 292 | char *old_opts; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 293 | char *mounthost=NULL; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 294 | char new_opts[1024]; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 295 | struct timeval total_timeout; |
| 296 | enum clnt_stat clnt_stat; |
Eric Andersen | 882cec3 | 2004-07-26 12:05:12 +0000 | [diff] [blame] | 297 | struct nfs_mount_data data; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 298 | char *opt, *opteq; |
| 299 | int val; |
| 300 | struct hostent *hp; |
| 301 | struct sockaddr_in server_addr; |
| 302 | struct sockaddr_in mount_server_addr; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 303 | struct pmap* pm_mnt; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 304 | int msock, fsock; |
| 305 | struct timeval retry_timeout; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 306 | union { |
| 307 | struct fhstatus nfsv2; |
| 308 | struct mountres3 nfsv3; |
| 309 | } status; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 310 | struct stat statbuf; |
| 311 | char *s; |
| 312 | int port; |
| 313 | int mountport; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 314 | int proto; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 315 | int bg; |
| 316 | int soft; |
| 317 | int intr; |
| 318 | int posix; |
| 319 | int nocto; |
| 320 | int noac; |
| 321 | int nolock; |
| 322 | int retry; |
| 323 | int tcp; |
| 324 | int mountprog; |
| 325 | int mountvers; |
| 326 | int nfsprog; |
| 327 | int nfsvers; |
| 328 | int retval; |
| 329 | time_t t; |
| 330 | time_t prevt; |
| 331 | time_t timeout; |
| 332 | |
| 333 | find_kernel_nfs_mount_version(); |
| 334 | |
| 335 | retval = EX_FAIL; |
| 336 | msock = fsock = -1; |
| 337 | mclient = NULL; |
| 338 | if (strlen(spec) >= sizeof(hostdir)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 339 | bb_error_msg("excessively long host:dir argument"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 340 | goto fail; |
| 341 | } |
| 342 | strcpy(hostdir, spec); |
| 343 | if ((s = strchr(hostdir, ':'))) { |
| 344 | hostname = hostdir; |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 345 | pathname = s + 1; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 346 | *s = '\0'; |
| 347 | /* Ignore all but first hostname in replicated mounts |
| 348 | until they can be fully supported. (mack@sgi.com) */ |
| 349 | if ((s = strchr(hostdir, ','))) { |
| 350 | *s = '\0'; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 351 | bb_error_msg("warning: multiple hostnames not supported"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 352 | } |
| 353 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 354 | bb_error_msg("directory to mount not in host:dir format"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 355 | goto fail; |
| 356 | } |
| 357 | |
| 358 | server_addr.sin_family = AF_INET; |
| 359 | #ifdef HAVE_inet_aton |
| 360 | if (!inet_aton(hostname, &server_addr.sin_addr)) |
| 361 | #endif |
| 362 | { |
| 363 | if ((hp = gethostbyname(hostname)) == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 364 | bb_herror_msg("%s", hostname); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 365 | goto fail; |
| 366 | } else { |
| 367 | if (hp->h_length > sizeof(struct in_addr)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 368 | bb_error_msg("got bad hp->h_length"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 369 | hp->h_length = sizeof(struct in_addr); |
| 370 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 371 | memcpy(&server_addr.sin_addr, |
| 372 | hp->h_addr, hp->h_length); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 376 | memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr)); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 377 | |
| 378 | /* add IP address to mtab options for use when unmounting */ |
| 379 | |
| 380 | s = inet_ntoa(server_addr.sin_addr); |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 381 | old_opts = *mount_opts; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 382 | if (!old_opts) |
| 383 | old_opts = ""; |
| 384 | if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 385 | bb_error_msg("excessively long option argument"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 386 | goto fail; |
| 387 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 388 | sprintf(new_opts, "%s%saddr=%s", |
| 389 | old_opts, *old_opts ? "," : "", s); |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 390 | *mount_opts = xstrdup(new_opts); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 391 | |
| 392 | /* Set default options. |
| 393 | * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to |
| 394 | * let the kernel decide. |
| 395 | * timeo is filled in after we know whether it'll be TCP or UDP. */ |
| 396 | memset(&data, 0, sizeof(data)); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 397 | data.retrans = 3; |
| 398 | data.acregmin = 3; |
| 399 | data.acregmax = 60; |
| 400 | data.acdirmin = 30; |
| 401 | data.acdirmax = 60; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 402 | #if NFS_MOUNT_VERSION >= 2 |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 403 | data.namlen = NAME_MAX; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 404 | #endif |
| 405 | |
| 406 | bg = 0; |
| 407 | soft = 0; |
| 408 | intr = 0; |
| 409 | posix = 0; |
| 410 | nocto = 0; |
| 411 | nolock = 0; |
| 412 | noac = 0; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 413 | retry = 10000; /* 10000 minutes ~ 1 week */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 414 | tcp = 0; |
| 415 | |
| 416 | mountprog = MOUNTPROG; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 417 | mountvers = 0; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 418 | port = 0; |
| 419 | mountport = 0; |
| 420 | nfsprog = NFS_PROGRAM; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 421 | nfsvers = 0; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 422 | |
| 423 | /* parse options */ |
| 424 | |
| 425 | for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) { |
| 426 | if ((opteq = strchr(opt, '='))) { |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 427 | val = atoi(opteq + 1); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 428 | *opteq = '\0'; |
| 429 | if (!strcmp(opt, "rsize")) |
| 430 | data.rsize = val; |
| 431 | else if (!strcmp(opt, "wsize")) |
| 432 | data.wsize = val; |
| 433 | else if (!strcmp(opt, "timeo")) |
| 434 | data.timeo = val; |
| 435 | else if (!strcmp(opt, "retrans")) |
| 436 | data.retrans = val; |
| 437 | else if (!strcmp(opt, "acregmin")) |
| 438 | data.acregmin = val; |
| 439 | else if (!strcmp(opt, "acregmax")) |
| 440 | data.acregmax = val; |
| 441 | else if (!strcmp(opt, "acdirmin")) |
| 442 | data.acdirmin = val; |
| 443 | else if (!strcmp(opt, "acdirmax")) |
| 444 | data.acdirmax = val; |
| 445 | else if (!strcmp(opt, "actimeo")) { |
| 446 | data.acregmin = val; |
| 447 | data.acregmax = val; |
| 448 | data.acdirmin = val; |
| 449 | data.acdirmax = val; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 450 | } |
| 451 | else if (!strcmp(opt, "retry")) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 452 | retry = val; |
| 453 | else if (!strcmp(opt, "port")) |
| 454 | port = val; |
| 455 | else if (!strcmp(opt, "mountport")) |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 456 | mountport = val; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 457 | else if (!strcmp(opt, "mounthost")) |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 458 | mounthost=xstrndup(opteq+1, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 459 | strcspn(opteq+1," \t\n\r,")); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 460 | else if (!strcmp(opt, "mountprog")) |
| 461 | mountprog = val; |
| 462 | else if (!strcmp(opt, "mountvers")) |
| 463 | mountvers = val; |
| 464 | else if (!strcmp(opt, "nfsprog")) |
| 465 | nfsprog = val; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 466 | else if (!strcmp(opt, "nfsvers") || |
| 467 | !strcmp(opt, "vers")) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 468 | nfsvers = val; |
| 469 | else if (!strcmp(opt, "proto")) { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 470 | if (!strncmp(opteq+1, "tcp", 3)) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 471 | tcp = 1; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 472 | else if (!strncmp(opteq+1, "udp", 3)) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 473 | tcp = 0; |
| 474 | else |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 475 | printf("Warning: Unrecognized proto= option.\n"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 476 | } else if (!strcmp(opt, "namlen")) { |
| 477 | #if NFS_MOUNT_VERSION >= 2 |
| 478 | if (nfs_mount_version >= 2) |
| 479 | data.namlen = val; |
| 480 | else |
| 481 | #endif |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 482 | printf("Warning: Option namlen is not supported.\n"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 483 | } else if (!strcmp(opt, "addr")) |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 484 | /* ignore */; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 485 | else { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 486 | printf("unknown nfs mount parameter: %s=%d\n", opt, val); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 487 | goto fail; |
| 488 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 489 | } |
| 490 | else { |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 491 | val = 1; |
| 492 | if (!strncmp(opt, "no", 2)) { |
| 493 | val = 0; |
| 494 | opt += 2; |
| 495 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 496 | if (!strcmp(opt, "bg")) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 497 | bg = val; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 498 | else if (!strcmp(opt, "fg")) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 499 | bg = !val; |
| 500 | else if (!strcmp(opt, "soft")) |
| 501 | soft = val; |
| 502 | else if (!strcmp(opt, "hard")) |
| 503 | soft = !val; |
| 504 | else if (!strcmp(opt, "intr")) |
| 505 | intr = val; |
| 506 | else if (!strcmp(opt, "posix")) |
| 507 | posix = val; |
| 508 | else if (!strcmp(opt, "cto")) |
| 509 | nocto = !val; |
| 510 | else if (!strcmp(opt, "ac")) |
| 511 | noac = !val; |
| 512 | else if (!strcmp(opt, "tcp")) |
| 513 | tcp = val; |
| 514 | else if (!strcmp(opt, "udp")) |
| 515 | tcp = !val; |
| 516 | else if (!strcmp(opt, "lock")) { |
| 517 | if (nfs_mount_version >= 3) |
| 518 | nolock = !val; |
| 519 | else |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 520 | printf("Warning: option nolock is not supported.\n"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 521 | } else { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 522 | printf("unknown nfs mount option: %s%s\n", val ? "" : "no", opt); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 523 | goto fail; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 527 | proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP; |
| 528 | |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 529 | data.flags = (soft ? NFS_MOUNT_SOFT : 0) |
| 530 | | (intr ? NFS_MOUNT_INTR : 0) |
| 531 | | (posix ? NFS_MOUNT_POSIX : 0) |
| 532 | | (nocto ? NFS_MOUNT_NOCTO : 0) |
| 533 | | (noac ? NFS_MOUNT_NOAC : 0); |
| 534 | #if NFS_MOUNT_VERSION >= 2 |
| 535 | if (nfs_mount_version >= 2) |
| 536 | data.flags |= (tcp ? NFS_MOUNT_TCP : 0); |
| 537 | #endif |
| 538 | #if NFS_MOUNT_VERSION >= 3 |
| 539 | if (nfs_mount_version >= 3) |
| 540 | data.flags |= (nolock ? NFS_MOUNT_NONLM : 0); |
| 541 | #endif |
Rob Landley | 29ba979 | 2006-04-17 23:02:57 +0000 | [diff] [blame] | 542 | if (nfsvers > MAX_NFSPROT || mountvers > MAX_NFSPROT) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 543 | bb_error_msg("NFSv%d not supported!", nfsvers); |
Rob Landley | 29ba979 | 2006-04-17 23:02:57 +0000 | [diff] [blame] | 544 | return 1; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 545 | } |
| 546 | if (nfsvers && !mountvers) |
| 547 | mountvers = (nfsvers < 3) ? 1 : nfsvers; |
| 548 | if (nfsvers && nfsvers < mountvers) { |
| 549 | mountvers = nfsvers; |
| 550 | } |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 551 | |
| 552 | /* Adjust options if none specified */ |
| 553 | if (!data.timeo) |
| 554 | data.timeo = tcp ? 70 : 7; |
| 555 | |
| 556 | #ifdef NFS_MOUNT_DEBUG |
| 557 | printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n", |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 558 | data.rsize, data.wsize, data.timeo, data.retrans); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 559 | printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n", |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 560 | data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 561 | printf("port = %d, bg = %d, retry = %d, flags = %.8x\n", |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 562 | port, bg, retry, data.flags); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 563 | printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n", |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 564 | mountprog, mountvers, nfsprog, nfsvers); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 565 | printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n", |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 566 | (data.flags & NFS_MOUNT_SOFT) != 0, |
| 567 | (data.flags & NFS_MOUNT_INTR) != 0, |
| 568 | (data.flags & NFS_MOUNT_POSIX) != 0, |
| 569 | (data.flags & NFS_MOUNT_NOCTO) != 0, |
| 570 | (data.flags & NFS_MOUNT_NOAC) != 0); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 571 | #if NFS_MOUNT_VERSION >= 2 |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 572 | printf("tcp = %d\n", |
| 573 | (data.flags & NFS_MOUNT_TCP) != 0); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 574 | #endif |
| 575 | #endif |
| 576 | |
| 577 | data.version = nfs_mount_version; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 578 | |
| 579 | if (*flags & MS_REMOUNT) |
Eric Andersen | 882cec3 | 2004-07-26 12:05:12 +0000 | [diff] [blame] | 580 | goto copy_data_and_return; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * If the previous mount operation on the same host was |
| 584 | * backgrounded, and the "bg" for this mount is also set, |
| 585 | * give up immediately, to avoid the initial timeout. |
| 586 | */ |
| 587 | if (bg && !running_bg && |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 588 | prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 589 | if (retry > 0) |
| 590 | retval = EX_BG; |
| 591 | return retval; |
| 592 | } |
| 593 | |
Mike Frysinger | fa6c484 | 2006-05-26 01:48:17 +0000 | [diff] [blame] | 594 | /* create mount daemon client */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 595 | /* See if the nfs host = mount host. */ |
| 596 | if (mounthost) { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 597 | if (mounthost[0] >= '0' && mounthost[0] <= '9') { |
| 598 | mount_server_addr.sin_family = AF_INET; |
| 599 | mount_server_addr.sin_addr.s_addr = inet_addr(hostname); |
| 600 | } else { |
| 601 | if ((hp = gethostbyname(mounthost)) == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 602 | bb_herror_msg("%s", mounthost); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 603 | goto fail; |
| 604 | } else { |
| 605 | if (hp->h_length > sizeof(struct in_addr)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 606 | bb_error_msg("got bad hp->h_length?"); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 607 | hp->h_length = sizeof(struct in_addr); |
| 608 | } |
| 609 | mount_server_addr.sin_family = AF_INET; |
| 610 | memcpy(&mount_server_addr.sin_addr, |
| 611 | hp->h_addr, hp->h_length); |
| 612 | } |
| 613 | } |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* |
| 617 | * The following loop implements the mount retries. On the first |
| 618 | * call, "running_bg" is 0. When the mount times out, and the |
| 619 | * "bg" option is set, the exit status EX_BG will be returned. |
| 620 | * For a backgrounded mount, there will be a second call by the |
| 621 | * child process with "running_bg" set to 1. |
| 622 | * |
| 623 | * The case where the mount point is not present and the "bg" |
| 624 | * option is set, is treated as a timeout. This is done to |
| 625 | * support nested mounts. |
| 626 | * |
| 627 | * The "retry" count specified by the user is the number of |
| 628 | * minutes to retry before giving up. |
| 629 | * |
| 630 | * Only the first error message will be displayed. |
| 631 | */ |
| 632 | retry_timeout.tv_sec = 3; |
| 633 | retry_timeout.tv_usec = 0; |
| 634 | total_timeout.tv_sec = 20; |
| 635 | total_timeout.tv_usec = 0; |
| 636 | timeout = time(NULL) + 60 * retry; |
| 637 | prevt = 0; |
| 638 | t = 30; |
| 639 | val = 1; |
| 640 | for (;;) { |
| 641 | if (bg && stat(node, &statbuf) == -1) { |
| 642 | if (running_bg) { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 643 | sleep(val); /* 1, 2, 4, 8, 16, 30, ... */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 644 | val *= 2; |
| 645 | if (val > 30) |
| 646 | val = 30; |
| 647 | } |
| 648 | } else { |
| 649 | /* be careful not to use too many CPU cycles */ |
| 650 | if (t - prevt < 30) |
| 651 | sleep(30); |
| 652 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 653 | pm_mnt = get_mountport(&mount_server_addr, |
| 654 | mountprog, |
| 655 | mountvers, |
| 656 | proto, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 657 | mountport); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 658 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 659 | /* contact the mount daemon via TCP */ |
| 660 | mount_server_addr.sin_port = htons(pm_mnt->pm_port); |
| 661 | msock = RPC_ANYSOCK; |
| 662 | |
| 663 | switch (pm_mnt->pm_prot) { |
| 664 | case IPPROTO_UDP: |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 665 | mclient = clntudp_create(&mount_server_addr, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 666 | pm_mnt->pm_prog, |
| 667 | pm_mnt->pm_vers, |
| 668 | retry_timeout, |
| 669 | &msock); |
| 670 | if (mclient) |
| 671 | break; |
| 672 | mount_server_addr.sin_port = htons(pm_mnt->pm_port); |
| 673 | msock = RPC_ANYSOCK; |
| 674 | case IPPROTO_TCP: |
| 675 | mclient = clnttcp_create(&mount_server_addr, |
| 676 | pm_mnt->pm_prog, |
| 677 | pm_mnt->pm_vers, |
| 678 | &msock, 0, 0); |
| 679 | break; |
| 680 | default: |
| 681 | mclient = 0; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 682 | } |
| 683 | if (mclient) { |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 684 | /* try to mount hostname:pathname */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 685 | mclient->cl_auth = authunix_create_default(); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 686 | |
| 687 | /* make pointers in xdr_mountres3 NULL so |
| 688 | * that xdr_array allocates memory for us |
| 689 | */ |
| 690 | memset(&status, 0, sizeof(status)); |
| 691 | |
| 692 | if (pm_mnt->pm_vers == 3) |
| 693 | clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT, |
| 694 | (xdrproc_t) xdr_dirpath, |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 695 | (caddr_t) &pathname, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 696 | (xdrproc_t) xdr_mountres3, |
| 697 | (caddr_t) &status, |
| 698 | total_timeout); |
| 699 | else |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 700 | clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 701 | (xdrproc_t) xdr_dirpath, |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 702 | (caddr_t) &pathname, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 703 | (xdrproc_t) xdr_fhstatus, |
| 704 | (caddr_t) &status, |
| 705 | total_timeout); |
| 706 | |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 707 | if (clnt_stat == RPC_SUCCESS) |
| 708 | break; /* we're done */ |
| 709 | if (errno != ECONNREFUSED) { |
| 710 | clnt_perror(mclient, "mount"); |
| 711 | goto fail; /* don't retry */ |
| 712 | } |
| 713 | if (!running_bg && prevt == 0) |
| 714 | clnt_perror(mclient, "mount"); |
| 715 | auth_destroy(mclient->cl_auth); |
| 716 | clnt_destroy(mclient); |
| 717 | mclient = 0; |
| 718 | close(msock); |
| 719 | } else { |
| 720 | if (!running_bg && prevt == 0) |
| 721 | clnt_pcreateerror("mount"); |
| 722 | } |
| 723 | prevt = t; |
| 724 | } |
| 725 | if (!bg) |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 726 | goto fail; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 727 | if (!running_bg) { |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 728 | prev_bg_host = xstrdup(hostname); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 729 | if (retry > 0) |
| 730 | retval = EX_BG; |
| 731 | goto fail; |
| 732 | } |
| 733 | t = time(NULL); |
| 734 | if (t >= timeout) |
| 735 | goto fail; |
| 736 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 737 | nfsvers = (pm_mnt->pm_vers < 2) ? 2 : pm_mnt->pm_vers; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 738 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 739 | if (nfsvers == 2) { |
| 740 | if (status.nfsv2.fhs_status != 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 741 | bb_error_msg("%s:%s failed, reason given by server: %s", |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 742 | hostname, pathname, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 743 | nfs_strerror(status.nfsv2.fhs_status)); |
| 744 | goto fail; |
| 745 | } |
| 746 | memcpy(data.root.data, |
| 747 | (char *) status.nfsv2.fhstatus_u.fhs_fhandle, |
| 748 | NFS_FHSIZE); |
| 749 | #if NFS_MOUNT_VERSION >= 4 |
| 750 | data.root.size = NFS_FHSIZE; |
| 751 | memcpy(data.old_root.data, |
| 752 | (char *) status.nfsv2.fhstatus_u.fhs_fhandle, |
| 753 | NFS_FHSIZE); |
| 754 | #endif |
| 755 | } else { |
| 756 | #if NFS_MOUNT_VERSION >= 4 |
Eric Andersen | 851895a | 2001-03-21 21:52:25 +0000 | [diff] [blame] | 757 | fhandle3 *my_fhandle; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 758 | if (status.nfsv3.fhs_status != 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 759 | bb_error_msg("%s:%s failed, reason given by server: %s", |
Matt Kraai | f9d6aa0 | 2001-07-26 14:26:53 +0000 | [diff] [blame] | 760 | hostname, pathname, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 761 | nfs_strerror(status.nfsv3.fhs_status)); |
| 762 | goto fail; |
| 763 | } |
Eric Andersen | 851895a | 2001-03-21 21:52:25 +0000 | [diff] [blame] | 764 | my_fhandle = &status.nfsv3.mountres3_u.mountinfo.fhandle; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 765 | memset(data.old_root.data, 0, NFS_FHSIZE); |
| 766 | memset(&data.root, 0, sizeof(data.root)); |
Eric Andersen | 851895a | 2001-03-21 21:52:25 +0000 | [diff] [blame] | 767 | data.root.size = my_fhandle->fhandle3_len; |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 768 | memcpy(data.root.data, |
Eric Andersen | 851895a | 2001-03-21 21:52:25 +0000 | [diff] [blame] | 769 | (char *) my_fhandle->fhandle3_val, |
| 770 | my_fhandle->fhandle3_len); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 771 | |
| 772 | data.flags |= NFS_MOUNT_VER3; |
| 773 | #endif |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 774 | } |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 775 | |
| 776 | /* create nfs socket for kernel */ |
| 777 | |
| 778 | if (tcp) { |
| 779 | if (nfs_mount_version < 3) { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 780 | printf("NFS over TCP is not supported.\n"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 781 | goto fail; |
| 782 | } |
| 783 | fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 784 | } else |
| 785 | fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); |
| 786 | if (fsock < 0) { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 787 | perror("nfs socket"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 788 | goto fail; |
| 789 | } |
| 790 | if (bindresvport(fsock, 0) < 0) { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 791 | perror("nfs bindresvport"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 792 | goto fail; |
| 793 | } |
| 794 | if (port == 0) { |
| 795 | server_addr.sin_port = PMAPPORT; |
| 796 | port = pmap_getport(&server_addr, nfsprog, nfsvers, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 797 | tcp ? IPPROTO_TCP : IPPROTO_UDP); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 798 | if (port == 0) |
| 799 | port = NFS_PORT; |
| 800 | #ifdef NFS_MOUNT_DEBUG |
| 801 | else |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 802 | printf("used portmapper to find NFS port\n"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 803 | #endif |
| 804 | } |
| 805 | #ifdef NFS_MOUNT_DEBUG |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 806 | printf("using port %d for nfs daemon\n", port); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 807 | #endif |
| 808 | server_addr.sin_port = htons(port); |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 809 | /* |
| 810 | * connect() the socket for kernels 1.3.10 and below only, |
| 811 | * to avoid problems with multihomed hosts. |
| 812 | * --Swen |
| 813 | */ |
Bernhard Reutner-Fischer | e2e56c7 | 2006-05-19 11:54:02 +0000 | [diff] [blame] | 814 | if (get_linux_version_code() <= KERNEL_VERSION(2,3,10) |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 815 | && connect(fsock, (struct sockaddr *) &server_addr, |
| 816 | sizeof (server_addr)) < 0) { |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 817 | perror("nfs connect"); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 818 | goto fail; |
| 819 | } |
| 820 | |
| 821 | /* prepare data structure for kernel */ |
| 822 | |
| 823 | data.fd = fsock; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 824 | memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr)); |
| 825 | strncpy(data.hostname, hostname, sizeof(data.hostname)); |
| 826 | |
| 827 | /* clean up */ |
| 828 | |
| 829 | auth_destroy(mclient->cl_auth); |
| 830 | clnt_destroy(mclient); |
| 831 | close(msock); |
Eric Andersen | 882cec3 | 2004-07-26 12:05:12 +0000 | [diff] [blame] | 832 | copy_data_and_return: |
| 833 | *mount_opts = xrealloc(*mount_opts, sizeof(data)); |
| 834 | memcpy(*mount_opts, &data, sizeof(data)); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 835 | return 0; |
| 836 | |
| 837 | /* abort */ |
| 838 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 839 | fail: |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 840 | if (msock != -1) { |
| 841 | if (mclient) { |
| 842 | auth_destroy(mclient->cl_auth); |
| 843 | clnt_destroy(mclient); |
| 844 | } |
| 845 | close(msock); |
| 846 | } |
| 847 | if (fsock != -1) |
| 848 | close(fsock); |
| 849 | return retval; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 850 | } |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 851 | |
| 852 | /* |
| 853 | * We need to translate between nfs status return values and |
| 854 | * the local errno values which may not be the same. |
| 855 | * |
| 856 | * Andreas Schwab <schwab@LS5.informatik.uni-dortmund.de>: change errno: |
| 857 | * "after #include <errno.h> the symbol errno is reserved for any use, |
| 858 | * it cannot even be used as a struct tag or field name". |
| 859 | */ |
| 860 | |
| 861 | #ifndef EDQUOT |
| 862 | #define EDQUOT ENOSPC |
| 863 | #endif |
| 864 | |
"Vladimir N. Oleynik" | 1f0262b | 2005-10-20 11:17:48 +0000 | [diff] [blame] | 865 | static const struct { |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 866 | enum nfs_stat stat; |
| 867 | int errnum; |
| 868 | } nfs_errtbl[] = { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 869 | { NFS_OK, 0 }, |
| 870 | { NFSERR_PERM, EPERM }, |
| 871 | { NFSERR_NOENT, ENOENT }, |
| 872 | { NFSERR_IO, EIO }, |
| 873 | { NFSERR_NXIO, ENXIO }, |
| 874 | { NFSERR_ACCES, EACCES }, |
| 875 | { NFSERR_EXIST, EEXIST }, |
| 876 | { NFSERR_NODEV, ENODEV }, |
| 877 | { NFSERR_NOTDIR, ENOTDIR }, |
| 878 | { NFSERR_ISDIR, EISDIR }, |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 879 | #ifdef NFSERR_INVAL |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 880 | { NFSERR_INVAL, EINVAL }, /* that Sun forgot */ |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 881 | #endif |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 882 | { NFSERR_FBIG, EFBIG }, |
| 883 | { NFSERR_NOSPC, ENOSPC }, |
| 884 | { NFSERR_ROFS, EROFS }, |
| 885 | { NFSERR_NAMETOOLONG, ENAMETOOLONG }, |
| 886 | { NFSERR_NOTEMPTY, ENOTEMPTY }, |
| 887 | { NFSERR_DQUOT, EDQUOT }, |
| 888 | { NFSERR_STALE, ESTALE }, |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 889 | #ifdef EWFLUSH |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 890 | { NFSERR_WFLUSH, EWFLUSH }, |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 891 | #endif |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 892 | /* Throw in some NFSv3 values for even more fun (HP returns these) */ |
| 893 | { 71, EREMOTE }, |
| 894 | |
| 895 | { -1, EIO } |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 896 | }; |
| 897 | |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 898 | static char *nfs_strerror(int status) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 899 | { |
| 900 | int i; |
| 901 | static char buf[256]; |
| 902 | |
| 903 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
Eric Andersen | 1ca20a7 | 2001-03-21 07:34:27 +0000 | [diff] [blame] | 904 | if (nfs_errtbl[i].stat == status) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 905 | return strerror(nfs_errtbl[i].errnum); |
| 906 | } |
Rob Landley | 8394729 | 2006-05-29 04:49:55 +0000 | [diff] [blame] | 907 | sprintf(buf, "unknown nfs status return value: %d", status); |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 908 | return buf; |
| 909 | } |
| 910 | |
Eric Andersen | 3e6ff90 | 2001-03-09 21:24:12 +0000 | [diff] [blame] | 911 | static bool_t |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 912 | xdr_fhandle (XDR *xdrs, fhandle objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 913 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 914 | if (!xdr_opaque (xdrs, objp, FHSIZE)) |
| 915 | return FALSE; |
| 916 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 919 | bool_t |
| 920 | xdr_fhstatus (XDR *xdrs, fhstatus *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 921 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 922 | if (!xdr_u_int (xdrs, &objp->fhs_status)) |
| 923 | return FALSE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 924 | switch (objp->fhs_status) { |
| 925 | case 0: |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 926 | if (!xdr_fhandle (xdrs, objp->fhstatus_u.fhs_fhandle)) |
| 927 | return FALSE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 928 | break; |
| 929 | default: |
| 930 | break; |
| 931 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 932 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 935 | bool_t |
| 936 | xdr_dirpath (XDR *xdrs, dirpath *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 937 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 938 | if (!xdr_string (xdrs, objp, MNTPATHLEN)) |
| 939 | return FALSE; |
| 940 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 943 | bool_t |
| 944 | xdr_fhandle3 (XDR *xdrs, fhandle3 *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 945 | { |
Eric Andersen | d242079 | 2004-01-30 22:56:20 +0000 | [diff] [blame] | 946 | if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (unsigned int *) &objp->fhandle3_len, FHSIZE3)) |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 947 | return FALSE; |
| 948 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 951 | bool_t |
| 952 | xdr_mountres3_ok (XDR *xdrs, mountres3_ok *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 953 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 954 | if (!xdr_fhandle3 (xdrs, &objp->fhandle)) |
| 955 | return FALSE; |
Rob Landley | 7a260f0 | 2006-06-19 03:20:03 +0000 | [diff] [blame] | 956 | if (!xdr_array (xdrs, &(objp->auth_flavours.auth_flavours_val), &(objp->auth_flavours.auth_flavours_len), ~0, |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 957 | sizeof (int), (xdrproc_t) xdr_int)) |
| 958 | return FALSE; |
| 959 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 962 | bool_t |
| 963 | xdr_mountstat3 (XDR *xdrs, mountstat3 *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 964 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 965 | if (!xdr_enum (xdrs, (enum_t *) objp)) |
| 966 | return FALSE; |
| 967 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 970 | bool_t |
| 971 | xdr_mountres3 (XDR *xdrs, mountres3 *objp) |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 972 | { |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 973 | if (!xdr_mountstat3 (xdrs, &objp->fhs_status)) |
| 974 | return FALSE; |
| 975 | switch (objp->fhs_status) { |
| 976 | case MNT_OK: |
| 977 | if (!xdr_mountres3_ok (xdrs, &objp->mountres3_u.mountinfo)) |
| 978 | return FALSE; |
| 979 | break; |
| 980 | default: |
| 981 | break; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 982 | } |
Eric Andersen | da1d1e7 | 2000-07-10 23:39:44 +0000 | [diff] [blame] | 983 | return TRUE; |
Eric Andersen | 1c43d0c | 1999-11-18 07:58:07 +0000 | [diff] [blame] | 984 | } |
| 985 | |