Xref: utzoo comp.unix.large:216 comp.unix.admin:744 Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!ogicse!orstcs!statware!mcf From: mcf@statware.UUCP (Mathieu Federspiel) Newsgroups: comp.unix.large,comp.unix.admin Subject: Re: Wanted -- tape management system Message-ID: <9654@statware.UUCP> Date: 31 Dec 90 17:01:37 GMT References: <1990Dec6.044038.21954@ccu1.aukuni.ac.nz> Reply-To: mcf@statware.UUCP (Mathieu Federspiel) Distribution: comp Organization: Statware, Corvallis, Oregon Lines: 513 The following programs handle the /dev files, by setting their permissions so that only the user who locks the tape drive has rw permissions. You will have to do some setup of files. #---------------------------------- 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