ar_io.c (76286) | ar_io.c (76351) |
---|---|
1/*- 2 * Copyright (c) 1992 Keith Muller. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 26 unchanged lines hidden (view full) --- 35 * SUCH DAMAGE. 36 */ 37 38#ifndef lint 39#if 0 40static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; 41#endif 42static const char rcsid[] = | 1/*- 2 * Copyright (c) 1992 Keith Muller. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 26 unchanged lines hidden (view full) --- 35 * SUCH DAMAGE. 36 */ 37 38#ifndef lint 39#if 0 40static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; 41#endif 42static const char rcsid[] = |
43 "$FreeBSD: head/bin/pax/ar_io.c 76286 2001-05-05 01:10:13Z kris $"; | 43 "$FreeBSD: head/bin/pax/ar_io.c 76351 2001-05-08 06:19:06Z kris $"; |
44#endif /* not lint */ 45 46#include <sys/types.h> 47#include <sys/ioctl.h> 48#include <sys/mtio.h> 49#include <sys/stat.h> 50#include <sys/wait.h> 51#include <err.h> 52#include <errno.h> 53#include <fcntl.h> 54#include <signal.h> 55#include <stdio.h> 56#include <string.h> 57#include <stdlib.h> 58#include <unistd.h> 59#include "pax.h" | 44#endif /* not lint */ 45 46#include <sys/types.h> 47#include <sys/ioctl.h> 48#include <sys/mtio.h> 49#include <sys/stat.h> 50#include <sys/wait.h> 51#include <err.h> 52#include <errno.h> 53#include <fcntl.h> 54#include <signal.h> 55#include <stdio.h> 56#include <string.h> 57#include <stdlib.h> 58#include <unistd.h> 59#include "pax.h" |
60#include "options.h" |
|
60#include "extern.h" 61 62/* 63 * Routines which deal directly with the archive I/O device/file. 64 */ 65 66#define DMOD 0666 /* default mode of created archives */ 67#define EXT_MODE O_RDONLY /* open mode for list/extract */ --- 86 unchanged lines hidden (view full) --- 154 */ 155 arcname = "<NONE>"; 156 lstrval = 1; 157 return(0); 158 } 159 if (arfd < 0) 160 return(-1); 161 | 61#include "extern.h" 62 63/* 64 * Routines which deal directly with the archive I/O device/file. 65 */ 66 67#define DMOD 0666 /* default mode of created archives */ 68#define EXT_MODE O_RDONLY /* open mode for list/extract */ --- 86 unchanged lines hidden (view full) --- 155 */ 156 arcname = "<NONE>"; 157 lstrval = 1; 158 return(0); 159 } 160 if (arfd < 0) 161 return(-1); 162 |
163 if (chdname != NULL) 164 if (chdir(chdname) != 0) 165 syswarn(1, errno, "Failed chdir to %s", chdname); |
|
162 /* 163 * set up is based on device type 164 */ 165 if (fstat(arfd, &arsb) < 0) { 166 syswarn(0, errno, "Failed stat on %s", arcname); 167 (void)close(arfd); 168 arfd = -1; 169 can_unlnk = 0; --- 132 unchanged lines hidden (view full) --- 302#ifdef __STDC__ 303void 304ar_close(void) 305#else 306void 307ar_close() 308#endif 309{ | 166 /* 167 * set up is based on device type 168 */ 169 if (fstat(arfd, &arsb) < 0) { 170 syswarn(0, errno, "Failed stat on %s", arcname); 171 (void)close(arfd); 172 arfd = -1; 173 can_unlnk = 0; --- 132 unchanged lines hidden (view full) --- 306#ifdef __STDC__ 307void 308ar_close(void) 309#else 310void 311ar_close() 312#endif 313{ |
310 FILE *outf; | |
311 312 if (arfd < 0) { 313 did_io = io_ok = flcnt = 0; 314 return; 315 } 316 | 314 315 if (arfd < 0) { 316 did_io = io_ok = flcnt = 0; 317 return; 318 } 319 |
317 if (act == LIST) 318 outf = stdout; 319 else 320 outf = stderr; 321 | |
322 /* 323 * Close archive file. This may take a LONG while on tapes (we may be 324 * forced to wait for the rewind to complete) so tell the user what is 325 * going on (this avoids the user hitting control-c thinking pax is 326 * broken). 327 */ 328 if (vflag && (artyp == ISTAPE)) { 329 if (vfpart) | 320 /* 321 * Close archive file. This may take a LONG while on tapes (we may be 322 * forced to wait for the rewind to complete) so tell the user what is 323 * going on (this avoids the user hitting control-c thinking pax is 324 * broken). 325 */ 326 if (vflag && (artyp == ISTAPE)) { 327 if (vfpart) |
330 (void)putc('\n', outf); 331 (void)fprintf(outf, | 328 (void)putc('\n', listf); 329 (void)fprintf(listf, |
332 "%s: Waiting for tape drive close to complete...", 333 argv0); | 330 "%s: Waiting for tape drive close to complete...", 331 argv0); |
334 (void)fflush(outf); | 332 (void)fflush(listf); |
335 } 336 337 /* 338 * if nothing was written to the archive (and we created it), we remove 339 * it 340 */ 341 if (can_unlnk && (fstat(arfd, &arsb) == 0) && (S_ISREG(arsb.st_mode)) && 342 (arsb.st_size == 0)) { --- 9 unchanged lines hidden (view full) --- 352 int status; 353 kill(zpid, SIGINT); 354 waitpid(zpid, &status, 0); 355 } 356 357 (void)close(arfd); 358 359 if (vflag && (artyp == ISTAPE)) { | 333 } 334 335 /* 336 * if nothing was written to the archive (and we created it), we remove 337 * it 338 */ 339 if (can_unlnk && (fstat(arfd, &arsb) == 0) && (S_ISREG(arsb.st_mode)) && 340 (arsb.st_size == 0)) { --- 9 unchanged lines hidden (view full) --- 350 int status; 351 kill(zpid, SIGINT); 352 waitpid(zpid, &status, 0); 353 } 354 355 (void)close(arfd); 356 357 if (vflag && (artyp == ISTAPE)) { |
360 (void)fputs("done.\n", outf); | 358 (void)fputs("done.\n", listf); |
361 vfpart = 0; | 359 vfpart = 0; |
362 (void)fflush(outf); | 360 (void)fflush(listf); |
363 } 364 arfd = -1; 365 366 if (!io_ok && !did_io) { 367 flcnt = 0; 368 return; 369 } 370 did_io = io_ok = 0; --- 9 unchanged lines hidden (view full) --- 380 flcnt = 0; 381 return; 382 } 383 384 /* 385 * Print out a summary of I/O for this archive volume. 386 */ 387 if (vfpart) { | 361 } 362 arfd = -1; 363 364 if (!io_ok && !did_io) { 365 flcnt = 0; 366 return; 367 } 368 did_io = io_ok = 0; --- 9 unchanged lines hidden (view full) --- 378 flcnt = 0; 379 return; 380 } 381 382 /* 383 * Print out a summary of I/O for this archive volume. 384 */ 385 if (vfpart) { |
388 (void)putc('\n', outf); | 386 (void)putc('\n', listf); |
389 vfpart = 0; 390 } 391 392 /* 393 * If we have not determined the format yet, we just say how many bytes 394 * we have skipped over looking for a header to id. there is no way we 395 * could have written anything yet. 396 */ 397 if (frmt == NULL) { 398# ifdef NET2_STAT | 387 vfpart = 0; 388 } 389 390 /* 391 * If we have not determined the format yet, we just say how many bytes 392 * we have skipped over looking for a header to id. there is no way we 393 * could have written anything yet. 394 */ 395 if (frmt == NULL) { 396# ifdef NET2_STAT |
399 (void)fprintf(outf, "%s: unknown format, %lu bytes skipped.\n", | 397 (void)fprintf(listf, "%s: unknown format, %lu bytes skipped.\n", |
400# else | 398# else |
401 (void)fprintf(outf, "%s: unknown format, %qu bytes skipped.\n", | 399 (void)fprintf(listf, "%s: unknown format, %qu bytes skipped.\n", |
402# endif 403 argv0, rdcnt); | 400# endif 401 argv0, rdcnt); |
404 (void)fflush(outf); | 402 (void)fflush(listf); |
405 flcnt = 0; 406 return; 407 } 408 | 403 flcnt = 0; 404 return; 405 } 406 |
409 (void)fprintf(outf, | 407 if (strcmp(NM_CPIO, argv0) == 0) 408 (void)fprintf(listf, "%qu blocks\n", (rdcnt ? rdcnt : wrcnt) / 5120); 409 else if (strcmp(NM_TAR, argv0) != 0) 410 (void)fprintf(listf, |
410# ifdef NET2_STAT 411 "%s: %s vol %d, %lu files, %lu bytes read, %lu bytes written.\n", 412# else 413 "%s: %s vol %d, %lu files, %qu bytes read, %qu bytes written.\n", 414# endif 415 argv0, frmt->name, arvol-1, flcnt, rdcnt, wrcnt); | 411# ifdef NET2_STAT 412 "%s: %s vol %d, %lu files, %lu bytes read, %lu bytes written.\n", 413# else 414 "%s: %s vol %d, %lu files, %qu bytes read, %qu bytes written.\n", 415# endif 416 argv0, frmt->name, arvol-1, flcnt, rdcnt, wrcnt); |
416 (void)fflush(outf); | 417 (void)fflush(listf); |
417 flcnt = 0; 418} 419 420/* 421 * ar_drain() 422 * drain any archive format independent padding from an archive read 423 * from a socket or a pipe. This is to prevent the process on the 424 * other side of the pipe from getting a SIGPIPE (pax will stop --- 754 unchanged lines hidden (view full) --- 1179 * also be called via a signal handler, so we must prevent a race. 1180 */ 1181 if (sigprocmask(SIG_BLOCK, &s_mask, &o_mask) < 0) 1182 syswarn(0, errno, "Unable to set signal mask"); 1183 ar_close(); 1184 if (sigprocmask(SIG_SETMASK, &o_mask, NULL) < 0) 1185 syswarn(0, errno, "Unable to restore signal mask"); 1186 | 418 flcnt = 0; 419} 420 421/* 422 * ar_drain() 423 * drain any archive format independent padding from an archive read 424 * from a socket or a pipe. This is to prevent the process on the 425 * other side of the pipe from getting a SIGPIPE (pax will stop --- 754 unchanged lines hidden (view full) --- 1180 * also be called via a signal handler, so we must prevent a race. 1181 */ 1182 if (sigprocmask(SIG_BLOCK, &s_mask, &o_mask) < 0) 1183 syswarn(0, errno, "Unable to set signal mask"); 1184 ar_close(); 1185 if (sigprocmask(SIG_SETMASK, &o_mask, NULL) < 0) 1186 syswarn(0, errno, "Unable to restore signal mask"); 1187 |
1187 if (done || !wr_trail) | 1188 if (done || !wr_trail || strcmp(NM_TAR, argv0) == 0) |
1188 return(-1); 1189 1190 tty_prnt("\nATTENTION! %s archive volume change required.\n", argv0); 1191 1192 /* 1193 * if i/o is on stdin or stdout, we cannot reopen it (we do not know 1194 * the name), the user will be forced to type it in. 1195 */ --- 156 unchanged lines hidden --- | 1189 return(-1); 1190 1191 tty_prnt("\nATTENTION! %s archive volume change required.\n", argv0); 1192 1193 /* 1194 * if i/o is on stdin or stdout, we cannot reopen it (we do not know 1195 * the name), the user will be forced to type it in. 1196 */ --- 156 unchanged lines hidden --- |