aboutsummaryrefslogtreecommitdiff
path: root/nfsmount.c
diff options
context:
space:
mode:
Diffstat (limited to 'nfsmount.c')
-rw-r--r--nfsmount.c1187
1 files changed, 443 insertions, 744 deletions
diff --git a/nfsmount.c b/nfsmount.c
index 03ce58447..8cdfebfce 100644
--- a/nfsmount.c
+++ b/nfsmount.c
@@ -25,6 +25,8 @@
25 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org> 25 * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
26 * - added Native Language Support 26 * - added Native Language Support
27 * 27 *
28 * Modified by Olaf Kirch and Trond Myklebust for new NFS code,
29 * plus NFSv3 stuff.
28 */ 30 */
29 31
30/* 32/*
@@ -47,27 +49,117 @@
47#include <arpa/inet.h> 49#include <arpa/inet.h>
48 50
49#include "nfsmount.h" 51#include "nfsmount.h"
52#include <linux/nfs.h> /* For the kernels nfs stuff */
53
54
55/* Disable the nls stuff */
56# undef bindtextdomain
57# define bindtextdomain(Domain, Directory) /* empty */
58# undef textdomain
59# define textdomain(Domain) /* empty */
60# define _(Text) (Text)
61# define N_(Text) (Text)
62
63#define MS_MGC_VAL 0xc0ed0000 /* Magic number indicatng "new" flags */
64#define MS_RDONLY 1 /* Mount read-only */
65#define MS_NOSUID 2 /* Ignore suid and sgid bits */
66#define MS_NODEV 4 /* Disallow access to device special files */
67#define MS_NOEXEC 8 /* Disallow program execution */
68#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
69#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
70#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
71#define S_QUOTA 128 /* Quota initialized for file/directory/symlink */
72#define S_APPEND 256 /* Append-only file */
73#define S_IMMUTABLE 512 /* Immutable file */
74#define MS_NOATIME 1024 /* Do not update access times. */
75#define MS_NODIRATIME 2048 /* Do not update directory access times */
50 76
51#include <linux/nfs.h>
52/* we suppose that libc-dev is providing NFSv3 headers (kernel >= 2.2) */
53#include <linux/nfs_mount.h>
54 77
55#define _ 78/*
56#define HAVE_inet_aton 79 * We want to be able to compile mount on old kernels in such a way
57#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ 80 * that the binary will work well on more recent kernels.
58#define sloppy 0 81 * Thus, if necessary we teach nfsmount.c the structure of new fields
59#define EX_FAIL 1 82 * that will come later.
60#define EX_BG 1 83 *
61#define xstrdup strdup 84 * Moreover, the new kernel includes conflict with glibc includes
62#define xstrndup strndup 85 * so it is easiest to ignore the kernel altogether (at compile time).
86 */
87
88#define NFS_MOUNT_VERSION 4
63 89
90struct nfs2_fh {
91 char data[32];
92};
93struct nfs3_fh {
94 unsigned short size;
95 unsigned char data[64];
96};
97
98struct nfs_mount_data {
99 int version; /* 1 */
100 int fd; /* 1 */
101 struct nfs2_fh old_root; /* 1 */
102 int flags; /* 1 */
103 int rsize; /* 1 */
104 int wsize; /* 1 */
105 int timeo; /* 1 */
106 int retrans; /* 1 */
107 int acregmin; /* 1 */
108 int acregmax; /* 1 */
109 int acdirmin; /* 1 */
110 int acdirmax; /* 1 */
111 struct sockaddr_in addr; /* 1 */
112 char hostname[256]; /* 1 */
113 int namlen; /* 2 */
114 unsigned int bsize; /* 3 */
115 struct nfs3_fh root; /* 4 */
116};
64 117
118/* bits in the flags field */
119
120#define NFS_MOUNT_SOFT 0x0001 /* 1 */
121#define NFS_MOUNT_INTR 0x0002 /* 1 */
122#define NFS_MOUNT_SECURE 0x0004 /* 1 */
123#define NFS_MOUNT_POSIX 0x0008 /* 1 */
124#define NFS_MOUNT_NOCTO 0x0010 /* 1 */
125#define NFS_MOUNT_NOAC 0x0020 /* 1 */
126#define NFS_MOUNT_TCP 0x0040 /* 2 */
127#define NFS_MOUNT_VER3 0x0080 /* 3 */
128#define NFS_MOUNT_KERBEROS 0x0100 /* 3 */
129#define NFS_MOUNT_NONLM 0x0200 /* 3 */
130
131
132#define UTIL_LINUX_VERSION "2.10m"
133#define util_linux_version "util-linux-2.10m"
134
135#define HAVE_inet_aton
136#define HAVE_scsi_h
137#define HAVE_blkpg_h
138#define HAVE_kd_h
139#define HAVE_termcap
140#define HAVE_locale_h
141#define HAVE_libintl_h
142#define ENABLE_NLS
143#define HAVE_langinfo_h
144#define HAVE_progname
145#define HAVE_openpty
146#define HAVE_nanosleep
147#define HAVE_personality
148#define HAVE_tm_gmtoff
149
150extern char *xstrdup (const char *s);
151extern char *xstrndup (const char *s, int n);
65static char *nfs_strerror(int stat); 152static char *nfs_strerror(int stat);
66 153
67#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r)) 154#define MAKE_VERSION(p,q,r) (65536*(p) + 256*(q) + (r))
155#define MAX_NFSPROT ((nfs_mount_version >= 4) ? 3 : 2)
68 156
69static int linux_version_code(void) 157#define EX_FAIL 32 /* mount failure */
70{ 158#define EX_BG 256 /* retry in background (internal only) */
159
160
161static int
162linux_version_code(void) {
71 struct utsname my_utsname; 163 struct utsname my_utsname;
72 int p, q, r; 164 int p, q, r;
73 165
@@ -75,15 +167,15 @@ static int linux_version_code(void)
75 p = atoi(strtok(my_utsname.release, ".")); 167 p = atoi(strtok(my_utsname.release, "."));
76 q = atoi(strtok(NULL, ".")); 168 q = atoi(strtok(NULL, "."));
77 r = atoi(strtok(NULL, ".")); 169 r = atoi(strtok(NULL, "."));
78 return MAKE_VERSION(p, q, r); 170 return MAKE_VERSION(p,q,r);
79 } 171 }
80 return 0; 172 return 0;
81} 173}
82 174
83/* 175/*
84 * nfs_mount_version according to the kernel sources seen at compile time. 176 * nfs_mount_version according to the sources seen at compile time.
85 */ 177 */
86static int nfs_mount_version = NFS_MOUNT_VERSION; 178int nfs_mount_version = NFS_MOUNT_VERSION;
87 179
88/* 180/*
89 * Unfortunately, the kernel prints annoying console messages 181 * Unfortunately, the kernel prints annoying console messages
@@ -96,22 +188,77 @@ static int nfs_mount_version = NFS_MOUNT_VERSION;
96 * NFS_MOUNT_VERSION: these nfsmount sources at compile time 188 * NFS_MOUNT_VERSION: these nfsmount sources at compile time
97 * nfs_mount_version: version this source and running kernel can handle 189 * nfs_mount_version: version this source and running kernel can handle
98 */ 190 */
99static void find_kernel_nfs_mount_version(void) 191static void
100{ 192find_kernel_nfs_mount_version(void) {
101 int kernel_version = linux_version_code(); 193 static int kernel_version = 0;
194
195 if (kernel_version)
196 return;
197
198 kernel_version = linux_version_code();
102 199
103 if (kernel_version) { 200 if (kernel_version) {
104 if (kernel_version < MAKE_VERSION(2, 1, 32)) 201 if (kernel_version < MAKE_VERSION(2,1,32))
105 nfs_mount_version = 1; 202 nfs_mount_version = 1;
106 else 203 else if (kernel_version < MAKE_VERSION(2,3,99))
107 nfs_mount_version = 3; 204 nfs_mount_version = 3;
205 else
206 nfs_mount_version = 4; /* since 2.3.99pre4 */
108 } 207 }
109 if (nfs_mount_version > NFS_MOUNT_VERSION) 208 if (nfs_mount_version > NFS_MOUNT_VERSION)
110 nfs_mount_version = NFS_MOUNT_VERSION; 209 nfs_mount_version = NFS_MOUNT_VERSION;
111} 210}
112 211
113int nfsmount(const char *spec, const char *node, unsigned long *flags, 212static struct pmap *
114 char **extra_opts, char **mount_opts, int running_bg) 213get_mountport(struct sockaddr_in *server_addr,
214 long unsigned prog,
215 long unsigned version,
216 long unsigned proto,
217 long unsigned port)
218{
219struct pmaplist *pmap;
220static struct pmap p = {0, 0, 0, 0};
221
222server_addr->sin_port = PMAPPORT;
223pmap = pmap_getmaps(server_addr);
224
225if (version > MAX_NFSPROT)
226 version = MAX_NFSPROT;
227if (!prog)
228 prog = MOUNTPROG;
229p.pm_prog = prog;
230p.pm_vers = version;
231p.pm_prot = proto;
232p.pm_port = port;
233
234while (pmap) {
235 if (pmap->pml_map.pm_prog != prog)
236 goto next;
237 if (!version && p.pm_vers > pmap->pml_map.pm_vers)
238 goto next;
239 if (version > 2 && pmap->pml_map.pm_vers != version)
240 goto next;
241 if (version && version <= 2 && pmap->pml_map.pm_vers > 2)
242 goto next;
243 if (pmap->pml_map.pm_vers > MAX_NFSPROT ||
244 (proto && p.pm_prot && pmap->pml_map.pm_prot != proto) ||
245 (port && pmap->pml_map.pm_port != port))
246 goto next;
247 memcpy(&p, &pmap->pml_map, sizeof(p));
248next:
249 pmap = pmap->pml_next;
250}
251if (!p.pm_vers)
252 p.pm_vers = MOUNTVERS;
253if (!p.pm_port)
254 p.pm_port = MOUNTPORT;
255if (!p.pm_prot)
256 p.pm_prot = IPPROTO_TCP;
257return &p;
258}
259
260int nfsmount(const char *spec, const char *node, int *flags,
261 char **extra_opts, char **mount_opts, int running_bg)
115{ 262{
116 static char *prev_bg_host; 263 static char *prev_bg_host;
117 char hostdir[1024]; 264 char hostdir[1024];
@@ -119,9 +266,8 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
119 char *hostname; 266 char *hostname;
120 char *dirname; 267 char *dirname;
121 char *old_opts; 268 char *old_opts;
122 char *mounthost = NULL; 269 char *mounthost=NULL;
123 char new_opts[1024]; 270 char new_opts[1024];
124 fhandle root_fhandle;
125 struct timeval total_timeout; 271 struct timeval total_timeout;
126 enum clnt_stat clnt_stat; 272 enum clnt_stat clnt_stat;
127 static struct nfs_mount_data data; 273 static struct nfs_mount_data data;
@@ -130,13 +276,18 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
130 struct hostent *hp; 276 struct hostent *hp;
131 struct sockaddr_in server_addr; 277 struct sockaddr_in server_addr;
132 struct sockaddr_in mount_server_addr; 278 struct sockaddr_in mount_server_addr;
279 struct pmap* pm_mnt;
133 int msock, fsock; 280 int msock, fsock;
134 struct timeval retry_timeout; 281 struct timeval retry_timeout;
135 struct fhstatus status; 282 union {
283 struct fhstatus nfsv2;
284 struct mountres3 nfsv3;
285 } status;
136 struct stat statbuf; 286 struct stat statbuf;
137 char *s; 287 char *s;
138 int port; 288 int port;
139 int mountport; 289 int mountport;
290 int proto;
140 int bg; 291 int bg;
141 int soft; 292 int soft;
142 int intr; 293 int intr;
@@ -162,7 +313,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
162 mclient = NULL; 313 mclient = NULL;
163 if (strlen(spec) >= sizeof(hostdir)) { 314 if (strlen(spec) >= sizeof(hostdir)) {
164 fprintf(stderr, _("mount: " 315 fprintf(stderr, _("mount: "
165 "excessively long host:dir argument\n")); 316 "excessively long host:dir argument\n"));
166 goto fail; 317 goto fail;
167 } 318 }
168 strcpy(hostdir, spec); 319 strcpy(hostdir, spec);
@@ -175,11 +326,11 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
175 if ((s = strchr(hostdir, ','))) { 326 if ((s = strchr(hostdir, ','))) {
176 *s = '\0'; 327 *s = '\0';
177 fprintf(stderr, _("mount: warning: " 328 fprintf(stderr, _("mount: warning: "
178 "multiple hostnames not supported\n")); 329 "multiple hostnames not supported\n"));
179 } 330 }
180 } else { 331 } else {
181 fprintf(stderr, _("mount: " 332 fprintf(stderr, _("mount: "
182 "directory to mount not in host:dir format\n")); 333 "directory to mount not in host:dir format\n"));
183 goto fail; 334 goto fail;
184 } 335 }
185 336
@@ -190,18 +341,20 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
190 { 341 {
191 if ((hp = gethostbyname(hostname)) == NULL) { 342 if ((hp = gethostbyname(hostname)) == NULL) {
192 fprintf(stderr, _("mount: can't get address for %s\n"), 343 fprintf(stderr, _("mount: can't get address for %s\n"),
193 hostname); 344 hostname);
194 goto fail; 345 goto fail;
195 } else { 346 } else {
196 if (hp->h_length > sizeof(struct in_addr)) { 347 if (hp->h_length > sizeof(struct in_addr)) {
197 fprintf(stderr, _("mount: got bad hp->h_length\n")); 348 fprintf(stderr,
349 _("mount: got bad hp->h_length\n"));
198 hp->h_length = sizeof(struct in_addr); 350 hp->h_length = sizeof(struct in_addr);
199 } 351 }
200 memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length); 352 memcpy(&server_addr.sin_addr,
353 hp->h_addr, hp->h_length);
201 } 354 }
202 } 355 }
203 356
204 memcpy(&mount_server_addr, &server_addr, sizeof(mount_server_addr)); 357 memcpy (&mount_server_addr, &server_addr, sizeof (mount_server_addr));
205 358
206 /* add IP address to mtab options for use when unmounting */ 359 /* add IP address to mtab options for use when unmounting */
207 360
@@ -210,10 +363,12 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
210 if (!old_opts) 363 if (!old_opts)
211 old_opts = ""; 364 old_opts = "";
212 if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) { 365 if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) {
213 fprintf(stderr, _("mount: " "excessively long option argument\n")); 366 fprintf(stderr, _("mount: "
367 "excessively long option argument\n"));
214 goto fail; 368 goto fail;
215 } 369 }
216 sprintf(new_opts, "%s%saddr=%s", old_opts, *old_opts ? "," : "", s); 370 sprintf(new_opts, "%s%saddr=%s",
371 old_opts, *old_opts ? "," : "", s);
217 *extra_opts = xstrdup(new_opts); 372 *extra_opts = xstrdup(new_opts);
218 373
219 /* Set default options. 374 /* Set default options.
@@ -221,13 +376,13 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
221 * let the kernel decide. 376 * let the kernel decide.
222 * timeo is filled in after we know whether it'll be TCP or UDP. */ 377 * timeo is filled in after we know whether it'll be TCP or UDP. */
223 memset(&data, 0, sizeof(data)); 378 memset(&data, 0, sizeof(data));
224 data.retrans = 3; 379 data.retrans = 3;
225 data.acregmin = 3; 380 data.acregmin = 3;
226 data.acregmax = 60; 381 data.acregmax = 60;
227 data.acdirmin = 30; 382 data.acdirmin = 30;
228 data.acdirmax = 60; 383 data.acdirmax = 60;
229#if NFS_MOUNT_VERSION >= 2 384#if NFS_MOUNT_VERSION >= 2
230 data.namlen = NAME_MAX; 385 data.namlen = NAME_MAX;
231#endif 386#endif
232 387
233 bg = 0; 388 bg = 0;
@@ -237,21 +392,21 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
237 nocto = 0; 392 nocto = 0;
238 nolock = 0; 393 nolock = 0;
239 noac = 0; 394 noac = 0;
240 retry = 10000; /* 10000 minutes ~ 1 week */ 395 retry = 10000; /* 10000 minutes ~ 1 week */
241 tcp = 0; 396 tcp = 0;
242 397
243 mountprog = MOUNTPROG; 398 mountprog = MOUNTPROG;
244 mountvers = MOUNTVERS; 399 mountvers = 0;
245 port = 0; 400 port = 0;
246 mountport = 0; 401 mountport = 0;
247 nfsprog = NFS_PROGRAM; 402 nfsprog = NFS_PROGRAM;
248 nfsvers = NFS_VERSION; 403 nfsvers = 0;
249 404
250 /* parse options */ 405 /* parse options */
251 406
252 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) { 407 for (opt = strtok(old_opts, ","); opt; opt = strtok(NULL, ",")) {
253 if ((opteq = strchr(opt, '='))) { 408 if ((opteq = strchr(opt, '='))) {
254 val = atoi(opteq + 1); 409 val = atoi(opteq + 1);
255 *opteq = '\0'; 410 *opteq = '\0';
256 if (!strcmp(opt, "rsize")) 411 if (!strcmp(opt, "rsize"))
257 data.rsize = val; 412 data.rsize = val;
@@ -274,27 +429,29 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
274 data.acregmax = val; 429 data.acregmax = val;
275 data.acdirmin = val; 430 data.acdirmin = val;
276 data.acdirmax = val; 431 data.acdirmax = val;
277 } else if (!strcmp(opt, "retry")) 432 }
433 else if (!strcmp(opt, "retry"))
278 retry = val; 434 retry = val;
279 else if (!strcmp(opt, "port")) 435 else if (!strcmp(opt, "port"))
280 port = val; 436 port = val;
281 else if (!strcmp(opt, "mountport")) 437 else if (!strcmp(opt, "mountport"))
282 mountport = val; 438 mountport = val;
283 else if (!strcmp(opt, "mounthost")) 439 else if (!strcmp(opt, "mounthost"))
284 mounthost = xstrndup(opteq + 1, 440 mounthost=xstrndup(opteq+1,
285 strcspn(opteq + 1, " \t\n\r,")); 441 strcspn(opteq+1," \t\n\r,"));
286 else if (!strcmp(opt, "mountprog")) 442 else if (!strcmp(opt, "mountprog"))
287 mountprog = val; 443 mountprog = val;
288 else if (!strcmp(opt, "mountvers")) 444 else if (!strcmp(opt, "mountvers"))
289 mountvers = val; 445 mountvers = val;
290 else if (!strcmp(opt, "nfsprog")) 446 else if (!strcmp(opt, "nfsprog"))
291 nfsprog = val; 447 nfsprog = val;
292 else if (!strcmp(opt, "nfsvers") || !strcmp(opt, "vers")) 448 else if (!strcmp(opt, "nfsvers") ||
449 !strcmp(opt, "vers"))
293 nfsvers = val; 450 nfsvers = val;
294 else if (!strcmp(opt, "proto")) { 451 else if (!strcmp(opt, "proto")) {
295 if (!strncmp(opteq + 1, "tcp", 3)) 452 if (!strncmp(opteq+1, "tcp", 3))
296 tcp = 1; 453 tcp = 1;
297 else if (!strncmp(opteq + 1, "udp", 3)) 454 else if (!strncmp(opteq+1, "udp", 3))
298 tcp = 0; 455 tcp = 0;
299 else 456 else
300 printf(_("Warning: Unrecognized proto= option.\n")); 457 printf(_("Warning: Unrecognized proto= option.\n"));
@@ -304,24 +461,24 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
304 data.namlen = val; 461 data.namlen = val;
305 else 462 else
306#endif 463#endif
307 printf(_ 464 printf(_("Warning: Option namlen is not supported.\n"));
308 ("Warning: Option namlen is not supported.\n"));
309 } else if (!strcmp(opt, "addr")) 465 } else if (!strcmp(opt, "addr"))
310 /* ignore */ ; 466 /* ignore */;
311 else { 467 else {
312 printf(_("unknown nfs mount parameter: " 468 printf(_("unknown nfs mount parameter: "
313 "%s=%d\n"), opt, val); 469 "%s=%d\n"), opt, val);
314 goto fail; 470 goto fail;
315 } 471 }
316 } else { 472 }
473 else {
317 val = 1; 474 val = 1;
318 if (!strncmp(opt, "no", 2)) { 475 if (!strncmp(opt, "no", 2)) {
319 val = 0; 476 val = 0;
320 opt += 2; 477 opt += 2;
321 } 478 }
322 if (!strcmp(opt, "bg")) 479 if (!strcmp(opt, "bg"))
323 bg = val; 480 bg = val;
324 else if (!strcmp(opt, "fg")) 481 else if (!strcmp(opt, "fg"))
325 bg = !val; 482 bg = !val;
326 else if (!strcmp(opt, "soft")) 483 else if (!strcmp(opt, "soft"))
327 soft = val; 484 soft = val;
@@ -343,17 +500,16 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
343 if (nfs_mount_version >= 3) 500 if (nfs_mount_version >= 3)
344 nolock = !val; 501 nolock = !val;
345 else 502 else
346 printf(_ 503 printf(_("Warning: option nolock is not supported.\n"));
347 ("Warning: option nolock is not supported.\n"));
348 } else { 504 } else {
349 if (!sloppy) { 505 printf(_("unknown nfs mount option: "
350 printf(_("unknown nfs mount option: " 506 "%s%s\n"), val ? "" : "no", opt);
351 "%s%s\n"), val ? "" : "no", opt); 507 goto fail;
352 goto fail;
353 }
354 } 508 }
355 } 509 }
356 } 510 }
511 proto = (tcp) ? IPPROTO_TCP : IPPROTO_UDP;
512
357 data.flags = (soft ? NFS_MOUNT_SOFT : 0) 513 data.flags = (soft ? NFS_MOUNT_SOFT : 0)
358 | (intr ? NFS_MOUNT_INTR : 0) 514 | (intr ? NFS_MOUNT_INTR : 0)
359 | (posix ? NFS_MOUNT_POSIX : 0) 515 | (posix ? NFS_MOUNT_POSIX : 0)
@@ -367,6 +523,19 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
367 if (nfs_mount_version >= 3) 523 if (nfs_mount_version >= 3)
368 data.flags |= (nolock ? NFS_MOUNT_NONLM : 0); 524 data.flags |= (nolock ? NFS_MOUNT_NONLM : 0);
369#endif 525#endif
526 if (nfsvers > MAX_NFSPROT) {
527 fprintf(stderr, "NFSv%d not supported!\n", nfsvers);
528 return 0;
529 }
530 if (mountvers > MAX_NFSPROT) {
531 fprintf(stderr, "NFSv%d not supported!\n", nfsvers);
532 return 0;
533 }
534 if (nfsvers && !mountvers)
535 mountvers = (nfsvers < 3) ? 1 : nfsvers;
536 if (nfsvers && nfsvers < mountvers) {
537 mountvers = nfsvers;
538 }
370 539
371 /* Adjust options if none specified */ 540 /* Adjust options if none specified */
372 if (!data.timeo) 541 if (!data.timeo)
@@ -374,21 +543,22 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
374 543
375#ifdef NFS_MOUNT_DEBUG 544#ifdef NFS_MOUNT_DEBUG
376 printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n", 545 printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
377 data.rsize, data.wsize, data.timeo, data.retrans); 546 data.rsize, data.wsize, data.timeo, data.retrans);
378 printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n", 547 printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n",
379 data.acregmin, data.acregmax, data.acdirmin, data.acdirmax); 548 data.acregmin, data.acregmax, data.acdirmin, data.acdirmax);
380 printf("port = %d, bg = %d, retry = %d, flags = %.8x\n", 549 printf("port = %d, bg = %d, retry = %d, flags = %.8x\n",
381 port, bg, retry, data.flags); 550 port, bg, retry, data.flags);
382 printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n", 551 printf("mountprog = %d, mountvers = %d, nfsprog = %d, nfsvers = %d\n",
383 mountprog, mountvers, nfsprog, nfsvers); 552 mountprog, mountvers, nfsprog, nfsvers);
384 printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n", 553 printf("soft = %d, intr = %d, posix = %d, nocto = %d, noac = %d\n",
385 (data.flags & NFS_MOUNT_SOFT) != 0, 554 (data.flags & NFS_MOUNT_SOFT) != 0,
386 (data.flags & NFS_MOUNT_INTR) != 0, 555 (data.flags & NFS_MOUNT_INTR) != 0,
387 (data.flags & NFS_MOUNT_POSIX) != 0, 556 (data.flags & NFS_MOUNT_POSIX) != 0,
388 (data.flags & NFS_MOUNT_NOCTO) != 0, 557 (data.flags & NFS_MOUNT_NOCTO) != 0,
389 (data.flags & NFS_MOUNT_NOAC) != 0); 558 (data.flags & NFS_MOUNT_NOAC) != 0);
390#if NFS_MOUNT_VERSION >= 2 559#if NFS_MOUNT_VERSION >= 2
391 printf("tcp = %d\n", (data.flags & NFS_MOUNT_TCP) != 0); 560 printf("tcp = %d\n",
561 (data.flags & NFS_MOUNT_TCP) != 0);
392#endif 562#endif
393#endif 563#endif
394 564
@@ -404,7 +574,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
404 * give up immediately, to avoid the initial timeout. 574 * give up immediately, to avoid the initial timeout.
405 */ 575 */
406 if (bg && !running_bg && 576 if (bg && !running_bg &&
407 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) { 577 prev_bg_host && strcmp(hostname, prev_bg_host) == 0) {
408 if (retry > 0) 578 if (retry > 0)
409 retval = EX_BG; 579 retval = EX_BG;
410 return retval; 580 return retval;
@@ -413,24 +583,25 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
413 /* create mount deamon client */ 583 /* create mount deamon client */
414 /* See if the nfs host = mount host. */ 584 /* See if the nfs host = mount host. */
415 if (mounthost) { 585 if (mounthost) {
416 if (mounthost[0] >= '0' && mounthost[0] <= '9') { 586 if (mounthost[0] >= '0' && mounthost[0] <= '9') {
417 mount_server_addr.sin_family = AF_INET; 587 mount_server_addr.sin_family = AF_INET;
418 mount_server_addr.sin_addr.s_addr = inet_addr(hostname); 588 mount_server_addr.sin_addr.s_addr = inet_addr(hostname);
419 } else { 589 } else {
420 if ((hp = gethostbyname(mounthost)) == NULL) { 590 if ((hp = gethostbyname(mounthost)) == NULL) {
421 fprintf(stderr, _("mount: can't get address for %s\n"), 591 fprintf(stderr, _("mount: can't get address for %s\n"),
422 hostname); 592 hostname);
423 goto fail; 593 goto fail;
424 } else { 594 } else {
425 if (hp->h_length > sizeof(struct in_addr)) { 595 if (hp->h_length > sizeof(struct in_addr)) {
426 fprintf(stderr, _("mount: got bad hp->h_length?\n")); 596 fprintf(stderr,
427 hp->h_length = sizeof(struct in_addr); 597 _("mount: got bad hp->h_length?\n"));
428 } 598 hp->h_length = sizeof(struct in_addr);
429 mount_server_addr.sin_family = AF_INET; 599 }
430 memcpy(&mount_server_addr.sin_addr, 600 mount_server_addr.sin_family = AF_INET;
431 hp->h_addr, hp->h_length); 601 memcpy(&mount_server_addr.sin_addr,
432 } 602 hp->h_addr, hp->h_length);
433 } 603 }
604 }
434 } 605 }
435 606
436 /* 607 /*
@@ -460,7 +631,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
460 for (;;) { 631 for (;;) {
461 if (bg && stat(node, &statbuf) == -1) { 632 if (bg && stat(node, &statbuf) == -1) {
462 if (running_bg) { 633 if (running_bg) {
463 sleep(val); /* 1, 2, 4, 8, 16, 30, ... */ 634 sleep(val); /* 1, 2, 4, 8, 16, 30, ... */
464 val *= 2; 635 val *= 2;
465 if (val > 30) 636 if (val > 30)
466 val = 30; 637 val = 30;
@@ -470,28 +641,60 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
470 if (t - prevt < 30) 641 if (t - prevt < 30)
471 sleep(30); 642 sleep(30);
472 643
644 pm_mnt = get_mountport(&mount_server_addr,
645 mountprog,
646 mountvers,
647 proto,
648 mountport);
649
473 /* contact the mount daemon via TCP */ 650 /* contact the mount daemon via TCP */
474 mount_server_addr.sin_port = htons(mountport); 651 mount_server_addr.sin_port = htons(pm_mnt->pm_port);
475 msock = RPC_ANYSOCK; 652 msock = RPC_ANYSOCK;
476 mclient = clnttcp_create(&mount_server_addr,
477 mountprog, mountvers, &msock, 0, 0);
478 653
479 /* if this fails, contact the mount daemon via UDP */ 654 switch (pm_mnt->pm_prot) {
480 if (!mclient) { 655 case IPPROTO_UDP:
481 mount_server_addr.sin_port = htons(mountport);
482 msock = RPC_ANYSOCK;
483 mclient = clntudp_create(&mount_server_addr, 656 mclient = clntudp_create(&mount_server_addr,
484 mountprog, mountvers, 657 pm_mnt->pm_prog,
485 retry_timeout, &msock); 658 pm_mnt->pm_vers,
659 retry_timeout,
660 &msock);
661 if (mclient)
662 break;
663 mount_server_addr.sin_port = htons(pm_mnt->pm_port);
664 msock = RPC_ANYSOCK;
665 case IPPROTO_TCP:
666 mclient = clnttcp_create(&mount_server_addr,
667 pm_mnt->pm_prog,
668 pm_mnt->pm_vers,
669 &msock, 0, 0);
670 break;
671 default:
672 mclient = 0;
486 } 673 }
487 if (mclient) { 674 if (mclient) {
488 /* try to mount hostname:dirname */ 675 /* try to mount hostname:dirname */
489 mclient->cl_auth = authunix_create_default(); 676 mclient->cl_auth = authunix_create_default();
677
678 /* make pointers in xdr_mountres3 NULL so
679 * that xdr_array allocates memory for us
680 */
681 memset(&status, 0, sizeof(status));
682
683 if (pm_mnt->pm_vers == 3)
684 clnt_stat = clnt_call(mclient, MOUNTPROC3_MNT,
685 (xdrproc_t) xdr_dirpath,
686 (caddr_t) &dirname,
687 (xdrproc_t) xdr_mountres3,
688 (caddr_t) &status,
689 total_timeout);
690 else
490 clnt_stat = clnt_call(mclient, MOUNTPROC_MNT, 691 clnt_stat = clnt_call(mclient, MOUNTPROC_MNT,
491 (xdrproc_t) xdr_dirpath, 692 (xdrproc_t) xdr_dirpath,
492 (caddr_t) & dirname, 693 (caddr_t) &dirname,
493 (xdrproc_t) xdr_fhstatus, 694 (xdrproc_t) xdr_fhstatus,
494 (caddr_t) & status, total_timeout); 695 (caddr_t) &status,
696 total_timeout);
697
495 if (clnt_stat == RPC_SUCCESS) 698 if (clnt_stat == RPC_SUCCESS)
496 break; /* we're done */ 699 break; /* we're done */
497 if (errno != ECONNREFUSED) { 700 if (errno != ECONNREFUSED) {
@@ -511,7 +714,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
511 prevt = t; 714 prevt = t;
512 } 715 }
513 if (!bg) 716 if (!bg)
514 goto fail; 717 goto fail;
515 if (!running_bg) { 718 if (!running_bg) {
516 prev_bg_host = xstrdup(hostname); 719 prev_bg_host = xstrdup(hostname);
517 if (retry > 0) 720 if (retry > 0)
@@ -522,21 +725,52 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
522 if (t >= timeout) 725 if (t >= timeout)
523 goto fail; 726 goto fail;
524 } 727 }
728 nfsvers = (pm_mnt->pm_vers < 2) ? 2 : pm_mnt->pm_vers;
525 729
526 if (status.fhs_status != 0) { 730 if (nfsvers == 2) {
527 fprintf(stderr, 731 if (status.nfsv2.fhs_status != 0) {
528 _("mount: %s:%s failed, reason given by server: %s\n"), 732 fprintf(stderr,
529 hostname, dirname, nfs_strerror(status.fhs_status)); 733 "mount: %s:%s failed, reason given by server: %s\n",
530 goto fail; 734 hostname, dirname,
735 nfs_strerror(status.nfsv2.fhs_status));
736 goto fail;
737 }
738 memcpy(data.root.data,
739 (char *) status.nfsv2.fhstatus_u.fhs_fhandle,
740 NFS_FHSIZE);
741#if NFS_MOUNT_VERSION >= 4
742 data.root.size = NFS_FHSIZE;
743 memcpy(data.old_root.data,
744 (char *) status.nfsv2.fhstatus_u.fhs_fhandle,
745 NFS_FHSIZE);
746#endif
747 } else {
748#if NFS_MOUNT_VERSION >= 4
749 fhandle3 *fhandle;
750 if (status.nfsv3.fhs_status != 0) {
751 fprintf(stderr,
752 "mount: %s:%s failed, reason given by server: %s\n",
753 hostname, dirname,
754 nfs_strerror(status.nfsv3.fhs_status));
755 goto fail;
756 }
757 fhandle = &status.nfsv3.mountres3_u.mountinfo.fhandle;
758 memset(data.old_root.data, 0, NFS_FHSIZE);
759 memset(&data.root, 0, sizeof(data.root));
760 data.root.size = fhandle->fhandle3_len;
761 memcpy(data.root.data,
762 (char *) fhandle->fhandle3_val,
763 fhandle->fhandle3_len);
764
765 data.flags |= NFS_MOUNT_VER3;
766#endif
531 } 767 }
532 memcpy((char *) &root_fhandle, (char *) status.fhstatus_u.fhs_fhandle,
533 sizeof(root_fhandle));
534 768
535 /* create nfs socket for kernel */ 769 /* create nfs socket for kernel */
536 770
537 if (tcp) { 771 if (tcp) {
538 if (nfs_mount_version < 3) { 772 if (nfs_mount_version < 3) {
539 printf(_("NFS over TCP is not supported.\n")); 773 printf(_("NFS over TCP is not supported.\n"));
540 goto fail; 774 goto fail;
541 } 775 }
542 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 776 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -553,7 +787,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
553 if (port == 0) { 787 if (port == 0) {
554 server_addr.sin_port = PMAPPORT; 788 server_addr.sin_port = PMAPPORT;
555 port = pmap_getport(&server_addr, nfsprog, nfsvers, 789 port = pmap_getport(&server_addr, nfsprog, nfsvers,
556 tcp ? IPPROTO_TCP : IPPROTO_UDP); 790 tcp ? IPPROTO_TCP : IPPROTO_UDP);
557 if (port == 0) 791 if (port == 0)
558 port = NFS_PORT; 792 port = NFS_PORT;
559#ifdef NFS_MOUNT_DEBUG 793#ifdef NFS_MOUNT_DEBUG
@@ -565,14 +799,14 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
565 printf(_("using port %d for nfs deamon\n"), port); 799 printf(_("using port %d for nfs deamon\n"), port);
566#endif 800#endif
567 server_addr.sin_port = htons(port); 801 server_addr.sin_port = htons(port);
568 /* 802 /*
569 * connect() the socket for kernels 1.3.10 and below only, 803 * connect() the socket for kernels 1.3.10 and below only,
570 * to avoid problems with multihomed hosts. 804 * to avoid problems with multihomed hosts.
571 * --Swen 805 * --Swen
572 */ 806 */
573 if (linux_version_code() <= 66314 807 if (linux_version_code() <= 66314
574 && connect(fsock, (struct sockaddr *) &server_addr, 808 && connect(fsock, (struct sockaddr *) &server_addr,
575 sizeof(server_addr)) < 0) { 809 sizeof (server_addr)) < 0) {
576 perror(_("nfs connect")); 810 perror(_("nfs connect"));
577 goto fail; 811 goto fail;
578 } 812 }
@@ -580,8 +814,6 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
580 /* prepare data structure for kernel */ 814 /* prepare data structure for kernel */
581 815
582 data.fd = fsock; 816 data.fd = fsock;
583 memcpy((char *) &data.root, (char *) &root_fhandle,
584 sizeof(root_fhandle));
585 memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr)); 817 memcpy((char *) &data.addr, (char *) &server_addr, sizeof(data.addr));
586 strncpy(data.hostname, hostname, sizeof(data.hostname)); 818 strncpy(data.hostname, hostname, sizeof(data.hostname));
587 819
@@ -594,7 +826,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
594 826
595 /* abort */ 827 /* abort */
596 828
597 fail: 829fail:
598 if (msock != -1) { 830 if (msock != -1) {
599 if (mclient) { 831 if (mclient) {
600 auth_destroy(mclient->cl_auth); 832 auth_destroy(mclient->cl_auth);
@@ -605,7 +837,7 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
605 if (fsock != -1) 837 if (fsock != -1)
606 close(fsock); 838 close(fsock);
607 return retval; 839 return retval;
608} 840}
609 841
610/* 842/*
611 * We need to translate between nfs status return values and 843 * We need to translate between nfs status return values and
@@ -624,37 +856,33 @@ static struct {
624 enum nfs_stat stat; 856 enum nfs_stat stat;
625 int errnum; 857 int errnum;
626} nfs_errtbl[] = { 858} nfs_errtbl[] = {
627 { 859 { NFS_OK, 0 },
628 NFS_OK, 0}, { 860 { NFSERR_PERM, EPERM },
629 NFSERR_PERM, EPERM}, { 861 { NFSERR_NOENT, ENOENT },
630 NFSERR_NOENT, ENOENT}, { 862 { NFSERR_IO, EIO },
631 NFSERR_IO, EIO}, { 863 { NFSERR_NXIO, ENXIO },
632 NFSERR_NXIO, ENXIO}, { 864 { NFSERR_ACCES, EACCES },
633 NFSERR_ACCES, EACCES}, { 865 { NFSERR_EXIST, EEXIST },
634 NFSERR_EXIST, EEXIST}, { 866 { NFSERR_NODEV, ENODEV },
635 NFSERR_NODEV, ENODEV}, { 867 { NFSERR_NOTDIR, ENOTDIR },
636 NFSERR_NOTDIR, ENOTDIR}, { 868 { NFSERR_ISDIR, EISDIR },
637 NFSERR_ISDIR, EISDIR},
638#ifdef NFSERR_INVAL 869#ifdef NFSERR_INVAL
639 { 870 { NFSERR_INVAL, EINVAL }, /* that Sun forgot */
640 NFSERR_INVAL, EINVAL}, /* that Sun forgot */
641#endif 871#endif
642 { 872 { NFSERR_FBIG, EFBIG },
643 NFSERR_FBIG, EFBIG}, { 873 { NFSERR_NOSPC, ENOSPC },
644 NFSERR_NOSPC, ENOSPC}, { 874 { NFSERR_ROFS, EROFS },
645 NFSERR_ROFS, EROFS}, { 875 { NFSERR_NAMETOOLONG, ENAMETOOLONG },
646 NFSERR_NAMETOOLONG, ENAMETOOLONG}, { 876 { NFSERR_NOTEMPTY, ENOTEMPTY },
647 NFSERR_NOTEMPTY, ENOTEMPTY}, { 877 { NFSERR_DQUOT, EDQUOT },
648 NFSERR_DQUOT, EDQUOT}, { 878 { NFSERR_STALE, ESTALE },
649 NFSERR_STALE, ESTALE},
650#ifdef EWFLUSH 879#ifdef EWFLUSH
651 { 880 { NFSERR_WFLUSH, EWFLUSH },
652 NFSERR_WFLUSH, EWFLUSH},
653#endif 881#endif
654 /* Throw in some NFSv3 values for even more fun (HP returns these) */ 882 /* Throw in some NFSv3 values for even more fun (HP returns these) */
655 { 883 { 71, EREMOTE },
656 71, EREMOTE}, { 884
657 -1, EIO} 885 { -1, EIO }
658}; 886};
659 887
660static char *nfs_strerror(int stat) 888static char *nfs_strerror(int stat)
@@ -670,621 +898,92 @@ static char *nfs_strerror(int stat)
670 return buf; 898 return buf;
671} 899}
672 900
673#if 0 901bool_t
674int my_getport(struct in_addr server, struct timeval *timeo, ...) 902xdr_fhandle (XDR *xdrs, fhandle objp)
675{ 903{
676 struct sockaddr_in sin; 904 //register int32_t *buf;
677 struct pmap pmap;
678 CLIENT *clnt;
679 int sock = RPC_ANYSOCK, port;
680
681 pmap.pm_prog = prog;
682 pmap.pm_vers = vers;
683 pmap.pm_prot = prot;
684 pmap.pm_port = 0;
685 sin.sin_family = AF_INET;
686 sin.sin_addr = server;
687 sin.sin_port = htons(111);
688 clnt = clntudp_create(&sin, 100000, 2, *timeo, &sock);
689 status = clnt_call(clnt, PMAP_GETPORT,
690 &pmap, (xdrproc_t) xdr_pmap,
691 &port, (xdrproc_t) xdr_uint);
692 if (status != SUCCESS) {
693 /* natter */
694 port = 0;
695 }
696 905
697 clnt_destroy(clnt); 906 if (!xdr_opaque (xdrs, objp, FHSIZE))
698 close(sock); 907 return FALSE;
699 return port; 908 return TRUE;
700} 909}
701#endif
702 910
703 911bool_t
704 912xdr_fhstatus (XDR *xdrs, fhstatus *objp)
705
706
707
708
709
710
711
712
713/*
714 * Please do not edit this file.
715 * It was generated using rpcgen.
716 */
717
718#include <rpc/types.h>
719#include <rpc/xdr.h>
720
721/*
722 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
723 * unrestricted use provided that this legend is included on all tape
724 * media and as a part of the software program in whole or part. Users
725 * may copy or modify Sun RPC without charge, but are not authorized
726 * to license or distribute it to anyone else except as part of a product or
727 * program developed by the user or with the express written consent of
728 * Sun Microsystems, Inc.
729 *
730 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
731 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
732 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
733 *
734 * Sun RPC is provided with no support and without any obligation on the
735 * part of Sun Microsystems, Inc. to assist in its use, correction,
736 * modification or enhancement.
737 *
738 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
739 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
740 * OR ANY PART THEREOF.
741 *
742 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
743 * or profits or other special, indirect and consequential damages, even if
744 * Sun has been advised of the possibility of such damages.
745 *
746 * Sun Microsystems, Inc.
747 * 2550 Garcia Avenue
748 * Mountain View, California 94043
749 */
750/*
751 * Copyright (c) 1985, 1990 by Sun Microsystems, Inc.
752 */
753
754/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
755
756bool_t xdr_fhandle(XDR * xdrs, fhandle objp)
757{ 913{
914 //register int32_t *buf;
758 915
759 if (!xdr_opaque(xdrs, objp, FHSIZE)) { 916 if (!xdr_u_int (xdrs, &objp->fhs_status))
760 return (FALSE); 917 return FALSE;
761 }
762 return (TRUE);
763}
764
765bool_t xdr_fhstatus(XDR * xdrs, fhstatus * objp)
766{
767
768 if (!xdr_u_int(xdrs, &objp->fhs_status)) {
769 return (FALSE);
770 }
771 switch (objp->fhs_status) { 918 switch (objp->fhs_status) {
772 case 0: 919 case 0:
773 if (!xdr_fhandle(xdrs, objp->fhstatus_u.fhs_fhandle)) { 920 if (!xdr_fhandle (xdrs, objp->fhstatus_u.fhs_fhandle))
774 return (FALSE); 921 return FALSE;
775 }
776 break; 922 break;
777 default: 923 default:
778 break; 924 break;
779 } 925 }
780 return (TRUE); 926 return TRUE;
781}
782
783bool_t xdr_dirpath(XDR * xdrs, dirpath * objp)
784{
785
786 if (!xdr_string(xdrs, objp, MNTPATHLEN)) {
787 return (FALSE);
788 }
789 return (TRUE);
790}
791
792bool_t xdr_name(XDR * xdrs, name * objp)
793{
794
795 if (!xdr_string(xdrs, objp, MNTNAMLEN)) {
796 return (FALSE);
797 }
798 return (TRUE);
799}
800
801bool_t xdr_mountlist(XDR * xdrs, mountlist * objp)
802{
803
804 if (!xdr_pointer
805 (xdrs, (char **) objp, sizeof(struct mountbody),
806 (xdrproc_t) xdr_mountbody)) {
807 return (FALSE);
808 }
809 return (TRUE);
810}
811
812bool_t xdr_mountbody(XDR * xdrs, mountbody * objp)
813{
814
815 if (!xdr_name(xdrs, &objp->ml_hostname)) {
816 return (FALSE);
817 }
818 if (!xdr_dirpath(xdrs, &objp->ml_directory)) {
819 return (FALSE);
820 }
821 if (!xdr_mountlist(xdrs, &objp->ml_next)) {
822 return (FALSE);
823 }
824 return (TRUE);
825}
826
827bool_t xdr_groups(XDR * xdrs, groups * objp)
828{
829
830 if (!xdr_pointer
831 (xdrs, (char **) objp, sizeof(struct groupnode),
832 (xdrproc_t) xdr_groupnode)) {
833 return (FALSE);
834 }
835 return (TRUE);
836}
837
838bool_t xdr_groupnode(XDR * xdrs, groupnode * objp)
839{
840
841 if (!xdr_name(xdrs, &objp->gr_name)) {
842 return (FALSE);
843 }
844 if (!xdr_groups(xdrs, &objp->gr_next)) {
845 return (FALSE);
846 }
847 return (TRUE);
848}
849
850bool_t xdr_exports(XDR * xdrs, exports * objp)
851{
852
853 if (!xdr_pointer
854 (xdrs, (char **) objp, sizeof(struct exportnode),
855 (xdrproc_t) xdr_exportnode)) {
856 return (FALSE);
857 }
858 return (TRUE);
859} 927}
860 928
861bool_t xdr_exportnode(XDR * xdrs, exportnode * objp) 929bool_t
930xdr_dirpath (XDR *xdrs, dirpath *objp)
862{ 931{
932 //register int32_t *buf;
863 933
864 if (!xdr_dirpath(xdrs, &objp->ex_dir)) { 934 if (!xdr_string (xdrs, objp, MNTPATHLEN))
865 return (FALSE); 935 return FALSE;
866 } 936 return TRUE;
867 if (!xdr_groups(xdrs, &objp->ex_groups)) {
868 return (FALSE);
869 }
870 if (!xdr_exports(xdrs, &objp->ex_next)) {
871 return (FALSE);
872 }
873 return (TRUE);
874} 937}
875 938
876bool_t xdr_ppathcnf(XDR * xdrs, ppathcnf * objp) 939bool_t
940xdr_fhandle3 (XDR *xdrs, fhandle3 *objp)
877{ 941{
942 //register int32_t *buf;
878 943
879 register long *buf; 944 if (!xdr_bytes (xdrs, (char **)&objp->fhandle3_val, (u_int *) &objp->fhandle3_len, FHSIZE3))
880 945 return FALSE;
881 int i; 946 return TRUE;
882
883 if (xdrs->x_op == XDR_ENCODE) {
884 buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
885 if (buf == NULL) {
886 if (!xdr_int(xdrs, &objp->pc_link_max)) {
887 return (FALSE);
888 }
889 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
890 return (FALSE);
891 }
892 if (!xdr_short(xdrs, &objp->pc_max_input)) {
893 return (FALSE);
894 }
895 if (!xdr_short(xdrs, &objp->pc_name_max)) {
896 return (FALSE);
897 }
898 if (!xdr_short(xdrs, &objp->pc_path_max)) {
899 return (FALSE);
900 }
901 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
902 return (FALSE);
903 }
904
905 } else {
906 IXDR_PUT_LONG(buf, objp->pc_link_max);
907 IXDR_PUT_SHORT(buf, objp->pc_max_canon);
908 IXDR_PUT_SHORT(buf, objp->pc_max_input);
909 IXDR_PUT_SHORT(buf, objp->pc_name_max);
910 IXDR_PUT_SHORT(buf, objp->pc_path_max);
911 IXDR_PUT_SHORT(buf, objp->pc_pipe_buf);
912 }
913 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
914 return (FALSE);
915 }
916 if (!xdr_char(xdrs, &objp->pc_xxx)) {
917 return (FALSE);
918 }
919 buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
920 if (buf == NULL) {
921 if (!xdr_vector
922 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
923 (xdrproc_t) xdr_short)) {
924 return (FALSE);
925 }
926
927 } else {
928 {
929 register short *genp;
930
931 for (i = 0, genp = objp->pc_mask; i < 2; i++) {
932 IXDR_PUT_SHORT(buf, *genp++);
933 }
934 };
935 }
936
937 return (TRUE);
938 } else if (xdrs->x_op == XDR_DECODE) {
939 buf = (long *) XDR_INLINE(xdrs, 6 * BYTES_PER_XDR_UNIT);
940 if (buf == NULL) {
941 if (!xdr_int(xdrs, &objp->pc_link_max)) {
942 return (FALSE);
943 }
944 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
945 return (FALSE);
946 }
947 if (!xdr_short(xdrs, &objp->pc_max_input)) {
948 return (FALSE);
949 }
950 if (!xdr_short(xdrs, &objp->pc_name_max)) {
951 return (FALSE);
952 }
953 if (!xdr_short(xdrs, &objp->pc_path_max)) {
954 return (FALSE);
955 }
956 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
957 return (FALSE);
958 }
959
960 } else {
961 objp->pc_link_max = IXDR_GET_LONG(buf);
962 objp->pc_max_canon = IXDR_GET_SHORT(buf);
963 objp->pc_max_input = IXDR_GET_SHORT(buf);
964 objp->pc_name_max = IXDR_GET_SHORT(buf);
965 objp->pc_path_max = IXDR_GET_SHORT(buf);
966 objp->pc_pipe_buf = IXDR_GET_SHORT(buf);
967 }
968 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
969 return (FALSE);
970 }
971 if (!xdr_char(xdrs, &objp->pc_xxx)) {
972 return (FALSE);
973 }
974 buf = (long *) XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
975 if (buf == NULL) {
976 if (!xdr_vector
977 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
978 (xdrproc_t) xdr_short)) {
979 return (FALSE);
980 }
981
982 } else {
983 {
984 register short *genp;
985
986 for (i = 0, genp = objp->pc_mask; i < 2; i++) {
987 *genp++ = IXDR_GET_SHORT(buf);
988 }
989 };
990 }
991 return (TRUE);
992 }
993
994 if (!xdr_int(xdrs, &objp->pc_link_max)) {
995 return (FALSE);
996 }
997 if (!xdr_short(xdrs, &objp->pc_max_canon)) {
998 return (FALSE);
999 }
1000 if (!xdr_short(xdrs, &objp->pc_max_input)) {
1001 return (FALSE);
1002 }
1003 if (!xdr_short(xdrs, &objp->pc_name_max)) {
1004 return (FALSE);
1005 }
1006 if (!xdr_short(xdrs, &objp->pc_path_max)) {
1007 return (FALSE);
1008 }
1009 if (!xdr_short(xdrs, &objp->pc_pipe_buf)) {
1010 return (FALSE);
1011 }
1012 if (!xdr_u_char(xdrs, &objp->pc_vdisable)) {
1013 return (FALSE);
1014 }
1015 if (!xdr_char(xdrs, &objp->pc_xxx)) {
1016 return (FALSE);
1017 }
1018 if (!xdr_vector
1019 (xdrs, (char *) objp->pc_mask, 2, sizeof(short),
1020 (xdrproc_t) xdr_short)) {
1021 return (FALSE);
1022 }
1023 return (TRUE);
1024} 947}
1025 948
1026 949bool_t
1027/* 950xdr_mountres3_ok (XDR *xdrs, mountres3_ok *objp)
1028 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
1029 * unrestricted use provided that this legend is included on all tape
1030 * media and as a part of the software program in whole or part. Users
1031 * may copy or modify Sun RPC without charge, but are not authorized
1032 * to license or distribute it to anyone else except as part of a product or
1033 * program developed by the user or with the express written consent of
1034 * Sun Microsystems, Inc.
1035 *
1036 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
1037 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1038 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
1039 *
1040 * Sun RPC is provided with no support and without any obligation on the
1041 * part of Sun Microsystems, Inc. to assist in its use, correction,
1042 * modification or enhancement.
1043 *
1044 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
1045 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
1046 * OR ANY PART THEREOF.
1047 *
1048 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
1049 * or profits or other special, indirect and consequential damages, even if
1050 * Sun has been advised of the possibility of such damages.
1051 *
1052 * Sun Microsystems, Inc.
1053 * 2550 Garcia Avenue
1054 * Mountain View, California 94043
1055 */
1056/*
1057 * Copyright (c) 1985, 1990 by Sun Microsystems, Inc.
1058 */
1059
1060/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
1061
1062#include <string.h> /* for memset() */
1063
1064/* Default timeout can be changed using clnt_control() */
1065static struct timeval TIMEOUT = { 25, 0 };
1066
1067void *mountproc_null_1(argp, clnt)
1068void *argp;
1069CLIENT *clnt;
1070{
1071 static char clnt_res;
1072
1073 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1074 if (clnt_call
1075 (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp,
1076 (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
1077 return (NULL);
1078 }
1079 return ((void *) &clnt_res);
1080}
1081
1082fhstatus *mountproc_mnt_1(argp, clnt)
1083dirpath *argp;
1084CLIENT *clnt;
1085{
1086 static fhstatus clnt_res;
1087
1088 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1089 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath,
1090 (caddr_t) argp, (xdrproc_t) xdr_fhstatus,
1091 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1092 return (NULL);
1093 }
1094 return (&clnt_res);
1095}
1096
1097mountlist *mountproc_dump_1(argp, clnt)
1098void *argp;
1099CLIENT *clnt;
1100{
1101 static mountlist clnt_res;
1102
1103 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1104 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void,
1105 (caddr_t) argp, (xdrproc_t) xdr_mountlist,
1106 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1107 return (NULL);
1108 }
1109 return (&clnt_res);
1110}
1111
1112void *mountproc_umnt_1(argp, clnt)
1113dirpath *argp;
1114CLIENT *clnt;
1115{
1116 static char clnt_res;
1117
1118 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1119 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath,
1120 (caddr_t) argp, (xdrproc_t) xdr_void,
1121 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1122 return (NULL);
1123 }
1124 return ((void *) &clnt_res);
1125}
1126
1127void *mountproc_umntall_1(argp, clnt)
1128void *argp;
1129CLIENT *clnt;
1130{ 951{
1131 static char clnt_res; 952 //register int32_t *buf;
1132 953
1133 memset((char *) &clnt_res, 0, sizeof(clnt_res)); 954 if (!xdr_fhandle3 (xdrs, &objp->fhandle))
1134 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void, 955 return FALSE;
1135 (caddr_t) argp, (xdrproc_t) xdr_void, 956 if (!xdr_array (xdrs, (char **)&objp->auth_flavours.auth_flavours_val, (u_int *) &objp->auth_flavours.auth_flavours_len, ~0,
1136 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { 957 sizeof (int), (xdrproc_t) xdr_int))
1137 return (NULL); 958 return FALSE;
1138 } 959 return TRUE;
1139 return ((void *) &clnt_res);
1140} 960}
1141 961
1142exports *mountproc_export_1(argp, clnt) 962bool_t
1143void *argp; 963xdr_mountstat3 (XDR *xdrs, mountstat3 *objp)
1144CLIENT *clnt;
1145{ 964{
1146 static exports clnt_res; 965 //register int32_t *buf;
1147
1148 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1149 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void,
1150 (caddr_t) argp, (xdrproc_t) xdr_exports,
1151 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1152 return (NULL);
1153 }
1154 return (&clnt_res);
1155}
1156 966
1157exports *mountproc_exportall_1(argp, clnt) 967 if (!xdr_enum (xdrs, (enum_t *) objp))
1158void *argp; 968 return FALSE;
1159CLIENT *clnt; 969 return TRUE;
1160{
1161 static exports clnt_res;
1162
1163 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1164 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void,
1165 (caddr_t) argp, (xdrproc_t) xdr_exports,
1166 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1167 return (NULL);
1168 }
1169 return (&clnt_res);
1170}
1171
1172void *mountproc_null_2(argp, clnt)
1173void *argp;
1174CLIENT *clnt;
1175{
1176 static char clnt_res;
1177
1178 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1179 if (clnt_call
1180 (clnt, MOUNTPROC_NULL, (xdrproc_t) xdr_void, argp,
1181 (xdrproc_t) xdr_void, &clnt_res, TIMEOUT) != RPC_SUCCESS) {
1182 return (NULL);
1183 }
1184 return ((void *) &clnt_res);
1185} 970}
1186 971
1187fhstatus *mountproc_mnt_2(argp, clnt) 972bool_t
1188dirpath *argp; 973xdr_mountres3 (XDR *xdrs, mountres3 *objp)
1189CLIENT *clnt;
1190{ 974{
1191 static fhstatus clnt_res; 975 //register int32_t *buf;
1192 976
1193 memset((char *) &clnt_res, 0, sizeof(clnt_res)); 977 if (!xdr_mountstat3 (xdrs, &objp->fhs_status))
1194 if (clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t) xdr_dirpath, 978 return FALSE;
1195 (caddr_t) argp, (xdrproc_t) xdr_fhstatus, 979 switch (objp->fhs_status) {
1196 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) { 980 case MNT_OK:
1197 return (NULL); 981 if (!xdr_mountres3_ok (xdrs, &objp->mountres3_u.mountinfo))
1198 } 982 return FALSE;
1199 return (&clnt_res); 983 break;
1200} 984 default:
1201 985 break;
1202mountlist *mountproc_dump_2(argp, clnt)
1203void *argp;
1204CLIENT *clnt;
1205{
1206 static mountlist clnt_res;
1207
1208 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1209 if (clnt_call(clnt, MOUNTPROC_DUMP, (xdrproc_t) xdr_void, argp,
1210 (xdrproc_t) xdr_mountlist, (caddr_t) & clnt_res,
1211 TIMEOUT) != RPC_SUCCESS) {
1212 return (NULL);
1213 }
1214 return (&clnt_res);
1215}
1216
1217void *mountproc_umnt_2(argp, clnt)
1218dirpath *argp;
1219CLIENT *clnt;
1220{
1221 static char clnt_res;
1222
1223 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1224 if (clnt_call(clnt, MOUNTPROC_UMNT, (xdrproc_t) xdr_dirpath,
1225 (caddr_t) argp, (xdrproc_t) xdr_void,
1226 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1227 return (NULL);
1228 }
1229 return ((void *) &clnt_res);
1230}
1231
1232void *mountproc_umntall_2(argp, clnt)
1233void *argp;
1234CLIENT *clnt;
1235{
1236 static char clnt_res;
1237
1238 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1239 if (clnt_call(clnt, MOUNTPROC_UMNTALL, (xdrproc_t) xdr_void,
1240 (caddr_t) argp, (xdrproc_t) xdr_void,
1241 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1242 return (NULL);
1243 }
1244 return ((void *) &clnt_res);
1245}
1246
1247exports *mountproc_export_2(argp, clnt)
1248void *argp;
1249CLIENT *clnt;
1250{
1251 static exports clnt_res;
1252
1253 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1254 if (clnt_call(clnt, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void,
1255 argp, (xdrproc_t) xdr_exports, (caddr_t) & clnt_res,
1256 TIMEOUT) != RPC_SUCCESS) {
1257 return (NULL);
1258 }
1259 return (&clnt_res);
1260}
1261
1262exports *mountproc_exportall_2(argp, clnt)
1263void *argp;
1264CLIENT *clnt;
1265{
1266 static exports clnt_res;
1267
1268 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1269 if (clnt_call(clnt, MOUNTPROC_EXPORTALL, (xdrproc_t) xdr_void, argp,
1270 (xdrproc_t) xdr_exports, (caddr_t) & clnt_res,
1271 TIMEOUT) != RPC_SUCCESS) {
1272 return (NULL);
1273 } 986 }
1274 return (&clnt_res); 987 return TRUE;
1275} 988}
1276 989
1277ppathcnf *mountproc_pathconf_2(argp, clnt)
1278dirpath *argp;
1279CLIENT *clnt;
1280{
1281 static ppathcnf clnt_res;
1282
1283 memset((char *) &clnt_res, 0, sizeof(clnt_res));
1284 if (clnt_call(clnt, MOUNTPROC_PATHCONF, (xdrproc_t) xdr_dirpath,
1285 (caddr_t) argp, (xdrproc_t) xdr_ppathcnf,
1286 (caddr_t) & clnt_res, TIMEOUT) != RPC_SUCCESS) {
1287 return (NULL);
1288 }
1289 return (&clnt_res);
1290}