Deleted Added
full compact
buf_subs.c (22988) buf_subs.c (28904)
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 *

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

29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
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 *

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

29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * $Id$
37 * $Id: buf_subs.c,v 1.7 1997/02/22 14:04:20 peter Exp $
38 */
39
40#ifndef lint
41static char const sccsid[] = "@(#)buf_subs.c 8.2 (Berkeley) 4/18/94";
42#endif /* not lint */
43
44#include <sys/types.h>
45#include <sys/time.h>

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

98 * does not specify a blocksize, we use the format default blocksize.
99 * We must be picky on writes, so we do not allow the user to create an
100 * archive that might be hard to read elsewhere. If all ok, we then
101 * open the first archive volume
102 */
103 if (!wrblksz)
104 wrblksz = frmt->bsz;
105 if (wrblksz > MAXBLK) {
38 */
39
40#ifndef lint
41static char const sccsid[] = "@(#)buf_subs.c 8.2 (Berkeley) 4/18/94";
42#endif /* not lint */
43
44#include <sys/types.h>
45#include <sys/time.h>

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

98 * does not specify a blocksize, we use the format default blocksize.
99 * We must be picky on writes, so we do not allow the user to create an
100 * archive that might be hard to read elsewhere. If all ok, we then
101 * open the first archive volume
102 */
103 if (!wrblksz)
104 wrblksz = frmt->bsz;
105 if (wrblksz > MAXBLK) {
106 warn(1, "Write block size of %d too large, maximium is: %d",
106 pax_warn(1, "Write block size of %d too large, maximium is: %d",
107 wrblksz, MAXBLK);
108 return(-1);
109 }
110 if (wrblksz % BLKMULT) {
107 wrblksz, MAXBLK);
108 return(-1);
109 }
110 if (wrblksz % BLKMULT) {
111 warn(1, "Write block size of %d is not a %d byte multiple",
111 pax_warn(1, "Write block size of %d is not a %d byte multiple",
112 wrblksz, BLKMULT);
113 return(-1);
114 }
115
116 /*
117 * we only allow wrblksz to be used with all archive operations
118 */
119 blksz = rdblksz = wrblksz;

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

143 /*
144 * leave space for the header pushback (see get_arc()). If we are
145 * going to append and user specified a write block size, check it
146 * right away
147 */
148 buf = &(bufmem[BLKMULT]);
149 if ((act == APPND) && wrblksz) {
150 if (wrblksz > MAXBLK) {
112 wrblksz, BLKMULT);
113 return(-1);
114 }
115
116 /*
117 * we only allow wrblksz to be used with all archive operations
118 */
119 blksz = rdblksz = wrblksz;

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

143 /*
144 * leave space for the header pushback (see get_arc()). If we are
145 * going to append and user specified a write block size, check it
146 * right away
147 */
148 buf = &(bufmem[BLKMULT]);
149 if ((act == APPND) && wrblksz) {
150 if (wrblksz > MAXBLK) {
151 warn(1,"Write block size %d too large, maximium is: %d",
151 pax_warn(1,"Write block size %d too large, maximium is: %d",
152 wrblksz, MAXBLK);
153 return(-1);
154 }
155 if (wrblksz % BLKMULT) {
152 wrblksz, MAXBLK);
153 return(-1);
154 }
155 if (wrblksz % BLKMULT) {
156 warn(1, "Write block size %d is not a %d byte multiple",
156 pax_warn(1, "Write block size %d is not a %d byte multiple",
157 wrblksz, BLKMULT);
158 return(-1);
159 }
160 }
161
162 /*
163 * open the archive
164 */

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

227appnd_start(skcnt)
228 off_t skcnt;
229#endif
230{
231 register int res;
232 off_t cnt;
233
234 if (exit_val != 0) {
157 wrblksz, BLKMULT);
158 return(-1);
159 }
160 }
161
162 /*
163 * open the archive
164 */

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

227appnd_start(skcnt)
228 off_t skcnt;
229#endif
230{
231 register int res;
232 off_t cnt;
233
234 if (exit_val != 0) {
235 warn(0, "Cannot append to an archive that may have flaws.");
235 pax_warn(0, "Cannot append to an archive that may have flaws.");
236 return(-1);
237 }
238 /*
239 * if the user did not specify a write blocksize, inherit the size used
240 * in the last archive volume read. (If a is set we still use rdblksz
241 * until next volume, cannot shift sizes within a single volume).
242 */
243 if (!wrblksz)

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

304 * ARCHIVE mode (write) conditions
305 */
306 if (ar_set_wr() < 0)
307 return(-1);
308 act = ARCHIVE;
309 return(0);
310
311 out:
236 return(-1);
237 }
238 /*
239 * if the user did not specify a write blocksize, inherit the size used
240 * in the last archive volume read. (If a is set we still use rdblksz
241 * until next volume, cannot shift sizes within a single volume).
242 */
243 if (!wrblksz)

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

304 * ARCHIVE mode (write) conditions
305 */
306 if (ar_set_wr() < 0)
307 return(-1);
308 act = ARCHIVE;
309 return(0);
310
311 out:
312 warn(1, "Unable to rewrite archive trailer, cannot append.");
312 pax_warn(1, "Unable to rewrite archive trailer, cannot append.");
313 return(-1);
314}
315
316/*
317 * rd_sync()
318 * A read error occurred on this archive volume. Resync the buffer and
319 * try to reset the device (if possible) so we can continue to read. Keep
320 * trying to do this until we get a valid read, or we reach the limit on

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

336 register int res;
337
338 /*
339 * if the user says bail out on first fault, we are out of here...
340 */
341 if (maxflt == 0)
342 return(-1);
343 if (act == APPND) {
313 return(-1);
314}
315
316/*
317 * rd_sync()
318 * A read error occurred on this archive volume. Resync the buffer and
319 * try to reset the device (if possible) so we can continue to read. Keep
320 * trying to do this until we get a valid read, or we reach the limit on

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

336 register int res;
337
338 /*
339 * if the user says bail out on first fault, we are out of here...
340 */
341 if (maxflt == 0)
342 return(-1);
343 if (act == APPND) {
344 warn(1, "Unable to append when there are archive read errors.");
344 pax_warn(1, "Unable to append when there are archive read errors.");
345 return(-1);
346 }
347
348 /*
349 * poke at device and try to get past media error
350 */
351 if (ar_rdsync() < 0) {
352 if (ar_next() < 0)

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

370 * Oh well, yet another failed read...
371 * if error limit reached, ditch. o.w. poke device to move past
372 * bad media and try again. if media is badly damaged, we ask
373 * the poor (and upset user at this point) for the next archive
374 * volume. remember the goal on reads is to get the most we
375 * can extract out of the archive.
376 */
377 if ((maxflt > 0) && (++errcnt > maxflt))
345 return(-1);
346 }
347
348 /*
349 * poke at device and try to get past media error
350 */
351 if (ar_rdsync() < 0) {
352 if (ar_next() < 0)

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

370 * Oh well, yet another failed read...
371 * if error limit reached, ditch. o.w. poke device to move past
372 * bad media and try again. if media is badly damaged, we ask
373 * the poor (and upset user at this point) for the next archive
374 * volume. remember the goal on reads is to get the most we
375 * can extract out of the archive.
376 */
377 if ((maxflt > 0) && (++errcnt > maxflt))
378 warn(0,"Archive read error limit (%d) reached",maxflt);
378 pax_warn(0,"Archive read error limit (%d) reached",maxflt);
379 else if (ar_rdsync() == 0)
380 continue;
381 if (ar_next() < 0)
382 break;
383 rdcnt = 0;
384 errcnt = 0;
385 }
386 return(-1);

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

649 * wr_rdfile()
650 * fill write buffer with the contents of a file. We are passed an open
651 * file descriptor to the file an the archive structure that describes the
652 * file we are storing. The variable "left" is modified to contain the
653 * number of bytes of the file we were NOT able to write to the archive.
654 * it is important that we always write EXACTLY the number of bytes that
655 * the format specific write routine told us to. The file can also get
656 * bigger, so reading to the end of file would create an improper archive,
379 else if (ar_rdsync() == 0)
380 continue;
381 if (ar_next() < 0)
382 break;
383 rdcnt = 0;
384 errcnt = 0;
385 }
386 return(-1);

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

