X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=rmt%2Frmt.c;h=2af48e3e0cd7f8560c2946a1faeb449c5da66169;hp=b8cd3f6b0ca802246ae4a29cf8727f73a0eb1ac6;hb=97d9098250fd2a49d9ef70d6bf93f49badff0f6c;hpb=b45f51d61e911ac8a040bef1efda6afd82261e03 diff --git a/rmt/rmt.c b/rmt/rmt.c index b8cd3f6..2af48e3 100644 --- a/rmt/rmt.c +++ b/rmt/rmt.c @@ -2,8 +2,8 @@ * Ported to Linux's Second Extended File System as part of the * dump and restore backup suit * Remy Card , 1994-1997 - * Stelian Pop , 1999 - * + * Stelian Pop , 1999-2000 + * Stelian Pop - Alcôve , 2000-2002 */ /* @@ -40,28 +40,23 @@ */ #ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1983, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)rmt.c 8.1 (Berkeley) 6/6/93"; -#endif static const char rcsid[] = - "$Id: rmt.c,v 1.2 1999/10/11 12:53:25 stelian Exp $"; -#endif /* not lint */ + "$Id: rmt.c,v 1.17 2002/04/12 13:02:16 stelian Exp $"; +#endif /* not linux */ /* * rmt */ +#include +#include #include #include #include #include #include +#ifndef __linux__ #include +#endif #include #include #include @@ -74,7 +69,7 @@ int maxrecsize = -1; #define SSIZE 64 char device[SSIZE]; -char count[SSIZE], mode[SSIZE], pos[SSIZE], op[SSIZE]; +char count[SSIZE], filemode[SSIZE], pos[SSIZE], op[SSIZE]; char resp[BUFSIZ]; @@ -83,18 +78,43 @@ FILE *debug; #define DEBUG1(f,a) if (debug) fprintf(debug, f, a) #define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2) +/* + * Support for Sun's extended RMT protocol + * code originally written by Jörg Schilling + * and relicensed by his permission from GPL to BSD for use in dump. + */ +#define RMTI_VERSION -1 +#define RMT_VERSION 1 + +/* Extended 'i' commands */ +#define RMTI_CACHE 0 +#define RMTI_NOCACHE 1 +#define RMTI_RETEN 2 +#define RMTI_ERASE 3 +#define RMTI_EOM 4 +#define RMTI_NBSF 5 + +/* Extended 's' comands */ +#define MTS_TYPE 'T' +#define MTS_DSREG 'D' +#define MTS_ERREG 'E' +#define MTS_RESID 'R' +#define MTS_FILENO 'F' +#define MTS_BLKNO 'B' +#define MTS_FLAGS 'f' +#define MTS_BF 'b' + char *checkbuf __P((char *, int)); void error __P((int)); void getstring __P((char *)); int -main(argc, argv) - int argc; - char **argv; +main(int argc, char *argv[]) { - int rval; + int rval = 0; char c; int n, i, cc; + unsigned long block = 0; argc--, argv++; if (argc > 0) { @@ -114,31 +134,33 @@ top: if (tape >= 0) (void) close(tape); getstring(device); - getstring(mode); - DEBUG2("rmtd: O %s %s\n", device, mode); + getstring(filemode); + DEBUG2("rmtd: O %s %s\n", device, filemode); /* * XXX the rmt protocol does not provide a means to * specify the permission bits; allow rw for everyone, * as modified by the users umask */ - tape = open(device, atoi(mode), 0666); + tape = OPEN(device, atoi(filemode), 0666); if (tape < 0) goto ioerror; + block = 0; goto respond; case 'C': - DEBUG("rmtd: C\n"); + DEBUG1("rmtd: C (%lu blocks)\n", block); getstring(device); /* discard */ if (close(tape) < 0) goto ioerror; tape = -1; + block = 0; goto respond; case 'L': getstring(count); getstring(pos); DEBUG2("rmtd: L %s %s\n", count, pos); - rval = lseek(tape, (off_t)atol(count), atoi(pos)); + rval = LSEEK(tape, (off_t)atol(count), atoi(pos)); if (rval < 0) goto ioerror; goto respond; @@ -146,7 +168,7 @@ top: case 'W': getstring(count); n = atoi(count); - DEBUG1("rmtd: W %s\n", count); + DEBUG2("rmtd: W %s (block = %lu)\n", count, block); record = checkbuf(record, n); for (i = 0; i < n; i += cc) { cc = read(0, &record[i], n - i); @@ -158,11 +180,12 @@ top: rval = write(tape, record, n); if (rval < 0) goto ioerror; + block += n >> 10; goto respond; case 'R': getstring(count); - DEBUG1("rmtd: R %s\n", count); + DEBUG2("rmtd: R %s (block %lu)\n", count, block); n = atoi(count); record = checkbuf(record, n); rval = read(tape, record, n); @@ -171,13 +194,17 @@ top: (void)sprintf(resp, "A%d\n", rval); (void)write(1, resp, strlen(resp)); (void)write(1, record, rval); + block += n >> 10; goto top; case 'I': getstring(op); getstring(count); DEBUG2("rmtd: I %s %s\n", op, count); - { struct mtop mtop; + if (atoi(op) == RMTI_VERSION) { + rval = RMT_VERSION; + } else { + struct mtop mtop; mtop.mt_op = atoi(op); mtop.mt_count = atoi(count); if (ioctl(tape, MTIOCTOP, (char *)&mtop) < 0) @@ -186,6 +213,56 @@ top: } goto respond; + case 'i': + { struct mtop mtop; + + getstring (op); + getstring (count); + DEBUG2 ("rmtd: i %s %s\n", op, count); + switch (atoi(op)) { +#ifdef MTCACHE + case RMTI_CACHE: + mtop.mt_op = MTCACHE; + break; +#endif +#ifdef MTNOCACHE + case RMTI_NOCACHE: + mtop.mt_op = MTNOCACHE; + break; +#endif +#ifdef MTRETEN + case RMTI_RETEN: + mtop.mt_op = MTRETEN; + break; +#endif +#ifdef MTERASE + case RMTI_ERASE: + mtop.mt_op = MTERASE; + break; +#endif +#ifdef MTEOM + case RMTI_EOM: + mtop.mt_op = MTEOM; + break; +#endif +#ifdef MTNBSF + case RMTI_NBSF: + mtop.mt_op = MTNBSF; + break; +#endif + default: + errno = EINVAL; + goto ioerror; + } + mtop.mt_count = atoi (count); + if (ioctl (tape, MTIOCTOP, (char *) &mtop) < 0) + goto ioerror; + + rval = mtop.mt_count; + + goto respond; + } + case 'S': /* status */ DEBUG("rmtd: S\n"); { struct mtget mtget; @@ -198,6 +275,49 @@ top: goto top; } + case 's': + { char s; + struct mtget mtget; + + if (read (0, &s, 1) != 1) + goto top; + + if (ioctl (tape, MTIOCGET, (char *) &mtget) < 0) + goto ioerror; + + switch (s) { + case MTS_TYPE: + rval = mtget.mt_type; + break; + case MTS_DSREG: + rval = mtget.mt_dsreg; + break; + case MTS_ERREG: + rval = mtget.mt_erreg; + break; + case MTS_RESID: + rval = mtget.mt_resid; + break; + case MTS_FILENO: + rval = mtget.mt_fileno; + break; + case MTS_BLKNO: + rval = mtget.mt_blkno; + break; + case MTS_FLAGS: + rval = mtget.mt_gstat; + break; + case MTS_BF: + rval = 0; + break; + default: + errno = EINVAL; + goto ioerror; + } + + goto respond; + } + case 'V': /* version */ getstring(op); DEBUG1("rmtd: V %s\n", op); @@ -218,9 +338,7 @@ ioerror: goto top; } -void -getstring(bp) - char *bp; +void getstring(char *bp) { int i; char *cp = bp; @@ -235,9 +353,7 @@ getstring(bp) } char * -checkbuf(record, size) - char *record; - int size; +checkbuf(char *record, int size) { if (size <= maxrecsize) @@ -257,8 +373,7 @@ checkbuf(record, size) } void -error(num) - int num; +error(int num) { DEBUG2("rmtd: E %d (%s)\n", num, strerror(num));