1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.82 */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <limits.h> 35*0Sstevel@tonic-gate #include <fcntl.h> 36*0Sstevel@tonic-gate #include <unistd.h> 37*0Sstevel@tonic-gate #include <stdlib.h> 38*0Sstevel@tonic-gate #include <string.h> 39*0Sstevel@tonic-gate #include <stdarg.h> 40*0Sstevel@tonic-gate #include <sys/types.h> 41*0Sstevel@tonic-gate #include <sys/stat.h> 42*0Sstevel@tonic-gate #include <sys/statvfs.h> 43*0Sstevel@tonic-gate #include <errno.h> 44*0Sstevel@tonic-gate #include <sys/mnttab.h> 45*0Sstevel@tonic-gate #include <sys/mntent.h> 46*0Sstevel@tonic-gate #include <sys/mount.h> 47*0Sstevel@tonic-gate #include <sys/vfstab.h> 48*0Sstevel@tonic-gate #include <sys/param.h> 49*0Sstevel@tonic-gate #include <sys/wait.h> 50*0Sstevel@tonic-gate #include <sys/signal.h> 51*0Sstevel@tonic-gate #include <sys/resource.h> 52*0Sstevel@tonic-gate #include <stropts.h> 53*0Sstevel@tonic-gate #include <sys/conf.h> 54*0Sstevel@tonic-gate #include <locale.h> 55*0Sstevel@tonic-gate #include "fslib.h" 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gate #define VFS_PATH "/usr/lib/fs" 58*0Sstevel@tonic-gate #define ALT_PATH "/etc/fs" 59*0Sstevel@tonic-gate #define REMOTE "/etc/dfs/fstypes" 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate #define ARGV_MAX 16 62*0Sstevel@tonic-gate #define TIME_MAX 50 63*0Sstevel@tonic-gate #define FSTYPE_MAX 8 64*0Sstevel@tonic-gate #define REMOTE_MAX 64 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate #define OLD 0 67*0Sstevel@tonic-gate #define NEW 1 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate #define READONLY 0 70*0Sstevel@tonic-gate #define READWRITE 1 71*0Sstevel@tonic-gate #define SUID 2 72*0Sstevel@tonic-gate #define NOSUID 3 73*0Sstevel@tonic-gate #define SETUID 4 74*0Sstevel@tonic-gate #define NOSETUID 5 75*0Sstevel@tonic-gate #define DEVICES 6 76*0Sstevel@tonic-gate #define NODEVICES 7 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate #define FORMAT "%a %b %e %H:%M:%S %Y\n" /* date time format */ 79*0Sstevel@tonic-gate /* a - abbreviated weekday name */ 80*0Sstevel@tonic-gate /* b - abbreviated month name */ 81*0Sstevel@tonic-gate /* e - day of month */ 82*0Sstevel@tonic-gate /* H - hour */ 83*0Sstevel@tonic-gate /* M - minute */ 84*0Sstevel@tonic-gate /* S - second */ 85*0Sstevel@tonic-gate /* Y - Year */ 86*0Sstevel@tonic-gate /* n - newline */ 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate extern int optind; 89*0Sstevel@tonic-gate extern char *optarg; 90*0Sstevel@tonic-gate 91*0Sstevel@tonic-gate extern void usage(void); 92*0Sstevel@tonic-gate extern char *flags(char *, int); 93*0Sstevel@tonic-gate extern char *remote(char *, FILE *); 94*0Sstevel@tonic-gate extern char *default_fstype(char *); 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate char *myopts[] = { 97*0Sstevel@tonic-gate MNTOPT_RO, 98*0Sstevel@tonic-gate MNTOPT_RW, 99*0Sstevel@tonic-gate MNTOPT_SUID, 100*0Sstevel@tonic-gate MNTOPT_NOSUID, 101*0Sstevel@tonic-gate MNTOPT_SETUID, 102*0Sstevel@tonic-gate MNTOPT_NOSETUID, 103*0Sstevel@tonic-gate MNTOPT_DEVICES, 104*0Sstevel@tonic-gate MNTOPT_NODEVICES, 105*0Sstevel@tonic-gate NULL 106*0Sstevel@tonic-gate }; 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate static char *myname; /* point to argv[0] */ 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate /* 111*0Sstevel@tonic-gate * Set the limit to double the number of characters a user should be allowed to 112*0Sstevel@tonic-gate * type in one line. 113*0Sstevel@tonic-gate * This should cover the different shells, which don't use POSIX_MAX_INPUT, 114*0Sstevel@tonic-gate * and should cover the case where a long option string can be in 115*0Sstevel@tonic-gate * the /etc/vfstab file. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate char mntflags[(_POSIX_MAX_INPUT+1) * 2]; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate char realdir[MAXPATHLEN]; /* buffer for realpath() calls */ 120*0Sstevel@tonic-gate char *vfstab = VFSTAB; 121*0Sstevel@tonic-gate char *mnttab = MNTTAB; 122*0Sstevel@tonic-gate char *specific_opts; /* holds specific mount options */ 123*0Sstevel@tonic-gate char *generic_opts; /* holds generic mount options */ 124*0Sstevel@tonic-gate int maxrun; 125*0Sstevel@tonic-gate int nrun; 126*0Sstevel@tonic-gate int lofscnt; /* presence of lofs prohibits parallel */ 127*0Sstevel@tonic-gate /* mounting */ 128*0Sstevel@tonic-gate int exitcode; 129*0Sstevel@tonic-gate int aflg, cflg, fflg, Fflg, gflg, oflg, pflg, rflg, vflg, Vflg, mflg, Oflg, 130*0Sstevel@tonic-gate dashflg, questflg, dflg, qflg; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate /* 133*0Sstevel@tonic-gate * Currently, mounting cachefs instances simultaneously uncovers various 134*0Sstevel@tonic-gate * problems. For the short term, we serialize cachefs activity while we fix 135*0Sstevel@tonic-gate * these cachefs bugs. 136*0Sstevel@tonic-gate */ 137*0Sstevel@tonic-gate #define CACHEFS_BUG 138*0Sstevel@tonic-gate #ifdef CACHEFS_BUG 139*0Sstevel@tonic-gate int cachefs_running; /* parallel cachefs not supported yet */ 140*0Sstevel@tonic-gate #endif 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate /* 143*0Sstevel@tonic-gate * Each vfsent_t describes a vfstab entry. It is used to manage and cleanup 144*0Sstevel@tonic-gate * each child that performs the particular mount for the entry. 145*0Sstevel@tonic-gate */ 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate typedef struct vfsent { 148*0Sstevel@tonic-gate struct vfstab v; /* the vfstab entry */ 149*0Sstevel@tonic-gate char *rpath; /* resolved pathname so far */ 150*0Sstevel@tonic-gate int mlevel; /* how deep is this mount point */ 151*0Sstevel@tonic-gate int order; /* vfstab serial order of this vfs */ 152*0Sstevel@tonic-gate int flag; 153*0Sstevel@tonic-gate pid_t pid; /* the pid of this mount process */ 154*0Sstevel@tonic-gate int exitcode; /* process's exitcode */ 155*0Sstevel@tonic-gate #define RDPIPE 0 156*0Sstevel@tonic-gate #define WRPIPE 1 157*0Sstevel@tonic-gate int sopipe[2]; /* pipe attached to child's stdout */ 158*0Sstevel@tonic-gate int sepipe[2]; /* pipe attached to child's stderr */ 159*0Sstevel@tonic-gate struct vfsent *next; /* used when in linked list */ 160*0Sstevel@tonic-gate } vfsent_t; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate #define VRPFAILED 0x01 /* most recent realpath failed on */ 163*0Sstevel@tonic-gate /* this mount point */ 164*0Sstevel@tonic-gate #define VNOTMOUNTED 0x02 /* mount point could not be mounted */ 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate vfsent_t *vfsll, *vfslltail; /* head and tail of the global */ 167*0Sstevel@tonic-gate /* linked list of vfstab entries */ 168*0Sstevel@tonic-gate vfsent_t **vfsarray; /* global array of vfsent_t's */ 169*0Sstevel@tonic-gate int vfsarraysize; /* length of the list */ 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* 172*0Sstevel@tonic-gate * This structure is used to build a linked list of 173*0Sstevel@tonic-gate * mnttab structures from /etc/mnttab. 174*0Sstevel@tonic-gate */ 175*0Sstevel@tonic-gate typedef struct mountent { 176*0Sstevel@tonic-gate struct extmnttab *ment; 177*0Sstevel@tonic-gate int flag; 178*0Sstevel@tonic-gate struct mountent *next; 179*0Sstevel@tonic-gate } mountent_t; 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate #define MSORTED 0x1 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate static vfsent_t **make_vfsarray(char **, int); 184*0Sstevel@tonic-gate static vfsent_t *new_vfsent(struct vfstab *, int); 185*0Sstevel@tonic-gate static vfsent_t *getvfsall(char *, int); 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate static void doexec(char *, char **); 188*0Sstevel@tonic-gate static void nomem(); 189*0Sstevel@tonic-gate static void cleanup(int); 190*0Sstevel@tonic-gate static char *setrpath(vfsent_t *); 191*0Sstevel@tonic-gate static int dowait(); 192*0Sstevel@tonic-gate static int setup_iopipe(vfsent_t *); 193*0Sstevel@tonic-gate static void setup_output(vfsent_t *); 194*0Sstevel@tonic-gate static void doio(vfsent_t *); 195*0Sstevel@tonic-gate static void do_mounts(); 196*0Sstevel@tonic-gate static int parmount(char **, int, char *); 197*0Sstevel@tonic-gate static int mlevelcmp(const void *, const void *); 198*0Sstevel@tonic-gate static int mordercmp(const void *, const void *); 199*0Sstevel@tonic-gate static int check_fields(char *, char *); 200*0Sstevel@tonic-gate static int cleanupkid(pid_t, int); 201*0Sstevel@tonic-gate static void print_mnttab(int, int); 202*0Sstevel@tonic-gate static void vfserror(int, char *); 203*0Sstevel@tonic-gate static void mnterror(int); 204*0Sstevel@tonic-gate static int ignore(char *); 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate /* 207*0Sstevel@tonic-gate * This is /usr/sbin/mount: the generic command that in turn 208*0Sstevel@tonic-gate * execs the appropriate /usr/lib/fs/{fstype}/mount. 209*0Sstevel@tonic-gate * The -F flag and argument are NOT passed. 210*0Sstevel@tonic-gate * If the usr file system is not mounted a duplicate copy 211*0Sstevel@tonic-gate * can be found in /sbin and this version execs the 212*0Sstevel@tonic-gate * appropriate /etc/fs/{fstype}/mount 213*0Sstevel@tonic-gate * 214*0Sstevel@tonic-gate * If the -F fstype, special or directory are missing, 215*0Sstevel@tonic-gate * /etc/vfstab is searched to fill in the missing arguments. 216*0Sstevel@tonic-gate * 217*0Sstevel@tonic-gate * -V will print the built command on the stdout. 218*0Sstevel@tonic-gate * It isn't passed either. 219*0Sstevel@tonic-gate */ 220*0Sstevel@tonic-gate void 221*0Sstevel@tonic-gate main(argc, argv) 222*0Sstevel@tonic-gate int argc; 223*0Sstevel@tonic-gate char *argv[]; 224*0Sstevel@tonic-gate { 225*0Sstevel@tonic-gate char *special, /* argument of special/resource */ 226*0Sstevel@tonic-gate *mountp, /* argument of mount directory */ 227*0Sstevel@tonic-gate *fstype, /* wherein the fstype name is filled */ 228*0Sstevel@tonic-gate *newargv[ARGV_MAX], /* arg list for specific command */ 229*0Sstevel@tonic-gate *farg = NULL, *Farg = NULL; 230*0Sstevel@tonic-gate int ii, ret, cc, fscnt; 231*0Sstevel@tonic-gate struct stat64 stbuf; 232*0Sstevel@tonic-gate struct vfstab vget, vref; 233*0Sstevel@tonic-gate mode_t mode; 234*0Sstevel@tonic-gate FILE *fd; 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 237*0Sstevel@tonic-gate 238*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 239*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 240*0Sstevel@tonic-gate #endif 241*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate myname = strrchr(argv[0], '/'); 244*0Sstevel@tonic-gate if (myname) 245*0Sstevel@tonic-gate myname++; 246*0Sstevel@tonic-gate else 247*0Sstevel@tonic-gate myname = argv[0]; 248*0Sstevel@tonic-gate if (myname == 0) myname = "path unknown"; 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate /* Process the args. */ 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate while ((cc = getopt(argc, argv, "?acd:f:F:gmno:pqrvVO")) != -1) 253*0Sstevel@tonic-gate switch (cc) { 254*0Sstevel@tonic-gate case 'a': 255*0Sstevel@tonic-gate aflg++; 256*0Sstevel@tonic-gate break; 257*0Sstevel@tonic-gate case 'c': 258*0Sstevel@tonic-gate cflg++; 259*0Sstevel@tonic-gate break; 260*0Sstevel@tonic-gate 261*0Sstevel@tonic-gate #ifdef DEBUG 262*0Sstevel@tonic-gate case 'd': 263*0Sstevel@tonic-gate dflg = atoi(optarg); 264*0Sstevel@tonic-gate break; 265*0Sstevel@tonic-gate #endif 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate case 'f': 268*0Sstevel@tonic-gate fflg++; 269*0Sstevel@tonic-gate farg = optarg; 270*0Sstevel@tonic-gate break; 271*0Sstevel@tonic-gate case 'F': 272*0Sstevel@tonic-gate Fflg++; 273*0Sstevel@tonic-gate Farg = optarg; 274*0Sstevel@tonic-gate break; 275*0Sstevel@tonic-gate case 'g': 276*0Sstevel@tonic-gate gflg++; 277*0Sstevel@tonic-gate break; 278*0Sstevel@tonic-gate case 'm': 279*0Sstevel@tonic-gate mflg++; 280*0Sstevel@tonic-gate break; /* do not update /etc/mnttab */ 281*0Sstevel@tonic-gate case 'o': 282*0Sstevel@tonic-gate oflg++; 283*0Sstevel@tonic-gate if ((specific_opts = strdup(optarg)) == NULL) 284*0Sstevel@tonic-gate nomem(); 285*0Sstevel@tonic-gate break; /* fstype dependent options */ 286*0Sstevel@tonic-gate case 'O': 287*0Sstevel@tonic-gate Oflg++; 288*0Sstevel@tonic-gate break; 289*0Sstevel@tonic-gate case 'p': 290*0Sstevel@tonic-gate pflg++; 291*0Sstevel@tonic-gate break; 292*0Sstevel@tonic-gate case 'q': 293*0Sstevel@tonic-gate qflg++; 294*0Sstevel@tonic-gate break; 295*0Sstevel@tonic-gate case 'r': 296*0Sstevel@tonic-gate rflg++; 297*0Sstevel@tonic-gate generic_opts = "ro"; 298*0Sstevel@tonic-gate break; 299*0Sstevel@tonic-gate case 'v': 300*0Sstevel@tonic-gate vflg++; 301*0Sstevel@tonic-gate break; 302*0Sstevel@tonic-gate case 'V': 303*0Sstevel@tonic-gate Vflg++; 304*0Sstevel@tonic-gate break; 305*0Sstevel@tonic-gate case '?': 306*0Sstevel@tonic-gate questflg++; 307*0Sstevel@tonic-gate break; 308*0Sstevel@tonic-gate } 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate /* copy '--' to specific */ 311*0Sstevel@tonic-gate if (strcmp(argv[optind-1], "--") == 0) 312*0Sstevel@tonic-gate dashflg++; 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate /* option checking */ 315*0Sstevel@tonic-gate /* more than two args not allowed if !aflg */ 316*0Sstevel@tonic-gate if (!aflg && (argc - optind > 2)) 317*0Sstevel@tonic-gate usage(); 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate /* pv mututally exclusive */ 320*0Sstevel@tonic-gate if (pflg + vflg + aflg > 1) { 321*0Sstevel@tonic-gate fprintf(stderr, gettext 322*0Sstevel@tonic-gate ("%s: -a, -p, and -v are mutually exclusive\n"), 323*0Sstevel@tonic-gate myname); 324*0Sstevel@tonic-gate usage(); 325*0Sstevel@tonic-gate } 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate /* 328*0Sstevel@tonic-gate * Can't have overlaying mounts on the same mount point during 329*0Sstevel@tonic-gate * a parallel mount. 330*0Sstevel@tonic-gate */ 331*0Sstevel@tonic-gate if (aflg && Oflg) { 332*0Sstevel@tonic-gate fprintf(stderr, gettext 333*0Sstevel@tonic-gate ("%s: -a and -O are mutually exclusive\n"), myname); 334*0Sstevel@tonic-gate usage(); 335*0Sstevel@tonic-gate } 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gate /* dfF mutually exclusive */ 338*0Sstevel@tonic-gate if (fflg + Fflg > 1) { 339*0Sstevel@tonic-gate fprintf(stderr, gettext 340*0Sstevel@tonic-gate ("%s: More than one FSType specified\n"), myname); 341*0Sstevel@tonic-gate usage(); 342*0Sstevel@tonic-gate } 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate /* no arguments, only allow p,v,V or [F]? */ 345*0Sstevel@tonic-gate if (!aflg && optind == argc) { 346*0Sstevel@tonic-gate if (cflg || fflg || mflg || oflg || rflg || qflg) 347*0Sstevel@tonic-gate usage(); 348*0Sstevel@tonic-gate 349*0Sstevel@tonic-gate if (Fflg && !questflg) 350*0Sstevel@tonic-gate usage(); 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate if (questflg) { 353*0Sstevel@tonic-gate if (Fflg) { 354*0Sstevel@tonic-gate newargv[2] = "-?"; 355*0Sstevel@tonic-gate newargv[3] = NULL; 356*0Sstevel@tonic-gate doexec(Farg, newargv); 357*0Sstevel@tonic-gate } 358*0Sstevel@tonic-gate usage(); 359*0Sstevel@tonic-gate } 360*0Sstevel@tonic-gate } 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate if (questflg) 363*0Sstevel@tonic-gate usage(); 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate /* one or two args, allow any but p,v */ 366*0Sstevel@tonic-gate if (optind != argc && (pflg || vflg)) { 367*0Sstevel@tonic-gate fprintf(stderr, 368*0Sstevel@tonic-gate gettext("%s: Cannot use -p and -v with arguments\n"), myname); 369*0Sstevel@tonic-gate usage(); 370*0Sstevel@tonic-gate } 371*0Sstevel@tonic-gate 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate /* if only reporting mnttab, generic prints mnttab and exits */ 374*0Sstevel@tonic-gate if (!aflg && optind == argc) { 375*0Sstevel@tonic-gate if (Vflg) { 376*0Sstevel@tonic-gate printf("%s", myname); 377*0Sstevel@tonic-gate if (pflg) 378*0Sstevel@tonic-gate printf(" -p"); 379*0Sstevel@tonic-gate if (vflg) 380*0Sstevel@tonic-gate printf(" -v"); 381*0Sstevel@tonic-gate printf("\n"); 382*0Sstevel@tonic-gate exit(0); 383*0Sstevel@tonic-gate } 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate print_mnttab(vflg, pflg); 386*0Sstevel@tonic-gate exit(0); 387*0Sstevel@tonic-gate } 388*0Sstevel@tonic-gate 389*0Sstevel@tonic-gate /* 390*0Sstevel@tonic-gate * Get filesystem type here. If "-F FStype" is specified, use 391*0Sstevel@tonic-gate * that fs type. Otherwise, determine the fs type from /etc/vfstab 392*0Sstevel@tonic-gate * if the entry exists. Otherwise, determine the local or remote 393*0Sstevel@tonic-gate * fs type from /etc/default/df or /etc/dfs/fstypes respectively. 394*0Sstevel@tonic-gate */ 395*0Sstevel@tonic-gate if (fflg) { 396*0Sstevel@tonic-gate if ((strcmp(farg, "S51K") != 0) && 397*0Sstevel@tonic-gate (strcmp(farg, "S52K") != 0)) { 398*0Sstevel@tonic-gate fstype = farg; 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate else 401*0Sstevel@tonic-gate fstype = "ufs"; 402*0Sstevel@tonic-gate } else /* if (Fflg) */ 403*0Sstevel@tonic-gate fstype = Farg; 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate fscnt = argc - optind; 406*0Sstevel@tonic-gate if (aflg && (fscnt != 1)) 407*0Sstevel@tonic-gate exit(parmount(argv + optind, fscnt, fstype)); 408*0Sstevel@tonic-gate 409*0Sstevel@tonic-gate /* 410*0Sstevel@tonic-gate * Then don't bother with the parallel over head. Everything 411*0Sstevel@tonic-gate * from this point is simple/normal single execution. 412*0Sstevel@tonic-gate */ 413*0Sstevel@tonic-gate aflg = 0; 414*0Sstevel@tonic-gate 415*0Sstevel@tonic-gate /* get special and/or mount-point from arg(s) */ 416*0Sstevel@tonic-gate if (fscnt == 2) 417*0Sstevel@tonic-gate special = argv[optind++]; 418*0Sstevel@tonic-gate else 419*0Sstevel@tonic-gate special = NULL; 420*0Sstevel@tonic-gate if (optind < argc) 421*0Sstevel@tonic-gate mountp = argv[optind++]; 422*0Sstevel@tonic-gate else 423*0Sstevel@tonic-gate mountp = NULL; 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate /* lookup only if we need to */ 426*0Sstevel@tonic-gate if (fstype == NULL || specific_opts == NULL || special == NULL || 427*0Sstevel@tonic-gate mountp == NULL) { 428*0Sstevel@tonic-gate if ((fd = fopen(vfstab, "r")) == NULL) { 429*0Sstevel@tonic-gate if (fstype == NULL || special == NULL || 430*0Sstevel@tonic-gate mountp == NULL) { 431*0Sstevel@tonic-gate fprintf(stderr, gettext( 432*0Sstevel@tonic-gate "%s: Cannot open %s\n"), 433*0Sstevel@tonic-gate myname, vfstab); 434*0Sstevel@tonic-gate exit(1); 435*0Sstevel@tonic-gate } else { 436*0Sstevel@tonic-gate /* 437*0Sstevel@tonic-gate * No vfstab, but we know what we want 438*0Sstevel@tonic-gate * to mount. 439*0Sstevel@tonic-gate */ 440*0Sstevel@tonic-gate goto out; 441*0Sstevel@tonic-gate } 442*0Sstevel@tonic-gate } 443*0Sstevel@tonic-gate vfsnull(&vref); 444*0Sstevel@tonic-gate vref.vfs_special = special; 445*0Sstevel@tonic-gate vref.vfs_mountp = mountp; 446*0Sstevel@tonic-gate vref.vfs_fstype = fstype; 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate /* get a vfstab entry matching mountp or special */ 449*0Sstevel@tonic-gate while ((ret = getvfsany(fd, &vget, &vref)) > 0) 450*0Sstevel@tonic-gate vfserror(ret, vget.vfs_special); 451*0Sstevel@tonic-gate 452*0Sstevel@tonic-gate /* if no entry and there was only one argument */ 453*0Sstevel@tonic-gate /* then the argument could be the special */ 454*0Sstevel@tonic-gate /* and not mount point as we thought earlier */ 455*0Sstevel@tonic-gate if (ret == -1 && special == NULL) { 456*0Sstevel@tonic-gate rewind(fd); 457*0Sstevel@tonic-gate special = vref.vfs_special = mountp; 458*0Sstevel@tonic-gate mountp = vref.vfs_mountp = NULL; 459*0Sstevel@tonic-gate /* skip erroneous lines; they were reported above */ 460*0Sstevel@tonic-gate while ((ret = getvfsany(fd, &vget, &vref)) > 0); 461*0Sstevel@tonic-gate } 462*0Sstevel@tonic-gate 463*0Sstevel@tonic-gate fclose(fd); 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate if (ret == 0) { 466*0Sstevel@tonic-gate if (fstype == NULL) 467*0Sstevel@tonic-gate fstype = vget.vfs_fstype; 468*0Sstevel@tonic-gate if (special == NULL) 469*0Sstevel@tonic-gate special = vget.vfs_special; 470*0Sstevel@tonic-gate if (mountp == NULL) 471*0Sstevel@tonic-gate mountp = vget.vfs_mountp; 472*0Sstevel@tonic-gate if (oflg == 0 && vget.vfs_mntopts) { 473*0Sstevel@tonic-gate oflg++; 474*0Sstevel@tonic-gate specific_opts = vget.vfs_mntopts; 475*0Sstevel@tonic-gate } 476*0Sstevel@tonic-gate } else if (special == NULL) { 477*0Sstevel@tonic-gate if (stat64(mountp, &stbuf) == -1) { 478*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: cannot stat %s\n"), 479*0Sstevel@tonic-gate myname, mountp); 480*0Sstevel@tonic-gate exit(2); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate if (((mode = (stbuf.st_mode & S_IFMT)) == S_IFBLK) || 483*0Sstevel@tonic-gate (mode == S_IFCHR)) { 484*0Sstevel@tonic-gate fprintf(stderr, 485*0Sstevel@tonic-gate gettext("%s: mount point cannot be determined\n"), 486*0Sstevel@tonic-gate myname); 487*0Sstevel@tonic-gate exit(1); 488*0Sstevel@tonic-gate } else 489*0Sstevel@tonic-gate { 490*0Sstevel@tonic-gate fprintf(stderr, 491*0Sstevel@tonic-gate gettext("%s: special cannot be determined\n"), 492*0Sstevel@tonic-gate myname); 493*0Sstevel@tonic-gate exit(1); 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate } else if (fstype == NULL) 496*0Sstevel@tonic-gate fstype = default_fstype(special); 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate out: 500*0Sstevel@tonic-gate if (check_fields(fstype, mountp)) 501*0Sstevel@tonic-gate exit(1); 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gate if (realpath(mountp, realdir) == NULL) { 504*0Sstevel@tonic-gate (void) fprintf(stderr, "mount: "); 505*0Sstevel@tonic-gate perror(mountp); 506*0Sstevel@tonic-gate exit(1); 507*0Sstevel@tonic-gate } 508*0Sstevel@tonic-gate 509*0Sstevel@tonic-gate if ((mountp = strdup(realdir)) == NULL) 510*0Sstevel@tonic-gate nomem(); 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gate /* create the new arg list, and end the list with a null pointer */ 513*0Sstevel@tonic-gate ii = 2; 514*0Sstevel@tonic-gate if (cflg) 515*0Sstevel@tonic-gate newargv[ii++] = "-c"; 516*0Sstevel@tonic-gate if (gflg) 517*0Sstevel@tonic-gate newargv[ii++] = "-g"; 518*0Sstevel@tonic-gate if (mflg) 519*0Sstevel@tonic-gate newargv[ii++] = "-m"; 520*0Sstevel@tonic-gate /* 521*0Sstevel@tonic-gate * The q option needs to go before the -o option as some 522*0Sstevel@tonic-gate * filesystems complain during first pass option parsing. 523*0Sstevel@tonic-gate */ 524*0Sstevel@tonic-gate if (qflg) 525*0Sstevel@tonic-gate newargv[ii++] = "-q"; 526*0Sstevel@tonic-gate if (oflg) { 527*0Sstevel@tonic-gate newargv[ii++] = "-o"; 528*0Sstevel@tonic-gate newargv[ii++] = specific_opts; 529*0Sstevel@tonic-gate } 530*0Sstevel@tonic-gate if (Oflg) 531*0Sstevel@tonic-gate newargv[ii++] = "-O"; 532*0Sstevel@tonic-gate if (rflg) 533*0Sstevel@tonic-gate newargv[ii++] = "-r"; 534*0Sstevel@tonic-gate if (dashflg) 535*0Sstevel@tonic-gate newargv[ii++] = "--"; 536*0Sstevel@tonic-gate newargv[ii++] = special; 537*0Sstevel@tonic-gate newargv[ii++] = mountp; 538*0Sstevel@tonic-gate newargv[ii] = NULL; 539*0Sstevel@tonic-gate 540*0Sstevel@tonic-gate doexec(fstype, newargv); 541*0Sstevel@tonic-gate exit(0); 542*0Sstevel@tonic-gate } 543*0Sstevel@tonic-gate 544*0Sstevel@tonic-gate void 545*0Sstevel@tonic-gate usage() 546*0Sstevel@tonic-gate { 547*0Sstevel@tonic-gate fprintf(stderr, gettext("Usage:\n%s [-v | -p]\n"), myname); 548*0Sstevel@tonic-gate fprintf(stderr, gettext( 549*0Sstevel@tonic-gate "%s [-F FSType] [-V] [current_options] [-o specific_options]"), 550*0Sstevel@tonic-gate myname); 551*0Sstevel@tonic-gate fprintf(stderr, gettext("\n\t{special | mount_point}\n")); 552*0Sstevel@tonic-gate 553*0Sstevel@tonic-gate fprintf(stderr, gettext( 554*0Sstevel@tonic-gate "%s [-F FSType] [-V] [current_options] [-o specific_options]"), 555*0Sstevel@tonic-gate myname); 556*0Sstevel@tonic-gate fprintf(stderr, gettext("\n\tspecial mount_point\n")); 557*0Sstevel@tonic-gate 558*0Sstevel@tonic-gate fprintf(stderr, gettext( 559*0Sstevel@tonic-gate "%s -a [-F FSType ] [-V] [current_options] [-o specific_options]\n"), 560*0Sstevel@tonic-gate myname); 561*0Sstevel@tonic-gate fprintf(stderr, gettext("\t[mount_point ...]\n")); 562*0Sstevel@tonic-gate 563*0Sstevel@tonic-gate exit(1); 564*0Sstevel@tonic-gate } 565*0Sstevel@tonic-gate 566*0Sstevel@tonic-gate /* 567*0Sstevel@tonic-gate * Get rid of "dev=[hex string]" clause, if any. It's not legal 568*0Sstevel@tonic-gate * when printing in vfstab format. 569*0Sstevel@tonic-gate */ 570*0Sstevel@tonic-gate void 571*0Sstevel@tonic-gate elide_dev(char *mntopts) 572*0Sstevel@tonic-gate { 573*0Sstevel@tonic-gate char *dev, *other; 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate if (mntopts != NULL) { 576*0Sstevel@tonic-gate dev = strstr(mntopts, "dev="); 577*0Sstevel@tonic-gate if (dev != NULL) { 578*0Sstevel@tonic-gate other = strpbrk(dev, ","); 579*0Sstevel@tonic-gate if (other == NULL) { 580*0Sstevel@tonic-gate /* last option */ 581*0Sstevel@tonic-gate if (dev != mntopts) { 582*0Sstevel@tonic-gate *--dev = '\0'; 583*0Sstevel@tonic-gate } else { 584*0Sstevel@tonic-gate *dev = '\0'; 585*0Sstevel@tonic-gate } 586*0Sstevel@tonic-gate } else { 587*0Sstevel@tonic-gate /* first or intermediate option */ 588*0Sstevel@tonic-gate memmove(dev, other+1, strlen(other+1)+1); 589*0Sstevel@tonic-gate } 590*0Sstevel@tonic-gate } 591*0Sstevel@tonic-gate } 592*0Sstevel@tonic-gate } 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate void 595*0Sstevel@tonic-gate print_mnttab(vflg, pflg) 596*0Sstevel@tonic-gate int vflg, pflg; 597*0Sstevel@tonic-gate { 598*0Sstevel@tonic-gate FILE *fd; 599*0Sstevel@tonic-gate FILE *rfp; /* this will be NULL if fopen fails */ 600*0Sstevel@tonic-gate int ret; 601*0Sstevel@tonic-gate char time_buf[TIME_MAX]; /* array to hold date and time */ 602*0Sstevel@tonic-gate struct extmnttab mget; 603*0Sstevel@tonic-gate time_t ltime; 604*0Sstevel@tonic-gate 605*0Sstevel@tonic-gate if ((fd = fopen(mnttab, "r")) == NULL) { 606*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: Cannot open mnttab\n"), myname); 607*0Sstevel@tonic-gate exit(1); 608*0Sstevel@tonic-gate } 609*0Sstevel@tonic-gate rfp = fopen(REMOTE, "r"); 610*0Sstevel@tonic-gate while ((ret = getextmntent(fd, &mget, sizeof (struct extmnttab))) 611*0Sstevel@tonic-gate == 0) { 612*0Sstevel@tonic-gate if (ignore(mget.mnt_mntopts)) 613*0Sstevel@tonic-gate continue; 614*0Sstevel@tonic-gate if (mget.mnt_special && mget.mnt_mountp && 615*0Sstevel@tonic-gate mget.mnt_fstype && mget.mnt_time) { 616*0Sstevel@tonic-gate ltime = atol(mget.mnt_time); 617*0Sstevel@tonic-gate cftime(time_buf, FORMAT, <ime); 618*0Sstevel@tonic-gate if (pflg) { 619*0Sstevel@tonic-gate elide_dev(mget.mnt_mntopts); 620*0Sstevel@tonic-gate printf("%s - %s %s - no %s\n", 621*0Sstevel@tonic-gate mget.mnt_special, 622*0Sstevel@tonic-gate mget.mnt_mountp, 623*0Sstevel@tonic-gate mget.mnt_fstype, 624*0Sstevel@tonic-gate mget.mnt_mntopts != NULL ? 625*0Sstevel@tonic-gate mget.mnt_mntopts : "-"); 626*0Sstevel@tonic-gate } else if (vflg) { 627*0Sstevel@tonic-gate printf("%s on %s type %s %s%s on %s", 628*0Sstevel@tonic-gate mget.mnt_special, 629*0Sstevel@tonic-gate mget.mnt_mountp, 630*0Sstevel@tonic-gate mget.mnt_fstype, 631*0Sstevel@tonic-gate remote(mget.mnt_fstype, rfp), 632*0Sstevel@tonic-gate flags(mget.mnt_mntopts, NEW), 633*0Sstevel@tonic-gate time_buf); 634*0Sstevel@tonic-gate } else 635*0Sstevel@tonic-gate printf("%s on %s %s%s on %s", 636*0Sstevel@tonic-gate mget.mnt_mountp, 637*0Sstevel@tonic-gate mget.mnt_special, 638*0Sstevel@tonic-gate remote(mget.mnt_fstype, rfp), 639*0Sstevel@tonic-gate flags(mget.mnt_mntopts, OLD), 640*0Sstevel@tonic-gate time_buf); 641*0Sstevel@tonic-gate } 642*0Sstevel@tonic-gate } 643*0Sstevel@tonic-gate if (ret > 0) 644*0Sstevel@tonic-gate mnterror(ret); 645*0Sstevel@tonic-gate } 646*0Sstevel@tonic-gate 647*0Sstevel@tonic-gate char * 648*0Sstevel@tonic-gate flags(mntopts, flag) 649*0Sstevel@tonic-gate char *mntopts; 650*0Sstevel@tonic-gate int flag; 651*0Sstevel@tonic-gate { 652*0Sstevel@tonic-gate char opts[sizeof (mntflags)]; 653*0Sstevel@tonic-gate char *value; 654*0Sstevel@tonic-gate int rdwr = 1; 655*0Sstevel@tonic-gate int suid = 1; 656*0Sstevel@tonic-gate int devices = 1; 657*0Sstevel@tonic-gate int setuid = 1; 658*0Sstevel@tonic-gate 659*0Sstevel@tonic-gate if (mntopts == NULL || *mntopts == '\0') 660*0Sstevel@tonic-gate return ("read/write/setuid/devices"); 661*0Sstevel@tonic-gate 662*0Sstevel@tonic-gate strcpy(opts, ""); 663*0Sstevel@tonic-gate while (*mntopts != '\0') { 664*0Sstevel@tonic-gate switch (getsubopt(&mntopts, myopts, &value)) { 665*0Sstevel@tonic-gate case READONLY: 666*0Sstevel@tonic-gate rdwr = 0; 667*0Sstevel@tonic-gate break; 668*0Sstevel@tonic-gate case READWRITE: 669*0Sstevel@tonic-gate rdwr = 1; 670*0Sstevel@tonic-gate break; 671*0Sstevel@tonic-gate case SUID: 672*0Sstevel@tonic-gate suid = 1; 673*0Sstevel@tonic-gate break; 674*0Sstevel@tonic-gate case NOSUID: 675*0Sstevel@tonic-gate suid = 0; 676*0Sstevel@tonic-gate break; 677*0Sstevel@tonic-gate case SETUID: 678*0Sstevel@tonic-gate setuid = 1; 679*0Sstevel@tonic-gate break; 680*0Sstevel@tonic-gate case NOSETUID: 681*0Sstevel@tonic-gate setuid = 0; 682*0Sstevel@tonic-gate break; 683*0Sstevel@tonic-gate case DEVICES: 684*0Sstevel@tonic-gate devices = 1; 685*0Sstevel@tonic-gate break; 686*0Sstevel@tonic-gate case NODEVICES: 687*0Sstevel@tonic-gate devices = 0; 688*0Sstevel@tonic-gate break; 689*0Sstevel@tonic-gate default: 690*0Sstevel@tonic-gate /* cat '/' separator to mntflags */ 691*0Sstevel@tonic-gate if (*opts != '\0' && value != NULL) 692*0Sstevel@tonic-gate strcat(opts, "/"); 693*0Sstevel@tonic-gate strcat(opts, value); 694*0Sstevel@tonic-gate break; 695*0Sstevel@tonic-gate } 696*0Sstevel@tonic-gate } 697*0Sstevel@tonic-gate 698*0Sstevel@tonic-gate strcpy(mntflags, ""); 699*0Sstevel@tonic-gate if (rdwr) 700*0Sstevel@tonic-gate strcat(mntflags, "read/write"); 701*0Sstevel@tonic-gate else if (flag == OLD) 702*0Sstevel@tonic-gate strcat(mntflags, "read only"); 703*0Sstevel@tonic-gate else 704*0Sstevel@tonic-gate strcat(mntflags, "read-only"); 705*0Sstevel@tonic-gate if (suid) { 706*0Sstevel@tonic-gate if (setuid) 707*0Sstevel@tonic-gate strcat(mntflags, "/setuid"); 708*0Sstevel@tonic-gate else 709*0Sstevel@tonic-gate strcat(mntflags, "/nosetuid"); 710*0Sstevel@tonic-gate if (devices) 711*0Sstevel@tonic-gate strcat(mntflags, "/devices"); 712*0Sstevel@tonic-gate else 713*0Sstevel@tonic-gate strcat(mntflags, "/nodevices"); 714*0Sstevel@tonic-gate } else { 715*0Sstevel@tonic-gate strcat(mntflags, "/nosetuid/nodevices"); 716*0Sstevel@tonic-gate } 717*0Sstevel@tonic-gate if (*opts != '\0') { 718*0Sstevel@tonic-gate strcat(mntflags, "/"); 719*0Sstevel@tonic-gate strcat(mntflags, opts); 720*0Sstevel@tonic-gate } 721*0Sstevel@tonic-gate 722*0Sstevel@tonic-gate /* 723*0Sstevel@tonic-gate * The assumed assertion 724*0Sstevel@tonic-gate * assert (strlen(mntflags) < sizeof mntflags); 725*0Sstevel@tonic-gate * is valid at this point in the code. Note that a call to "assert" 726*0Sstevel@tonic-gate * is not appropriate in production code since it halts the program. 727*0Sstevel@tonic-gate */ 728*0Sstevel@tonic-gate return (mntflags); 729*0Sstevel@tonic-gate } 730*0Sstevel@tonic-gate 731*0Sstevel@tonic-gate char * 732*0Sstevel@tonic-gate remote(fstype, rfp) 733*0Sstevel@tonic-gate char *fstype; 734*0Sstevel@tonic-gate FILE *rfp; 735*0Sstevel@tonic-gate { 736*0Sstevel@tonic-gate char buf[BUFSIZ]; 737*0Sstevel@tonic-gate char *fs; 738*0Sstevel@tonic-gate extern char *strtok(); 739*0Sstevel@tonic-gate 740*0Sstevel@tonic-gate if (rfp == NULL || fstype == NULL || 741*0Sstevel@tonic-gate strlen(fstype) > (size_t)FSTYPE_MAX) 742*0Sstevel@tonic-gate return (""); /* not a remote */ 743*0Sstevel@tonic-gate rewind(rfp); 744*0Sstevel@tonic-gate while (fgets(buf, sizeof (buf), rfp) != NULL) { 745*0Sstevel@tonic-gate fs = strtok(buf, " \t\n"); 746*0Sstevel@tonic-gate if (strcmp(fstype, fs) == 0) 747*0Sstevel@tonic-gate return ("remote/"); /* is a remote fs */ 748*0Sstevel@tonic-gate } 749*0Sstevel@tonic-gate return (""); /* not a remote */ 750*0Sstevel@tonic-gate } 751*0Sstevel@tonic-gate 752*0Sstevel@tonic-gate 753*0Sstevel@tonic-gate void 754*0Sstevel@tonic-gate vfserror(int flag, char *special) 755*0Sstevel@tonic-gate { 756*0Sstevel@tonic-gate if (special == NULL) 757*0Sstevel@tonic-gate special = "<null>"; 758*0Sstevel@tonic-gate switch (flag) { 759*0Sstevel@tonic-gate case VFS_TOOLONG: 760*0Sstevel@tonic-gate fprintf(stderr, 761*0Sstevel@tonic-gate gettext("%s: Warning: Line in vfstab for \"%s\" exceeds %d characters\n"), 762*0Sstevel@tonic-gate myname, special, VFS_LINE_MAX-1); 763*0Sstevel@tonic-gate break; 764*0Sstevel@tonic-gate case VFS_TOOFEW: 765*0Sstevel@tonic-gate fprintf(stderr, 766*0Sstevel@tonic-gate gettext("%s: Warning: Line for \"%s\" in vfstab has too few entries\n"), 767*0Sstevel@tonic-gate myname, special); 768*0Sstevel@tonic-gate break; 769*0Sstevel@tonic-gate case VFS_TOOMANY: 770*0Sstevel@tonic-gate fprintf(stderr, 771*0Sstevel@tonic-gate gettext("%s: Warning: Line for \"%s\" in vfstab has too many entries\n"), 772*0Sstevel@tonic-gate myname, special); 773*0Sstevel@tonic-gate break; 774*0Sstevel@tonic-gate default: 775*0Sstevel@tonic-gate fprintf(stderr, gettext( 776*0Sstevel@tonic-gate "%s: Warning: Error in line for \"%s\" in vfstab\n"), 777*0Sstevel@tonic-gate myname, special); 778*0Sstevel@tonic-gate } 779*0Sstevel@tonic-gate } 780*0Sstevel@tonic-gate 781*0Sstevel@tonic-gate void 782*0Sstevel@tonic-gate mnterror(flag) 783*0Sstevel@tonic-gate int flag; 784*0Sstevel@tonic-gate { 785*0Sstevel@tonic-gate switch (flag) { 786*0Sstevel@tonic-gate case MNT_TOOLONG: 787*0Sstevel@tonic-gate fprintf(stderr, 788*0Sstevel@tonic-gate gettext("%s: Line in mnttab exceeds %d characters\n"), 789*0Sstevel@tonic-gate myname, MNT_LINE_MAX-2); 790*0Sstevel@tonic-gate break; 791*0Sstevel@tonic-gate case MNT_TOOFEW: 792*0Sstevel@tonic-gate fprintf(stderr, 793*0Sstevel@tonic-gate gettext("%s: Line in mnttab has too few entries\n"), 794*0Sstevel@tonic-gate myname); 795*0Sstevel@tonic-gate break; 796*0Sstevel@tonic-gate case MNT_TOOMANY: 797*0Sstevel@tonic-gate fprintf(stderr, 798*0Sstevel@tonic-gate gettext("%s: Line in mnttab has too many entries\n"), 799*0Sstevel@tonic-gate myname); 800*0Sstevel@tonic-gate break; 801*0Sstevel@tonic-gate } 802*0Sstevel@tonic-gate exit(1); 803*0Sstevel@tonic-gate } 804*0Sstevel@tonic-gate 805*0Sstevel@tonic-gate void 806*0Sstevel@tonic-gate doexec(fstype, newargv) 807*0Sstevel@tonic-gate char *fstype, *newargv[]; 808*0Sstevel@tonic-gate { 809*0Sstevel@tonic-gate char full_path[PATH_MAX]; 810*0Sstevel@tonic-gate char alter_path[PATH_MAX]; 811*0Sstevel@tonic-gate char *vfs_path = VFS_PATH; 812*0Sstevel@tonic-gate char *alt_path = ALT_PATH; 813*0Sstevel@tonic-gate int i; 814*0Sstevel@tonic-gate 815*0Sstevel@tonic-gate /* build the full pathname of the fstype dependent command. */ 816*0Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, myname); 817*0Sstevel@tonic-gate sprintf(alter_path, "%s/%s/%s", alt_path, fstype, myname); 818*0Sstevel@tonic-gate newargv[1] = myname; 819*0Sstevel@tonic-gate 820*0Sstevel@tonic-gate if (Vflg) { 821*0Sstevel@tonic-gate printf("%s -F %s", newargv[1], fstype); 822*0Sstevel@tonic-gate for (i = 2; newargv[i]; i++) 823*0Sstevel@tonic-gate printf(" %s", newargv[i]); 824*0Sstevel@tonic-gate printf("\n"); 825*0Sstevel@tonic-gate fflush(stdout); 826*0Sstevel@tonic-gate exit(0); 827*0Sstevel@tonic-gate } 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate /* 830*0Sstevel@tonic-gate * Try to exec the fstype dependent portion of the mount. 831*0Sstevel@tonic-gate * See if the directory is there before trying to exec dependent 832*0Sstevel@tonic-gate * portion. This is only useful for eliminating the 833*0Sstevel@tonic-gate * '..mount: not found' message when '/usr' is mounted 834*0Sstevel@tonic-gate */ 835*0Sstevel@tonic-gate if (access(full_path, 0) == 0) { 836*0Sstevel@tonic-gate execv(full_path, &newargv[1]); 837*0Sstevel@tonic-gate if (errno == EACCES) { 838*0Sstevel@tonic-gate fprintf(stderr, 839*0Sstevel@tonic-gate gettext("%s: Cannot execute %s - permission denied\n"), 840*0Sstevel@tonic-gate myname, full_path); 841*0Sstevel@tonic-gate } 842*0Sstevel@tonic-gate if (errno == ENOEXEC) { 843*0Sstevel@tonic-gate newargv[0] = "sh"; 844*0Sstevel@tonic-gate newargv[1] = full_path; 845*0Sstevel@tonic-gate execv("/sbin/sh", &newargv[0]); 846*0Sstevel@tonic-gate } 847*0Sstevel@tonic-gate } 848*0Sstevel@tonic-gate execv(alter_path, &newargv[1]); 849*0Sstevel@tonic-gate if (errno == EACCES) { 850*0Sstevel@tonic-gate fprintf(stderr, gettext( 851*0Sstevel@tonic-gate "%s: Cannot execute %s - permission denied\n"), 852*0Sstevel@tonic-gate myname, alter_path); 853*0Sstevel@tonic-gate exit(1); 854*0Sstevel@tonic-gate } 855*0Sstevel@tonic-gate if (errno == ENOEXEC) { 856*0Sstevel@tonic-gate newargv[0] = "sh"; 857*0Sstevel@tonic-gate newargv[1] = alter_path; 858*0Sstevel@tonic-gate execv("/sbin/sh", &newargv[0]); 859*0Sstevel@tonic-gate } 860*0Sstevel@tonic-gate fprintf(stderr, 861*0Sstevel@tonic-gate gettext("%s: Operation not applicable to FSType %s\n"), 862*0Sstevel@tonic-gate myname, fstype); 863*0Sstevel@tonic-gate exit(1); 864*0Sstevel@tonic-gate } 865*0Sstevel@tonic-gate 866*0Sstevel@tonic-gate char *mntopts[] = { MNTOPT_IGNORE, NULL }; 867*0Sstevel@tonic-gate #define IGNORE 0 868*0Sstevel@tonic-gate 869*0Sstevel@tonic-gate /* 870*0Sstevel@tonic-gate * Return 1 if "ignore" appears in the options string 871*0Sstevel@tonic-gate */ 872*0Sstevel@tonic-gate int 873*0Sstevel@tonic-gate ignore(opts) 874*0Sstevel@tonic-gate char *opts; 875*0Sstevel@tonic-gate { 876*0Sstevel@tonic-gate char *value; 877*0Sstevel@tonic-gate char *saveptr, *my_opts; 878*0Sstevel@tonic-gate int rval = 0; 879*0Sstevel@tonic-gate 880*0Sstevel@tonic-gate if (opts == NULL || *opts == NULL) 881*0Sstevel@tonic-gate return (0); 882*0Sstevel@tonic-gate 883*0Sstevel@tonic-gate /* 884*0Sstevel@tonic-gate * we make a copy of the option string to pass to getsubopt(), 885*0Sstevel@tonic-gate * because getsubopt() modifies the string. We also save 886*0Sstevel@tonic-gate * the original pointer returned by strdup, because getsubopt 887*0Sstevel@tonic-gate * changes the pointer passed into it. If strdup fails (unlikely), 888*0Sstevel@tonic-gate * we act as if the "ignore" option isn't set rather than fail. 889*0Sstevel@tonic-gate */ 890*0Sstevel@tonic-gate 891*0Sstevel@tonic-gate if ((saveptr = my_opts = strdup(opts)) == NULL) 892*0Sstevel@tonic-gate nomem(); 893*0Sstevel@tonic-gate 894*0Sstevel@tonic-gate while (*my_opts != '\0') { 895*0Sstevel@tonic-gate if (getsubopt(&my_opts, mntopts, &value) == IGNORE) 896*0Sstevel@tonic-gate rval = 1; 897*0Sstevel@tonic-gate } 898*0Sstevel@tonic-gate 899*0Sstevel@tonic-gate free(saveptr); 900*0Sstevel@tonic-gate 901*0Sstevel@tonic-gate return (rval); 902*0Sstevel@tonic-gate } 903*0Sstevel@tonic-gate 904*0Sstevel@tonic-gate /* 905*0Sstevel@tonic-gate * Perform the parallel version of mount. If count == 0, mount all 906*0Sstevel@tonic-gate * vfstab filesystems with the automnt field == "yes". Use fstype if 907*0Sstevel@tonic-gate * supplied. If mntlist supplied, then attempt to only mount those. 908*0Sstevel@tonic-gate */ 909*0Sstevel@tonic-gate 910*0Sstevel@tonic-gate int 911*0Sstevel@tonic-gate parmount(char **mntlist, int count, char *fstype) 912*0Sstevel@tonic-gate { 913*0Sstevel@tonic-gate int maxfd = OPEN_MAX; 914*0Sstevel@tonic-gate struct rlimit rl; 915*0Sstevel@tonic-gate vfsent_t **vl, *vp; 916*0Sstevel@tonic-gate 917*0Sstevel@tonic-gate /* 918*0Sstevel@tonic-gate * Process scaling. After running a series 919*0Sstevel@tonic-gate * of tests based on the number of simultaneous processes and 920*0Sstevel@tonic-gate * processors available, optimum performance was achieved near or 921*0Sstevel@tonic-gate * at (PROCN * 2). 922*0Sstevel@tonic-gate */ 923*0Sstevel@tonic-gate if ((maxrun = sysconf(_SC_NPROCESSORS_ONLN)) == -1) 924*0Sstevel@tonic-gate maxrun = 4; 925*0Sstevel@tonic-gate else 926*0Sstevel@tonic-gate maxrun = maxrun * 2 + 1; 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { 929*0Sstevel@tonic-gate rl.rlim_cur = rl.rlim_max; 930*0Sstevel@tonic-gate if (setrlimit(RLIMIT_NOFILE, &rl) == 0) 931*0Sstevel@tonic-gate maxfd = (int)rl.rlim_cur; 932*0Sstevel@tonic-gate } 933*0Sstevel@tonic-gate 934*0Sstevel@tonic-gate /* 935*0Sstevel@tonic-gate * The parent needs to maintain 3 of its own fd's, plus 2 for 936*0Sstevel@tonic-gate * each child (the stdout and stderr pipes). 937*0Sstevel@tonic-gate */ 938*0Sstevel@tonic-gate maxfd = (maxfd / 2) - 6; /* 6 takes care of temporary */ 939*0Sstevel@tonic-gate /* periods of open fds */ 940*0Sstevel@tonic-gate if (maxfd < maxrun) 941*0Sstevel@tonic-gate maxrun = maxfd; 942*0Sstevel@tonic-gate if (maxrun < 4) 943*0Sstevel@tonic-gate maxrun = 4; /* sanity check */ 944*0Sstevel@tonic-gate 945*0Sstevel@tonic-gate if (count == 0) 946*0Sstevel@tonic-gate mntlist = NULL; /* used as a flag later */ 947*0Sstevel@tonic-gate else 948*0Sstevel@tonic-gate fstype = NULL; /* mount points supplied: */ 949*0Sstevel@tonic-gate /* ignore fstype */ 950*0Sstevel@tonic-gate /* 951*0Sstevel@tonic-gate * Read the whole vfstab into a linked list for quick processing. 952*0Sstevel@tonic-gate * On average, this is the most efficient way to collect and 953*0Sstevel@tonic-gate * manipulate the vfstab data. 954*0Sstevel@tonic-gate */ 955*0Sstevel@tonic-gate vfsll = getvfsall(fstype, mntlist == NULL); 956*0Sstevel@tonic-gate 957*0Sstevel@tonic-gate /* 958*0Sstevel@tonic-gate * Make an array out of the vfs linked list for sorting purposes. 959*0Sstevel@tonic-gate */ 960*0Sstevel@tonic-gate if (vfsll == NULL || 961*0Sstevel@tonic-gate (vfsarray = make_vfsarray(mntlist, count)) == NULL) { 962*0Sstevel@tonic-gate if (mntlist == NULL) /* not an error - just none found */ 963*0Sstevel@tonic-gate return (0); 964*0Sstevel@tonic-gate 965*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: No valid entries found in %s\n"), 966*0Sstevel@tonic-gate myname, vfstab); 967*0Sstevel@tonic-gate return (1); 968*0Sstevel@tonic-gate } 969*0Sstevel@tonic-gate 970*0Sstevel@tonic-gate /* 971*0Sstevel@tonic-gate * Sort the entries based on their resolved path names 972*0Sstevel@tonic-gate * 973*0Sstevel@tonic-gate * If an lofs is encountered, then the original order of the vfstab 974*0Sstevel@tonic-gate * file needs to be maintained until we are done mounting lofs's. 975*0Sstevel@tonic-gate */ 976*0Sstevel@tonic-gate if (!lofscnt) 977*0Sstevel@tonic-gate qsort((void *)vfsarray, vfsarraysize, sizeof (vfsent_t *), 978*0Sstevel@tonic-gate mlevelcmp); 979*0Sstevel@tonic-gate 980*0Sstevel@tonic-gate /* 981*0Sstevel@tonic-gate * Shrink the vfsll linked list down to the new list. This will 982*0Sstevel@tonic-gate * speed up the pid search in cleanupkid() later. 983*0Sstevel@tonic-gate */ 984*0Sstevel@tonic-gate vfsll = vfsarray[0]; 985*0Sstevel@tonic-gate for (vl = vfsarray; vp = *vl; ) 986*0Sstevel@tonic-gate vp->next = *++vl; 987*0Sstevel@tonic-gate 988*0Sstevel@tonic-gate /* 989*0Sstevel@tonic-gate * Try to handle interrupts in a reasonable way. 990*0Sstevel@tonic-gate */ 991*0Sstevel@tonic-gate sigset(SIGHUP, cleanup); 992*0Sstevel@tonic-gate sigset(SIGQUIT, cleanup); 993*0Sstevel@tonic-gate sigset(SIGINT, cleanup); 994*0Sstevel@tonic-gate 995*0Sstevel@tonic-gate do_mounts(); /* do the mounts */ 996*0Sstevel@tonic-gate return (exitcode); 997*0Sstevel@tonic-gate } 998*0Sstevel@tonic-gate 999*0Sstevel@tonic-gate /* 1000*0Sstevel@tonic-gate * Read all vstab (fp) entries into memory if fstype == NULL. 1001*0Sstevel@tonic-gate * If fstype is specified, than read all those that match it. 1002*0Sstevel@tonic-gate * 1003*0Sstevel@tonic-gate * Returns a linked list. 1004*0Sstevel@tonic-gate */ 1005*0Sstevel@tonic-gate vfsent_t * 1006*0Sstevel@tonic-gate getvfsall(char *fstype, int takeall) 1007*0Sstevel@tonic-gate { 1008*0Sstevel@tonic-gate vfsent_t *vhead, *vtail; 1009*0Sstevel@tonic-gate struct vfstab vget; 1010*0Sstevel@tonic-gate FILE *fp; 1011*0Sstevel@tonic-gate int cnt = 0, ret; 1012*0Sstevel@tonic-gate 1013*0Sstevel@tonic-gate if ((fp = fopen(vfstab, "r")) == NULL) { 1014*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: Cannot open %s\n"), 1015*0Sstevel@tonic-gate myname, vfstab); 1016*0Sstevel@tonic-gate exit(1); 1017*0Sstevel@tonic-gate } 1018*0Sstevel@tonic-gate 1019*0Sstevel@tonic-gate vhead = vtail = NULL; 1020*0Sstevel@tonic-gate 1021*0Sstevel@tonic-gate while ((ret = getvfsent(fp, &vget)) != -1) { 1022*0Sstevel@tonic-gate vfsent_t *vp; 1023*0Sstevel@tonic-gate 1024*0Sstevel@tonic-gate if (ret > 0) { 1025*0Sstevel@tonic-gate vfserror(ret, vget.vfs_mountp); 1026*0Sstevel@tonic-gate continue; 1027*0Sstevel@tonic-gate } 1028*0Sstevel@tonic-gate 1029*0Sstevel@tonic-gate /* 1030*0Sstevel@tonic-gate * If mount points were not specified, then we ignore 1031*0Sstevel@tonic-gate * entries that aren't marked "yes". 1032*0Sstevel@tonic-gate */ 1033*0Sstevel@tonic-gate if (takeall && 1034*0Sstevel@tonic-gate (vget.vfs_automnt == NULL || 1035*0Sstevel@tonic-gate strcmp(vget.vfs_automnt, "yes"))) 1036*0Sstevel@tonic-gate continue; 1037*0Sstevel@tonic-gate 1038*0Sstevel@tonic-gate if (fstype && vget.vfs_fstype && 1039*0Sstevel@tonic-gate strcmp(fstype, vget.vfs_fstype)) 1040*0Sstevel@tonic-gate continue; 1041*0Sstevel@tonic-gate 1042*0Sstevel@tonic-gate if (vget.vfs_mountp == NULL || 1043*0Sstevel@tonic-gate (vget.vfs_fstype && (strcmp(vget.vfs_fstype, "swap") == 0))) 1044*0Sstevel@tonic-gate continue; 1045*0Sstevel@tonic-gate 1046*0Sstevel@tonic-gate if (check_fields(vget.vfs_fstype, vget.vfs_mountp)) { 1047*0Sstevel@tonic-gate exitcode = 1; 1048*0Sstevel@tonic-gate continue; 1049*0Sstevel@tonic-gate } 1050*0Sstevel@tonic-gate 1051*0Sstevel@tonic-gate vp = new_vfsent(&vget, cnt); /* create new vfs entry */ 1052*0Sstevel@tonic-gate if (vhead == NULL) 1053*0Sstevel@tonic-gate vhead = vp; 1054*0Sstevel@tonic-gate else 1055*0Sstevel@tonic-gate vtail->next = vp; 1056*0Sstevel@tonic-gate vtail = vp; 1057*0Sstevel@tonic-gate cnt++; 1058*0Sstevel@tonic-gate } 1059*0Sstevel@tonic-gate fclose(fp); 1060*0Sstevel@tonic-gate if (vtail == NULL) { 1061*0Sstevel@tonic-gate vfsarraysize = 0; 1062*0Sstevel@tonic-gate vfslltail = NULL; 1063*0Sstevel@tonic-gate return (NULL); 1064*0Sstevel@tonic-gate } 1065*0Sstevel@tonic-gate vtail->next = NULL; 1066*0Sstevel@tonic-gate vfslltail = vtail; /* save it in the global variable */ 1067*0Sstevel@tonic-gate vfsarraysize = cnt; 1068*0Sstevel@tonic-gate return (vhead); 1069*0Sstevel@tonic-gate } 1070*0Sstevel@tonic-gate 1071*0Sstevel@tonic-gate 1072*0Sstevel@tonic-gate /* 1073*0Sstevel@tonic-gate * Returns an array of vfsent_t's based on vfsll & mntlist. 1074*0Sstevel@tonic-gate */ 1075*0Sstevel@tonic-gate vfsent_t ** 1076*0Sstevel@tonic-gate make_vfsarray(char **mntlist, int count) 1077*0Sstevel@tonic-gate { 1078*0Sstevel@tonic-gate vfsent_t *vp, *vmark, *vpprev, **vpp; 1079*0Sstevel@tonic-gate int ndx, found; 1080*0Sstevel@tonic-gate 1081*0Sstevel@tonic-gate if (vfsll == NULL) 1082*0Sstevel@tonic-gate return (NULL); 1083*0Sstevel@tonic-gate 1084*0Sstevel@tonic-gate if (count > 0) 1085*0Sstevel@tonic-gate vfsarraysize = count; 1086*0Sstevel@tonic-gate 1087*0Sstevel@tonic-gate vpp = (vfsent_t **)malloc(sizeof (*vpp) * (vfsarraysize + 1)); 1088*0Sstevel@tonic-gate if (vpp == NULL) 1089*0Sstevel@tonic-gate nomem(); 1090*0Sstevel@tonic-gate 1091*0Sstevel@tonic-gate if (mntlist == NULL) { 1092*0Sstevel@tonic-gate /* 1093*0Sstevel@tonic-gate * No mount list specified: take all vfstab mount points. 1094*0Sstevel@tonic-gate */ 1095*0Sstevel@tonic-gate for (ndx = 0, vp = vfsll; vp; vp = vp->next) { 1096*0Sstevel@tonic-gate (void) setrpath(vp); 1097*0Sstevel@tonic-gate /* 1098*0Sstevel@tonic-gate * Sigh. lofs entries can complicate matters so much 1099*0Sstevel@tonic-gate * that the best way to avoid problems is to 1100*0Sstevel@tonic-gate * stop parallel mounting when an lofs is 1101*0Sstevel@tonic-gate * encountered, so we keep a count of how many 1102*0Sstevel@tonic-gate * there are. 1103*0Sstevel@tonic-gate * Fortunately this is rare. 1104*0Sstevel@tonic-gate */ 1105*0Sstevel@tonic-gate if (vp->v.vfs_fstype && 1106*0Sstevel@tonic-gate (strcmp(vp->v.vfs_fstype, MNTTYPE_LOFS) == 0)) 1107*0Sstevel@tonic-gate lofscnt++; 1108*0Sstevel@tonic-gate 1109*0Sstevel@tonic-gate vpp[ndx++] = vp; 1110*0Sstevel@tonic-gate } 1111*0Sstevel@tonic-gate vpp[ndx] = NULL; 1112*0Sstevel@tonic-gate return (vpp); 1113*0Sstevel@tonic-gate } 1114*0Sstevel@tonic-gate 1115*0Sstevel@tonic-gate /* 1116*0Sstevel@tonic-gate * A list of mount points was specified on the command line 1117*0Sstevel@tonic-gate * and we need to search for each one. 1118*0Sstevel@tonic-gate */ 1119*0Sstevel@tonic-gate vpprev = vfslltail; 1120*0Sstevel@tonic-gate vpprev->next = vfsll; /* make a circle out of it */ 1121*0Sstevel@tonic-gate vmark = vp = vfsll; 1122*0Sstevel@tonic-gate /* 1123*0Sstevel@tonic-gate * For each specified mount point: 1124*0Sstevel@tonic-gate */ 1125*0Sstevel@tonic-gate for (ndx = 0; *mntlist; mntlist++) { 1126*0Sstevel@tonic-gate found = 0; 1127*0Sstevel@tonic-gate /* 1128*0Sstevel@tonic-gate * Circle our entire linked list, looking for *mntlist. 1129*0Sstevel@tonic-gate */ 1130*0Sstevel@tonic-gate while (vp) { 1131*0Sstevel@tonic-gate if (strcmp(*mntlist, vp->v.vfs_mountp) == 0) { 1132*0Sstevel@tonic-gate vpp[ndx++] = vp; /* found it. */ 1133*0Sstevel@tonic-gate (void) setrpath(vp); 1134*0Sstevel@tonic-gate if (vp->v.vfs_fstype && 1135*0Sstevel@tonic-gate (strcmp(vp->v.vfs_fstype, 1136*0Sstevel@tonic-gate MNTTYPE_LOFS) == 0)) 1137*0Sstevel@tonic-gate lofscnt++; 1138*0Sstevel@tonic-gate 1139*0Sstevel@tonic-gate if (vp == vpprev) { /* list exhausted */ 1140*0Sstevel@tonic-gate vp = NULL; 1141*0Sstevel@tonic-gate found++; 1142*0Sstevel@tonic-gate break; 1143*0Sstevel@tonic-gate } 1144*0Sstevel@tonic-gate /* 1145*0Sstevel@tonic-gate * Remove it from the circular list. vpprev 1146*0Sstevel@tonic-gate * remains unchanged. 1147*0Sstevel@tonic-gate */ 1148*0Sstevel@tonic-gate vp = vp->next; 1149*0Sstevel@tonic-gate vpprev->next->next = NULL; 1150*0Sstevel@tonic-gate vpprev->next = vp; 1151*0Sstevel@tonic-gate /* 1152*0Sstevel@tonic-gate * Set vmark to the first elem that we check 1153*0Sstevel@tonic-gate * each time. 1154*0Sstevel@tonic-gate */ 1155*0Sstevel@tonic-gate vmark = vp; 1156*0Sstevel@tonic-gate found++; 1157*0Sstevel@tonic-gate break; 1158*0Sstevel@tonic-gate } 1159*0Sstevel@tonic-gate vpprev = vp; 1160*0Sstevel@tonic-gate vp = vp->next; 1161*0Sstevel@tonic-gate if (vp == vmark) /* break out if we completed */ 1162*0Sstevel@tonic-gate /* the circle */ 1163*0Sstevel@tonic-gate break; 1164*0Sstevel@tonic-gate } 1165*0Sstevel@tonic-gate 1166*0Sstevel@tonic-gate if (!found) { 1167*0Sstevel@tonic-gate fprintf(stderr, gettext( 1168*0Sstevel@tonic-gate "%s: Warning: %s not found in %s\n"), 1169*0Sstevel@tonic-gate myname, *mntlist, vfstab); 1170*0Sstevel@tonic-gate exitcode = 1; 1171*0Sstevel@tonic-gate } 1172*0Sstevel@tonic-gate } 1173*0Sstevel@tonic-gate if (ndx == 0) 1174*0Sstevel@tonic-gate return (NULL); 1175*0Sstevel@tonic-gate 1176*0Sstevel@tonic-gate vpp[ndx] = NULL; /* null terminate the list */ 1177*0Sstevel@tonic-gate vfsarraysize = ndx; /* adjust vfsarraysize */ 1178*0Sstevel@tonic-gate return (vpp); 1179*0Sstevel@tonic-gate } 1180*0Sstevel@tonic-gate 1181*0Sstevel@tonic-gate /* 1182*0Sstevel@tonic-gate * Performs the exec argument processing, all of the child forking and 1183*0Sstevel@tonic-gate * execing, and child cleanup. 1184*0Sstevel@tonic-gate * Sets exitcode to non-zero if any errors occurred. 1185*0Sstevel@tonic-gate */ 1186*0Sstevel@tonic-gate void 1187*0Sstevel@tonic-gate do_mounts() 1188*0Sstevel@tonic-gate { 1189*0Sstevel@tonic-gate int i, isave, cnt; 1190*0Sstevel@tonic-gate vfsent_t *vp, *vpprev, **vl; 1191*0Sstevel@tonic-gate char *newargv[ARGV_MAX]; 1192*0Sstevel@tonic-gate pid_t child; 1193*0Sstevel@tonic-gate 1194*0Sstevel@tonic-gate /* 1195*0Sstevel@tonic-gate * create the arg list once; the only differences among 1196*0Sstevel@tonic-gate * the calls are the options, special and mountp fields. 1197*0Sstevel@tonic-gate */ 1198*0Sstevel@tonic-gate i = 2; 1199*0Sstevel@tonic-gate if (cflg) 1200*0Sstevel@tonic-gate newargv[i++] = "-c"; 1201*0Sstevel@tonic-gate if (gflg) 1202*0Sstevel@tonic-gate newargv[i++] = "-g"; 1203*0Sstevel@tonic-gate if (mflg) 1204*0Sstevel@tonic-gate newargv[i++] = "-m"; 1205*0Sstevel@tonic-gate if (Oflg) 1206*0Sstevel@tonic-gate newargv[i++] = "-O"; 1207*0Sstevel@tonic-gate if (qflg) 1208*0Sstevel@tonic-gate newargv[i++] = "-q"; 1209*0Sstevel@tonic-gate if (rflg) 1210*0Sstevel@tonic-gate newargv[i++] = "-r"; 1211*0Sstevel@tonic-gate if (dashflg) 1212*0Sstevel@tonic-gate newargv[i++] = "--"; 1213*0Sstevel@tonic-gate if (oflg) { 1214*0Sstevel@tonic-gate newargv[i++] = "-o"; 1215*0Sstevel@tonic-gate newargv[i++] = specific_opts; 1216*0Sstevel@tonic-gate } 1217*0Sstevel@tonic-gate isave = i; 1218*0Sstevel@tonic-gate 1219*0Sstevel@tonic-gate /* 1220*0Sstevel@tonic-gate * Main loop for the mount processes 1221*0Sstevel@tonic-gate */ 1222*0Sstevel@tonic-gate vl = vfsarray; 1223*0Sstevel@tonic-gate cnt = vfsarraysize; 1224*0Sstevel@tonic-gate for (vpprev = *vl; vp = *vl; vpprev = vp, vl++, cnt--) { 1225*0Sstevel@tonic-gate /* 1226*0Sstevel@tonic-gate * Check to see if we cross a mount level: e.g., 1227*0Sstevel@tonic-gate * /a/b -> /a/b/c. If so, we need to wait for all current 1228*0Sstevel@tonic-gate * mounts to finish, rerun realpath on the remaining mount 1229*0Sstevel@tonic-gate * points, and resort the list. 1230*0Sstevel@tonic-gate * 1231*0Sstevel@tonic-gate * Also, we mount serially as long as there are lofs's 1232*0Sstevel@tonic-gate * to mount to avoid improper mount ordering. 1233*0Sstevel@tonic-gate */ 1234*0Sstevel@tonic-gate if (vp->mlevel > vpprev->mlevel || lofscnt > 0) { 1235*0Sstevel@tonic-gate vfsent_t **vlp; 1236*0Sstevel@tonic-gate 1237*0Sstevel@tonic-gate while (nrun > 0 && (dowait() != -1)) 1238*0Sstevel@tonic-gate ; 1239*0Sstevel@tonic-gate /* 1240*0Sstevel@tonic-gate * Gads! It's possible for real path mounts points to 1241*0Sstevel@tonic-gate * change after mounts are done at a lower mount 1242*0Sstevel@tonic-gate * level. 1243*0Sstevel@tonic-gate * Thus, we need to recalculate mount levels and 1244*0Sstevel@tonic-gate * resort the list from this point. 1245*0Sstevel@tonic-gate */ 1246*0Sstevel@tonic-gate for (vlp = vl; *vlp; vlp++) 1247*0Sstevel@tonic-gate (void) setrpath(*vlp); 1248*0Sstevel@tonic-gate /* 1249*0Sstevel@tonic-gate * Sort the remaining entries based on their newly 1250*0Sstevel@tonic-gate * resolved path names. 1251*0Sstevel@tonic-gate * Do not sort if we still have lofs's to mount. 1252*0Sstevel@tonic-gate */ 1253*0Sstevel@tonic-gate if (lofscnt == 0) { 1254*0Sstevel@tonic-gate qsort((void *)vl, cnt, sizeof (vfsent_t *), 1255*0Sstevel@tonic-gate mlevelcmp); 1256*0Sstevel@tonic-gate vp = *vl; 1257*0Sstevel@tonic-gate } 1258*0Sstevel@tonic-gate } 1259*0Sstevel@tonic-gate 1260*0Sstevel@tonic-gate if (vp->flag & VRPFAILED) { 1261*0Sstevel@tonic-gate fprintf(stderr, gettext( 1262*0Sstevel@tonic-gate "%s: Nonexistent mount point: %s\n"), 1263*0Sstevel@tonic-gate myname, vp->v.vfs_mountp); 1264*0Sstevel@tonic-gate vp->flag |= VNOTMOUNTED; 1265*0Sstevel@tonic-gate exitcode = 1; 1266*0Sstevel@tonic-gate continue; 1267*0Sstevel@tonic-gate } 1268*0Sstevel@tonic-gate 1269*0Sstevel@tonic-gate /* 1270*0Sstevel@tonic-gate * If mount options were not specified on the command 1271*0Sstevel@tonic-gate * line, then use the ones found in the vfstab entry, 1272*0Sstevel@tonic-gate * if any. 1273*0Sstevel@tonic-gate */ 1274*0Sstevel@tonic-gate i = isave; 1275*0Sstevel@tonic-gate if (!oflg && vp->v.vfs_mntopts) { 1276*0Sstevel@tonic-gate newargv[i++] = "-o"; 1277*0Sstevel@tonic-gate newargv[i++] = vp->v.vfs_mntopts; 1278*0Sstevel@tonic-gate } 1279*0Sstevel@tonic-gate newargv[i++] = vp->v.vfs_special; 1280*0Sstevel@tonic-gate newargv[i++] = vp->rpath; 1281*0Sstevel@tonic-gate newargv[i] = NULL; 1282*0Sstevel@tonic-gate 1283*0Sstevel@tonic-gate /* 1284*0Sstevel@tonic-gate * This should never really fail. 1285*0Sstevel@tonic-gate */ 1286*0Sstevel@tonic-gate while (setup_iopipe(vp) == -1 && (dowait() != -1)) 1287*0Sstevel@tonic-gate ; 1288*0Sstevel@tonic-gate 1289*0Sstevel@tonic-gate while (nrun >= maxrun && (dowait() != -1)) /* throttle */ 1290*0Sstevel@tonic-gate ; 1291*0Sstevel@tonic-gate 1292*0Sstevel@tonic-gate #ifdef CACHEFS_BUG 1293*0Sstevel@tonic-gate if (vp->v.vfs_fstype && 1294*0Sstevel@tonic-gate (strcmp(vp->v.vfs_fstype, "cachefs") == 0)) { 1295*0Sstevel@tonic-gate while (cachefs_running && (dowait() != -1)) 1296*0Sstevel@tonic-gate ; 1297*0Sstevel@tonic-gate cachefs_running = 1; 1298*0Sstevel@tonic-gate } 1299*0Sstevel@tonic-gate #endif 1300*0Sstevel@tonic-gate 1301*0Sstevel@tonic-gate if ((child = fork()) == -1) { 1302*0Sstevel@tonic-gate perror("fork"); 1303*0Sstevel@tonic-gate cleanup(-1); 1304*0Sstevel@tonic-gate /* not reached */ 1305*0Sstevel@tonic-gate } 1306*0Sstevel@tonic-gate if (child == 0) { /* child */ 1307*0Sstevel@tonic-gate signal(SIGHUP, SIG_IGN); 1308*0Sstevel@tonic-gate signal(SIGQUIT, SIG_IGN); 1309*0Sstevel@tonic-gate signal(SIGINT, SIG_IGN); 1310*0Sstevel@tonic-gate setup_output(vp); 1311*0Sstevel@tonic-gate doexec(vp->v.vfs_fstype, newargv); 1312*0Sstevel@tonic-gate perror("exec"); 1313*0Sstevel@tonic-gate exit(1); 1314*0Sstevel@tonic-gate } 1315*0Sstevel@tonic-gate 1316*0Sstevel@tonic-gate /* parent */ 1317*0Sstevel@tonic-gate (void) close(vp->sopipe[WRPIPE]); 1318*0Sstevel@tonic-gate (void) close(vp->sepipe[WRPIPE]); 1319*0Sstevel@tonic-gate vp->pid = child; 1320*0Sstevel@tonic-gate nrun++; 1321*0Sstevel@tonic-gate } 1322*0Sstevel@tonic-gate /* 1323*0Sstevel@tonic-gate * Mostly done by now - wait and clean up the stragglers. 1324*0Sstevel@tonic-gate */ 1325*0Sstevel@tonic-gate cleanup(0); 1326*0Sstevel@tonic-gate } 1327*0Sstevel@tonic-gate 1328*0Sstevel@tonic-gate 1329*0Sstevel@tonic-gate /* 1330*0Sstevel@tonic-gate * Setup stdout and stderr pipes for the children's output. 1331*0Sstevel@tonic-gate */ 1332*0Sstevel@tonic-gate int 1333*0Sstevel@tonic-gate setup_iopipe(vfsent_t *mp) 1334*0Sstevel@tonic-gate { 1335*0Sstevel@tonic-gate /* 1336*0Sstevel@tonic-gate * Make a stdout and stderr pipe. This should never fail. 1337*0Sstevel@tonic-gate */ 1338*0Sstevel@tonic-gate if (pipe(mp->sopipe) == -1) 1339*0Sstevel@tonic-gate return (-1); 1340*0Sstevel@tonic-gate if (pipe(mp->sepipe) == -1) { 1341*0Sstevel@tonic-gate (void) close(mp->sopipe[RDPIPE]); 1342*0Sstevel@tonic-gate (void) close(mp->sopipe[WRPIPE]); 1343*0Sstevel@tonic-gate return (-1); 1344*0Sstevel@tonic-gate } 1345*0Sstevel@tonic-gate /* 1346*0Sstevel@tonic-gate * Don't block on an empty pipe. 1347*0Sstevel@tonic-gate */ 1348*0Sstevel@tonic-gate (void) fcntl(mp->sopipe[RDPIPE], F_SETFL, O_NDELAY|O_NONBLOCK); 1349*0Sstevel@tonic-gate (void) fcntl(mp->sepipe[RDPIPE], F_SETFL, O_NDELAY|O_NONBLOCK); 1350*0Sstevel@tonic-gate /* 1351*0Sstevel@tonic-gate * Don't pass extra fds into children. 1352*0Sstevel@tonic-gate */ 1353*0Sstevel@tonic-gate (void) fcntl(mp->sopipe[RDPIPE], F_SETFD, FD_CLOEXEC); 1354*0Sstevel@tonic-gate (void) fcntl(mp->sepipe[RDPIPE], F_SETFD, FD_CLOEXEC); 1355*0Sstevel@tonic-gate 1356*0Sstevel@tonic-gate return (0); 1357*0Sstevel@tonic-gate } 1358*0Sstevel@tonic-gate 1359*0Sstevel@tonic-gate /* 1360*0Sstevel@tonic-gate * Called by a child to attach its stdout and stderr to the write side of 1361*0Sstevel@tonic-gate * the pipes. 1362*0Sstevel@tonic-gate */ 1363*0Sstevel@tonic-gate void 1364*0Sstevel@tonic-gate setup_output(vfsent_t *vp) 1365*0Sstevel@tonic-gate { 1366*0Sstevel@tonic-gate 1367*0Sstevel@tonic-gate (void) close(fileno(stdout)); 1368*0Sstevel@tonic-gate (void) dup(vp->sopipe[WRPIPE]); 1369*0Sstevel@tonic-gate (void) close(vp->sopipe[WRPIPE]); 1370*0Sstevel@tonic-gate 1371*0Sstevel@tonic-gate (void) close(fileno(stderr)); 1372*0Sstevel@tonic-gate (void) dup(vp->sepipe[WRPIPE]); 1373*0Sstevel@tonic-gate (void) close(vp->sepipe[WRPIPE]); 1374*0Sstevel@tonic-gate } 1375*0Sstevel@tonic-gate 1376*0Sstevel@tonic-gate /* 1377*0Sstevel@tonic-gate * Parent uses this to print any stdout or stderr output issued by 1378*0Sstevel@tonic-gate * the child. 1379*0Sstevel@tonic-gate */ 1380*0Sstevel@tonic-gate static void 1381*0Sstevel@tonic-gate doio(vfsent_t *vp) 1382*0Sstevel@tonic-gate { 1383*0Sstevel@tonic-gate int bytes; 1384*0Sstevel@tonic-gate char ibuf[BUFSIZ]; 1385*0Sstevel@tonic-gate 1386*0Sstevel@tonic-gate while ((bytes = read(vp->sepipe[RDPIPE], ibuf, sizeof (ibuf))) > 0) 1387*0Sstevel@tonic-gate write(fileno(stderr), ibuf, bytes); 1388*0Sstevel@tonic-gate while ((bytes = read(vp->sopipe[RDPIPE], ibuf, sizeof (ibuf))) > 0) 1389*0Sstevel@tonic-gate write(fileno(stdout), ibuf, bytes); 1390*0Sstevel@tonic-gate 1391*0Sstevel@tonic-gate (void) close(vp->sopipe[RDPIPE]); 1392*0Sstevel@tonic-gate (void) close(vp->sepipe[RDPIPE]); 1393*0Sstevel@tonic-gate } 1394*0Sstevel@tonic-gate 1395*0Sstevel@tonic-gate /* 1396*0Sstevel@tonic-gate * Waits for 1 child to die. 1397*0Sstevel@tonic-gate * 1398*0Sstevel@tonic-gate * Returns -1 if no children are left to wait for. 1399*0Sstevel@tonic-gate * Returns 0 if a child died without an error. 1400*0Sstevel@tonic-gate * Returns 1 if a child died with an error. 1401*0Sstevel@tonic-gate */ 1402*0Sstevel@tonic-gate int 1403*0Sstevel@tonic-gate dowait() 1404*0Sstevel@tonic-gate { 1405*0Sstevel@tonic-gate int child, wstat; 1406*0Sstevel@tonic-gate 1407*0Sstevel@tonic-gate if ((child = wait(&wstat)) == -1) 1408*0Sstevel@tonic-gate return (-1); 1409*0Sstevel@tonic-gate nrun--; 1410*0Sstevel@tonic-gate return (cleanupkid(child, wstat) != 0); 1411*0Sstevel@tonic-gate } 1412*0Sstevel@tonic-gate 1413*0Sstevel@tonic-gate /* 1414*0Sstevel@tonic-gate * Locates the child mount process represented by pid, outputs any io 1415*0Sstevel@tonic-gate * it may have, and returns its exit code. 1416*0Sstevel@tonic-gate * Sets the global exitcode if an error occurred. 1417*0Sstevel@tonic-gate */ 1418*0Sstevel@tonic-gate int 1419*0Sstevel@tonic-gate cleanupkid(pid_t pid, int wstat) 1420*0Sstevel@tonic-gate { 1421*0Sstevel@tonic-gate vfsent_t *vp, *prevp; 1422*0Sstevel@tonic-gate int ret; 1423*0Sstevel@tonic-gate 1424*0Sstevel@tonic-gate if (WIFEXITED(wstat)) /* this should always be true */ 1425*0Sstevel@tonic-gate ret = WEXITSTATUS(wstat); 1426*0Sstevel@tonic-gate else 1427*0Sstevel@tonic-gate ret = 1; /* assume some kind of error */ 1428*0Sstevel@tonic-gate if (ret) 1429*0Sstevel@tonic-gate exitcode = 1; 1430*0Sstevel@tonic-gate 1431*0Sstevel@tonic-gate /* 1432*0Sstevel@tonic-gate * Find our child. 1433*0Sstevel@tonic-gate * This search gets smaller and smaller as children are cleaned 1434*0Sstevel@tonic-gate * up. 1435*0Sstevel@tonic-gate */ 1436*0Sstevel@tonic-gate for (prevp = NULL, vp = vfsll; vp; vp = vp->next) { 1437*0Sstevel@tonic-gate if (vp->pid != pid) { 1438*0Sstevel@tonic-gate prevp = vp; 1439*0Sstevel@tonic-gate continue; 1440*0Sstevel@tonic-gate } 1441*0Sstevel@tonic-gate /* 1442*0Sstevel@tonic-gate * Found: let's remove it from this linked list. 1443*0Sstevel@tonic-gate */ 1444*0Sstevel@tonic-gate if (prevp) { 1445*0Sstevel@tonic-gate prevp->next = vp->next; 1446*0Sstevel@tonic-gate vp->next = NULL; 1447*0Sstevel@tonic-gate } 1448*0Sstevel@tonic-gate break; 1449*0Sstevel@tonic-gate } 1450*0Sstevel@tonic-gate 1451*0Sstevel@tonic-gate if (vp == NULL) { 1452*0Sstevel@tonic-gate /* 1453*0Sstevel@tonic-gate * This should never happen. 1454*0Sstevel@tonic-gate */ 1455*0Sstevel@tonic-gate fprintf(stderr, gettext( 1456*0Sstevel@tonic-gate "%s: Unknown child %d\n"), myname, pid); 1457*0Sstevel@tonic-gate exitcode = 1; 1458*0Sstevel@tonic-gate return (ret); 1459*0Sstevel@tonic-gate } 1460*0Sstevel@tonic-gate doio(vp); /* Any output? */ 1461*0Sstevel@tonic-gate 1462*0Sstevel@tonic-gate if (vp->v.vfs_fstype && (strcmp(vp->v.vfs_fstype, MNTTYPE_LOFS) == 0)) 1463*0Sstevel@tonic-gate lofscnt--; 1464*0Sstevel@tonic-gate 1465*0Sstevel@tonic-gate #ifdef CACHEFS_BUG 1466*0Sstevel@tonic-gate if (vp->v.vfs_fstype && (strcmp(vp->v.vfs_fstype, "cachefs") == 0)) 1467*0Sstevel@tonic-gate cachefs_running = 0; 1468*0Sstevel@tonic-gate #endif 1469*0Sstevel@tonic-gate 1470*0Sstevel@tonic-gate vp->exitcode = ret; 1471*0Sstevel@tonic-gate return (ret); 1472*0Sstevel@tonic-gate } 1473*0Sstevel@tonic-gate 1474*0Sstevel@tonic-gate 1475*0Sstevel@tonic-gate static vfsent_t zvmount = { 0 }; 1476*0Sstevel@tonic-gate 1477*0Sstevel@tonic-gate vfsent_t * 1478*0Sstevel@tonic-gate new_vfsent(struct vfstab *vin, int order) 1479*0Sstevel@tonic-gate { 1480*0Sstevel@tonic-gate vfsent_t *new; 1481*0Sstevel@tonic-gate 1482*0Sstevel@tonic-gate new = (vfsent_t *)malloc(sizeof (*new)); 1483*0Sstevel@tonic-gate if (new == NULL) 1484*0Sstevel@tonic-gate nomem(); 1485*0Sstevel@tonic-gate 1486*0Sstevel@tonic-gate *new = zvmount; 1487*0Sstevel@tonic-gate if (vin->vfs_special && 1488*0Sstevel@tonic-gate (new->v.vfs_special = strdup(vin->vfs_special)) == NULL) 1489*0Sstevel@tonic-gate nomem(); 1490*0Sstevel@tonic-gate if (vin->vfs_mountp && 1491*0Sstevel@tonic-gate (new->v.vfs_mountp = strdup(vin->vfs_mountp)) == NULL) 1492*0Sstevel@tonic-gate nomem(); 1493*0Sstevel@tonic-gate if (vin->vfs_fstype && 1494*0Sstevel@tonic-gate (new->v.vfs_fstype = strdup(vin->vfs_fstype)) == NULL) 1495*0Sstevel@tonic-gate nomem(); 1496*0Sstevel@tonic-gate /* 1497*0Sstevel@tonic-gate * If specific mount options were specified on the command 1498*0Sstevel@tonic-gate * line, then use those. Else, use the ones on the vfstab 1499*0Sstevel@tonic-gate * line, if any. In other words, specific options on the 1500*0Sstevel@tonic-gate * command line override those in /etc/vfstab. 1501*0Sstevel@tonic-gate */ 1502*0Sstevel@tonic-gate if (oflg) { 1503*0Sstevel@tonic-gate if ((new->v.vfs_mntopts = strdup(specific_opts)) == NULL) 1504*0Sstevel@tonic-gate nomem(); 1505*0Sstevel@tonic-gate } else if (vin->vfs_mntopts && 1506*0Sstevel@tonic-gate (new->v.vfs_mntopts = strdup(vin->vfs_mntopts)) == NULL) 1507*0Sstevel@tonic-gate nomem(); 1508*0Sstevel@tonic-gate 1509*0Sstevel@tonic-gate new->order = order; 1510*0Sstevel@tonic-gate return (new); 1511*0Sstevel@tonic-gate } 1512*0Sstevel@tonic-gate 1513*0Sstevel@tonic-gate /* 1514*0Sstevel@tonic-gate * Runs realpath on vp's mount point, records success or failure, 1515*0Sstevel@tonic-gate * resets the mount level based on the new realpath, and returns 1516*0Sstevel@tonic-gate * realpath()'s return value. 1517*0Sstevel@tonic-gate */ 1518*0Sstevel@tonic-gate char * 1519*0Sstevel@tonic-gate setrpath(vfsent_t *vp) 1520*0Sstevel@tonic-gate { 1521*0Sstevel@tonic-gate char *rp; 1522*0Sstevel@tonic-gate 1523*0Sstevel@tonic-gate if ((rp = realpath(vp->v.vfs_mountp, realdir)) == NULL) 1524*0Sstevel@tonic-gate vp->flag |= VRPFAILED; 1525*0Sstevel@tonic-gate else 1526*0Sstevel@tonic-gate vp->flag &= ~VRPFAILED; 1527*0Sstevel@tonic-gate 1528*0Sstevel@tonic-gate if (vp->rpath) 1529*0Sstevel@tonic-gate free(vp->rpath); 1530*0Sstevel@tonic-gate if ((vp->rpath = strdup(realdir)) == NULL) 1531*0Sstevel@tonic-gate nomem(); 1532*0Sstevel@tonic-gate vp->mlevel = fsgetmlevel(vp->rpath); 1533*0Sstevel@tonic-gate return (rp); 1534*0Sstevel@tonic-gate } 1535*0Sstevel@tonic-gate 1536*0Sstevel@tonic-gate 1537*0Sstevel@tonic-gate /* 1538*0Sstevel@tonic-gate * sort first by mlevel (1...N), then by vfstab order. 1539*0Sstevel@tonic-gate */ 1540*0Sstevel@tonic-gate int 1541*0Sstevel@tonic-gate mlevelcmp(const void *a, const void *b) 1542*0Sstevel@tonic-gate { 1543*0Sstevel@tonic-gate vfsent_t *a1, *b1; 1544*0Sstevel@tonic-gate int lcmp; 1545*0Sstevel@tonic-gate 1546*0Sstevel@tonic-gate a1 = *(vfsent_t **)a; 1547*0Sstevel@tonic-gate b1 = *(vfsent_t **)b; 1548*0Sstevel@tonic-gate 1549*0Sstevel@tonic-gate lcmp = a1->mlevel - b1->mlevel; 1550*0Sstevel@tonic-gate if (lcmp == 0) 1551*0Sstevel@tonic-gate lcmp = a1->order - b1->order; 1552*0Sstevel@tonic-gate return (lcmp); 1553*0Sstevel@tonic-gate } 1554*0Sstevel@tonic-gate 1555*0Sstevel@tonic-gate /* sort by vfstab order. 0..N */ 1556*0Sstevel@tonic-gate mordercmp(const void *a, const void *b) 1557*0Sstevel@tonic-gate { 1558*0Sstevel@tonic-gate vfsent_t *a1, *b1; 1559*0Sstevel@tonic-gate 1560*0Sstevel@tonic-gate a1 = *(vfsent_t **)a; 1561*0Sstevel@tonic-gate b1 = *(vfsent_t **)b; 1562*0Sstevel@tonic-gate return (a1->order - b1->order); 1563*0Sstevel@tonic-gate } 1564*0Sstevel@tonic-gate 1565*0Sstevel@tonic-gate /* 1566*0Sstevel@tonic-gate * cleanup the existing children and exit with an error 1567*0Sstevel@tonic-gate * if asig != 0. 1568*0Sstevel@tonic-gate */ 1569*0Sstevel@tonic-gate void 1570*0Sstevel@tonic-gate cleanup(int asig) 1571*0Sstevel@tonic-gate { 1572*0Sstevel@tonic-gate while (nrun > 0 && (dowait() != -1)) 1573*0Sstevel@tonic-gate ; 1574*0Sstevel@tonic-gate 1575*0Sstevel@tonic-gate if (asig != 0) 1576*0Sstevel@tonic-gate exit(1); 1577*0Sstevel@tonic-gate } 1578*0Sstevel@tonic-gate 1579*0Sstevel@tonic-gate 1580*0Sstevel@tonic-gate int 1581*0Sstevel@tonic-gate check_fields(char *fstype, char *mountp) 1582*0Sstevel@tonic-gate { 1583*0Sstevel@tonic-gate struct stat64 stbuf; 1584*0Sstevel@tonic-gate 1585*0Sstevel@tonic-gate if (strlen(fstype) > (size_t)FSTYPE_MAX) { 1586*0Sstevel@tonic-gate fprintf(stderr, 1587*0Sstevel@tonic-gate gettext("%s: FSType %s exceeds %d characters\n"), 1588*0Sstevel@tonic-gate myname, fstype, FSTYPE_MAX); 1589*0Sstevel@tonic-gate return (1); 1590*0Sstevel@tonic-gate } 1591*0Sstevel@tonic-gate 1592*0Sstevel@tonic-gate if (mountp == NULL) { 1593*0Sstevel@tonic-gate fprintf(stderr, 1594*0Sstevel@tonic-gate gettext("%s: Mount point cannot be determined\n"), 1595*0Sstevel@tonic-gate myname); 1596*0Sstevel@tonic-gate return (1); 1597*0Sstevel@tonic-gate } 1598*0Sstevel@tonic-gate if (*mountp != '/') { 1599*0Sstevel@tonic-gate fprintf(stderr, gettext( 1600*0Sstevel@tonic-gate "%s: Mount point %s is not an absolute pathname.\n"), 1601*0Sstevel@tonic-gate myname, mountp); 1602*0Sstevel@tonic-gate return (1); 1603*0Sstevel@tonic-gate } 1604*0Sstevel@tonic-gate /* 1605*0Sstevel@tonic-gate * Don't do some of these checks if aflg because a mount point may 1606*0Sstevel@tonic-gate * not exist now, but will be mounted before we get to it. 1607*0Sstevel@tonic-gate * This is one of the quirks of "secondary mounting". 1608*0Sstevel@tonic-gate */ 1609*0Sstevel@tonic-gate if (!aflg && stat64(mountp, &stbuf) < 0) { 1610*0Sstevel@tonic-gate if (errno == ENOENT || errno == ENOTDIR) 1611*0Sstevel@tonic-gate fprintf(stderr, 1612*0Sstevel@tonic-gate gettext("%s: Mount point %s does not exist.\n"), 1613*0Sstevel@tonic-gate myname, mountp); 1614*0Sstevel@tonic-gate else { 1615*0Sstevel@tonic-gate fprintf(stderr, 1616*0Sstevel@tonic-gate gettext("%s: Cannot stat mount point %s.\n"), 1617*0Sstevel@tonic-gate myname, mountp); 1618*0Sstevel@tonic-gate perror(myname); 1619*0Sstevel@tonic-gate } 1620*0Sstevel@tonic-gate return (1); 1621*0Sstevel@tonic-gate } 1622*0Sstevel@tonic-gate return (0); 1623*0Sstevel@tonic-gate } 1624*0Sstevel@tonic-gate 1625*0Sstevel@tonic-gate void 1626*0Sstevel@tonic-gate nomem() 1627*0Sstevel@tonic-gate { 1628*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: Out of memory\n"), myname); 1629*0Sstevel@tonic-gate while (nrun > 0 && (dowait() != -1)) 1630*0Sstevel@tonic-gate ; 1631*0Sstevel@tonic-gate exit(1); 1632*0Sstevel@tonic-gate } 1633