vnconfig.c: removed all the silly mount/swapon functionality that never
belonged there. much of it didn't work anyway. vnconfig.8: update man page. still needs work.
This commit is contained in:
parent
3dddacd1ce
commit
481ef64aa0
|
@ -41,21 +41,16 @@
|
|||
.Os BSD 4
|
||||
.Sh NAME
|
||||
.Nm vnconfig
|
||||
.Nd configure and enable vnode disks
|
||||
.Nd configure vnode disks
|
||||
.Sh SYNOPSIS
|
||||
.Nm vnconfig
|
||||
.Op Fl cdeuv
|
||||
.Op Fl cuv
|
||||
.Ar special_file Ar regular_file
|
||||
.Oo Ar feature Oc
|
||||
.Nm vnconfig
|
||||
.Fl a
|
||||
.Op Fl cdeuv
|
||||
.Op Fl f Ar config_file
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm vnconfig
|
||||
command configures and enables vnode pseudo disk devices.
|
||||
The first form of the command will associate the special file
|
||||
command configures vnode pseudo disk devices.
|
||||
It will associate the special file
|
||||
.Ar special_file
|
||||
with the regular file
|
||||
.Ar regular_file
|
||||
|
@ -71,18 +66,8 @@ If successful, references to
|
|||
.Ar special_file
|
||||
will access the contents of
|
||||
.Ar regular_file .
|
||||
.It Fl e
|
||||
Configures the device and enables any
|
||||
.Ar feature
|
||||
that was specified.
|
||||
If no feature was specified,
|
||||
.Fl e
|
||||
is the same as
|
||||
.Fl c .
|
||||
.It Fl d
|
||||
Disables (if possible) the specified feature.
|
||||
.It Fl u
|
||||
Disables and ``unconfigures'' the device.
|
||||
Unconfigures the device.
|
||||
.It Fl v
|
||||
Print messages to stdout describing actions taken.
|
||||
.El
|
||||
|
@ -90,52 +75,10 @@ Print messages to stdout describing actions taken.
|
|||
If no action option is given,
|
||||
.Fl c
|
||||
is assumed.
|
||||
.Pp
|
||||
The
|
||||
.Ar feature
|
||||
argument specifies a feature that can be enabled via the
|
||||
.Fl e
|
||||
option:
|
||||
.Bl -tag -width indent
|
||||
.It Dv swap
|
||||
Swapping is enabled on the special file.
|
||||
See
|
||||
.Xr swapon 2 .
|
||||
.It Dv Pf mountro= Pa mount_point
|
||||
The special file is mounted read-only on
|
||||
.Ar mount_point .
|
||||
See
|
||||
.Xr mount 2 .
|
||||
.It Dv Pf mountrw= Pa mount_point
|
||||
The special file is mounted read-write on
|
||||
.Ar mount_point .
|
||||
See
|
||||
.Xr mount 2 .
|
||||
.It Dv Pf mount= Pa mount_point
|
||||
Same as ``mountrw=''.
|
||||
.El
|
||||
.Pp
|
||||
The second (-a) form of the command reads a command file and performs the
|
||||
specified actions for each device/file pair.
|
||||
With
|
||||
.Fl f
|
||||
it reads the indicated configuration file
|
||||
.Ar config_file .
|
||||
Otherwise it uses a default configuration file.
|
||||
A configuration file contains one line per device/file pair in the form:
|
||||
.Bd -literal
|
||||
special_file regular_file [ feature ]
|
||||
.Ed
|
||||
.Pp
|
||||
where fields are seperated by white space.
|
||||
The previously described action options serve to configure, enable,
|
||||
disable or unconfigure all devices in the configuration file.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /etc/vntab -compact
|
||||
.It Pa /etc/vntab
|
||||
default configuration file for
|
||||
.Fl a
|
||||
option.
|
||||
.Bl -tag -width /etc/rvnd?? -compact
|
||||
.It Pa /dev/rvnd??
|
||||
.It Pa /dev/vnd??
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
.Pp
|
||||
|
@ -144,22 +87,12 @@ option.
|
|||
Configures the vnode disk
|
||||
.Pa vnd0c .
|
||||
.Pp
|
||||
.Dl vnconfig -e /dev/vnd0c /var/swapfile swap
|
||||
.Dl vnconfig -u /dev/vnd0c /tmp/diskimage
|
||||
.Pp
|
||||
Configures
|
||||
Unconfigures the
|
||||
.Pa vnd0c
|
||||
and enables swapping on it.
|
||||
.Pp
|
||||
.Dl vnconfig -d /dev/vnd0c myfilesystem mount=/mnt
|
||||
.Pp
|
||||
Unmounts (disables)
|
||||
.Pa vnd0c .
|
||||
.Pp
|
||||
.Dl vnconfig -ae
|
||||
.Pp
|
||||
Configures and enables all devices specified in
|
||||
.Pa /etc/vntab .
|
||||
device.
|
||||
.Sh SEE ALSO
|
||||
.Xr swapon 2 ,
|
||||
.Xr mount 2 ,
|
||||
.Xr unmount 2 .
|
||||
.Xr swapon 8 ,
|
||||
.Xr mount 8 ,
|
||||
.Xr umount 8 .
|
||||
|
|
|
@ -40,163 +40,78 @@
|
|||
* @(#)vnconfig.c 8.1 (Berkeley) 12/15/93
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <dev/vnioctl.h>
|
||||
|
||||
#define MAXVNDISK 16
|
||||
#define LINESIZE 1024
|
||||
|
||||
struct vndisk {
|
||||
char *dev;
|
||||
char *file;
|
||||
int flags;
|
||||
char *oarg;
|
||||
} vndisks[MAXVNDISK];
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define VN_CONFIG 0x01
|
||||
#define VN_UNCONFIG 0x02
|
||||
#define VN_ENABLE 0x04
|
||||
#define VN_DISABLE 0x08
|
||||
#define VN_SWAP 0x10
|
||||
#define VN_MOUNTRO 0x20
|
||||
#define VN_MOUNTRW 0x40
|
||||
#define VN_IGNORE 0x80
|
||||
|
||||
int nvndisks;
|
||||
|
||||
int all = 0;
|
||||
int verbose = 0;
|
||||
char *configfile;
|
||||
char *pname;
|
||||
|
||||
char *rawdevice __P((char *));
|
||||
void usage __P((void));
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
extern int optind, optopt, opterr;
|
||||
extern char *optarg;
|
||||
register int i, rv;
|
||||
int flags = 0;
|
||||
int i, rv, flags = 0;
|
||||
|
||||
pname = argv[0];
|
||||
configfile = _PATH_VNTAB;
|
||||
while ((i = getopt(argc, argv, "acdef:uv")) != EOF)
|
||||
while ((i = getopt(argc, argv, "cuv")) != EOF)
|
||||
switch (i) {
|
||||
|
||||
/* all -- use config file */
|
||||
case 'a':
|
||||
all++;
|
||||
break;
|
||||
|
||||
/* configure */
|
||||
case 'c':
|
||||
flags |= VN_CONFIG;
|
||||
flags &= ~VN_UNCONFIG;
|
||||
break;
|
||||
|
||||
/* disable */
|
||||
case 'd':
|
||||
flags |= VN_DISABLE;
|
||||
flags &= ~VN_ENABLE;
|
||||
break;
|
||||
|
||||
/* enable */
|
||||
case 'e':
|
||||
flags |= (VN_ENABLE|VN_CONFIG);
|
||||
flags &= ~(VN_DISABLE|VN_UNCONFIG);
|
||||
break;
|
||||
|
||||
/* alternate config file */
|
||||
case 'f':
|
||||
configfile = optarg;
|
||||
break;
|
||||
|
||||
/* unconfigure */
|
||||
case 'u':
|
||||
flags |= (VN_DISABLE|VN_UNCONFIG);
|
||||
flags &= ~(VN_ENABLE|VN_CONFIG);
|
||||
flags |= VN_UNCONFIG;
|
||||
flags &= ~VN_CONFIG;
|
||||
break;
|
||||
|
||||
/* verbose */
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "invalid option '%c'\n", optopt);
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (flags == 0)
|
||||
flags = VN_CONFIG;
|
||||
if (all)
|
||||
readconfig(flags);
|
||||
else {
|
||||
if (argc < optind + 2)
|
||||
usage();
|
||||
vndisks[0].dev = argv[optind++];
|
||||
vndisks[0].file = argv[optind++];
|
||||
vndisks[0].flags = flags;
|
||||
if (optind < argc)
|
||||
getoptions(&vndisks[0], argv[optind]);
|
||||
nvndisks = 1;
|
||||
}
|
||||
rv = 0;
|
||||
for (i = 0; i < nvndisks; i++)
|
||||
rv += config(&vndisks[i]);
|
||||
if (argc < optind + 2)
|
||||
usage();
|
||||
rv = config(argv[optind], argv[optind + 1], flags);
|
||||
exit(rv);
|
||||
}
|
||||
|
||||
config(vnp)
|
||||
struct vndisk *vnp;
|
||||
{
|
||||
char *dev, *file, *oarg;
|
||||
config(dev, file, flags)
|
||||
char *dev;
|
||||
char *file;
|
||||
int flags;
|
||||
{
|
||||
struct vn_ioctl vnio;
|
||||
register int rv;
|
||||
char *rdev;
|
||||
FILE *f;
|
||||
extern int errno;
|
||||
|
||||
dev = vnp->dev;
|
||||
file = vnp->file;
|
||||
flags = vnp->flags;
|
||||
oarg = vnp->oarg;
|
||||
|
||||
if (flags & VN_IGNORE)
|
||||
return(0);
|
||||
char *rdev;
|
||||
int rv;
|
||||
|
||||
rdev = rawdevice(dev);
|
||||
f = fopen(rdev, "rw");
|
||||
if (f == NULL) {
|
||||
perror("open");
|
||||
warn("opening file");
|
||||
return(1);
|
||||
}
|
||||
vnio.vn_file = file;
|
||||
|
||||
/*
|
||||
* Disable the device
|
||||
*/
|
||||
if (flags & VN_DISABLE) {
|
||||
if (flags & (VN_MOUNTRO|VN_MOUNTRW)) {
|
||||
rv = unmount(oarg, 0);
|
||||
if (rv) {
|
||||
if (errno == EBUSY)
|
||||
flags &= ~VN_UNCONFIG;
|
||||
if ((flags & VN_UNCONFIG) == 0)
|
||||
perror("umount");
|
||||
} else if (verbose)
|
||||
printf("%s: unmounted\n", dev);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Clear (un-configure) the device
|
||||
*/
|
||||
|
@ -208,7 +123,7 @@ config(vnp)
|
|||
printf("%s: not configured\n", dev);
|
||||
rv = 0;
|
||||
} else
|
||||
perror("VNIOCCLR");
|
||||
warn("VNIOCCLR");
|
||||
} else if (verbose)
|
||||
printf("%s: cleared\n", dev);
|
||||
}
|
||||
|
@ -218,128 +133,17 @@ config(vnp)
|
|||
if (flags & VN_CONFIG) {
|
||||
rv = ioctl(fileno(f), VNIOCSET, &vnio);
|
||||
if (rv) {
|
||||
perror("VNIOCSET");
|
||||
flags &= ~VN_ENABLE;
|
||||
warn("VNIOCSET");
|
||||
} else if (verbose)
|
||||
printf("%s: %d bytes on %s\n",
|
||||
dev, vnio.vn_size, file);
|
||||
}
|
||||
/*
|
||||
* Enable special functions on the device
|
||||
*/
|
||||
if (flags & VN_ENABLE) {
|
||||
if (flags & VN_SWAP) {
|
||||
rv = swapon(dev);
|
||||
if (rv)
|
||||
perror("swapon");
|
||||
else if (verbose)
|
||||
printf("%s: swapping enabled\n", dev);
|
||||
}
|
||||
if (flags & (VN_MOUNTRO|VN_MOUNTRW)) {
|
||||
struct ufs_args args;
|
||||
int mflags;
|
||||
|
||||
args.fspec = dev;
|
||||
mflags = (flags & VN_MOUNTRO) ? MNT_RDONLY : 0;
|
||||
rv = mount(MOUNT_UFS, oarg, mflags, &args);
|
||||
if (rv)
|
||||
perror("mount");
|
||||
else if (verbose)
|
||||
printf("%s: mounted on %s\n", dev, oarg);
|
||||
}
|
||||
}
|
||||
done:
|
||||
fclose(f);
|
||||
fflush(stdout);
|
||||
return(rv < 0);
|
||||
}
|
||||
|
||||
#define EOL(c) ((c) == '\0' || (c) == '\n')
|
||||
#define WHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
|
||||
|
||||
readconfig(flags)
|
||||
int flags;
|
||||
{
|
||||
char buf[LINESIZE];
|
||||
FILE *f;
|
||||
register char *cp, *sp;
|
||||
register int ix;
|
||||
|
||||
f = fopen(configfile, "r");
|
||||
if (f == NULL) {
|
||||
perror(configfile);
|
||||
exit(1);
|
||||
}
|
||||
ix = 0;
|
||||
while (fgets(buf, LINESIZE, f) != NULL) {
|
||||
cp = buf;
|
||||
if (*cp == '#')
|
||||
continue;
|
||||
while (!EOL(*cp) && WHITE(*cp))
|
||||
cp++;
|
||||
if (EOL(*cp))
|
||||
continue;
|
||||
sp = cp;
|
||||
while (!EOL(*cp) && !WHITE(*cp))
|
||||
cp++;
|
||||
if (EOL(*cp))
|
||||
continue;
|
||||
*cp++ = '\0';
|
||||
vndisks[ix].dev = malloc(cp - sp);
|
||||
strcpy(vndisks[ix].dev, sp);
|
||||
while (!EOL(*cp) && WHITE(*cp))
|
||||
cp++;
|
||||
if (EOL(*cp))
|
||||
continue;
|
||||
sp = cp;
|
||||
while (!EOL(*cp) && !WHITE(*cp))
|
||||
cp++;
|
||||
*cp++ = '\0';
|
||||
vndisks[ix].file = malloc(cp - sp);
|
||||
strcpy(vndisks[ix].file, sp);
|
||||
while (!EOL(*cp) && WHITE(*cp))
|
||||
cp++;
|
||||
vndisks[ix].flags = flags;
|
||||
if (!EOL(*cp)) {
|
||||
sp = cp;
|
||||
while (!EOL(*cp) && !WHITE(*cp))
|
||||
cp++;
|
||||
*cp++ = '\0';
|
||||
getoptions(&vndisks[ix], sp);
|
||||
}
|
||||
nvndisks++;
|
||||
ix++;
|
||||
}
|
||||
}
|
||||
|
||||
getoptions(vnp, fstr)
|
||||
struct vndisk *vnp;
|
||||
char *fstr;
|
||||
{
|
||||
int flags = 0;
|
||||
char *oarg = NULL;
|
||||
|
||||
if (strcmp(fstr, "swap") == 0)
|
||||
flags |= VN_SWAP;
|
||||
else if (strncmp(fstr, "mount=", 6) == 0) {
|
||||
flags |= VN_MOUNTRW;
|
||||
oarg = &fstr[6];
|
||||
} else if (strncmp(fstr, "mountrw=", 8) == 0) {
|
||||
flags |= VN_MOUNTRW;
|
||||
oarg = &fstr[8];
|
||||
} else if (strncmp(fstr, "mountro=", 8) == 0) {
|
||||
flags |= VN_MOUNTRO;
|
||||
oarg = &fstr[8];
|
||||
} else if (strcmp(fstr, "ignore") == 0)
|
||||
flags |= VN_IGNORE;
|
||||
vnp->flags |= flags;
|
||||
if (oarg) {
|
||||
vnp->oarg = malloc(strlen(oarg) + 1);
|
||||
strcpy(vnp->oarg, oarg);
|
||||
} else
|
||||
vnp->oarg = NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
rawdevice(dev)
|
||||
char *dev;
|
||||
|
@ -362,9 +166,9 @@ rawdevice(dev)
|
|||
return (rawbuf);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-acdefuv] [special-device file]\n",
|
||||
pname);
|
||||
fprintf(stderr, "usage: vnconfig [-cuv] [special-device file]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue