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