]>
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";
25 static char sccsid
[] = "@(#)rmt.c 5.4 (Berkeley) 6/29/88";
28 /* JF added #ifdef about SO_RCVBUF in attempt to make this run on more
29 machines. Maybe it'll work */
35 #include <sys/types.h>
36 #include <sys/socket.h>
40 #if defined (i386) && defined (AIX)
52 char count
[SSIZE
], mode
[SSIZE
], pos
[SSIZE
], op
[SSIZE
];
55 extern char *sys_errlist
[];
61 #define DEBUG(f) if (debug) fprintf(debug, f)
62 #define DEBUG1(f,a) if (debug) fprintf(debug, f, a)
63 #define DEBUG2(f,a1,a2) if (debug) fprintf(debug, f, a1, a2)
75 debug
= fopen(*argv
, "w");
78 (void) setbuf(debug
, (char *)0);
83 if (read(0, &c
, 1) != 1)
90 getstring(device
); getstring(mode
);
91 DEBUG2("rmtd: O %s %s\n", device
, mode
);
92 #if defined (i386) && defined (AIX)
93 /* This is alleged to fix a byte ordering problem. */
94 /* I'm quite suspicious if it's right. -- mib */
96 int oflag
= atoi (mode
);
112 tape
= open (device
, nflag
, 0666);
115 tape
= open(device
, atoi(mode
),0666);
123 getstring(device
); /* discard */
130 getstring(count
); getstring(pos
);
131 DEBUG2("rmtd: L %s %s\n", count
, pos
);
132 rval
= lseek(tape
, (long) atoi(count
), atoi(pos
));
140 DEBUG1("rmtd: W %s\n", count
);
141 record
= checkbuf(record
, n
);
142 for (i
= 0; i
< n
; i
+= cc
) {
143 cc
= read(0, &record
[i
], n
- i
);
145 DEBUG("rmtd: premature eof\n");
149 rval
= write(tape
, record
, n
);
156 DEBUG1("rmtd: R %s\n", count
);
158 record
= checkbuf(record
, n
);
159 rval
= read(tape
, record
, n
);
162 (void) sprintf(resp
, "A%d\n", rval
);
163 (void) write(1, resp
, strlen(resp
));
164 (void) write(1, record
, rval
);
168 getstring(op
); getstring(count
);
169 DEBUG2("rmtd: I %s %s\n", op
, count
);
171 mtop
.mt_op
= atoi(op
);
172 mtop
.mt_count
= atoi(count
);
173 if (ioctl(tape
, MTIOCTOP
, (char *)&mtop
) < 0)
175 rval
= mtop
.mt_count
;
179 case 'S': /* status */
181 { struct mtget mtget
;
182 if (ioctl(tape
, MTIOCGET
, (char *)&mtget
) < 0)
184 rval
= sizeof (mtget
);
185 (void) sprintf(resp
, "A%d\n", rval
);
186 (void) write(1, resp
, strlen(resp
));
187 (void) write(1, (char *)&mtget
, sizeof (mtget
));
192 DEBUG1("rmtd: garbage command %c\n", c
);
196 DEBUG1("rmtd: A %d\n", rval
);
197 (void) sprintf(resp
, "A%d\n", rval
);
198 (void) write(1, resp
, strlen(resp
));
211 for (i
= 0; i
< SSIZE
; i
++) {
212 if (read(0, cp
+i
, 1) != 1)
221 checkbuf(record
, size
)
225 extern char *malloc();
227 if (size
<= maxrecsize
)
231 record
= malloc(size
);
233 DEBUG("rmtd: cannot allocate buffer space\n");
238 while (size
> 1024 &&
239 setsockopt(0, SOL_SOCKET
, SO_RCVBUF
, &size
, sizeof (size
)) < 0)
242 size
= 1+((size
-1)%1024
);
251 DEBUG2("rmtd: E %d (%s)\n", num
, sys_errlist
[num
]);
252 (void) sprintf(resp
, "E%d\n%s\n", num
, sys_errlist
[num
]);
253 (void) write(1, resp
, strlen (resp
));
This page took 0.044779 seconds and 5 git commands to generate.