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