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