* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
#ifdef HAVE_SYS_GENTAPE_H /* e.g., ISC UNIX */
#if defined (_I386) && defined (_AIX)
char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
extern char *sys_errlist
[];
#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);
if (read (0, &c
, 1) != 1)
DEBUG2 ("rmtd: O %s %s\n", device
, mode
);
#if defined (i386) && defined (AIX)
/* This is alleged to fix a byte ordering problem. */
/* I'm quite suspicious if it's right. -- mib */
tape
= open (device
, nflag
, 0666);
tape
= open (device
, atoi (mode
), 0666);
getstring (device
); /* discard */
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
);
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
, (char *) &size
, sizeof (size
)) < 0)
size
= 1 + ((size
- 1) % 1024);
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
));