a237e38e9161f0acd6451439d4a7dd597e66291dth/*
a237e38e9161f0acd6451439d4a7dd597e66291dth * CDDL HEADER START
a237e38e9161f0acd6451439d4a7dd597e66291dth *
a237e38e9161f0acd6451439d4a7dd597e66291dth * The contents of this file are subject to the terms of the
a237e38e9161f0acd6451439d4a7dd597e66291dth * Common Development and Distribution License (the "License").
a237e38e9161f0acd6451439d4a7dd597e66291dth * You may not use this file except in compliance with the License.
a237e38e9161f0acd6451439d4a7dd597e66291dth *
a237e38e9161f0acd6451439d4a7dd597e66291dth * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a237e38e9161f0acd6451439d4a7dd597e66291dth * or http://www.opensolaris.org/os/licensing.
a237e38e9161f0acd6451439d4a7dd597e66291dth * See the License for the specific language governing permissions
a237e38e9161f0acd6451439d4a7dd597e66291dth * and limitations under the License.
a237e38e9161f0acd6451439d4a7dd597e66291dth *
a237e38e9161f0acd6451439d4a7dd597e66291dth * When distributing Covered Code, include this CDDL HEADER in each
a237e38e9161f0acd6451439d4a7dd597e66291dth * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a237e38e9161f0acd6451439d4a7dd597e66291dth * If applicable, add the following below this CDDL HEADER, with the
a237e38e9161f0acd6451439d4a7dd597e66291dth * fields enclosed by brackets "[]" replaced with your own identifying
a237e38e9161f0acd6451439d4a7dd597e66291dth * information: Portions Copyright [yyyy] [name of copyright owner]
a237e38e9161f0acd6451439d4a7dd597e66291dth *
a237e38e9161f0acd6451439d4a7dd597e66291dth * CDDL HEADER END
a237e38e9161f0acd6451439d4a7dd597e66291dth */
a237e38e9161f0acd6451439d4a7dd597e66291dth/*
a237e38e9161f0acd6451439d4a7dd597e66291dth * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
a237e38e9161f0acd6451439d4a7dd597e66291dth * Use is subject to license terms.
a237e38e9161f0acd6451439d4a7dd597e66291dth */
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth#pragma ident "%Z%%M% %I% %E% SMI"
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <stdio.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <stdlib.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <string.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <libintl.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <errno.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/fstyp.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/fsid.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/mntent.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/mnttab.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/mount.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/signal.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <sys/stat.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <fslib.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth#include <locale.h>
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth#define RET_OK 0
a237e38e9161f0acd6451439d4a7dd597e66291dth#define RET_ERR 33
a237e38e9161f0acd6451439d4a7dd597e66291dth#define EXIT_MAGIC 2
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic void usage(void);
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic char optbuf[MAX_MNTOPT_STR] = { '\0', };
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic int optsize = 0;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic char fstype[] = "sharefs";
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth/*
a237e38e9161f0acd6451439d4a7dd597e66291dth * usage: mount [-Ormq] [-o options] special mountp
a237e38e9161f0acd6451439d4a7dd597e66291dth *
a237e38e9161f0acd6451439d4a7dd597e66291dth * This mount program is exec'ed by /usr/sbin/mount if '-F sharefs' is
a237e38e9161f0acd6451439d4a7dd597e66291dth * specified.
a237e38e9161f0acd6451439d4a7dd597e66291dth */
a237e38e9161f0acd6451439d4a7dd597e66291dthint
a237e38e9161f0acd6451439d4a7dd597e66291dthmain(int argc, char *argv[])
a237e38e9161f0acd6451439d4a7dd597e66291dth{
a237e38e9161f0acd6451439d4a7dd597e66291dth int c;
a237e38e9161f0acd6451439d4a7dd597e66291dth char *special; /* Entity being mounted */
a237e38e9161f0acd6451439d4a7dd597e66291dth char *mountp; /* Entity being mounted on */
a237e38e9161f0acd6451439d4a7dd597e66291dth char *savedoptbuf;
a237e38e9161f0acd6451439d4a7dd597e66291dth char *myname;
a237e38e9161f0acd6451439d4a7dd597e66291dth char *typename;
a237e38e9161f0acd6451439d4a7dd597e66291dth int flags = 0;
a237e38e9161f0acd6451439d4a7dd597e66291dth int error_flag = 0;
a237e38e9161f0acd6451439d4a7dd597e66291dth int q_flag = 0;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth int len;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) setlocale(LC_ALL, "");
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth#if !defined(TEXT_DOMAIN)
a237e38e9161f0acd6451439d4a7dd597e66291dth#define TEXT_DOMAIN "SYS_TEST"
a237e38e9161f0acd6451439d4a7dd597e66291dth#endif
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) textdomain(TEXT_DOMAIN);
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth myname = strrchr(argv[0], '/');
a237e38e9161f0acd6451439d4a7dd597e66291dth myname = myname ? myname + 1 : argv[0];
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth len = strlen(fstype) + 1 + strlen(myname);
a237e38e9161f0acd6451439d4a7dd597e66291dth typename = malloc(len + 1);
a237e38e9161f0acd6451439d4a7dd597e66291dth if (!typename) {
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) fprintf(stderr, gettext("%s: out of memory\n"),
a237e38e9161f0acd6451439d4a7dd597e66291dth myname);
a237e38e9161f0acd6451439d4a7dd597e66291dth return (EXIT_MAGIC);
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) snprintf(typename, len, "%s %s", fstype, myname);
a237e38e9161f0acd6451439d4a7dd597e66291dth argv[0] = typename;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth while ((c = getopt(argc, argv, "o:rmOq")) != EOF) {
a237e38e9161f0acd6451439d4a7dd597e66291dth switch (c) {
a237e38e9161f0acd6451439d4a7dd597e66291dth case '?':
a237e38e9161f0acd6451439d4a7dd597e66291dth error_flag = 1;
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth case 'o':
a237e38e9161f0acd6451439d4a7dd597e66291dth if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
a237e38e9161f0acd6451439d4a7dd597e66291dth sizeof (optbuf)) {
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) fprintf(stderr,
a237e38e9161f0acd6451439d4a7dd597e66291dth gettext("%s: Invalid argument: %s\n"),
a237e38e9161f0acd6451439d4a7dd597e66291dth myname, optarg);
a237e38e9161f0acd6451439d4a7dd597e66291dth free(typename);
a237e38e9161f0acd6451439d4a7dd597e66291dth return (EXIT_MAGIC);
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth optsize = strlen(optbuf);
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth case 'O':
a237e38e9161f0acd6451439d4a7dd597e66291dth flags |= MS_OVERLAY;
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth case 'r':
a237e38e9161f0acd6451439d4a7dd597e66291dth flags |= MS_RDONLY;
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth case 'm':
a237e38e9161f0acd6451439d4a7dd597e66291dth flags |= MS_NOMNTTAB;
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth case 'q':
a237e38e9161f0acd6451439d4a7dd597e66291dth q_flag = 1;
a237e38e9161f0acd6451439d4a7dd597e66291dth break;
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth default:
a237e38e9161f0acd6451439d4a7dd597e66291dth usage();
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth if ((argc - optind != 2) || error_flag) {
a237e38e9161f0acd6451439d4a7dd597e66291dth usage();
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth special = argv[argc - 2];
a237e38e9161f0acd6451439d4a7dd597e66291dth mountp = argv[argc - 1];
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dth if ((savedoptbuf = strdup(optbuf)) == NULL) {
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) fprintf(stderr, gettext("%s: out of memory\n"),
a237e38e9161f0acd6451439d4a7dd597e66291dth myname);
a237e38e9161f0acd6451439d4a7dd597e66291dth free(typename);
a237e38e9161f0acd6451439d4a7dd597e66291dth exit(EXIT_MAGIC);
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth if (mount(special, mountp, flags | MS_OPTIONSTR, fstype, NULL, 0,
a237e38e9161f0acd6451439d4a7dd597e66291dth optbuf, MAX_MNTOPT_STR)) {
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) fprintf(stderr, "mount: ");
a237e38e9161f0acd6451439d4a7dd597e66291dth perror(special);
a237e38e9161f0acd6451439d4a7dd597e66291dth free(typename);
a237e38e9161f0acd6451439d4a7dd597e66291dth exit(RET_ERR);
a237e38e9161f0acd6451439d4a7dd597e66291dth }
a237e38e9161f0acd6451439d4a7dd597e66291dth if (optsize && !q_flag)
a237e38e9161f0acd6451439d4a7dd597e66291dth cmp_requested_to_actual_options(savedoptbuf, optbuf,
a237e38e9161f0acd6451439d4a7dd597e66291dth special, mountp);
a237e38e9161f0acd6451439d4a7dd597e66291dth free(typename);
a237e38e9161f0acd6451439d4a7dd597e66291dth return (RET_OK);
a237e38e9161f0acd6451439d4a7dd597e66291dth}
a237e38e9161f0acd6451439d4a7dd597e66291dth
a237e38e9161f0acd6451439d4a7dd597e66291dthstatic void
a237e38e9161f0acd6451439d4a7dd597e66291dthusage(void)
a237e38e9161f0acd6451439d4a7dd597e66291dth{
a237e38e9161f0acd6451439d4a7dd597e66291dth (void) fprintf(stderr,
a237e38e9161f0acd6451439d4a7dd597e66291dth gettext("Usage: mount [-Ormq] [-o options] special mountpoint\n"));
a237e38e9161f0acd6451439d4a7dd597e66291dth exit(RET_ERR);
a237e38e9161f0acd6451439d4a7dd597e66291dth}