ar_io.c (79452) | ar_io.c (90110) |
---|---|
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 79452 2001-07-09 09:24:06Z brian $"; | 43 "$FreeBSD: head/bin/pax/ar_io.c 90110 2002-02-02 06:48:10Z imp $"; |
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> --- 28 unchanged lines hidden (view full) --- 80static struct stat arsb; /* stat of archive device at open */ 81static int invld_rec; /* tape has out of spec record size */ 82static int wr_trail = 1; /* trailer was rewritten in append */ 83static int can_unlnk = 0; /* do we unlink null archives? */ 84char *arcname; /* printable name of archive */ 85const char *gzip_program; /* name of gzip program */ 86static pid_t zpid = -1; /* pid of child process */ 87 | 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> --- 28 unchanged lines hidden (view full) --- 80static struct stat arsb; /* stat of archive device at open */ 81static int invld_rec; /* tape has out of spec record size */ 82static int wr_trail = 1; /* trailer was rewritten in append */ 83static int can_unlnk = 0; /* do we unlink null archives? */ 84char *arcname; /* printable name of archive */ 85const char *gzip_program; /* name of gzip program */ 86static pid_t zpid = -1; /* pid of child process */ 87 |
88static int get_phys __P((void)); | 88static int get_phys(void); |
89extern sigset_t s_mask; | 89extern sigset_t s_mask; |
90static void ar_start_gzip __P((int, const char *, int)); | 90static void ar_start_gzip(int, const char *, int); |
91 92/* 93 * ar_open() 94 * Opens the next archive volume. Determines the type of the device and 95 * sets up block sizes as required by the archive device and the format. 96 * Note: we may be called with name == NULL on the first open only. 97 * Return: 98 * -1 on failure, 0 otherwise 99 */ 100 | 91 92/* 93 * ar_open() 94 * Opens the next archive volume. Determines the type of the device and 95 * sets up block sizes as required by the archive device and the format. 96 * Note: we may be called with name == NULL on the first open only. 97 * Return: 98 * -1 on failure, 0 otherwise 99 */ 100 |
101#ifdef __STDC__ | |
102int 103ar_open(char *name) | 101int 102ar_open(char *name) |
104#else 105int 106ar_open(name) 107 char *name; 108#endif | |
109{ 110 struct mtget mb; 111 112 if (arfd != -1) 113 (void)close(arfd); 114 arfd = -1; 115 can_unlnk = did_io = io_ok = invld_rec = 0; 116 artyp = ISREG; --- 181 unchanged lines hidden (view full) --- 298 lstrval = 1; 299 return(0); 300} 301 302/* 303 * ar_close() 304 * closes archive device, increments volume number, and prints i/o summary 305 */ | 103{ 104 struct mtget mb; 105 106 if (arfd != -1) 107 (void)close(arfd); 108 arfd = -1; 109 can_unlnk = did_io = io_ok = invld_rec = 0; 110 artyp = ISREG; --- 181 unchanged lines hidden (view full) --- 292 lstrval = 1; 293 return(0); 294} 295 296/* 297 * ar_close() 298 * closes archive device, increments volume number, and prints i/o summary 299 */ |
306#ifdef __STDC__ | |
307void 308ar_close(void) | 300void 301ar_close(void) |
309#else 310void 311ar_close() 312#endif | |
313{ 314 315 if (arfd < 0) { 316 did_io = io_ok = flcnt = 0; 317 return; 318 } 319 320 /* --- 99 unchanged lines hidden (view full) --- 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 426 * reading an archive once a format dependent trailer is detected). 427 */ | 302{ 303 304 if (arfd < 0) { 305 did_io = io_ok = flcnt = 0; 306 return; 307 } 308 309 /* --- 99 unchanged lines hidden (view full) --- 409 410/* 411 * ar_drain() 412 * drain any archive format independent padding from an archive read 413 * from a socket or a pipe. This is to prevent the process on the 414 * other side of the pipe from getting a SIGPIPE (pax will stop 415 * reading an archive once a format dependent trailer is detected). 416 */ |
428#ifdef __STDC__ | |
429void 430ar_drain(void) | 417void 418ar_drain(void) |
431#else 432void 433ar_drain() 434#endif | |
435{ 436 register int res; 437 char drbuf[MAXBLK]; 438 439 /* 440 * we only drain from a pipe/socket. Other devices can be closed 441 * without reading up to end of file. We sure hope that pipe is closed 442 * on the other side so we will get an EOF. --- 14 unchanged lines hidden (view full) --- 457 * Set up device right before switching from read to write in an append. 458 * device dependent code (if required) to do this should be added here. 459 * For all archive devices we are already positioned at the place we want 460 * to start writing when this routine is called. 461 * Return: 462 * 0 if all ready to write, -1 otherwise 463 */ 464 | 419{ 420 register int res; 421 char drbuf[MAXBLK]; 422 423 /* 424 * we only drain from a pipe/socket. Other devices can be closed 425 * without reading up to end of file. We sure hope that pipe is closed 426 * on the other side so we will get an EOF. --- 14 unchanged lines hidden (view full) --- 441 * Set up device right before switching from read to write in an append. 442 * device dependent code (if required) to do this should be added here. 443 * For all archive devices we are already positioned at the place we want 444 * to start writing when this routine is called. 445 * Return: 446 * 0 if all ready to write, -1 otherwise 447 */ 448 |
465#ifdef __STDC__ | |
466int 467ar_set_wr(void) | 449int 450ar_set_wr(void) |
468#else 469int 470ar_set_wr() 471#endif | |
472{ 473 off_t cpos; 474 475 /* 476 * we must make sure the trailer is rewritten on append, ar_next() 477 * will stop us if the archive containing the trailer was not written 478 */ 479 wr_trail = 0; --- 20 unchanged lines hidden (view full) --- 500 * ar_app_ok() 501 * check if the last volume in the archive allows appends. We cannot check 502 * this until we are ready to write since there is no spec that says all 503 * volumes in a single archive have to be of the same type... 504 * Return: 505 * 0 if we can append, -1 otherwise. 506 */ 507 | 451{ 452 off_t cpos; 453 454 /* 455 * we must make sure the trailer is rewritten on append, ar_next() 456 * will stop us if the archive containing the trailer was not written 457 */ 458 wr_trail = 0; --- 20 unchanged lines hidden (view full) --- 479 * ar_app_ok() 480 * check if the last volume in the archive allows appends. We cannot check 481 * this until we are ready to write since there is no spec that says all 482 * volumes in a single archive have to be of the same type... 483 * Return: 484 * 0 if we can append, -1 otherwise. 485 */ 486 |
508#ifdef __STDC__ | |
509int 510ar_app_ok(void) | 487int 488ar_app_ok(void) |
511#else 512int 513ar_app_ok() 514#endif | |
515{ 516 if (artyp == ISPIPE) { 517 paxwarn(1, "Cannot append to an archive obtained from a pipe."); 518 return(-1); 519 } 520 521 if (!invld_rec) 522 return(0); --- 6 unchanged lines hidden (view full) --- 529 * ar_read() 530 * read up to a specified number of bytes from the archive into the 531 * supplied buffer. When dealing with tapes we may not always be able to 532 * read what we want. 533 * Return: 534 * Number of bytes in buffer. 0 for end of file, -1 for a read error. 535 */ 536 | 489{ 490 if (artyp == ISPIPE) { 491 paxwarn(1, "Cannot append to an archive obtained from a pipe."); 492 return(-1); 493 } 494 495 if (!invld_rec) 496 return(0); --- 6 unchanged lines hidden (view full) --- 503 * ar_read() 504 * read up to a specified number of bytes from the archive into the 505 * supplied buffer. When dealing with tapes we may not always be able to 506 * read what we want. 507 * Return: 508 * Number of bytes in buffer. 0 for end of file, -1 for a read error. 509 */ 510 |
537#ifdef __STDC__ | |
538int 539ar_read(register char *buf, register int cnt) | 511int 512ar_read(register char *buf, register int cnt) |
540#else 541int 542ar_read(buf, cnt) 543 register char *buf; 544 register int cnt; 545#endif | |
546{ 547 register int res = 0; 548 549 /* 550 * if last i/o was in error, no more reads until reset or new volume 551 */ 552 if (lstrval <= 0) 553 return(lstrval); --- 65 unchanged lines hidden (view full) --- 619 * device so it appears as a single "block". Deals with errors and tries 620 * to recover when faced with short writes. 621 * Return: 622 * Number of bytes written. 0 indicates end of volume reached and with no 623 * flaws (as best that can be detected). A -1 indicates an unrecoverable 624 * error in the archive occured. 625 */ 626 | 513{ 514 register int res = 0; 515 516 /* 517 * if last i/o was in error, no more reads until reset or new volume 518 */ 519 if (lstrval <= 0) 520 return(lstrval); --- 65 unchanged lines hidden (view full) --- 586 * device so it appears as a single "block". Deals with errors and tries 587 * to recover when faced with short writes. 588 * Return: 589 * Number of bytes written. 0 indicates end of volume reached and with no 590 * flaws (as best that can be detected). A -1 indicates an unrecoverable 591 * error in the archive occured. 592 */ 593 |
627#ifdef __STDC__ | |
628int 629ar_write(register char *buf, register int bsz) | 594int 595ar_write(register char *buf, register int bsz) |
630#else 631int 632ar_write(buf, bsz) 633 register char *buf; 634 register int bsz; 635#endif | |
636{ 637 register int res; 638 off_t cpos; 639 640 /* 641 * do not allow pax to create a "bad" archive. Once a write fails on 642 * an archive volume prevent further writes to it. 643 */ --- 100 unchanged lines hidden (view full) --- 744/* 745 * ar_rdsync() 746 * Try to move past a bad spot on a flawed archive as needed to continue 747 * I/O. Clears error flags to allow I/O to continue. 748 * Return: 749 * 0 when ok to try i/o again, -1 otherwise. 750 */ 751 | 596{ 597 register int res; 598 off_t cpos; 599 600 /* 601 * do not allow pax to create a "bad" archive. Once a write fails on 602 * an archive volume prevent further writes to it. 603 */ --- 100 unchanged lines hidden (view full) --- 704/* 705 * ar_rdsync() 706 * Try to move past a bad spot on a flawed archive as needed to continue 707 * I/O. Clears error flags to allow I/O to continue. 708 * Return: 709 * 0 when ok to try i/o again, -1 otherwise. 710 */ 711 |
752#ifdef __STDC__ | |
753int 754ar_rdsync(void) | 712int 713ar_rdsync(void) |
755#else 756int 757ar_rdsync() 758#endif | |
759{ 760 long fsbz; 761 off_t cpos; 762 off_t mpos; 763 struct mtop mb; 764 765 /* 766 * Fail resync attempts at user request (done) or this is going to be --- 68 unchanged lines hidden (view full) --- 835 * Move the I/O position within the archive foward the specified number of 836 * bytes as supported by the device. If we cannot move the requested 837 * number of bytes, return the actual number of bytes moved in skipped. 838 * Return: 839 * 0 if moved the requested distance, -1 on complete failure, 1 on 840 * partial move (the amount moved is in skipped) 841 */ 842 | 714{ 715 long fsbz; 716 off_t cpos; 717 off_t mpos; 718 struct mtop mb; 719 720 /* 721 * Fail resync attempts at user request (done) or this is going to be --- 68 unchanged lines hidden (view full) --- 790 * Move the I/O position within the archive foward the specified number of 791 * bytes as supported by the device. If we cannot move the requested 792 * number of bytes, return the actual number of bytes moved in skipped. 793 * Return: 794 * 0 if moved the requested distance, -1 on complete failure, 1 on 795 * partial move (the amount moved is in skipped) 796 */ 797 |
843#ifdef __STDC__ | |
844int 845ar_fow(off_t sksz, off_t *skipped) | 798int 799ar_fow(off_t sksz, off_t *skipped) |
846#else 847int 848ar_fow(sksz, skipped) 849 off_t sksz; 850 off_t *skipped; 851#endif | |
852{ 853 off_t cpos; 854 off_t mpos; 855 856 *skipped = 0; 857 if (sksz <= 0) 858 return(0); 859 --- 41 unchanged lines hidden (view full) --- 901 * count as supported by the device. With tapes drives we RESET rdblksz to 902 * the PHYSICAL blocksize. 903 * NOTE: We should only be called to move backwards so we can rewrite the 904 * last records (the trailer) of an archive (APPEND). 905 * Return: 906 * 0 if moved the requested distance, -1 on complete failure 907 */ 908 | 800{ 801 off_t cpos; 802 off_t mpos; 803 804 *skipped = 0; 805 if (sksz <= 0) 806 return(0); 807 --- 41 unchanged lines hidden (view full) --- 849 * count as supported by the device. With tapes drives we RESET rdblksz to 850 * the PHYSICAL blocksize. 851 * NOTE: We should only be called to move backwards so we can rewrite the 852 * last records (the trailer) of an archive (APPEND). 853 * Return: 854 * 0 if moved the requested distance, -1 on complete failure 855 */ 856 |
909#ifdef __STDC__ | |
910int 911ar_rev(off_t sksz) | 857int 858ar_rev(off_t sksz) |
912#else 913int 914ar_rev(sksz) 915 off_t sksz; 916#endif | |
917{ 918 off_t cpos; 919 struct mtop mb; 920 register int phyblk; 921 922 /* 923 * make sure we do not have try to reverse on a flawed archive 924 */ --- 114 unchanged lines hidden (view full) --- 1039 * block size so we know how many bytes we skip over when we move with 1040 * mtio commands. We also make sure we are BEFORE THE TAPE FILEMARK when 1041 * return. 1042 * This is one really SLOW routine... 1043 * Return: 1044 * physical block size if ok (ok > 0), -1 otherwise 1045 */ 1046 | 859{ 860 off_t cpos; 861 struct mtop mb; 862 register int phyblk; 863 864 /* 865 * make sure we do not have try to reverse on a flawed archive 866 */ --- 114 unchanged lines hidden (view full) --- 981 * block size so we know how many bytes we skip over when we move with 982 * mtio commands. We also make sure we are BEFORE THE TAPE FILEMARK when 983 * return. 984 * This is one really SLOW routine... 985 * Return: 986 * physical block size if ok (ok > 0), -1 otherwise 987 */ 988 |
1047#ifdef __STDC__ | |
1048static int 1049get_phys(void) | 989static int 990get_phys(void) |
1050#else 1051static int 1052get_phys() 1053#endif | |
1054{ 1055 register int padsz = 0; 1056 register int res; 1057 register int phyblk; 1058 struct mtop mb; 1059 char scbuf[MAXBLK]; 1060 1061 /* --- 95 unchanged lines hidden (view full) --- 1157 * prompts the user for the next volume in this archive. For some devices 1158 * we may allow the media to be changed. Otherwise a new archive is 1159 * prompted for. By pax spec, if there is no controlling tty or an eof is 1160 * read on tty input, we must quit pax. 1161 * Return: 1162 * 0 when ready to continue, -1 when all done 1163 */ 1164 | 991{ 992 register int padsz = 0; 993 register int res; 994 register int phyblk; 995 struct mtop mb; 996 char scbuf[MAXBLK]; 997 998 /* --- 95 unchanged lines hidden (view full) --- 1094 * prompts the user for the next volume in this archive. For some devices 1095 * we may allow the media to be changed. Otherwise a new archive is 1096 * prompted for. By pax spec, if there is no controlling tty or an eof is 1097 * read on tty input, we must quit pax. 1098 * Return: 1099 * 0 when ready to continue, -1 when all done 1100 */ 1101 |
1165#ifdef __STDC__ | |
1166int 1167ar_next(void) | 1102int 1103ar_next(void) |
1168#else 1169int 1170ar_next() 1171#endif | |
1172{ 1173 char buf[PAXPATHLEN+2]; 1174 static int freeit = 0; 1175 sigset_t o_mask; 1176 1177 /* 1178 * WE MUST CLOSE THE DEVICE. A lot of devices must see last close, (so 1179 * things like writing EOF etc will be done) (Watch out ar_close() can --- 174 unchanged lines hidden --- | 1104{ 1105 char buf[PAXPATHLEN+2]; 1106 static int freeit = 0; 1107 sigset_t o_mask; 1108 1109 /* 1110 * WE MUST CLOSE THE DEVICE. A lot of devices must see last close, (so 1111 * things like writing EOF etc will be done) (Watch out ar_close() can --- 174 unchanged lines hidden --- |