* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)rmt.c 5.2 (Berkeley) %G%";
char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
#define DEBUG(f) if (debug) fprintf(debug, f)
#define DEBUG1(f,a) if (debug) fprintf(debug, f, a)
#define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
debug
= fopen(*argv
, "w");
(void) setbuf(debug
, (char *)0);
getstring(device
); getstring(mode
);
DEBUG2("rmtd: O %s %s\n", device
, mode
);
tape
= open(device
, atoi(mode
));
getstring(device
); /* discard */
getstring(count
); getstring(pos
);
DEBUG2("rmtd: L %s %s\n", count
, pos
);
rval
= lseek(tape
, (long) atoi(count
), atoi(pos
));
DEBUG1("rmtd: W %s\n", count
);
record
= checkbuf(record
, n
);
for (i
= 0; i
< n
; i
+= cc
) {
cc
= read(0, &record
[i
], n
- i
);
DEBUG("rmtd: premature eof\n");
rval
= write(tape
, record
, n
);
DEBUG1("rmtd: R %s\n", count
);
record
= checkbuf(record
, n
);
rval
= read(tape
, record
, n
);
(void) sprintf(resp
, "A%d\n", rval
);
(void) write(1, resp
, strlen(resp
));
(void) write(1, record
, rval
);
getstring(op
); getstring(count
);
DEBUG2("rmtd: I %s %s\n", op
, count
);
mtop
.mt_count
= atoi(count
);
if (ioctl(tape
, MTIOCTOP
, (char *)&mtop
) < 0)
if (ioctl(tape
, MTIOCGET
, (char *)&mtget
) < 0)
(void) sprintf(resp
, "A%d\n", rval
);
(void) write(1, resp
, strlen(resp
));
(void) write(1, (char *)&mtget
, sizeof (mtget
));
DEBUG1("rmtd: garbage command %c\n", c
);
DEBUG1("rmtd: A %d\n", rval
);
(void) sprintf(resp
, "A%d\n", rval
);
(void) write(1, resp
, strlen(resp
));
for (i
= 0; i
< SSIZE
; i
++) {
if (read(0, cp
+i
, 1) != 1)
DEBUG("rmtd: cannot allocate buffer space\n");
setsockopt(0, SOL_SOCKET
, SO_RCVBUF
, &size
, sizeof (size
)) < 0)
DEBUG2("rmtd: E %d (%s)\n", num
, sys_errlist
[num
]);
(void) sprintf(resp
, "E%d\n%s\n", num
, sys_errlist
[num
]);
(void) write(1, resp
, strlen (resp
));