Deleted Added
full compact
ar_subs.c (76019) ar_subs.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_subs.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_subs.c 8.2 (Berkeley) 4/18/94";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/ar_subs.c 76019 2001-04-26 09:22:28Z kris $";
43 "$FreeBSD: head/bin/pax/ar_subs.c 76351 2001-05-08 06:19:06Z kris $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <signal.h>
50#include <string.h>
51#include <stdio.h>

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

125
126 /*
127 * modify the name as requested by the user if name
128 * survives modification, do a listing of the file
129 */
130 if ((res = mod_name(arcn)) < 0)
131 break;
132 if (res == 0)
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <signal.h>
50#include <string.h>
51#include <stdio.h>

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

125
126 /*
127 * modify the name as requested by the user if name
128 * survives modification, do a listing of the file
129 */
130 if ((res = mod_name(arcn)) < 0)
131 break;
132 if (res == 0)
133 ls_list(arcn, now);
133 ls_list(arcn, now, stdout);
134 }
135
136 /*
137 * skip to next archive format header using values calculated
138 * by the format header read routine
139 */
140 if (rd_skip(arcn->skip + arcn->pad) == 1)
141 break;

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

166#endif
167{
168 register ARCHD *arcn;
169 register int res;
170 off_t cnt;
171 ARCHD archd;
172 struct stat sb;
173 int fd;
134 }
135
136 /*
137 * skip to next archive format header using values calculated
138 * by the format header read routine
139 */
140 if (rd_skip(arcn->skip + arcn->pad) == 1)
141 break;

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

166#endif
167{
168 register ARCHD *arcn;
169 register int res;
170 off_t cnt;
171 ARCHD archd;
172 struct stat sb;
173 int fd;
174 time_t now;
174
175 arcn = &archd;
176 /*
177 * figure out archive type; pass any format specific options to the
178 * archive option processing routine; call the format init routine;
179 * start up the directory modification time and access mode database
180 */
181 if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
182 ((*frmt->st_rd)() < 0) || (dir_start() < 0))
183 return;
184
185 /*
186 * When we are doing interactive rename, we store the mapping of names
187 * so we can fix up hard links files later in the archive.
188 */
189 if (iflag && (name_start() < 0))
190 return;
191
175
176 arcn = &archd;
177 /*
178 * figure out archive type; pass any format specific options to the
179 * archive option processing routine; call the format init routine;
180 * start up the directory modification time and access mode database
181 */
182 if ((get_arc() < 0) || ((*frmt->options)() < 0) ||
183 ((*frmt->st_rd)() < 0) || (dir_start() < 0))
184 return;
185
186 /*
187 * When we are doing interactive rename, we store the mapping of names
188 * so we can fix up hard links files later in the archive.
189 */
190 if (iflag && (name_start() < 0))
191 return;
192
193 now = time(NULL);
194
192 /*
193 * step through each entry on the archive until the format read routine
194 * says it is done
195 */
196 while (next_head(arcn) == 0) {
197
198 /*
199 * check for pattern, and user specified options match. When

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

271 }
272 } else if (arcn->sb.st_mtime <= sb.st_mtime) {
273 (void)rd_skip(arcn->skip + arcn->pad);
274 continue;
275 }
276 }
277
278 if (vflag) {
195 /*
196 * step through each entry on the archive until the format read routine
197 * says it is done
198 */
199 while (next_head(arcn) == 0) {
200
201 /*
202 * check for pattern, and user specified options match. When

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

274 }
275 } else if (arcn->sb.st_mtime <= sb.st_mtime) {
276 (void)rd_skip(arcn->skip + arcn->pad);
277 continue;
278 }
279 }
280
281 if (vflag) {
279 (void)fputs(arcn->name, stderr);
280 vfpart = 1;
282 if (vflag > 1)
283 ls_list(arcn, now, listf);
284 else {
285 (void)fputs(arcn->name, listf);
286 vfpart = 1;
287 }
281 }
282
283 /*
288 }
289
290 /*
291 * if required, chdir around.
292 */
293 if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
294 if (chdir(arcn->pat->chdname) != 0)
295 syswarn(1, errno, "Cannot chdir to %s",
296 arcn->pat->chdname);
297
298 /*
284 * all ok, extract this member based on type
285 */
286 if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
287 /*
288 * process archive members that are not regular files.
289 * throw out padding and any data that might follow the
290 * header (as determined by the format).
291 */
292 if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
293 res = lnk_creat(arcn);
294 else
295 res = node_creat(arcn);
296
297 (void)rd_skip(arcn->skip + arcn->pad);
298 if (res < 0)
299 purg_lnk(arcn);
300
301 if (vflag && vfpart) {
299 * all ok, extract this member based on type
300 */
301 if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
302 /*
303 * process archive members that are not regular files.
304 * throw out padding and any data that might follow the
305 * header (as determined by the format).
306 */
307 if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
308 res = lnk_creat(arcn);
309 else
310 res = node_creat(arcn);
311
312 (void)rd_skip(arcn->skip + arcn->pad);
313 if (res < 0)
314 purg_lnk(arcn);
315
316 if (vflag && vfpart) {
302 (void)putc('\n', stderr);
317 (void)putc('\n', listf);
303 vfpart = 0;
304 }
305 continue;
306 }
307 /*
308 * we have a file with data here. If we can not create it, skip
309 * over the data and purge the name from hard link table
310 */

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

315 }
316 /*
317 * extract the file from the archive and skip over padding and
318 * any unprocessed data
319 */
320 res = (*frmt->rd_data)(arcn, fd, &cnt);
321 file_close(arcn, fd);
322 if (vflag && vfpart) {
318 vfpart = 0;
319 }
320 continue;
321 }
322 /*
323 * we have a file with data here. If we can not create it, skip
324 * over the data and purge the name from hard link table
325 */

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

