Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!orstcs!statware!mcf
From: mcf@statware.UUCP (Mathieu Federspiel)
Newsgroups: comp.sys.hp
Subject: Re: allocate/deallocate command wanted
Message-ID: <4527@statware.UUCP>
Date: 17 Aug 89 22:47:06 GMT
References: <210024@speclab.bgp-usgs.gov>
Reply-To: mcf@statware.UUCP (Mathieu Federspiel)
Distribution: na
Organization: Statware, Corvallis, Oregon
Lines: 520
In article <210024@speclab.bgp-usgs.gov> rclark@speclab.bgp-usgs.gov (Roger N. Clark) writes:
>
>Unix needs an allocate/deallocate command for devices. Anyone know
>of a public domain version they could post? For HP and other
This group has helped me with several pieces of software, so here
is my thanks. I was asked to write the following programs for our
tape drives several years ago. They use the method mentioned by
several others about using the permissions on the device files to
restrict access to the tape drive. Enjoy!
#---------------------------------- cut here ----------------------------------
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by mcf at statware on Thu Aug 17 15:42:15 1989
#
# This archive contains:
# tmount.c tumount.c tmount.1
#
# Error checking via wc(1) will be performed.
LANG=""; export LANG
echo x - tmount.c
cat >tmount.c <<'@EOF'
/*
tmount: mount (reserve) tape drive for user
By: Mathieu Federspiel, mcf@statware
October 1987
*/
#include
#include
#include
#include
#include
#include
#define LOCKF "/usr/spool/uucp/LCK..mt\0"
#define DEVF "/dev/MT\0"
#define MAXDEVS 20
void exit();
char *progname;
main(argc, argv)
int argc;
char *argv[];
{
FILE *flock, *efopen();
int tmpi, ndevs, errflg=0;
char *devname[MAXDEVS], *DEVFILE, *LOCKFILE;
char *tapenr="1";
int thisuser, thisgroup;
struct stat statbuf;
struct passwd *getpwuid(), pwbuf;
extern int optind;
extern char *optarg;
/* User help section */
progname=argv[0];
/* get options */
while ((tmpi = getopt(argc, argv, "t:")) != EOF)
switch (tmpi) {
case 't':
tapenr = optarg;
break;
case '?':
errflg++;
}
if (errflg) {
(void)printf("Usage: tmount [-t tape_number]\n");
exit(1);
}
/* build DEVFILE and LOCKFILE from tapenr; default 1 */
if ((DEVFILE=(char *)malloc((unsigned)50)) == NULL) {
(void)printf("Malloc failed: DEVFILE\n");
exit(1);
}
if ((LOCKFILE=(char *)malloc((unsigned)50)) == NULL) {
(void)printf("Malloc failed: LOCKFILE\n");
exit(1);
}
DEVFILE=strcat(DEVF,tapenr);
LOCKFILE=strcat(LOCKF,tapenr);
/* allocate space for device file names and get them */
for (tmpi=0;tmpitumount.c <<'@EOF'
/*
tumount: unmount (free) tape drive for other users
By: Mathieu Federspiel, mcf@statware
October 1987
*/
#include
#include
#include
#include
#include
#include
#include
#include
#define LOCKF "/usr/spool/uucp/LCK..mt\0"
#define DEVF "/dev/MT\0"
#define MAXDEVS 20
void exit();
char *progname;
main(argc, argv)
int argc;
char *argv[];
{
FILE *efopen();
int open(), close(), fd;
int tmpi, ndevs, errflg=0, lineopt=0;
char *devname[MAXDEVS], *DEVFILE, *LOCKFILE;
char *tapenr="1";
int thisuser, thisgroup;
struct stat statbuf;
struct mtop top;
struct passwd *getpwuid(), pwbuf;
extern int optind;
extern char *optarg;
/* User help section */
progname=argv[0];
/* get options */
while ((tmpi = getopt(argc, argv, "t:l")) != EOF)
switch (tmpi) {
case 't':
tapenr = optarg;
break;
case 'l':
lineopt++;
break;
case '?':
errflg++;
}
if (errflg) {
(void)printf("Usage: tumount [-t tape_number] [-l]\n");
exit(1);
}
/* build DEVFILE and LOCKFILE from tapenr; default 1 */
if ((DEVFILE=(char *)malloc((unsigned)50)) == NULL) {
(void)printf("Malloc failed: DEVFILE\n");
exit(1);
}
if ((LOCKFILE=(char *)malloc((unsigned)50)) == NULL) {
(void)printf("Malloc failed: LOCKFILE\n");
exit(1);
}
DEVFILE=strcat(DEVF,tapenr);
LOCKFILE=strcat(LOCKF,tapenr);
/* allocate space for device file names and get them */
for (tmpi=0;tmpitmount.1 <<'@EOF'
.TH TMOUNT,TUMOUNT 1 "LOCAL"
.SH NAME
tmount, tumount \-
mount and umount tape drives
.SH SYNOPSIS
.B tmount
[ -t drive_number ]
.B tumount
[ -t drive_number ] [ -l ]
.SH HP-UX COMPATIBILITY
.TP 10
Level:
HP-UX/STANDARD
.TP
Origin:
Statware
.SH DESCRIPTION
These two utilities reserve or free tape drives for a
single user.
This prevents one user from destroying another's tape which may
be mounted at the time.
The tape drive is reserved by permitting read and write to the tape's
device files only by the owner of the device.
The owner is set by
.BR tmount ,
and set back to root by
.BR tumount .
In addition, a lock file is created which will provide information
to others about who is using the tape drive.
For the tape drive, \fIall\fR device files which access this device
are modified to have the current user as owner with no access permission
for other users.
The names of all device files are maintained in /dev/MT*.
By default, the file /dev/MT1 is read.
The option \fI-t\fR
may be used to specify another tape drive.
For example,
.B tmount -t2
is used to reserve the tape drive defined by the device files
listed in /dev/MT2.
It is up to the system administrator to enter the correct
device files in the appropriate /dev/MT* file.
Note that as this system depends upon the access permissions
of the device files, any device may be reserved by using
tmount and tumount.
The system administrator may define any number of /dev/MT*
files to control any number of devices.
Tumount will attempt to take the tape drive off line, using
.BR ioctl(2) .
This is disabled with \fI-l\fR.
.SH FILES
.nf
/usr/spool/uucp/LCK..mt*
/dev/MT*
.fi
.SH ERROR MESSAGES
Tmount and tumount return 0 on successful completion, 1
otherwise.
.TP
Set UID failed.
The SUID bit is not set; owner must be root.
.TP
Tape drive not mounted.
For tumount, drive is not mounted; i.e., tmount has not been used
to reserve the tape drive.
.TP
Permission denied: owner is uid, uname.
Tape is mounted for another user.
This error will be issued by both tmount and tumount if tmount has
been used to reserve the tape drive.
.TP
Other errors:
Indicate invalid device file specified in /dev/MT* or other
invalid access to a file.
See the system administrator for proper setup of file
permissions.
@EOF
if test "`wc -lwc