ar_io.c (c9a8d1f4ddce0e113129507ab55689b6e922f60d) ar_io.c (46be34b90213ebd9037cb2c24aec0009d7f2f5c1)
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 "$Id$";
43 "$Id: ar_io.c,v 1.10 1998/05/15 06:27:34 charnier Exp $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <sys/ioctl.h>
49#include <sys/mtio.h>
50#include <signal.h>
51#include <string.h>

--- 8 unchanged lines hidden (view full) ---

60/*
61 * Routines which deal directly with the archive I/O device/file.
62 */
63
64#define DMOD 0666 /* default mode of created archives */
65#define EXT_MODE O_RDONLY /* open mode for list/extract */
66#define AR_MODE (O_WRONLY | O_CREAT | O_TRUNC) /* mode for archive */
67#define APP_MODE O_RDWR /* mode for append */
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/stat.h>
48#include <sys/ioctl.h>
49#include <sys/mtio.h>
50#include <signal.h>
51#include <string.h>

--- 8 unchanged lines hidden (view full) ---

60/*
61 * Routines which deal directly with the archive I/O device/file.
62 */
63
64#define DMOD 0666 /* default mode of created archives */
65#define EXT_MODE O_RDONLY /* open mode for list/extract */
66#define AR_MODE (O_WRONLY | O_CREAT | O_TRUNC) /* mode for archive */
67#define APP_MODE O_RDWR /* mode for append */
68#define STDO "<STDOUT>" /* psuedo name for stdout */
69#define STDN "<STDIN>" /* psuedo name for stdin */
68#define STDO "<STDOUT>" /* pseudo name for stdout */
69#define STDN "<STDIN>" /* pseudo name for stdin */
70static int arfd = -1; /* archive file descriptor */
71static int artyp = ISREG; /* archive type: file/FIFO/tape */
72static int arvol = 1; /* archive volume number */
73static int lstrval = -1; /* return value from last i/o */
74static int io_ok; /* i/o worked on volume after resync */
75static int did_io; /* did i/o ever occur on volume? */
76static int done; /* set via tty termination */
77static struct stat arsb; /* stat of archive device at open */

--- 180 unchanged lines hidden (view full) ---

258 }
259 /*
260 * See if we can find the blocking factor from the file size
261 */
262 for (rdblksz = MAXBLK; rdblksz > 0; rdblksz -= BLKMULT)
263 if ((arsb.st_size % rdblksz) == 0)
264 break;
265 /*
70static int arfd = -1; /* archive file descriptor */
71static int artyp = ISREG; /* archive type: file/FIFO/tape */
72static int arvol = 1; /* archive volume number */
73static int lstrval = -1; /* return value from last i/o */
74static int io_ok; /* i/o worked on volume after resync */
75static int did_io; /* did i/o ever occur on volume? */
76static int done; /* set via tty termination */
77static struct stat arsb; /* stat of archive device at open */

--- 180 unchanged lines hidden (view full) ---

258 }
259 /*
260 * See if we can find the blocking factor from the file size
261 */
262 for (rdblksz = MAXBLK; rdblksz > 0; rdblksz -= BLKMULT)
263 if ((arsb.st_size % rdblksz) == 0)
264 break;
265 /*
266 * When we cannont find a match, we may have a flawed archive.
266 * When we cannot find a match, we may have a flawed archive.
267 */
268 if (rdblksz <= 0)
269 rdblksz = FILEBLK;
270 /*
271 * for performance go for large reads when we can
272 */
273 if (act == APPND)
274 blksz = rdblksz;

--- 410 unchanged lines hidden (view full) ---

685 * we cannot fix errors to these devices
686 */
687 break;
688 }
689
690 /*
691 * Better tell the user the bad news...
692 * if this is a block aligned archive format, we may have a bad archive
267 */
268 if (rdblksz <= 0)
269 rdblksz = FILEBLK;
270 /*
271 * for performance go for large reads when we can
272 */
273 if (act == APPND)
274 blksz = rdblksz;

--- 410 unchanged lines hidden (view full) ---

685 * we cannot fix errors to these devices
686 */
687 break;
688 }
689
690 /*
691 * Better tell the user the bad news...
692 * if this is a block aligned archive format, we may have a bad archive
693 * if the format wants the header to start at a BLKMULT boundry. While
693 * if the format wants the header to start at a BLKMULT boundary. While
694 * we can deal with the mis-aligned data, it violates spec and other
695 * archive readers will likely fail. if the format is not block
696 * aligned, the user may be lucky (and the archive is ok).
697 */
698 if (res >= 0) {
699 if (res > 0)
700 wr_trail = 1;
701 io_ok = 1;

--- 56 unchanged lines hidden (view full) ---

758 did_io = 1;
759
760 switch(artyp) {
761 case ISTAPE:
762 /*
763 * if the last i/o was a successful data transfer, we assume
764 * the fault is just a bad record on the tape that we are now
765 * past. If we did not get any data since the last resync try
694 * we can deal with the mis-aligned data, it violates spec and other
695 * archive readers will likely fail. if the format is not block
696 * aligned, the user may be lucky (and the archive is ok).
697 */
698 if (res >= 0) {
699 if (res > 0)
700 wr_trail = 1;
701 io_ok = 1;

--- 56 unchanged lines hidden (view full) ---

758 did_io = 1;
759
760 switch(artyp) {
761 case ISTAPE:
762 /*
763 * if the last i/o was a successful data transfer, we assume
764 * the fault is just a bad record on the tape that we are now
765 * past. If we did not get any data since the last resync try
766 * to move the tape foward one PHYSICAL record past any
766 * to move the tape forward one PHYSICAL record past any
767 * damaged tape section. Some tape drives are stubborn and need
768 * to be pushed.
769 */
770 if (io_ok) {
771 io_ok = 0;
772 lstrval = 1;
773 break;
774 }

--- 90 unchanged lines hidden (view full) ---

865 if ((mpos = cpos + sksz) > arsb.st_size) {
866 *skipped = arsb.st_size - cpos;
867 mpos = arsb.st_size;
868 } else
869 *skipped = sksz;
870 if (lseek(arfd, mpos, SEEK_SET) >= 0)
871 return(0);
872 }
767 * damaged tape section. Some tape drives are stubborn and need
768 * to be pushed.
769 */
770 if (io_ok) {
771 io_ok = 0;
772 lstrval = 1;
773 break;
774 }

--- 90 unchanged lines hidden (view full) ---

865 if ((mpos = cpos + sksz) > arsb.st_size) {
866 *skipped = arsb.st_size - cpos;
867 mpos = arsb.st_size;
868 } else
869 *skipped = sksz;
870 if (lseek(arfd, mpos, SEEK_SET) >= 0)
871 return(0);
872 }
873 sys_warn(1, errno, "Foward positioning operation on archive failed");
873 sys_warn(1, errno, "Forward positioning operation on archive failed");
874 lstrval = -1;
875 return(-1);
876}
877
878/*
879 * ar_rev()
880 * move the i/o position within the archive backwards the specified byte
881 * count as supported by the device. With tapes drives we RESET rdblksz to

--- 408 unchanged lines hidden ---
874 lstrval = -1;
875 return(-1);
876}
877
878/*
879 * ar_rev()
880 * move the i/o position within the archive backwards the specified byte
881 * count as supported by the device. With tapes drives we RESET rdblksz to

--- 408 unchanged lines hidden ---