#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <sys/mnttab.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <locale.h>
#include <sys/stat.h>
#include <string.h>
#include <fslib.h>
#define NAME_MAX 64
#define FSTYPE "proc"
static void rpterr(char *, char *);
static void do_mount(char *, char *, int);
static void usage(void);
static char optbuf[MAX_MNTOPT_STR] = { '\0', };
static int optsize = 0;
static int roflag = 0;
static int mflg = 0;
static int Oflg = 0;
static int qflg = 0;
static char typename[NAME_MAX], *myname;
static char fstype[] = FSTYPE;
int
main(int argc, char *argv[])
{
char *special, *mountp;
int errflag = 0;
int cc;
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
myname = strrchr(argv[0], '/');
if (myname)
myname++;
else
myname = argv[0];
(void) snprintf(typename, sizeof (typename), "%s %s", fstype, myname);
argv[0] = typename;
while ((cc = getopt(argc, argv, "?o:rmOq")) != -1)
switch (cc) {
case 'm':
mflg++;
break;
case 'r':
if (roflag)
errflag = 1;
else
roflag++;
break;
case 'O':
Oflg++;
break;
case 'o':
if (strlcpy(optbuf, optarg, sizeof (optbuf)) >=
sizeof (optbuf)) {
(void) fprintf(stderr,
gettext("%s: Invalid argument: %s\n"),
myname, optarg);
return (2);
}
optsize = strlen(optbuf);
break;
case 'q':
qflg = 1;
break;
case '?':
errflag = 1;
break;
}
if (((argc - optind) != 2) || (errflag))
usage();
special = argv[optind++];
mountp = argv[optind++];
do_mount(special, mountp, roflag ? MS_RDONLY : 0);
return (0);
}
void
rpterr(char *bs, char *mp)
{
switch (errno) {
case EPERM:
(void) fprintf(stderr, gettext("%s: insufficient privileges\n"),
myname);
break;
case ENXIO:
(void) fprintf(stderr, gettext("%s: %s no such device\n"),
myname, bs);
break;
case ENOTDIR:
(void) fprintf(stderr,
gettext("%s: %s not a directory\n\tor a component of %s is not a directory\n"),
myname, mp, bs);
break;
case ENOENT:
(void) fprintf(stderr,
gettext("%s: %s or %s, no such file or directory\n"),
myname, bs, mp);
break;
case EINVAL:
(void) fprintf(stderr, gettext("%s: %s is not this fstype.\n"),
myname, bs);
break;
case EBUSY:
(void) fprintf(stderr,
gettext("%s: %s is already mounted or %s is busy\n"),
myname, bs, mp);
break;
case ENOTBLK:
(void) fprintf(stderr, gettext("%s: %s not a block device\n"),
myname, bs);
break;
case EROFS:
(void) fprintf(stderr, gettext("%s: %s write-protected\n"),
myname, bs);
break;
case ENOSPC:
(void) fprintf(stderr,
gettext("%s: the state of %s is not okay\n"
"\tand it was attempted to mount read/write\n"),
myname, bs);
break;
default:
perror(myname);
(void) fprintf(stderr, gettext("%s: cannot mount %s\n"),
myname, bs);
}
}
static void
do_mount(char *special, char *mountp, int rflag)
{
char *savedoptbuf;
if ((savedoptbuf = strdup(optbuf)) == NULL) {
(void) fprintf(stderr, gettext("%s: out of memory\n"),
myname);
exit(2);
}
if (Oflg)
rflag |= MS_OVERLAY;
if (mflg)
rflag |= MS_NOMNTTAB;
if (mount(special, mountp, rflag | MS_OPTIONSTR, fstype, NULL, 0,
optbuf, MAX_MNTOPT_STR)) {
rpterr(special, mountp);
exit(2);
}
if (optsize && !qflg)
cmp_requested_to_actual_options(savedoptbuf, optbuf,
special, mountp);
}
static void
usage(void)
{
(void) fprintf(stderr,
gettext("%s usage:\n%s [-F %s] [-r] [-o specific_options] "
"{special | mount_point}\n%s [-F %s] [-r] [-o specific_options]"
" special mount_point\n"),
fstype, myname, fstype, myname, fstype);
exit(1);
}