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