330 }
331 /*
332 * extract the file from the archive and skip over padding and
333 * any unprocessed data
334 */
335 res = (*frmt->rd_data)(arcn, fd, &cnt);
336 file_close(arcn, fd);
337 if (vflag && vfpart) {
323 (void)putc('\n', stderr);
338 (void)putc('\n', listf);
324 vfpart = 0;
325 }
326 if (!res)
327 (void)rd_skip(cnt + arcn->pad);
339 vfpart = 0;
340 }
341 if (!res)
342 (void)rd_skip(cnt + arcn->pad);
343
344 /*
345 * if required, chdir around.
346 */
347 if ((arcn->pat != NULL) && (arcn->pat->chdname != NULL))
348 if (fchdir(cwdfd) != 0)
349 syswarn(1, errno,
350 "Can't fchdir to starting directory");
328 }
329
330 /*
331 * all done, restore directory modes and times as required; make sure
332 * all patterns supplied by the user were matched; block off signals
333 * to avoid chance for multiple entry into the cleanup code.
334 */
335 (void)(*frmt->end_rd)();

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

356#endif
357{
358 register int res;
359 register int hlk;
360 register int wr_one;
361 off_t cnt;
362 int (*wrf)();
363 int fd = -1;
351 }
352
353 /*
354 * all done, restore directory modes and times as required; make sure
355 * all patterns supplied by the user were matched; block off signals
356 * to avoid chance for multiple entry into the cleanup code.
357 */
358 (void)(*frmt->end_rd)();

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