649 * wr_rdfile()
650 * fill write buffer with the contents of a file. We are passed an open
651 * file descriptor to the file an the archive structure that describes the
652 * file we are storing. The variable "left" is modified to contain the
653 * number of bytes of the file we were NOT able to write to the archive.
654 * it is important that we always write EXACTLY the number of bytes that
655 * the format specific write routine told us to. The file can also get
656 * bigger, so reading to the end of file would create an improper archive,
657 * we just detect this case and warn the user. We never create a bad
657 * we just detect this case and pax_warn the user. We never create a bad
658 * archive if we can avoid it. Of course trying to archive files that are
659 * active is asking for trouble. It we fail, we pass back how much we
660 * could NOT copy and let the caller deal with it.
661 * Return:
662 * 0 ok, -1 if archive write failure. a short read of the file returns a
663 * 0, but "left" is set to be greater than zero.
664 */
665

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

695 bufpt += res;
696 }
697
698 /*
699 * better check the file did not change during this operation
700 * or the file read failed.
701 */
702 if (res < 0)
658 * archive if we can avoid it. Of course trying to archive files that are
659 * active is asking for trouble. It we fail, we pass back how much we
660 * could NOT copy and let the caller deal with it.
661 * Return:
662 * 0 ok, -1 if archive write failure. a short read of the file returns a
663 * 0, but "left" is set to be greater than zero.
664 */
665

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

