]>
Dogcows Code - chaz/tar/blob - src/rmt.c
2 * Copyright (c) 1983 Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
21 All rights reserved.\n";
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #ifdef HAVE_SYS_GENTAPE_H /* e.g., ISC UNIX */
32 #include <sys/gentape.h>
42 #if defined (_I386) && defined (_AIX)
56 extern char *malloc ();
69 char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
72 extern char *sys_errlist
[];
76 #define DEBUG(f) if (debug) fprintf(debug, f)
77 #define DEBUG1(f,a) if (debug) fprintf(debug, f, a)
78 #define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
92 debug
= fopen (*argv
, "w");
95 (void) setbuf (debug
, (char *) 0);
100 if (read (0, &c
, 1) != 1)
110 DEBUG2 ("rmtd: O %s %s\n", device
, mode
);
111 #if defined (i386) && defined (AIX)
112 /* This is alleged to fix a byte ordering problem. */
113 /* I'm quite suspicious if it's right. -- mib */
115 int oflag
= atoi (mode
);
117 if ((oflag
& 3) == 0)
131 tape
= open (device
, nflag
, 0666);
134 tape
= open (device
, atoi (mode
), 0666);
142 getstring (device
); /* discard */
143 if (close (tape
) < 0)
151 DEBUG2 ("rmtd: L %s %s\n", count
, pos
);
152 rval
= lseek (tape
, (long) atoi (count
), atoi (pos
));
160 DEBUG1 ("rmtd: W %s\n", count
);
161 record
= checkbuf (record
, n
);
162 for (i
= 0; i
< n
; i
+= cc
)
164 cc
= read (0, &record
[i
], n
- i
);
167 DEBUG ("rmtd: premature eof\n");
171 rval
= write (tape
, record
, n
);
178 DEBUG1 ("rmtd: R %s\n", count
);
180 record
= checkbuf (record
, n
);
181 rval
= read (tape
, record
, n
);
184 (void) sprintf (resp
, "A%d\n", rval
);
185 (void) write (1, resp
, strlen (resp
));
186 (void) write (1, record
, rval
);
192 DEBUG2 ("rmtd: I %s %s\n", op
, count
);
196 mtop
.mt_op
= atoi (op
);
197 mtop
.mt_count
= atoi (count
);
198 if (ioctl (tape
, MTIOCTOP
, (char *) &mtop
) < 0)
200 rval
= mtop
.mt_count
;
205 case 'S': /* status */
210 if (ioctl (tape
, MTIOCGET
, (char *) &mtget
) < 0)
212 rval
= sizeof (mtget
);
213 (void) sprintf (resp
, "A%d\n", rval
);
214 (void) write (1, resp
, strlen (resp
));
215 (void) write (1, (char *) &mtget
, sizeof (mtget
));
221 DEBUG1 ("rmtd: garbage command %c\n", c
);
225 DEBUG1 ("rmtd: A %d\n", rval
);
226 (void) sprintf (resp
, "A%d\n", rval
);
227 (void) write (1, resp
, strlen (resp
));
241 for (i
= 0; i
< SSIZE
; i
++)
243 if (read (0, cp
+ i
, 1) != 1)
252 checkbuf (record
, size
)
256 if (size
<= maxrecsize
)
260 record
= malloc (size
);
263 DEBUG ("rmtd: cannot allocate buffer space\n");
268 while (size
> 1024 &&
269 setsockopt (0, SOL_SOCKET
, SO_RCVBUF
, (char *) &size
, sizeof (size
)) < 0)
272 size
= 1 + ((size
- 1) % 1024);
282 DEBUG2 ("rmtd: E %d (%s)\n", num
, sys_errlist
[num
]);
283 (void) sprintf (resp
, "E%d\n%s\n", num
, sys_errlist
[num
]);
284 (void) write (1, resp
, strlen (resp
));
This page took 0.047071 seconds and 5 git commands to generate.