10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
230Sstevel@tonic-gate /* All Rights Reserved */
240Sstevel@tonic-gate
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
27767Ssjelinek * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
280Sstevel@tonic-gate * Use is subject to license terms.
290Sstevel@tonic-gate */
300Sstevel@tonic-gate
310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <stdio.h>
340Sstevel@tonic-gate #include <limits.h>
350Sstevel@tonic-gate #include <locale.h>
360Sstevel@tonic-gate #include <libintl.h>
370Sstevel@tonic-gate #include <sys/fstyp.h>
380Sstevel@tonic-gate #include <errno.h>
390Sstevel@tonic-gate #include <sys/vfstab.h>
400Sstevel@tonic-gate #include <sys/types.h>
410Sstevel@tonic-gate #include <sys/stat.h>
420Sstevel@tonic-gate #include <fcntl.h>
430Sstevel@tonic-gate #include <string.h>
44767Ssjelinek #include <libdiskmgt.h>
45767Ssjelinek #include "fslib.h"
46767Ssjelinek
47767Ssjelinek
48767Ssjelinek static int match(char **opts, char *s);
49*1107Ssjelinek static int has_Nflag(char *opts);
500Sstevel@tonic-gate
510Sstevel@tonic-gate #define FSTYPE_MAX 8
520Sstevel@tonic-gate #define ARGV_MAX 1024
530Sstevel@tonic-gate #define VFS_PATH "/usr/lib/fs"
540Sstevel@tonic-gate #define ALT_PATH "/etc/fs"
550Sstevel@tonic-gate
560Sstevel@tonic-gate extern char *default_fstype();
570Sstevel@tonic-gate void stat_snap(char *, char *, char *);
580Sstevel@tonic-gate char *special = NULL; /* device special name */
590Sstevel@tonic-gate char *fstype = NULL; /* fstype name is filled in here */
600Sstevel@tonic-gate char *cbasename; /* name of command */
610Sstevel@tonic-gate char *newargv[ARGV_MAX]; /* args for the fstype specific command */
620Sstevel@tonic-gate char vfstab[] = VFSTAB;
630Sstevel@tonic-gate int newargc = 2;
640Sstevel@tonic-gate
650Sstevel@tonic-gate /*
660Sstevel@tonic-gate * TRANSLATION_NOTE - the usage strings in the c_usgstr[] of the
670Sstevel@tonic-gate * following structures should be given a translation; the call to gettext
680Sstevel@tonic-gate * is in the usage() function. The strings are the ones containing
690Sstevel@tonic-gate * "[-F FSType]".
700Sstevel@tonic-gate */
710Sstevel@tonic-gate
720Sstevel@tonic-gate struct commands {
730Sstevel@tonic-gate char *c_basename;
740Sstevel@tonic-gate char *c_optstr;
750Sstevel@tonic-gate char *c_usgstr[4]; /* make sure as large as largest array size */
760Sstevel@tonic-gate } cmd_data[] = {
770Sstevel@tonic-gate "clri", "F:o:?V",
780Sstevel@tonic-gate {
790Sstevel@tonic-gate "[-F FSType] [-V] special inumber ...",
800Sstevel@tonic-gate NULL
810Sstevel@tonic-gate },
820Sstevel@tonic-gate "mkfs", "F:o:mb:?V",
830Sstevel@tonic-gate {
840Sstevel@tonic-gate "[-F FSType] [-V] [-m] [-o specific_options] special ",
850Sstevel@tonic-gate "[operands]", NULL
860Sstevel@tonic-gate },
870Sstevel@tonic-gate "dcopy", "F:o:?V",
880Sstevel@tonic-gate {
890Sstevel@tonic-gate "[-F FSType] [-V] special inumber ...",
900Sstevel@tonic-gate NULL
910Sstevel@tonic-gate },
920Sstevel@tonic-gate "fsdb", "F:o:z:?V",
930Sstevel@tonic-gate {
940Sstevel@tonic-gate "[-F FSType] [-V] [-o specific_options] special",
950Sstevel@tonic-gate NULL
960Sstevel@tonic-gate },
970Sstevel@tonic-gate "fssnap", "F:dio:?V",
980Sstevel@tonic-gate {
990Sstevel@tonic-gate "[-F FSType] [-V] -o special_options /mount/point",
1000Sstevel@tonic-gate "-d [-F FSType] [-V] /mount/point | dev",
1010Sstevel@tonic-gate "-i [-F FSType] [-V] [-o special-options] [/mount/point | dev]",
1020Sstevel@tonic-gate NULL
1030Sstevel@tonic-gate },
1040Sstevel@tonic-gate "labelit", "F:o:?nV",
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate "[-F FSType] [-V] [-o specific_options] special [operands]",
1070Sstevel@tonic-gate NULL
1080Sstevel@tonic-gate },
1090Sstevel@tonic-gate NULL, "F:o:?V",
1100Sstevel@tonic-gate {
1110Sstevel@tonic-gate "[-F FSType] [-V] [-o specific_options] special [operands]",
1120Sstevel@tonic-gate NULL
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate };
1150Sstevel@tonic-gate struct commands *c_ptr;
1160Sstevel@tonic-gate
117821Sdh145677 static void usage(char *cmd, char **usg);
118821Sdh145677 static void lookup(void);
119821Sdh145677
120821Sdh145677 int
main(int argc,char * argv[])121821Sdh145677 main(int argc, char *argv[])
1220Sstevel@tonic-gate {
123821Sdh145677 char *ptr;
1240Sstevel@tonic-gate char full_path[PATH_MAX];
1250Sstevel@tonic-gate char *vfs_path = VFS_PATH;
1260Sstevel@tonic-gate char *alt_path = ALT_PATH;
1270Sstevel@tonic-gate int i;
128767Ssjelinek int j;
1290Sstevel@tonic-gate int verbose = 0; /* set if -V is specified */
1300Sstevel@tonic-gate int F_flg = 0;
1310Sstevel@tonic-gate int mflag = 0;
132767Ssjelinek int Nflag = 0;
1330Sstevel@tonic-gate char *oopts = NULL;
134767Ssjelinek char *tmpopts = NULL; /* used for in use checking */
1350Sstevel@tonic-gate int iflag = 0;
1360Sstevel@tonic-gate int usgflag = 0;
1370Sstevel@tonic-gate int arg; /* argument from getopt() */
138767Ssjelinek char *msg;
139767Ssjelinek int error;
1400Sstevel@tonic-gate extern char *optarg; /* getopt specific */
1410Sstevel@tonic-gate extern int optind;
1420Sstevel@tonic-gate extern int opterr;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
1470Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
1480Sstevel@tonic-gate #endif
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate cbasename = ptr = argv[0];
1530Sstevel@tonic-gate while (*ptr) {
1540Sstevel@tonic-gate if (*ptr++ == '/')
1550Sstevel@tonic-gate cbasename = ptr;
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate if (argc == 1) {
1600Sstevel@tonic-gate for (c_ptr = cmd_data; ((c_ptr->c_basename != NULL) &&
1610Sstevel@tonic-gate (strcmp(c_ptr->c_basename, cbasename) != 0)); c_ptr++)
1620Sstevel@tonic-gate ;
1630Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
1640Sstevel@tonic-gate exit(2);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate for (c_ptr = cmd_data; ((c_ptr->c_basename != NULL) &&
1680Sstevel@tonic-gate (strcmp(c_ptr->c_basename, cbasename) != 0)); c_ptr++)
1690Sstevel@tonic-gate ;
1700Sstevel@tonic-gate while ((arg = getopt(argc, argv, c_ptr->c_optstr)) != -1) {
1710Sstevel@tonic-gate switch (arg) {
1720Sstevel@tonic-gate case 'V': /* echo complete command line */
1730Sstevel@tonic-gate verbose = 1;
1740Sstevel@tonic-gate break;
1750Sstevel@tonic-gate case 'F': /* FSType specified */
1760Sstevel@tonic-gate F_flg++;
1770Sstevel@tonic-gate fstype = optarg;
1780Sstevel@tonic-gate break;
1790Sstevel@tonic-gate case 'o': /* FSType specific arguments */
1800Sstevel@tonic-gate newargv[newargc++] = "-o";
1810Sstevel@tonic-gate newargv[newargc++] = optarg;
1820Sstevel@tonic-gate oopts = optarg;
183767Ssjelinek if (!Nflag) {
184767Ssjelinek tmpopts = optarg;
185767Ssjelinek Nflag = has_Nflag(tmpopts);
186767Ssjelinek }
1870Sstevel@tonic-gate break;
1880Sstevel@tonic-gate case '?': /* print usage message */
1890Sstevel@tonic-gate newargv[newargc++] = "-?";
1900Sstevel@tonic-gate usgflag = 1;
1910Sstevel@tonic-gate break;
1920Sstevel@tonic-gate case 'm': /* FSType specific arguments */
1930Sstevel@tonic-gate mflag = 1;
1940Sstevel@tonic-gate newargv[newargc] = (char *)malloc(3);
1950Sstevel@tonic-gate sprintf(newargv[newargc++], "-%c", arg);
1960Sstevel@tonic-gate if (optarg)
1970Sstevel@tonic-gate newargv[newargc++] = optarg;
1980Sstevel@tonic-gate break;
1990Sstevel@tonic-gate case 'i': /* fssnap only */
2000Sstevel@tonic-gate iflag = 1;
2010Sstevel@tonic-gate /*FALLTHROUGH*/
2020Sstevel@tonic-gate default:
2030Sstevel@tonic-gate newargv[newargc] = (char *)malloc(3);
2040Sstevel@tonic-gate sprintf(newargv[newargc++], "-%c", arg);
2050Sstevel@tonic-gate if (optarg)
2060Sstevel@tonic-gate newargv[newargc++] = optarg;
2070Sstevel@tonic-gate break;
2080Sstevel@tonic-gate }
2090Sstevel@tonic-gate optarg = NULL;
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate if (F_flg > 1) {
212767Ssjelinek (void) fprintf(stderr,
213767Ssjelinek gettext("%s: more than one FSType specified\n"),
214767Ssjelinek cbasename);
2150Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
2160Sstevel@tonic-gate exit(2);
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate if (fstype != NULL) {
2190Sstevel@tonic-gate if (strlen(fstype) > FSTYPE_MAX) {
220767Ssjelinek (void) fprintf(stderr,
2210Sstevel@tonic-gate gettext("%s: FSType %s exceeds %d characters\n"),
2220Sstevel@tonic-gate cbasename, fstype, FSTYPE_MAX);
2230Sstevel@tonic-gate exit(2);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate /* perform a lookup if fstype is not specified */
2280Sstevel@tonic-gate special = argv[optind];
2290Sstevel@tonic-gate optind++;
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate /* handle -i (fssnap command only) */
2320Sstevel@tonic-gate if (iflag) {
2330Sstevel@tonic-gate int diff = argc - optind;
2340Sstevel@tonic-gate /*
2350Sstevel@tonic-gate * There is no reason to ever call a file system specific
2360Sstevel@tonic-gate * version since its all in kstats.
2370Sstevel@tonic-gate */
2380Sstevel@tonic-gate if (diff > 0) /* gave more than one mountpoint or device */
2390Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
2400Sstevel@tonic-gate stat_snap(cbasename, diff == 0 ? argv[argc-1] : NULL, oopts);
2410Sstevel@tonic-gate exit(0);
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate if ((special == NULL) && (!usgflag)) {
245767Ssjelinek (void) fprintf(stderr, gettext("%s: special not specified\n"),
2460Sstevel@tonic-gate cbasename);
2470Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
2480Sstevel@tonic-gate exit(2);
2490Sstevel@tonic-gate }
250767Ssjelinek
2510Sstevel@tonic-gate if ((fstype == NULL) && (usgflag))
2520Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
2530Sstevel@tonic-gate if (fstype == NULL)
2540Sstevel@tonic-gate lookup();
2550Sstevel@tonic-gate if (fstype == NULL) {
256767Ssjelinek (void) fprintf(stderr,
257767Ssjelinek gettext("%s: FSType cannot be identified\n"), cbasename);
2580Sstevel@tonic-gate usage(cbasename, c_ptr->c_usgstr);
2590Sstevel@tonic-gate exit(2);
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate newargv[newargc++] = special;
2620Sstevel@tonic-gate for (; optind < argc; optind++)
2630Sstevel@tonic-gate newargv[newargc++] = argv[optind];
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate /* build the full pathname of the fstype dependent command */
2660Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", vfs_path, fstype, cbasename);
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate newargv[1] = cbasename;
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate if (verbose) {
2710Sstevel@tonic-gate printf("%s -F %s ", cbasename, fstype);
2720Sstevel@tonic-gate for (i = 2; newargv[i]; i++)
2730Sstevel@tonic-gate printf("%s ", newargv[i]);
2740Sstevel@tonic-gate printf("\n");
2750Sstevel@tonic-gate exit(0);
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate /*
279767Ssjelinek * Prior to executing the command for mkfs check for device in use.
280767Ssjelinek * If the mflag is set, user wants to see command that created
281767Ssjelinek * an already existing filesystem. Do not check for in use in this
282767Ssjelinek * case. If Nflag is set user wants to see what the parameters
283767Ssjelinek * would be to create the filesystem. Do not check for in use in
284767Ssjelinek * this case.
285767Ssjelinek */
286767Ssjelinek if (strcmp(cbasename, "mkfs") == 0 && !mflag && !Nflag) {
287767Ssjelinek if (dm_inuse(special, &msg, DM_WHO_MKFS, &error) ||
288767Ssjelinek error) {
289767Ssjelinek if (error != 0) {
290767Ssjelinek (void) fprintf(stderr, gettext("Error occurred"
291767Ssjelinek " with device in use checking: %s\n"),
292767Ssjelinek strerror(error));
293767Ssjelinek } else {
294767Ssjelinek (void) fprintf(stderr, "%s", msg);
295767Ssjelinek free(msg);
296767Ssjelinek exit(2);
297767Ssjelinek }
298767Ssjelinek }
299767Ssjelinek }
300767Ssjelinek
301767Ssjelinek /*
3020Sstevel@tonic-gate * Execute the FSType specific command.
3030Sstevel@tonic-gate */
3040Sstevel@tonic-gate execv(full_path, &newargv[1]);
3050Sstevel@tonic-gate if ((errno == ENOENT) || (errno == EACCES)) {
3060Sstevel@tonic-gate /* build the alternate pathname */
3070Sstevel@tonic-gate sprintf(full_path, "%s/%s/%s", alt_path, fstype, cbasename);
3080Sstevel@tonic-gate if (verbose) {
3090Sstevel@tonic-gate printf("%s -F %s ", cbasename, fstype);
3100Sstevel@tonic-gate for (i = 2; newargv[i]; i++)
3110Sstevel@tonic-gate printf("%s ", newargv[i]);
3120Sstevel@tonic-gate printf("\n");
3130Sstevel@tonic-gate exit(0);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate execv(full_path, &newargv[1]);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate if (errno == ENOEXEC) {
3180Sstevel@tonic-gate newargv[0] = "sh";
3190Sstevel@tonic-gate newargv[1] = full_path;
3200Sstevel@tonic-gate execv("/sbin/sh", &newargv[0]);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate if (errno != ENOENT) {
3230Sstevel@tonic-gate perror(cbasename);
324767Ssjelinek (void) fprintf(stderr, gettext("%s: cannot execute %s\n"),
325767Ssjelinek cbasename, full_path);
3260Sstevel@tonic-gate exit(2);
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate if (sysfs(GETFSIND, fstype) == (-1)) {
330767Ssjelinek (void) fprintf(stderr,
3310Sstevel@tonic-gate gettext("%s: FSType %s not installed in the kernel\n"),
3320Sstevel@tonic-gate cbasename, fstype);
3330Sstevel@tonic-gate exit(2);
3340Sstevel@tonic-gate }
335767Ssjelinek (void) fprintf(stderr,
3360Sstevel@tonic-gate gettext("%s: Operation not applicable for FSType %s \n"),
3370Sstevel@tonic-gate cbasename, fstype);
338821Sdh145677 return (2);
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate
341821Sdh145677 static void
usage(char * cmd,char ** usg)342821Sdh145677 usage(char *cmd, char **usg)
3430Sstevel@tonic-gate {
3440Sstevel@tonic-gate int i;
345767Ssjelinek (void) fprintf(stderr, gettext("Usage:\n"));
3460Sstevel@tonic-gate for (i = 0; usg[i] != NULL; i++)
347767Ssjelinek (void) fprintf(stderr, "%s %s\n", gettext(cmd),
348767Ssjelinek gettext(usg[i]));
3490Sstevel@tonic-gate exit(2);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate /*
3540Sstevel@tonic-gate * This looks up the /etc/vfstab entry given the device 'special'.
3550Sstevel@tonic-gate * It is called when the fstype is not specified on the command line.
3560Sstevel@tonic-gate *
3570Sstevel@tonic-gate * The following global variables are used:
3580Sstevel@tonic-gate * special, fstype
3590Sstevel@tonic-gate */
3600Sstevel@tonic-gate
361821Sdh145677 static void
lookup(void)362821Sdh145677 lookup(void)
3630Sstevel@tonic-gate {
3640Sstevel@tonic-gate FILE *fd;
3650Sstevel@tonic-gate int ret;
3660Sstevel@tonic-gate struct vfstab vget, vref;
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate if ((fd = fopen(vfstab, "r")) == NULL) {
369767Ssjelinek (void) fprintf(stderr, gettext("%s: cannot open vfstab\n"),
370767Ssjelinek cbasename);
3710Sstevel@tonic-gate exit(1);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate vfsnull(&vref);
3740Sstevel@tonic-gate vref.vfs_special = special;
3750Sstevel@tonic-gate ret = getvfsany(fd, &vget, &vref);
3760Sstevel@tonic-gate if (ret == -1) {
3770Sstevel@tonic-gate rewind(fd);
3780Sstevel@tonic-gate vfsnull(&vref);
3790Sstevel@tonic-gate vref.vfs_fsckdev = special;
3800Sstevel@tonic-gate ret = getvfsany(fd, &vget, &vref);
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate fclose(fd);
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate switch (ret) {
3850Sstevel@tonic-gate case -1:
3860Sstevel@tonic-gate fstype = default_fstype(special);
3870Sstevel@tonic-gate break;
3880Sstevel@tonic-gate case 0:
3890Sstevel@tonic-gate fstype = vget.vfs_fstype;
3900Sstevel@tonic-gate break;
3910Sstevel@tonic-gate case VFS_TOOLONG:
392767Ssjelinek (void) fprintf(stderr,
3930Sstevel@tonic-gate gettext("%s: line in vfstab exceeds %d characters\n"),
3940Sstevel@tonic-gate cbasename, VFS_LINE_MAX-2);
3950Sstevel@tonic-gate exit(1);
3960Sstevel@tonic-gate break;
3970Sstevel@tonic-gate case VFS_TOOFEW:
398767Ssjelinek (void) fprintf(stderr,
3990Sstevel@tonic-gate gettext("%s: line in vfstab has too few entries\n"),
4000Sstevel@tonic-gate cbasename);
4010Sstevel@tonic-gate exit(1);
4020Sstevel@tonic-gate break;
4030Sstevel@tonic-gate }
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate void
stat_snap(char * cmd,char * mountpoint,char * opts)407821Sdh145677 stat_snap(char *cmd, char *mountpoint, char *opts)
4080Sstevel@tonic-gate {
4090Sstevel@tonic-gate int fd; /* check mount point if given */
4100Sstevel@tonic-gate int en;
4110Sstevel@tonic-gate char *errstr;
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate if (mountpoint) {
4140Sstevel@tonic-gate if ((fd = open(mountpoint, O_RDONLY)) < 0) {
4150Sstevel@tonic-gate en = errno;
4160Sstevel@tonic-gate errstr = strerror(errno);
4170Sstevel@tonic-gate if (errstr == NULL)
4180Sstevel@tonic-gate errstr = gettext("Unknown error");
4190Sstevel@tonic-gate
420767Ssjelinek (void) fprintf(stderr,
421767Ssjelinek gettext("%s: %s: error %d: %s\n"),
422767Ssjelinek cmd, mountpoint, en, errstr);
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate exit(2);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate close(fd);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate fssnap_show_status(mountpoint, opts, 1, (opts ? 0 : 1));
4290Sstevel@tonic-gate }
430767Ssjelinek static int
has_Nflag(char * opts)431767Ssjelinek has_Nflag(char *opts)
432767Ssjelinek {
433767Ssjelinek while (opts != NULL && *opts != '\0') {
434767Ssjelinek if (match(&opts, "N")) {
435767Ssjelinek return (1);
436767Ssjelinek }
437767Ssjelinek if (!opts)
438767Ssjelinek break;
439767Ssjelinek if (*opts == ',')
440767Ssjelinek opts ++;
441767Ssjelinek if (*opts == ' ')
442767Ssjelinek opts ++;
443767Ssjelinek }
444767Ssjelinek return (0);
445767Ssjelinek }
446767Ssjelinek /*
447767Ssjelinek * Parses the -o [fs specific options string] to search for the UFS -N flag.
448767Ssjelinek * Return the opts string pointing to the next position in the string if
449767Ssjelinek * match is not found. A delimiter of , or ' ' can be used depending on the
450767Ssjelinek * caller, newfs or mkfs.
451767Ssjelinek */
452767Ssjelinek static int
match(char ** opts,char * s)453767Ssjelinek match(char **opts, char *s)
454767Ssjelinek {
455767Ssjelinek char *cs;
456767Ssjelinek char *tmp_str;
457767Ssjelinek
458767Ssjelinek cs = *opts;
459767Ssjelinek
460767Ssjelinek while (*cs++ == *s) {
461767Ssjelinek if (*s++ == '\0') {
462767Ssjelinek goto true;
463767Ssjelinek }
464767Ssjelinek }
465767Ssjelinek if (*s != '\0') {
466767Ssjelinek /*
467767Ssjelinek * If we cannot find the delimiter it means we
468767Ssjelinek * have hit the end of the string.
469767Ssjelinek */
470767Ssjelinek tmp_str = strchr(*opts, ',');
471767Ssjelinek if (!tmp_str)
472767Ssjelinek tmp_str = strchr(*opts, ' ');
473767Ssjelinek
474767Ssjelinek *opts = tmp_str;
475767Ssjelinek return (0);
476767Ssjelinek }
477767Ssjelinek true:
478767Ssjelinek cs--;
479767Ssjelinek *opts = cs;
480767Ssjelinek return (1);
481767Ssjelinek }
482