695 bufpt += res;
696 }
697
698 /*
699 * better check the file did not change during this operation
700 * or the file read failed.
701 */
702 if (res < 0)
703 syswarn(1, errno, "Read fault on %s", arcn->org_name);
703 sys_warn(1, errno, "Read fault on %s", arcn->org_name);
704 else if (size != 0L)
704 else if (size != 0L)
705 warn(1, "File changed size during read %s", arcn->org_name);
705 pax_warn(1, "File changed size during read %s", arcn->org_name);
706 else if (fstat(ifd, &sb) < 0)
706 else if (fstat(ifd, &sb) < 0)
707 syswarn(1, errno, "Failed stat on %s", arcn->org_name);
707 sys_warn(1, errno, "Failed stat on %s", arcn->org_name);
708 else if (arcn->sb.st_mtime != sb.st_mtime)
708 else if (arcn->sb.st_mtime != sb.st_mtime)
709 warn(1, "File %s was modified during copy to archive",
709 pax_warn(1, "File %s was modified during copy to archive",
710 arcn->org_name);
711 *left = size;
712 return(0);
713}
714
715/*
716 * rd_wrfile()
717 * extract the contents of a file from the archive. If we are unable to

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

756 /*
757 * pass the blocksize of the file being written to the write routine,
758 * if the size is zero, use the default MINFBSZ
759 */
760 if (fstat(ofd, &sb) == 0) {
761 if (sb.st_blksize > 0)
762 sz = (int)sb.st_blksize;
763 } else
710 arcn->org_name);
711 *left = size;
712 return(0);
713}
714
715/*
716 * rd_wrfile()
717 * extract the contents of a file from the archive. If we are unable to

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

756 /*
757 * pass the blocksize of the file being written to the write routine,
758 * if the size is zero, use the default MINFBSZ
759 */
760 if (fstat(ofd, &sb) == 0) {
761 if (sb.st_blksize > 0)
762 sz = (int)sb.st_blksize;
763 } else
764 syswarn(0,errno,"Unable to obtain block size for file %s",fnm);
764 sys_warn(0,errno,"Unable to obtain block size for file %s",fnm);
765 rem = sz;
766 *left = 0L;
767
768 /*
769 * Copy the archive to the file the number of bytes specified. We have
770 * to assume that we want to recover file holes as none of the archive
771 * formats can record the location of file holes.
772 */

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

812 if ((size > 0L) && (*left == 0L))
813 return(-1);
814
815 /*
816 * some formats record a crc on file data. If so, then we compare the
817 * calculated crc to the crc stored in the archive
818 */
819 if (docrc && (size == 0L) && (arcn->crc != crc))
765 rem = sz;
766 *left = 0L;
767
768 /*
769 * Copy the archive to the file the number of bytes specified. We have
770 * to assume that we want to recover file holes as none of the archive
771 * formats can record the location of file holes.
772 */

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

