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