]>
Dogcows Code - chaz/tar/blob - src/rmt.c
442a8310740aecc0de24d65cc33c52b25d4d4eb0
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>
38 #if defined (_I386) && defined (_AIX)
52 extern char *malloc ();
65 char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
68 extern char *sys_errlist
[];
72 #define DEBUG(f) if (debug) fprintf(debug, f)
73 #define DEBUG1(f,a) if (debug) fprintf(debug, f, a)
74 #define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
88 debug
= fopen (*argv
, "w");
91 (void) setbuf (debug
, (char *) 0);
96 if (read (0, &c
, 1) != 1)
106 DEBUG2 ("rmtd: O %s %s\n", device
, mode
);
107 #if defined (i386) && defined (AIX)
108 /* This is alleged to fix a byte ordering problem. */
109 /* I'm quite suspicious if it's right. -- mib */
111 int oflag
= atoi (mode
);
113 if ((oflag
& 3) == 0)
127 tape
= open (device
, nflag
, 0666);
130 tape
= open (device
, atoi (mode
), 0666);
138 getstring (device
); /* discard */
139 if (close (tape
) < 0)
147 DEBUG2 ("rmtd: L %s %s\n", count
, pos
);
148 rval
= lseek (tape
, (long) atoi (count
), atoi (pos
));
156 DEBUG1 ("rmtd: W %s\n", count
);
157 record
= checkbuf (record
, n
);
158 for (i
= 0; i
< n
; i
+= cc
)
160 cc
= read (0, &record
[i
], n
- i
);
163 DEBUG ("rmtd: premature eof\n");
167 rval
= write (tape
, record
, n
);
174 DEBUG1 ("rmtd: R %s\n", count
);
176 record
= checkbuf (record
, n
);
177 rval
= read (tape
, record
, n
);
180 (void) sprintf (resp
, "A%d\n", rval
);
181 (void) write (1, resp
, strlen (resp
));
182 (void) write (1, record
, rval
);
188 DEBUG2 ("rmtd: I %s %s\n", op
, count
);
192 mtop
.mt_op
= atoi (op
);
193 mtop
.mt_count
= atoi (count
);
194 if (ioctl (tape
, MTIOCTOP
, (char *) &mtop
) < 0)
196 rval
= mtop
.mt_count
;
201 case 'S': /* status */
206 if (ioctl (tape
, MTIOCGET
, (char *) &mtget
) < 0)
208 rval
= sizeof (mtget
);
209 (void) sprintf (resp
, "A%d\n", rval
);
210 (void) write (1, resp
, strlen (resp
));
211 (void) write (1, (char *) &mtget
, sizeof (mtget
));
217 DEBUG1 ("rmtd: garbage command %c\n", c
);
221 DEBUG1 ("rmtd: A %d\n", rval
);
222 (void) sprintf (resp
, "A%d\n", rval
);
223 (void) write (1, resp
, strlen (resp
));
237 for (i
= 0; i
< SSIZE
; i
++)
239 if (read (0, cp
+ i
, 1) != 1)
248 checkbuf (record
, size
)
252 if (size
<= maxrecsize
)
256 record
= malloc (size
);
259 DEBUG ("rmtd: cannot allocate buffer space\n");
264 while (size
> 1024 &&
265 setsockopt (0, SOL_SOCKET
, SO_RCVBUF
, (char *) &size
, sizeof (size
)) < 0)
268 size
= 1 + ((size
- 1) % 1024);
278 DEBUG2 ("rmtd: E %d (%s)\n", num
, sys_errlist
[num
]);
279 (void) sprintf (resp
, "E%d\n%s\n", num
, sys_errlist
[num
]);
280 (void) write (1, resp
, strlen (resp
));
This page took 0.048798 seconds and 4 git commands to generate.