379#endif
380{
381 register int res;
382 register int hlk;
383 register int wr_one;
384 off_t cnt;
385 int (*wrf)();
386 int fd = -1;
387 time_t now;
364
365 /*
366 * if this format supports hard link storage, start up the database
367 * that detects them.
368 */
369 if (((hlk = frmt->hlk) == 1) && (lnk_start() < 0))
370 return;
371

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

383 if (iflag && (name_start() < 0))
384 return;
385
386 /*
387 * if this not append, and there are no files, we do no write a trailer
388 */
389 wr_one = is_app;
390
388
389 /*
390 * if this format supports hard link storage, start up the database
391 * that detects them.
392 */
393 if (((hlk = frmt->hlk) == 1) && (lnk_start() < 0))
394 return;
395

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

407 if (iflag && (name_start() < 0))
408 return;
409
410 /*
411 * if this not append, and there are no files, we do no write a trailer
412 */
413 wr_one = is_app;
414
415 now = time(NULL);
416
391 /*
392 * while there are files to archive, process them one at at time
393 */
394 while (next_file(arcn) == 0) {
395 /*
396 * check if this file meets user specified options match.
397 */
398 if (sel_chk(arcn) != 0)

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

452 * purge link table entry
453 */
454 rdfile_close(arcn, &fd);
455 purg_lnk(arcn);
456 continue;
457 }
458
459 if (vflag) {
417 /*
418 * while there are files to archive, process them one at at time
419 */
420 while (next_file(arcn) == 0) {
421 /*
422 * check if this file meets user specified options match.
423 */
424 if (sel_chk(arcn) != 0)

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

478 * purge link table entry
479 */
480 rdfile_close(arcn, &fd);
481 purg_lnk(arcn);
482 continue;
483 }
484
485 if (vflag) {
460 (void)fputs(arcn->name, stderr);
461 vfpart = 1;
486 if (vflag > 1)
487 ls_list(arcn, now, listf);
488 else {
489 (void)fputs(arcn->name, listf);
490 vfpart = 1;
491 }
462 }
463 ++flcnt;
464
465 /*
466 * looks safe to store the file, have the format specific
467 * routine write routine store the file header on the archive
468 */
469 if ((res = (*wrf)(arcn)) < 0) {
470 rdfile_close(arcn, &fd);
471 break;
472 }
473 wr_one = 1;
474 if (res > 0) {
475 /*
476 * format write says no file data needs to be stored
477 * so we are done messing with this file
478 */
479 if (vflag && vfpart) {
492 }
493 ++flcnt;
494
495 /*
496 * looks safe to store the file, have the format specific
497 * routine write routine store the file header on the archive
498 */
499 if ((res = (*wrf)(arcn)) < 0) {
500 rdfile_close(arcn, &fd);
501 break;
502 }
503 wr_one = 1;
504 if (res > 0) {
505 /*
506 * format write says no file data needs to be stored
507 * so we are done messing with this file
508 */
509 if (vflag && vfpart) {
480 (void)putc('\n', stderr);
510 (void)putc('\n', listf);
481 vfpart = 0;
482 }
483 rdfile_close(arcn, &fd);
484 continue;
485 }
486
487 /*
488 * Add file data to the archive, quit on write error. if we
489 * cannot write the entire file contents to the archive we
490 * must pad the archive to replace the missing file data
491 * (otherwise during an extract the file header for the file
492 * which FOLLOWS this one will not be where we expect it to
493 * be).
494 */
495 res = (*frmt->wr_data)(arcn, fd, &cnt);
496 rdfile_close(arcn, &fd);
497 if (vflag && vfpart) {
511 vfpart = 0;
512 }
513 rdfile_close(arcn, &fd);
514 continue;
515 }
516
517 /*
518 * Add file data to the archive, quit on write error. if we
519 * cannot write the entire file contents to the archive we
520 * must pad the archive to replace the missing file data
521 * (otherwise during an extract the file header for the file
522 * which FOLLOWS this one will not be where we expect it to
523 * be).
524 */
525 res = (*frmt->wr_data)(arcn, fd, &cnt);
526 rdfile_close(arcn, &fd);
527 if (vflag && vfpart) {
498 (void)putc('\n', stderr);
528 (void)putc('\n', listf);
499 vfpart = 0;
500 }
501 if (res < 0)
502 break;
503
504 /*
505 * pad as required, cnt is number of bytes not written
506 */

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

607 */
608 if ((udev = frmt->udev) && (dev_start() < 0))
609 return;
610
611 /*
612 * reading the archive may take a long time. If verbose tell the user
613 */
614 if (vflag) {
529 vfpart = 0;
530 }
531 if (res < 0)
532 break;
533
534 /*
535 * pad as required, cnt is number of bytes not written
536 */

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

637 */
638 if ((udev = frmt->udev) && (dev_start() < 0))
639 return;
640
641 /*
642 * reading the archive may take a long time. If verbose tell the user
643 */
644 if (vflag) {
615 (void)fprintf(stderr,
645 (void)fprintf(listf,
616 "%s: Reading archive to position at the end...", argv0);
617 vfpart = 1;
618 }
619
620 /*
621 * step through the archive until the format says it is done
622 */
623 while (next_head(arcn) == 0) {

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

669 */
670 if (appnd_start(tlen) < 0)
671 return;
672
673 /*
674 * tell the user we are done reading.
675 */
676 if (vflag && vfpart) {
646 "%s: Reading archive to position at the end...", argv0);
647 vfpart = 1;
648 }
649
650 /*
651 * step through the archive until the format says it is done
652 */
653 while (next_head(arcn) == 0) {

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

699 */
700 if (appnd_start(tlen) < 0)
701 return;
702
703 /*
704 * tell the user we are done reading.
705 */
706 if (vflag && vfpart) {
677 (void)fputs("done.\n", stderr);
707 (void)fputs("done.\n", listf);
678 vfpart = 0;
679 }
680
681 /*
682 * go to the writing phase to add the new members
683 */
684 wr_archive(arcn, 1);
685}

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

867 } else if (Yflag) {
868 if (arcn->sb.st_ctime <= sb.st_ctime)
869 continue;
870 } else if (arcn->sb.st_mtime <= sb.st_mtime)
871 continue;
872 }
873
874 if (vflag) {
708 vfpart = 0;
709 }
710
711 /*
712 * go to the writing phase to add the new members
713 */
714 wr_archive(arcn, 1);
715}

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