812 if ((size > 0L) && (*left == 0L))
813 return(-1);
814
815 /*
816 * some formats record a crc on file data. If so, then we compare the
817 * calculated crc to the crc stored in the archive
818 */
819 if (docrc && (size == 0L) && (arcn->crc != crc))
820 warn(1,"Actual crc does not match expected crc %s",arcn->name);
820 pax_warn(1,"Actual crc does not match expected crc %s",arcn->name);
821 return(0);
822}
823
824/*
825 * cp_file()
826 * copy the contents of one file to another. used during -rw phase of pax
827 * just as in rd_wrfile() we use a special write function to write the
828 * destination file so we can properly copy files with holes.

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

859 /*
860 * pass the blocksize of the file being written to the write routine,
861 * if the size is zero, use the default MINFBSZ
862 */
863 if (fstat(fd2, &sb) == 0) {
864 if (sb.st_blksize > 0)
865 sz = sb.st_blksize;
866 } else
821 return(0);
822}
823
824/*
825 * cp_file()
826 * copy the contents of one file to another. used during -rw phase of pax
827 * just as in rd_wrfile() we use a special write function to write the
828 * destination file so we can properly copy files with holes.

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

859 /*
860 * pass the blocksize of the file being written to the write routine,
861 * if the size is zero, use the default MINFBSZ
862 */
863 if (fstat(fd2, &sb) == 0) {
864 if (sb.st_blksize > 0)
865 sz = sb.st_blksize;
866 } else
867 syswarn(0,errno,"Unable to obtain block size for file %s",fnm);
867 sys_warn(0,errno,"Unable to obtain block size for file %s",fnm);
868 rem = sz;
869
870 /*
871 * read the source file and copy to destination file until EOF
872 */
873 for(;;) {
874 if ((cnt = read(fd1, buf, blksz)) <= 0)
875 break;

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

881 break;
882 cpcnt += cnt;
883 }
884
885 /*
886 * check to make sure the copy is valid.
887 */
888 if (res < 0)
868 rem = sz;
869
870 /*
871 * read the source file and copy to destination file until EOF
872 */
873 for(;;) {
874 if ((cnt = read(fd1, buf, blksz)) <= 0)
875 break;

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

881 break;
882 cpcnt += cnt;
883 }
884
885 /*
886 * check to make sure the copy is valid.
887 */
888 if (res < 0)
889 syswarn(1, errno, "Failed write during copy of %s to %s",
889 sys_warn(1, errno, "Failed write during copy of %s to %s",
890 arcn->org_name, arcn->name);
891 else if (cpcnt != arcn->sb.st_size)
890 arcn->org_name, arcn->name);
891 else if (cpcnt != arcn->sb.st_size)
892 warn(1, "File %s changed size during copy to %s",
892 pax_warn(1, "File %s changed size during copy to %s",
893 arcn->org_name, arcn->name);
894 else if (fstat(fd1, &sb) < 0)
893 arcn->org_name, arcn->name);
894 else if (fstat(fd1, &sb) < 0)
895 syswarn(1, errno, "Failed stat of %s", arcn->org_name);
895 sys_warn(1, errno, "Failed stat of %s", arcn->org_name);
896 else if (arcn->sb.st_mtime != sb.st_mtime)
896 else if (arcn->sb.st_mtime != sb.st_mtime)
897 warn(1, "File %s was modified during copy to %s",
897 pax_warn(1, "File %s was modified during copy to %s",
898 arcn->org_name, arcn->name);
899
900 /*
901 * if the last block has a file hole (all zero), we must make sure this
902 * gets updated in the file. We force the last block of zeros to be
903 * written. just closing with the file offset moved foward may not put
904 * a hole at the end of the file.
905 */

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

982
983 /*
984 * if we have reached the user specified byte count for each archive
985 * volume, prompt for the next volume. (The non-standrad -R flag).
986 * NOTE: If the wrlimit is smaller than wrcnt, we will always write
987 * at least one record. We always round limit UP to next blocksize.
988 */
989 if ((wrlimit > 0) && (wrcnt > wrlimit)) {
898 arcn->org_name, arcn->name);
899
900 /*
901 * if the last block has a file hole (all zero), we must make sure this
902 * gets updated in the file. We force the last block of zeros to be
903 * written. just closing with the file offset moved foward may not put
904 * a hole at the end of the file.
905 */

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

982
983 /*
984 * if we have reached the user specified byte count for each archive
985 * volume, prompt for the next volume. (The non-standrad -R flag).
986 * NOTE: If the wrlimit is smaller than wrcnt, we will always write
987 * at least one record. We always round limit UP to next blocksize.
988 */
989 if ((wrlimit > 0) && (wrcnt > wrlimit)) {
990 warn(0, "User specified archive volume byte limit reached.");
990 pax_warn(0, "User specified archive volume byte limit reached.");
991 if (ar_next() < 0) {
992 wrcnt = 0;
993 exit_val = 1;
994 return(-1);
995 }
996 wrcnt = 0;
997
998 /*

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

1038 }
1039 } else
1040 bufpt = buf;
1041 return(totcnt);
1042 } else if (cnt > 0) {
1043 /*
1044 * Oh drat we got a partial write!
1045 * if format doesnt care about alignment let it go,
991 if (ar_next() < 0) {
992 wrcnt = 0;
993 exit_val = 1;
994 return(-1);
995 }
996 wrcnt = 0;
997
998 /*

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

1038 }
1039 } else
1040 bufpt = buf;
1041 return(totcnt);
1042 } else if (cnt > 0) {
1043 /*
1044 * Oh drat we got a partial write!
1045 * if format doesnt care about alignment let it go,
1046 * we warned the user in ar_write().... but this means
1046 * we pax_warned the user in ar_write().... but this means
1047 * the last record on this volume violates pax spec....
1048 */
1049 totcnt += cnt;
1050 wrcnt += cnt;
1051 bufpt = buf + cnt;
1052 cnt = bufcnt - cnt;
1053 bcopy(bufpt, buf, cnt);
1054 bufpt = buf + cnt;

--- 30 unchanged lines hidden ---
1047 * the last record on this volume violates pax spec....
1048 */
1049 totcnt += cnt;
1050 wrcnt += cnt;
1051 bufpt = buf + cnt;
1052 cnt = bufcnt - cnt;
1053 bcopy(bufpt, buf, cnt);
1054 bufpt = buf + cnt;

--- 30 unchanged lines hidden ---