home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume22
/
mntdisk
/
part02
< prev
next >
Wrap
Text File
|
1991-08-21
|
36KB
|
1,437 lines
Newsgroups: comp.sources.misc
From: Mike J. Fuller <mikef@kristen.lerc.nasa.gov>
Subject: v22i032: mntdisk - Allow general users to mount disks, Part02/03
Message-ID: <1991Aug21.162823.11581@sparky.IMD.Sterling.COM>
X-Md4-Signature: 56265c52a32f19aee4e8156bcc471174
Date: Wed, 21 Aug 1991 16:28:23 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Mike J. Fuller <mikef@kristen.lerc.nasa.gov>
Posting-number: Volume 22, Issue 32
Archive-name: mntdisk/part02
Environment: SunOS
#!/bin/sh
# this is mntdisk.shar.part.02 (part 2 of a multipart archive)
# do not concatenate these parts, unpack them in order with /bin/sh
# file mntdisk.c continued
#
if test ! -r _shar_seq_.tmp; then
echo 'Please unpack part 1 first!'
exit 1
fi
(read Scheck
if test "$Scheck" != 2; then
echo Please unpack part "$Scheck" next!
exit 1
else
exit 0
fi
) < _shar_seq_.tmp || exit 1
if test ! -f _shar_wnt_.tmp; then
echo 'x - still skipping mntdisk.c'
else
echo 'x - continuing file mntdisk.c'
sed 's/^X//' << 'SHAR_EOF' >> 'mntdisk.c' &&
X
/* Written by Mike J. Fuller (mikef@sarah.lerc.nasa.gov)
X for NASA Lewis Research Center */
X
#ifndef lint
X static char ID[] = "@(#)mntdisk.c 1.00 91/07/02";
#endif
X
#include "mntdisk.h"
#include <sys/mount.h>
X
#ifdef __STDC__
X extern int run(char *command);
X extern char *mounted(char *device);
X extern char *username(int uid);
X extern int dounmount(char *device, char *mountpoint);
#ifdef EXPORT
X extern int doexport(char *mountpoint, int ro, int unexport);
#endif
X extern int domount(char *device, char *mountpoint, char *mtype,
X char *moptstr, int mopts);
X extern int no_fs(char *device);
X extern int can_overwrite(char *device);
X extern int mountpoint_ok(char *mp, char *nmp);
X extern void setmodes(char *device, mode_t mode);
X extern int makeowner(char *device);
X extern int spinup(char *device);
#if TIMEOUT > 0
X extern void spindown(char *device, int time);
#endif
X extern int lock(char *device);
X extern int unlock(char *device);
X extern int fsck(char *device);
X extern int ufschecks(char *device, int mode, int skip);
X extern int device_ok(char *device, char *ndevice);
X extern void exit(int);
X extern void closelog(void);
#else
X extern int run();
X extern char *mounted();
X extern char *username();
X extern int dounmount();
#ifdef EXPORT
X extern int doexport();
#endif
X extern int domount();
X extern int no_fs();
X extern int can_overwrite();
X extern int mountpoint_ok();
X extern void setmodes();
X extern int makeowner();
X extern int spinup();
#if TIMEOUT > 0
X extern void spindown();
#endif
X extern int lock();
X extern int unlock();
X extern int fsck();
X extern int ufschecks();
X extern int device_ok();
X extern void exit();
X extern void closelog();
#endif
X
/*****************************************************************************/
X
static int mode;
int mask, uid, quiet = 0;
char *prog;
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
X unmountdisk(char *device, int ejectflag)
#else
X static int unmountdisk(device, ejectflag)
X char *device;
X int ejectflag;
#endif
{
X char bdevice[MAXPATHLEN], *mountpoint;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X
X if((mountpoint = mounted(bdevice)) == (char *) 0) {
X (void) fprintf(stderr, "%s: Error: device '%s' not mounted.\n", prog,
X bdevice);
X return(1);
X }
X
#ifdef EXPORT
X switch(mode) {
X case FLOPPY:
X case EOD:
X case CD:
/* XXX - should check return code, but it may fail the second time if the
X unmount fails the first time. */
X (void) doexport(mountpoint, 0, 1);
X case DOSFLOPPY:
X break;
X }
#endif
X if(dounmount(bdevice, mountpoint))
X return(1);
X
X if(! quiet)
X (void) printf("%s: '%s' unmounted from '%s'.\n", prog, bdevice,
X mountpoint);
#ifdef SYSLOG
X syslog(LOG_INFO,
X "%s unmounted '%s' from '%s'.", username(uid), device, mountpoint);
#endif
X
X switch(mode) {
X case DOSFLOPPY:
X case FLOPPY:
X setmodes(device, FLOPMODE);
X break;
X case EOD:
X setmodes(device, EODMODE);
X case CD:
X break;
X }
X
#if TIMEOUT > 0
X if(! ejectflag && (mode == EOD))
X spindown(device, TIMEOUT);
#endif
X return(0);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
X ejectdisk(char *device)
#else
static int ejectdisk(device)
X char *device;
#endif
{
X char bdevice[MAXPATHLEN], disk[MAXPATHLEN], buf[MAXPATHLEN], *c;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) strcpy(disk, device);
X disk[strlen(disk) - 1] = '\0';
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if(mode == EOD)
X (void) sprintf(buf, EODEJECT, disk);
X else
X (void) sprintf(buf, "/usr/bin/eject /dev/r%s", device);
X if(run(buf))
X return(1);
X
X if(! quiet)
X (void) printf("%s: '%s' ejected.\n", prog, disk);
#ifdef SYSLOG
X syslog(LOG_INFO, "%s ejected '%s'.", username(uid), device);
#endif
X return(0);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
X spindisk(char *device)
#else
static int spindisk(device)
X char *device;
#endif
{
X char bdevice[MAXPATHLEN], disk[MAXPATHLEN], buf[MAXPATHLEN], *c;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) strcpy(disk, device);
X disk[strlen(disk) - 1] = '\0';
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if(run(sprintf(buf, EODSTOP, disk)))
X return(1);
X
X if(! quiet)
X (void) printf("%s: '%s' spun down.\n", prog, disk);
#ifdef SYSLOG
X syslog(LOG_INFO, "%s spun down '%s'.", username(uid), device);
#endif
X return(0);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
X formatdisk(char *device, int hdflag, int batch)
#else
static int formatdisk(device, hdflag, batch)
X char *device;
X int hdflag, batch;
#endif
{
X char bdevice[MAXPATHLEN], rdevice[MAXPATHLEN], buf[MAXPATHLEN], *c;
X char eoddevice[MAXPATHLEN];
X int rc;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) sprintf(rdevice, "/dev/r%s", device);
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if((mode == EOD) && spinup(device)) {
X (void) fprintf(stderr, "%s: Error: cannot spin up drive '%s'.\n",
X prog, rdevice);
X return(1);
X }
X
#ifdef DEBUG
X if(! can_overwrite(rdevice)) {
#else
X if(uid && ! can_overwrite(rdevice)) {
#endif
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X if(! batch) {
X (void) printf("%s: Warning: formatting will destroy ", prog);
X (void) printf("any data on '%s'.\n", rdevice);
X (void) printf("Press return to continue or ^C to abort...");
X (void) gets(buf);
X }
X
X switch(mode) {
X case EOD:
X (void) strcpy(eoddevice, device);
X eoddevice[strlen(eoddevice) - 1] = '\0';
X (void) sprintf(buf, EODFORMAT, eoddevice);
X break;
X case FLOPPY:
X if(hdflag)
X (void) sprintf(buf, "/usr/bin/fdformat -f %s", rdevice);
X else
X (void) sprintf(buf, "/usr/bin/fdformat -fl %s", rdevice);
X break;
X case DOSFLOPPY:
X if(hdflag)
X (void) sprintf(buf, "/usr/bin/fdformat -fd %s", rdevice);
X else
X (void) sprintf(buf, "/usr/bin/fdformat -fdl %s", rdevice);
X break;
X }
X rc = run(buf);
X
/* XXX - this stuff used to be needed back when eodutil didn't label the
X disk after formatting. I left it here just in case it is ever needed
X again.
X if(! (rc = run(buf)) && (mode == EOD)) {
X FILE *fp;
X char fn[MAXPATHLEN];
X
X if((fp = fopen(sprintf(fn, "/tmp/%s.%d", prog, getpid()), "w")) ==
X (FILE *) 0) {
X (void) fprintf(stderr,
X "%s: Error: cannot create input file for format.\n", prog);
X return(1);
X }
X
X (void) fputs("label", fp);
X (void) fputs("quit", fp);
X fclose(fp);
#ifdef DEBUG
X rc = run(sprintf(buf, "/usr/etc/format -t 'Artecon EOD ISO' -f %s %s",
X fn, eoddevice));
#else
X rc = run(sprintf(buf,
X "/usr/etc/format -s -t 'Artecon EOD ISO' -f %s %s",
X fn, eoddevice));
#endif
X unlink(fn);
X }
X */
X
#ifdef SYSLOG
X if(! rc)
X syslog(LOG_INFO, "%s formatted '%s'.", username(uid), device);
#endif
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(rc);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
initdisk(char *device, int batch)
#else
static int initdisk(device, batch)
X char *device;
X int batch;
#endif
{
X char bdevice[MAXPATHLEN], rdevice[MAXPATHLEN], buf[MAXPATHLEN], *c;
X int rc;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) sprintf(rdevice, "/dev/r%s", device);
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if((mode == EOD) && spinup(device)) {
X (void) fprintf(stderr, "%s: Error: cannot spin up drive '%s'.\n",
X prog, rdevice);
X return(1);
X }
X
#ifdef DEBUG
X if(! can_overwrite(rdevice)) {
#else
X if(uid && ! can_overwrite(rdevice)) {
#endif
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X if(! batch) {
X (void) printf("%s: Warning: initializing will destroy ", prog);
X (void) printf("any data on '%s'.\n", rdevice);
X (void) printf("Press return to continue or ^C to abort...");
X (void) gets(buf);
X }
X
X (void) sprintf(buf, "/usr/etc/newfs %s %s", (mode == EOD) ? EODPARAMS :
X FLOPPARAMS, rdevice);
X if(run(buf)) {
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X rc = makeowner(rdevice);
#ifdef SYSLOG
X if(! rc)
X syslog(LOG_INFO, "%s initialized '%s'.", username(uid), device);
#endif
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(rc);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
checkdisk(char *device)
#else
static int checkdisk(device)
char *device;
#endif
{
X char bdevice[MAXPATHLEN], rdevice[MAXPATHLEN], *c;
X int rc;
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) sprintf(rdevice, "/dev/r%s", device);
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if((mode == EOD) && spinup(device)) {
X (void) fprintf(stderr, "%s: Error: cannot spin up drive '%s'.\n",
X prog, rdevice);
X return(1);
X }
X
X if(no_fs(rdevice)) {
X (void) fprintf(stderr, "%s: Error: '%s' has no filesystem.\n",
X prog, rdevice);
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X rc = fsck(rdevice);
#ifdef SYSLOG
X if(! rc)
X syslog(LOG_INFO, "%s checked '%s'.", username(uid), device);
#endif
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(rc);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static int
mountdisk(char *device, char *mountpoint, int ro)
#else
static int
mountdisk(device, mountpoint, ro)
X char *device, *mountpoint;
X int ro;
#endif
{
X char buf[MAXPATHLEN], bdevice[MAXPATHLEN], rdevice[MAXPATHLEN], *c, *mtype;
X int mopts = M_NEWTYPE | M_NOSUB;
X char moptstr[BUFSIZ];
X extern char *realpath();
X
X moptstr[0] = '\0';
X if((mountpoint = realpath(mountpoint, buf)) == (char *) 0) {
X perror(buf);
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X (void) sprintf(bdevice, "/dev/%s", device);
X (void) sprintf(rdevice, "/dev/r%s", device);
X
X if((c = mounted(bdevice)) != (char *) 0) {
X (void) fprintf(stderr,
X "%s: Error: '%s' is currently mounted on '%s'.\n",
X prog, bdevice, c);
X return(1);
X }
X
X if(((mode == EOD) || (mode == FLOPPY)) && ufschecks(device, mode, ro)) {
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X if(ro) {
X mopts |= M_RDONLY;
X (void) strcat(moptstr, "ro");
X }
X else
X (void) strcat(moptstr, "rw");
X
X switch(mode) {
X case FLOPPY:
X case EOD:
X mopts |= M_NOSUID;
X (void) strcat(moptstr, ",nosuid");
X mtype = "4.2";
X break;
X case CD:
X switch(no_fs(rdevice)) {
X case -1:
X return(1);
X case 0:
X mtype = "4.2";
X break;
X case 1:
X mtype = "hsfs";
X break;
X }
X break;
X case DOSFLOPPY:
X mtype = "pcfs";
X break;
X }
X
X if(domount(bdevice, mountpoint, mtype, moptstr, mopts)) {
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(device, TIMEOUT);
#endif
X return(1);
X }
X
X if(! quiet)
X (void) printf("%s: '%s' mounted on '%s'.\n", prog, device, mountpoint);
#ifdef SYSLOG
X syslog(LOG_INFO, "%s mounted '%s' on '%s'.", username(uid), device,
X mountpoint);
#endif
X
X switch(mode) {
X case FLOPPY:
X case EOD:
X setmodes(device, MODE);
X case CD:
#ifdef EXPORT
X if(doexport(mountpoint, ro, 0))
X return(1);
#endif
X break;
X case DOSFLOPPY:
X setmodes(device, MODE);
X break;
X }
X
X return(0);
}
X
/*****************************************************************************/
X
#ifdef __STDC__
static void
usage(char *device, char *mountpoint)
#else
static void usage(device, mountpoint)
X char *device, *mountpoint;
#endif
{
X switch(mode) {
X case EOD:
X (void) fprintf(stderr,
X "Usage: %s {cefimrsu}[bdlq] [disk] [dir]\n", prog);
X break;
X case FLOPPY:
X (void) fprintf(stderr,
X "Usage: %s {cefhimru}[bdlq] [disk] [dir]\n", prog);
X break;
X case CD:
X (void) fprintf(stderr,
X "Usage: %s {emu}[dlq] [disk] [dir]\n", prog);
X break;
X case DOSFLOPPY:
X (void) fprintf(stderr,
X "Usage: %s {efhmru}[bdlq] [disk] [dir]\n", prog);
X break;
X }
X
X if((mode == EOD) || (mode == FLOPPY))
X (void) fputs("Where:\tc = Check a disk\n", stderr);
X (void) fputs("\te = Eject a disk\n", stderr);
X if(mode != CD)
X (void) fputs("\tf = Format a disk\n", stderr);
X if((mode == FLOPPY) || (mode == DOSFLOPPY))
X (void)
X fputs("\th = Format a high density disk (default = low density)\n",
X stderr);
X if((mode == EOD) || (mode == FLOPPY))
X (void) fputs("\ti = Initialize a disk\n", stderr);
X (void) fputs("\tm = Mount a disk\n", stderr);
X if(mode != CD)
X (void) fputs("\tr = Mount a disk read-only (default = read-write)\n",
X stderr);
X if(mode == EOD)
X (void) fputs("\ts = Spin down a disk\n", stderr);
X (void) fputs("\tu = Unmount a disk\n", stderr);
X if(mode != CD)
X (void) fputs("\tb = Batch mode (default = interactive)\n", stderr);
X (void) fprintf(stderr, "\td = disk (default = '%s')\n", device);
X (void) fputs("\tl = Lock disk\n", stderr);
X (void) fputs("\tq = Quiet (default = verbose)\n", stderr);
X (void) fprintf(stderr,
X " dir = directory to mount disk on (default = %s)\n",
X mountpoint);
X
X exit(1);
}
X
/*****************************************************************************/
X
static char *cleanupdevice;
X
/*****************************************************************************/
X
static void cleanup(sig, code, scp, addr)
X int sig, code;
X struct sigcontext *scp;
X char *addr;
{
#if TIMEOUT > 0
X if(mode == EOD)
X spindown(cleanupdevice, TIMEOUT);
#endif
X (void) unlock(cleanupdevice);
#ifdef SYSLOG
X closelog();
#endif
X exit(sig);
}
X
/*****************************************************************************/
X
int main(argc, argv)
X int argc;
X char *argv[];
{
X int ejectflag = 0, roflag = 0, formatflag = 0, initflag = 0, lockflag = 0;
X int mountflag = 0, unmountflag = 0, checkflag = 0, spinflag = 0;
X int hdflag = 0, batchflag = 0;
X char *c, *d, *device, *mountpoint;
X
X prog = ((c = strrchr(argv[0], '/')) == (char *) 0) ? argv[0] : (c + 1);
X uid = getuid();
X mask = umask(0);
X
X if(geteuid()) {
X (void) fprintf(stderr,
X "%s: Error: must be running as root or set-uid root.\n", prog);
X exit(1);
X }
X
#ifdef ENABLE_EOD
X if(! strcmp(prog, "eodmount")) {
X mode = EOD;
X device = EODDEVICE;
X mountpoint = EODMNT;
X }
X else
#endif
#ifdef ENABLE_FLOPPY
X if(! strcmp(prog, "fdmount")) {
X mode = FLOPPY;
X device = FDDEVICE;
X mountpoint = FLOPMNT;
X }
X else
#endif
#ifdef ENABLE_DOSFLOPPY
X if(! strcmp(prog, "dosmount")) {
X mode = DOSFLOPPY;
X device = FDDEVICE;
X mountpoint = DOSMNT;
X }
X else
#endif
#ifdef ENABLE_CD
X if(! strcmp(prog, "cdmount")) {
X mode = CD;
X device = CDDEVICE;
X mountpoint = CDMNT;
X }
X else
#endif
X {
#ifdef DEBUG
X mode = FLOPPY;
X device = FDDEVICE;
X mountpoint = FLOPMNT;
#else
X (void) fprintf(stderr, "%s: Error: argv[0].\n", prog);
X exit(1);
#endif
X }
X
X if(argc == 1)
X usage(device, mountpoint);
X argv++;
X for(c = *argv++; *c != '\0'; c++)
X if(mode == CD)
X switch (*c) {
X case 'e':
X ++ejectflag;
X break;
X case 'm':
X case 'r':
X ++mountflag;
X ++roflag;
X break;
X case 'u':
X ++unmountflag;
X break;
X case 'd':
X if(*argv == (char *) 0) {
X (void) fprintf(stderr, "Error: a disk must be specified ");
X (void) fprintf(stderr, "with the 'd' option.\n");
X usage(device, mountpoint);
X }
X d = *argv++;
X if(! device_ok(device, d)) {
X (void) fprintf(stderr, "Error: invalid disk '%s'.\n", d);
X usage(device, mountpoint);
X }
X device = d;
X break;
X case 'l':
X ++lockflag;
X break;
X case 'q':
X ++quiet;
X break;
X case '-':
X break;
X default:
X (void) fprintf(stderr, "Error: unknown option '%c'.\n", *c);
X usage(device, mountpoint);
X break;
X }
X else
X switch (*c) {
X case 'c':
X ++checkflag;
X break;
X case 'e':
X ++ejectflag;
X break;
X case 'f':
X ++formatflag;
X break;
X case 'h':
X if((mode != FLOPPY) && (mode != DOSFLOPPY)) {
X (void) fprintf(stderr, "Error: unknown option '%c'.\n", *c);
X usage(device, mountpoint);
X }
X ++hdflag;
X ++formatflag;
X break;
X case 'i':
X ++initflag;
X break;
X case 'm':
X ++mountflag;
X break;
X case 's':
X if(mode != EOD) {
X (void) fprintf(stderr, "Error: unknown option '%c'.\n", *c);
X usage(device, mountpoint);
X }
X ++spinflag;
X break;
X case 'u':
X ++unmountflag;
X break;
X case 'b':
X ++batchflag;
X break;
X case 'd':
X if(*argv == (char *) 0) {
X (void) fprintf(stderr, "Error: a disk must be specified ");
X (void) fprintf(stderr, "with the 'd' option.\n");
X usage(device, mountpoint);
X }
X d = *argv++;
X if(! device_ok(device, d)) {
X (void) fprintf(stderr, "Error: invalid disk '%s'.\n", d);
X usage(device, mountpoint);
X }
X device = d;
X break;
X case 'l':
X ++lockflag;
X break;
X case 'q':
X ++quiet;
X break;
X case 'r':
X ++mountflag;
X ++roflag;
X break;
X case '-':
X break;
X default:
X (void) fprintf(stderr, "Error: unknown option '%c'.\n", *c);
X usage(device, mountpoint);
X break;
X }
X
X
X if(*argv != (char *) 0)
X d = *argv++;
X else
X d = mountpoint;
X if(mountflag && ! mountpoint_ok(mountpoint, d))
X usage(device, mountpoint);
X mountpoint = d;
X
X if((*argv != (char *) 0) ||
X ! (checkflag || ejectflag || formatflag || initflag || mountflag ||
X spinflag || unmountflag) ||
X (spinflag && mountflag) || (spinflag && ejectflag))
X usage(device, mountpoint);
X
X cleanupdevice = device;
X (void) signal(SIGHUP, cleanup);
X (void) signal(SIGINT, cleanup);
#ifndef DEBUG
X (void) signal(SIGABRT, cleanup);
#endif
X
X if(lock(device))
X exit(1);
#ifdef SYSLOG
X openlog(prog, LOG_NOWAIT, SYSLOG);
#endif
X if((unmountflag && unmountdisk(device, ejectflag)) ||
X (formatflag && formatdisk(device, hdflag, batchflag)) ||
X (initflag && initdisk(device, batchflag || formatflag)) ||
X (checkflag && checkdisk(device)) ||
X (spinflag && spindisk(device)) ||
X (ejectflag && ejectdisk(device)) ||
X (mountflag && mountdisk(device, mountpoint, roflag))) {
X (void) unlock(device);
#ifdef SYSLOG
X closelog();
#endif
X exit(1);
X }
X if(! (mountflag && lockflag)) {
#ifdef SYSLOG
X closelog();
#endif
X (void) unlock(device);
X }
X
X return(0);
}
SHAR_EOF
echo 'File mntdisk.c is complete' &&
chmod 0644 mntdisk.c ||
echo 'restore of mntdisk.c failed'
Wc_c="`wc -c < 'mntdisk.c'`"
test 19477 -eq "$Wc_c" ||
echo 'mntdisk.c: original size 19477, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= mntdisk.h ==============
if test -f 'mntdisk.h' -a X"$1" != X"-c"; then
echo 'x - skipping mntdisk.h (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting mntdisk.h (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mntdisk.h' &&
/* mntdisk.h -- compile time options for MNTDISK */
X
/* Mode for disk device special files when disk is mounted. */
#define MODE 0440
X
/* Syslog(3) facility to log user actions under.
X May be commented out to save some code if you're not going to use it. */
#define SYSLOG LOG_LOCAL1
X
/* Don't check for device special files and skip the default fsck(8) for
X users in group wheel.
X May be commented out if you don't trust people in group wheel :-) */
#define WHEEL
X
/* Options to be passed to exportfs(8) when the disk is mounted.
X May be commented out if you don't want to export mounted disks. */
#define EXPORT "access=your_netgroup"
X
/* Enable FDMOUNT. */
/* Comment out if you don't want users to be able to mount UFS floppies. */
#define ENABLE_FLOPPY
X
/* Enable CDMOUNT. */
/* Comment out if you don't want users to be able to mount CD-ROMs. */
#define ENABLE_CD
X
/* Enable EODMOUNT. */
/* Comment out if you don't want users to be able to mount EODs. */
/* #define ENABLE_EOD */
X
/* Enable DOSMOUNT. */
/* Comment out if you don't want users to be able to mount DOS floppies. */
#define ENABLE_DOSFLOPPY
X
/* The rest of these PROBABLY don't need to be changed.
X If you have preferences, then they should be self-explanatory :-) */
#define FDDEVICE "fd0c"
#define FLOPPARAMS "-b 4096 -f 512 -m 5 -o space -C 7"
#define FLOPMODE 0666
#define FLOPMNT "/floppy"
#define DOSMNT "/pcfs"
X
#define CDDEVICE "sr0"
#define CDMNT "/cdrom"
X
#define EODDEVICE "eod0c"
#define EODEJECT "/usr/local/etc/eodutil.new %s eject"
#define EODFORMAT "/usr/local/etc/eodutil.new %s format"
#define EODSTART "/usr/local/etc/eodutil.old %s start"
#define EODSTOP "/usr/local/etc/eodutil.old %s stop"
#define EODPARAMS "-c 128 -i 16384 -m 5 -o space -r 2400 -C 7"
#define EODMODE 0660
#define EODMNT "/eod"
#define TIMEOUT 0
X
/* Nothing after here should need to be changed. */
#define EOD 1
#define FLOPPY 2
#define CD 3
#define DOSFLOPPY 4
X
#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <syslog.h>
SHAR_EOF
chmod 0644 mntdisk.h ||
echo 'restore of mntdisk.h failed'
Wc_c="`wc -c < 'mntdisk.h'`"
test 2056 -eq "$Wc_c" ||
echo 'mntdisk.h: original size 2056, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= mntdisk.man ==============
if test -f 'mntdisk.man' -a X"$1" != X"-c"; then
echo 'x - skipping mntdisk.man (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting mntdisk.man (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mntdisk.man' &&
.\" @(#)mntdisk.l 1.00 91/06/06
.TH MNTDISK L "6 June 1991"
.SH NAME
mntdisk \- allow a user to manipulate a disk
.SH SYNOPSIS
.B fdmount
{
.B cefhimru
}[
.B bdlq
] [
.I disk
] [
.I dir
]
.LP
.B dosmount
{
.B efhmru
}[
.B bdlq
] [
.I disk
] [
.I dir
]
.LP
.B eodmount
{
.B cefimrsu
}[
.B bdlq
] [
.I disk
] [
.I dir
]
.LP
.B cdmount
{
.B emu
}[
.B dlq
] [
.I disk
] [
.I dir
]
.SH DESCRIPTION
All four incarnations of
.B mntdisk
allow users to perform basic operations on some type of removable
disk media in a reasonably secure manner.
.SH FUNCTIONS
.TP
.B c
Check a
.IR disk .
This function merely runs
.B fsck(8)
to check the consistency of the filesystem on the
.IR disk .
Therefore, it is available only under
.B fdmount
and
.BR eodmount .
.TP
.B e
Eject a
.IR disk .
This function causes the
.I disk
to be ejected from the drive. It is available under all four
incarnation of
.BR mntdisk ,
although it may seem superfluous for eraseable-optical disk drives and
cd-rom disk drives.
.TP
.B f
Format a
.IR disk .
Under
.B fdmount
and
.B eodmount
it does a low-level format on a
.IR disk ,
while under
.B dosmount
it does a low-level format
.B and
puts a DOS filesystem on the
.IR disk .
Therefore, under
.B fdmount
and
.BR eodmount ,
a disk needs to be formatted and initialized (see the
.B i
option) before it can be used, whereas under
.B dosmount
a disk only needs to be formatted before it can be used.
.TP
.B h
Format a high density
.IR disk .
This option is available only under
.B dosmount
and
.BR fdmount ,
and behaves the same as the
.B f
option (above), except it formats a high density (1.44M) disk whereas
the
.B f
option formats a low density (720K) disk.
.TP
.B i
Initialize a
.IR disk .
This option is available under
.B fdmount
and
.BR eodmount .
It places a UNIX filesystem on the
.IR disk ,
identical in structure to the UNIX filesystem which you are accustomed
to. Note that although this option is normally used in conjunction
with the
.B f
option (above), once the disk has been formatted, it can be
initialized repeatedly without being reformatted if you wish to
discard all the information on the disk quickly.
.TP
.B m
Mount a
.IR disk
on directory
.IR dir .
This causes the filesystem on the
.I disk
to be placed in the overall file system hierarchy at the pathname
location
.IR dir ,
which must already exist. If
.I dir
was not empty, its original contents will remain covered until the
.I disk
is unmounted. If no
.I dir
is given, the
.I disk
will be mounted on a default directory as specified below.
.TP
.B r
Mount a
.I disk
read-only. This option is the same as the
.B m
option (above), except that the
.I disk
cannot be written to. This may speed file access on slow disks since
the access times on files won't be updated. For obvious reasons, this
is the same as the
.B m
option (above) for CD ROMs.
.TP
.B s
Spin down a
.I disk.
This option is only available under
.BR eodmount ,
since only optical drives can be spun down manually. This causes the
.I disk
to stop spinning until it is mounted or otherwise accessed again.
This option is good for saving wear and tear on the disk drive if you
wish to leave a disk in the drive for later use. Note that the
.I disk
cannot be spun down if it is currently mounted or otherwise busy.
.TP
.B u
Unmount a
.IR disk .
This option causes the
.I disk
to be removed from the filesystem hierarchy.
.SH OPTIONS
.TP
.B b
Batch mode.
In this mode, user input is never asked for and an affirmative answer
is assumed to all questions which would normally be asked. Note that
this option may be dangerous and is best used only by users who are
familiar with all the questions which may be asked.
.TP
.B d
.IR Disk .
This option specifies an alternate disk device. Note that, for
obvious security reasons, '/dev/' is assumed to be prepended to the
device name and only variations on the default device can be used.
.TP
.B l
Lock
.IR disk .
Normally a
.I disk
that has been mounted by one user may be unmounted by any other user.
Of course, if the
.I disk
is currently busy, no one can unmount it. Therefore, this should not
be a problem unless you are really paranoid. When this option is
specified, only the user who originally mounted the
.I disk
can unmount it. Use this option with care because if you mount a
disk, forget about it, and go home, you will leave the drive useless for
others.
.TP
.B q
Quiet. In this mode, informational output is suppressed. Error
messages, however, will still be printed when necessary.
.SH EXAMPLES
.LP
To check and mount an erasable-optical disk on the default directory,
one might use:
.IP
.B sarah% eodmount cm
.LP
To format, initialize, and mount a floppy disk on ~/tmp, one might
use:
.IP
.B holodeck% fdmount fim ~/tmp
.LP
To mount and lock a read-only DOS floppy disk on the default
directory, one might use:
.IP
.B panic% dosmount rl
.LP
To unmount and eject a CD-ROM, one might use:
.IP
.B dredd% cdmount ue
.SH FILES
.PD 0
.TP 20
.B /pcfs
default directory upon which to mount DOS disks
.TP
.B /cdrom
default directory upon which to mount CD ROM disk
.TP
.B /eod
default directory upon which to mount erasable-optical disks
.TP
.B /floppy
default directory upon which to mount floppy disks
.PD
.SH SEE ALSO
.BR fsck (8),
.BR mount (8),
.BR umount (8).
.SH DIAGNOSTICS
.BI "mntdisk: " filename ": device busy"
.br
There is a process running with files open on the
.IR disk ,
most likely your current shell.
.LP
Most other error messages should be fairly self explanatory, although
some of the less common error messages may seem somewhat cryptic to
the inexperienced user.
.SH AUTHOR
Mike J. Fuller
.br
NASA Lewis Research Center
.br
mikef@sarah.lerc.nasa.gov
.PD
.SH BUGS
Mounting a disk with the right magic but a garbage filesystem will
surely crash the system. Of course, if you are truly malicious and
only want to crash the system, the power switch is located on the back
of the computer by the power cord. It is faster and doesn't leave a
log of who did it.
.LP
.B cdmount
doesn't check for device special files on 4.2 filesystem CD ROMs. I
would check for it, but that slows down the mounting process and I
won't lose sleep over someone going to the trouble to have a custom CD
ROM with device special files made.
.LP
I have seen instances where trying access the floppy drive when there
is no disk in it will crash the system, but have been unable to
reproduce it. However, this is an operating system bug and something
I can't check for, so if you only want to crash the system, see above.
.LP
The difference between formatting and initializing a disk is confusing
for many users and is only compounded by the difference for
.BR dosmount .
However, if you have ever waited for an erasable-optical disk to
format and initialize, as opposed to just initialize, you would want
the options separate, too.
.LP
Exporting of disks is a compile time option. Thus, there is no way
for a user to control the exporting of his disk.
.LP
Because a filesystem must be unexported before it is unmounted, if the
unmount fails because a filesystem is busy, the unexport will fail on
subsequent attempts to unmount the filesystem because it was already
done on the first attempt.
SHAR_EOF
chmod 0644 mntdisk.man ||
echo 'restore of mntdisk.man failed'
Wc_c="`wc -c < 'mntdisk.man'`"
test 7206 -eq "$Wc_c" ||
echo 'mntdisk.man: original size 7206, current size' "$Wc_c"
rm -f _shar_wnt_.tmp
fi
# ============= mntdisk.ps ==============
if test -f 'mntdisk.ps' -a X"$1" != X"-c"; then
echo 'x - skipping mntdisk.ps (File already exists)'
rm -f _shar_wnt_.tmp
else
> _shar_wnt_.tmp
echo 'x - extracting mntdisk.ps (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'mntdisk.ps' &&
%!PS-Adobe-1.0
%%Creator: sarah:mikef (Mike J. Fuller,105-204,8163,867-7164)
%%Title: stdin
%%CreationDate: Fri Jun 7 13:20:31 1991
%%DocumentFonts: Times-Roman Times-Italic Times-Bold Symbol Times-Roman DIThacks
%%Pages: (atend)
%%EndComments
% Start of pscat.pro -- prolog for troff translator
% Copyright (c) 1985,1987 Adobe Systems Incorporated. All Rights Reserved.
% GOVERNMENT END USERS: See Notice file in TranScript library directory
% -- probably /usr/lib/ps/Notice
% RCS: $Header: pscat.pro,v 2.2 87/11/17 16:40:32 byron Rel $
save /pscatsave exch def
/$pscat 50 dict def
$pscat begin
/fm [1 0 0 1 0 0] def
/xo 0 def /yo 0 def
/M /moveto load def
/R /show load def
/S {exch currentpoint exch pop moveto show}def
/T {exch currentpoint pop exch moveto show}def
/U {3 1 roll moveto show}def
/siz 0 def
/font 0 def
/Z {/siz exch def SF}def
/F {/font exch def SF}def
/SF{font 0 ne
X {catfonts font 1 sub get fm 0 siz put fm 3 siz neg put
X fm makefont setfont}if}def
/BP{save/catsv exch def 0 792 translate 72 432 div dup neg scale
X xo yo translate 0 0 moveto}def
/BPL{save/catsv exch def 72 8.25 mul 792 translate -90 rotate
X 72 432 div dup neg scale xo yo translate 0 0 moveto}def
/EP{catsv restore showpage}def
X
/SetStTime{statusdict /manualfeedtimeout 120 put} def
/SetStatus{statusdict /manualfeed true put
X statusdict /product get (LaserWriter) eq
X {version (23.0) eq % Don't redefine EP if printer is not "Classic LW"
X {/EP {catsv restore
X {statusdict /printerstatus get exec 16#22000000 and 0 eq{exit}if}loop
X showpage}def}if }if}def
% definitions for PPROC callback functions
% each PPROC is called with the following number on the stack:
% pointsize charcode railmag pswidth pschar x y wid
/$pprocs 50 dict def
/fractm [.65 0 0 .6 0 0] def
% fractions
/PS1{gsave $pprocs begin
X /wid exch def pop pop pop pop pop /ch exch def /size exch def
X /pair $pprocs ch get def /cf currentfont def
X cf fractm makefont setfont
X 0 .3 size mul 6 mul 2 copy neg rmoveto pair 0 get show rmoveto
X currentfont cf setfont (\244) show setfont
X pair 1 get show grestore wid .06 div 0 rmoveto end}def
$pprocs begin
8#34 [(1)(4)] def
8#36 [(1)(2)] def
8#46 [(3)(4)] def
end
% DIThacks fonts for some special chars
50 dict dup begin
/FontType 3 def
/FontName /DIThacks def
/FontMatrix [.001 0.0 0.0 .001 0.0 0.0] def
/FontBBox [-220 -280 900 900] def% a lie but ...
/Encoding 256 array def
0 1 255{Encoding exch /.notdef put}for
Encoding
X dup 8#040/space put %space
X dup 8#110/rc put %right ceil
X dup 8#111/lt put %left top curl
X dup 8#112/bv put %bold vert
X dup 8#113/lk put %left mid curl
X dup 8#114/lb put %left bot curl
X dup 8#115/rt put %right top curl
X dup 8#116/rk put %right mid curl
X dup 8#117/rb put %right bot curl
X dup 8#120/rf put %right floor
X dup 8#121/lf put %left floor
X dup 8#122/lc put %left ceil
X dup 8#140/sq put %square
X dup 8#141/bx put %box
X dup 8#142/ci put %circle
X dup 8#143/br put %box rule
X dup 8#144/rn put %root extender
X dup 8#145/vr put %vertical rule
X dup 8#146/ob put %outline bullet
X dup 8#147/bu put %bullet
X dup 8#150/ru put %rule
X dup 8#151/ul put %underline
X pop
/DITfd 100 dict def
/BuildChar{0 begin
X /cc exch def /fd exch def
X /charname fd /Encoding get cc get def
X /charwid fd /Metrics get charname get def
X /charproc fd /CharProcs get charname get def
X charwid 0 fd /FontBBox get aload pop setcachedevice
X 40 setlinewidth
X newpath 0 0 moveto gsave charproc grestore
X end}def
/BuildChar load 0 DITfd put
%/UniqueID 5 def
/CharProcs 50 dict def
CharProcs begin
/space{}def
/.notdef{}def
/ru{500 0 rls}def
/rn{0 750 moveto 500 0 rls}def
/vr{20 800 moveto 0 -770 rls}def
SHAR_EOF
true || echo 'restore of mntdisk.ps failed'
fi
echo 'End of part 2'
echo 'File mntdisk.ps is continued in part 3'
echo 3 > _shar_seq_.tmp
exit 0
exit 0 # Just in case...
--
Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
Sterling Software, IMD UUCP: uunet!sparky!kent
Phone: (402) 291-8300 FAX: (402) 291-4362
Please send comp.sources.misc-related mail to kent@uunet.uu.net.