static char sccsid
[] = "@(#)rmt.c 4.3 82/05/19";
#define MAXRECSIZ (10*1024) /* small enuf for pdp-11's too */
char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
debug
= fopen(*argv
, "w");
(void) setbuf(debug
, (char *)0);
gets(device
); gets(mode
);
if (debug
) fprintf(debug
, "rmtd: O %s %s\n", device
, mode
);
tape
= open(device
, atoi(mode
));
if (debug
) fprintf(debug
, "rmtd: C\n");
gets(device
); /* discard */
if (debug
) fprintf(debug
, "rmtd: L %s %s\n", count
, pos
);
rval
= lseek(tape
, (long) atoi(count
), atoi(pos
));
if (debug
) fprintf(debug
, "rmtd: W %s\n", count
);
for (i
= 0; i
< n
; i
+= cc
) {
cc
= read(0, &record
[i
], n
- i
);
if (debug
) fprintf(debug
, "rmtd: premature eof\n");
rval
= write(tape
, record
, n
);
if (debug
) fprintf(debug
, "rmtd: R %s\n", count
);
rval
= read(tape
, record
, n
);
(void) sprintf(resp
, "A%d\n", rval
);
(void) write(1, resp
, strlen(resp
));
(void) write(1, record
, rval
);
if (debug
) fprintf(debug
, "rmtd: I %s %s\n", op
, count
);
mtop
.mt_count
= atoi(count
);
if (ioctl(tape
, MTIOCTOP
, (char *)&mtop
) < 0)
if (debug
) fprintf(debug
, "rmtd: S\n");
if (ioctl(tape
, MTIOCGET
, (char *)&mtget
) < 0)
(void) write(1, (char *)&mtget
, sizeof (mtget
));
if (debug
) fprintf(debug
, "rmtd: garbage command %c\n", c
);
if (debug
) fprintf(debug
, "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)
if (debug
) fprintf(debug
, "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
));