897 } else if (Yflag) {
898 if (arcn->sb.st_ctime <= sb.st_ctime)
899 continue;
900 } else if (arcn->sb.st_mtime <= sb.st_mtime)
901 continue;
902 }
903
904 if (vflag) {
875 (void)fputs(arcn->name, stderr);
905 (void)fputs(arcn->name, listf);
876 vfpart = 1;
877 }
878 ++flcnt;
879
880 /*
881 * try to create a hard link to the src file if requested
882 * but make sure we are not trying to overwrite ourselves.
883 */
884 if (lflag)
885 res = cross_lnk(arcn);
886 else
887 res = chk_same(arcn);
888 if (res <= 0) {
889 if (vflag && vfpart) {
906 vfpart = 1;
907 }
908 ++flcnt;
909
910 /*
911 * try to create a hard link to the src file if requested
912 * but make sure we are not trying to overwrite ourselves.
913 */
914 if (lflag)
915 res = cross_lnk(arcn);
916 else
917 res = chk_same(arcn);
918 if (res <= 0) {
919 if (vflag && vfpart) {
890 (void)putc('\n', stderr);
920 (void)putc('\n', listf);
891 vfpart = 0;
892 }
893 continue;
894 }
895
896 /*
897 * have to create a new file
898 */
899 if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
900 /*
901 * create a link or special file
902 */
903 if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
904 res = lnk_creat(arcn);
905 else
906 res = node_creat(arcn);
907 if (res < 0)
908 purg_lnk(arcn);
909 if (vflag && vfpart) {
921 vfpart = 0;
922 }
923 continue;
924 }
925
926 /*
927 * have to create a new file
928 */
929 if ((arcn->type != PAX_REG) && (arcn->type != PAX_CTG)) {
930 /*
931 * create a link or special file
932 */
933 if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))
934 res = lnk_creat(arcn);
935 else
936 res = node_creat(arcn);
937 if (res < 0)
938 purg_lnk(arcn);
939 if (vflag && vfpart) {
910 (void)putc('\n', stderr);
940 (void)putc('\n', listf);
911 vfpart = 0;
912 }
913 continue;
914 }
915
916 /*
917 * have to copy a regular file to the destination directory.
918 * first open source file and then create the destination file

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

932 /*
933 * copy source file data to the destination file
934 */
935 cp_file(arcn, fdsrc, fddest);
936 file_close(arcn, fddest);
937 rdfile_close(arcn, &fdsrc);
938
939 if (vflag && vfpart) {
941 vfpart = 0;
942 }
943 continue;
944 }
945
946 /*
947 * have to copy a regular file to the destination directory.
948 * first open source file and then create the destination file

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

962 /*
963 * copy source file data to the destination file
964 */
965 cp_file(arcn, fdsrc, fddest);
966 file_close(arcn, fddest);
967 rdfile_close(arcn, &fdsrc);
968
969 if (vflag && vfpart) {
940 (void)putc('\n', stderr);
970 (void)putc('\n', listf);
941 vfpart = 0;
942 }
943 }
944
945 /*
946 * restore directory modes and times as required; make sure all
947 * patterns were selected block off signals to avoid chance for
948 * multiple entry into the cleanup code.

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

983{
984 register int ret;
985 register char *hdend;
986 register int res;
987 register int shftsz;
988 register int hsz;
989 register int in_resync = 0; /* set when we are in resync mode */
990 int cnt = 0; /* counter for trailer function */
971 vfpart = 0;
972 }
973 }
974
975 /*
976 * restore directory modes and times as required; make sure all
977 * patterns were selected block off signals to avoid chance for
978 * multiple entry into the cleanup code.

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

1013{
1014 register int ret;
1015 register char *hdend;
1016 register int res;
1017 register int shftsz;
1018 register int hsz;
1019 register int in_resync = 0; /* set when we are in resync mode */
1020 int cnt = 0; /* counter for trailer function */
1021 int first = 1; /* on 1st read, EOF isn't premature. */
991
992 /*
993 * set up initial conditions, we want a whole frmt->hsz block as we
994 * have no data yet.
995 */
996 res = hsz = frmt->hsz;
997 hdend = hdbuf;
998 shftsz = hsz - 1;
999 for(;;) {
1000 /*
1001 * keep looping until we get a contiguous FULL buffer
1002 * (frmt->hsz is the proper size)
1003 */
1004 for (;;) {
1005 if ((ret = rd_wrbuf(hdend, res)) == res)
1006 break;
1007
1008 /*
1022
1023 /*
1024 * set up initial conditions, we want a whole frmt->hsz block as we
1025 * have no data yet.
1026 */
1027 res = hsz = frmt->hsz;
1028 hdend = hdbuf;
1029 shftsz = hsz - 1;
1030 for(;;) {
1031 /*
1032 * keep looping until we get a contiguous FULL buffer
1033 * (frmt->hsz is the proper size)
1034 */
1035 for (;;) {
1036 if ((ret = rd_wrbuf(hdend, res)) == res)
1037 break;
1038
1039 /*
1040 * If we read 0 bytes (EOF) from an archive when we
1041 * expect to find a header, we have stepped upon
1042 * an archive without the customary block of zeroes
1043 * end marker. It's just stupid to error out on
1044 * them, so exit gracefully.
1045 */
1046 if (first && ret == 0)
1047 return(-1);
1048 first = 0;
1049
1050 /*
1009 * some kind of archive read problem, try to resync the
1010 * storage device, better give the user the bad news.
1011 */
1012 if ((ret == 0) || (rd_sync() < 0)) {
1013 paxwarn(1,"Premature end of file on archive read");
1014 return(-1);
1015 }
1016 if (!in_resync) {

--- 224 unchanged lines hidden ---
1051 * some kind of archive read problem, try to resync the
1052 * storage device, better give the user the bad news.
1053 */
1054 if ((ret == 0) || (rd_sync() < 0)) {
1055 paxwarn(1,"Premature end of file on archive read");
1056 return(-1);
1057 }
1058 if (!in_resync) {

--- 224 unchanged lines hidden ---