Deleted Added
full compact
tar.c (85618) tar.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[] = "@(#)tar.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[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/tar.c 85618 2001-10-28 02:51:43Z dillon $";
43 "$FreeBSD: head/bin/pax/tar.c 90110 2002-02-02 06:48:10Z imp $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <string.h>
50#include <stdio.h>
51#include <unistd.h>
52#include <stdlib.h>
53#include "pax.h"
54#include "extern.h"
55#include "tar.h"
56
57/*
58 * Routines for reading, writing and header identify of various versions of tar
59 */
60
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <string.h>
50#include <stdio.h>
51#include <unistd.h>
52#include <stdlib.h>
53#include "pax.h"
54#include "extern.h"
55#include "tar.h"
56
57/*
58 * Routines for reading, writing and header identify of various versions of tar
59 */
60
61static u_long tar_chksm __P((register char *, register int));
62static char *name_split __P((register char *, register int));
63static int ul_oct __P((u_long, register char *, register int, int));
61static u_long tar_chksm(register char *, register int);
62static char *name_split(register char *, register int);
63static int ul_oct(u_long, register char *, register int, int);
64#ifndef NET2_STAT
64#ifndef NET2_STAT
65static int uqd_oct __P((u_quad_t, register char *, register int, int));
65static int uqd_oct(u_quad_t, register char *, register int, int);
66#endif
67
68/*
69 * Routines common to all versions of tar
70 */
71
72static int tar_nodir; /* do not write dirs under old tar */
73
74/*
75 * tar_endwr()
76 * add the tar trailer of two null blocks
77 * Return:
78 * 0 if ok, -1 otherwise (what wr_skip returns)
79 */
80
66#endif
67
68/*
69 * Routines common to all versions of tar
70 */
71
72static int tar_nodir; /* do not write dirs under old tar */
73
74/*
75 * tar_endwr()
76 * add the tar trailer of two null blocks
77 * Return:
78 * 0 if ok, -1 otherwise (what wr_skip returns)
79 */
80
81#ifdef __STDC__
82int
83tar_endwr(void)
81int
82tar_endwr(void)
84#else
85int
86tar_endwr()
87#endif
88{
89 return(wr_skip((off_t)(NULLCNT*BLKMULT)));
90}
91
92/*
93 * tar_endrd()
94 * no cleanup needed here, just return size of trailer (for append)
95 * Return:
96 * size of trailer (2 * BLKMULT)
97 */
98
83{
84 return(wr_skip((off_t)(NULLCNT*BLKMULT)));
85}
86
87/*
88 * tar_endrd()
89 * no cleanup needed here, just return size of trailer (for append)
90 * Return:
91 * size of trailer (2 * BLKMULT)
92 */
93
99#ifdef __STDC__
100off_t
101tar_endrd(void)
94off_t
95tar_endrd(void)
102#else
103off_t
104tar_endrd()
105#endif
106{
107 return((off_t)(NULLCNT*BLKMULT));
108}
109
110/*
111 * tar_trail()
112 * Called to determine if a header block is a valid trailer. We are passed
113 * the block, the in_sync flag (which tells us we are in resync mode;
114 * looking for a valid header), and cnt (which starts at zero) which is
115 * used to count the number of empty blocks we have seen so far.
116 * Return:
117 * 0 if a valid trailer, -1 if not a valid trailer, or 1 if the block
118 * could never contain a header.
119 */
120
96{
97 return((off_t)(NULLCNT*BLKMULT));
98}
99
100/*
101 * tar_trail()
102 * Called to determine if a header block is a valid trailer. We are passed
103 * the block, the in_sync flag (which tells us we are in resync mode;
104 * looking for a valid header), and cnt (which starts at zero) which is
105 * used to count the number of empty blocks we have seen so far.
106 * Return:
107 * 0 if a valid trailer, -1 if not a valid trailer, or 1 if the block
108 * could never contain a header.
109 */
110
121#ifdef __STDC__
122int
123tar_trail(register char *buf, register int in_resync, register int *cnt)
111int
112tar_trail(register char *buf, register int in_resync, register int *cnt)
124#else
125int
126tar_trail(buf, in_resync, cnt)
127 register char *buf;
128 register int in_resync;
129 register int *cnt;
130#endif
131{
132 register int i;
133
134 /*
135 * look for all zero, trailer is two consecutive blocks of zero
136 */
137 for (i = 0; i < BLKMULT; ++i) {
138 if (buf[i] != '\0')

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

164 * termination characters are used by the various versions of tar in the
165 * different fields. term selects which kind to use. str is '0' padded
166 * at the front to len. we are unable to use only one format as many old
167 * tar readers are very cranky about this.
168 * Return:
169 * 0 if the number fit into the string, -1 otherwise
170 */
171
113{
114 register int i;
115
116 /*
117 * look for all zero, trailer is two consecutive blocks of zero
118 */
119 for (i = 0; i < BLKMULT; ++i) {
120 if (buf[i] != '\0')

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

146 * termination characters are used by the various versions of tar in the
147 * different fields. term selects which kind to use. str is '0' padded
148 * at the front to len. we are unable to use only one format as many old
149 * tar readers are very cranky about this.
150 * Return:
151 * 0 if the number fit into the string, -1 otherwise
152 */
153
172#ifdef __STDC__
173static int
174ul_oct(u_long val, register char *str, register int len, int term)
154static int
155ul_oct(u_long val, register char *str, register int len, int term)
175#else
176static int
177ul_oct(val, str, len, term)
178 u_long val;
179 register char *str;
180 register int len;
181 int term;
182#endif
183{
184 register char *pt;
185
186 /*
187 * term selects the appropriate character(s) for the end of the string
188 */
189 pt = str + len - 1;
190 switch(term) {

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

228 * termination characters are used by the various versions of tar in the
229 * different fields. term selects which kind to use. str is '0' padded
230 * at the front to len. we are unable to use only one format as many old
231 * tar readers are very cranky about this.
232 * Return:
233 * 0 if the number fit into the string, -1 otherwise
234 */
235
156{
157 register char *pt;
158
159 /*
160 * term selects the appropriate character(s) for the end of the string
161 */
162 pt = str + len - 1;
163 switch(term) {

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

201 * termination characters are used by the various versions of tar in the
202 * different fields. term selects which kind to use. str is '0' padded
203 * at the front to len. we are unable to use only one format as many old
204 * tar readers are very cranky about this.
205 * Return:
206 * 0 if the number fit into the string, -1 otherwise
207 */
208
236#ifdef __STDC__
237static int
238uqd_oct(u_quad_t val, register char *str, register int len, int term)
209static int
210uqd_oct(u_quad_t val, register char *str, register int len, int term)
239#else
240static int
241uqd_oct(val, str, len, term)
242 u_quad_t val;
243 register char *str;
244 register int len;
245 int term;
246#endif
247{
248 register char *pt;
249
250 /*
251 * term selects the appropriate character(s) for the end of the string
252 */
253 pt = str + len - 1;
254 switch(term) {

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

291 * calculate the checksum for a tar block counting the checksum field as
292 * all blanks (BLNKSUM is that value pre-calculated, the sum of 8 blanks).
293 * NOTE: we use len to short circuit summing 0's on write since we ALWAYS
294 * pad headers with 0.
295 * Return:
296 * unsigned long checksum
297 */
298
211{
212 register char *pt;
213
214 /*
215 * term selects the appropriate character(s) for the end of the string
216 */
217 pt = str + len - 1;
218 switch(term) {

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

255 * calculate the checksum for a tar block counting the checksum field as
256 * all blanks (BLNKSUM is that value pre-calculated, the sum of 8 blanks).
257 * NOTE: we use len to short circuit summing 0's on write since we ALWAYS
258 * pad headers with 0.
259 * Return:
260 * unsigned long checksum
261 */
262
299#ifdef __STDC__
300static u_long
301tar_chksm(register char *blk, register int len)
263static u_long
264tar_chksm(register char *blk, register int len)
302#else
303static u_long
304tar_chksm(blk, len)
305 register char *blk;
306 register int len;
307#endif
308{
309 register char *stop;
310 register char *pt;
311 u_long chksm = BLNKSUM; /* initial value is checksum field sum */
312
313 /*
314 * add the part of the block before the checksum field
315 */

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

339 * tar_id()
340 * determine if a block given to us is a valid tar header (and not a USTAR
341 * header). We have to be on the lookout for those pesky blocks of all
342 * zero's.
343 * Return:
344 * 0 if a tar header, -1 otherwise
345 */
346
265{
266 register char *stop;
267 register char *pt;
268 u_long chksm = BLNKSUM; /* initial value is checksum field sum */
269
270 /*
271 * add the part of the block before the checksum field
272 */

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

296 * tar_id()
297 * determine if a block given to us is a valid tar header (and not a USTAR
298 * header). We have to be on the lookout for those pesky blocks of all
299 * zero's.
300 * Return:
301 * 0 if a tar header, -1 otherwise
302 */
303
347#ifdef __STDC__
348int
349tar_id(register char *blk, int size)
304int
305tar_id(register char *blk, int size)
350#else
351int
352tar_id(blk, size)
353 register char *blk;
354 int size;
355#endif
356{
357 register HD_TAR *hd;
358 register HD_USTAR *uhd;
359
360 if (size < BLKMULT)
361 return(-1);
362 hd = (HD_TAR *)blk;
363 uhd = (HD_USTAR *)blk;

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

380
381/*
382 * tar_opt()
383 * handle tar format specific -o options
384 * Return:
385 * 0 if ok -1 otherwise
386 */
387
306{
307 register HD_TAR *hd;
308 register HD_USTAR *uhd;
309
310 if (size < BLKMULT)
311 return(-1);
312 hd = (HD_TAR *)blk;
313 uhd = (HD_USTAR *)blk;

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

330
331/*
332 * tar_opt()
333 * handle tar format specific -o options
334 * Return:
335 * 0 if ok -1 otherwise
336 */
337
388#ifdef __STDC__
389int
390tar_opt(void)
338int
339tar_opt(void)
391#else
392int
393tar_opt()
394#endif
395{
396 OPLIST *opt;
397
398 while ((opt = opt_next()) != NULL) {
399 if (strcmp(opt->name, TAR_OPTION) ||
400 strcmp(opt->value, TAR_NODIR)) {
401 paxwarn(1, "Unknown tar format -o option/value pair %s=%s",
402 opt->name, opt->value);

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

422/*
423 * tar_rd()
424 * extract the values out of block already determined to be a tar header.
425 * store the values in the ARCHD parameter.
426 * Return:
427 * 0
428 */
429
340{
341 OPLIST *opt;
342
343 while ((opt = opt_next()) != NULL) {
344 if (strcmp(opt->name, TAR_OPTION) ||
345 strcmp(opt->value, TAR_NODIR)) {
346 paxwarn(1, "Unknown tar format -o option/value pair %s=%s",
347 opt->name, opt->value);

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

367/*
368 * tar_rd()
369 * extract the values out of block already determined to be a tar header.
370 * store the values in the ARCHD parameter.
371 * Return:
372 * 0
373 */
374
430#ifdef __STDC__
431int
432tar_rd(register ARCHD *arcn, register char *buf)
375int
376tar_rd(register ARCHD *arcn, register char *buf)
433#else
434int
435tar_rd(arcn, buf)
436 register ARCHD *arcn;
437 register char *buf;
438#endif
439{
440 register HD_TAR *hd;
441 register char *pt;
442
443 /*
444 * we only get proper sized buffers passed to us
445 */
446 if (tar_id(buf, BLKMULT) < 0)

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

560 * are too long. Be careful of the term (last arg) to ul_oct, each field
561 * of tar has it own spec for the termination character(s).
562 * ASSUMED: space after header in header block is zero filled
563 * Return:
564 * 0 if file has data to be written after the header, 1 if file has NO
565 * data to write after the header, -1 if archive write failed
566 */
567
377{
378 register HD_TAR *hd;
379 register char *pt;
380
381 /*
382 * we only get proper sized buffers passed to us
383 */
384 if (tar_id(buf, BLKMULT) < 0)

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

498 * are too long. Be careful of the term (last arg) to ul_oct, each field
499 * of tar has it own spec for the termination character(s).
500 * ASSUMED: space after header in header block is zero filled
501 * Return:
502 * 0 if file has data to be written after the header, 1 if file has NO
503 * data to write after the header, -1 if archive write failed
504 */
505
568#ifdef __STDC__
569int
570tar_wr(register ARCHD *arcn)
506int
507tar_wr(register ARCHD *arcn)
571#else
572int
573tar_wr(arcn)
574 register ARCHD *arcn;
575#endif
576{
577 register HD_TAR *hd;
578 int len;
579 char hdblk[sizeof(HD_TAR)];
580
581 /*
582 * check for those file system types which tar cannot store
583 */

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

727
728/*
729 * ustar_strd()
730 * initialization for ustar read
731 * Return:
732 * 0 if ok, -1 otherwise
733 */
734
508{
509 register HD_TAR *hd;
510 int len;
511 char hdblk[sizeof(HD_TAR)];
512
513 /*
514 * check for those file system types which tar cannot store
515 */

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

659
660/*
661 * ustar_strd()
662 * initialization for ustar read
663 * Return:
664 * 0 if ok, -1 otherwise
665 */
666
735#ifdef __STDC__
736int
737ustar_strd(void)
667int
668ustar_strd(void)
738#else
739int
740ustar_strd()
741#endif
742{
743 if ((usrtb_start() < 0) || (grptb_start() < 0))
744 return(-1);
745 return(0);
746}
747
748/*
749 * ustar_stwr()
750 * initialization for ustar write
751 * Return:
752 * 0 if ok, -1 otherwise
753 */
754
669{
670 if ((usrtb_start() < 0) || (grptb_start() < 0))
671 return(-1);
672 return(0);
673}
674
675/*
676 * ustar_stwr()
677 * initialization for ustar write
678 * Return:
679 * 0 if ok, -1 otherwise
680 */
681
755#ifdef __STDC__
756int
757ustar_stwr(void)
682int
683ustar_stwr(void)
758#else
759int
760ustar_stwr()
761#endif
762{
763 if ((uidtb_start() < 0) || (gidtb_start() < 0))
764 return(-1);
765 return(0);
766}
767
768/*
769 * ustar_id()
770 * determine if a block given to us is a valid ustar header. We have to
771 * be on the lookout for those pesky blocks of all zero's
772 * Return:
773 * 0 if a ustar header, -1 otherwise
774 */
775
684{
685 if ((uidtb_start() < 0) || (gidtb_start() < 0))
686 return(-1);
687 return(0);
688}
689
690/*
691 * ustar_id()
692 * determine if a block given to us is a valid ustar header. We have to
693 * be on the lookout for those pesky blocks of all zero's
694 * Return:
695 * 0 if a ustar header, -1 otherwise
696 */
697
776#ifdef __STDC__
777int
778ustar_id(char *blk, int size)
698int
699ustar_id(char *blk, int size)
779#else
780int
781ustar_id(blk, size)
782 char *blk;
783 int size;
784#endif
785{
786 register HD_USTAR *hd;
787
788 if (size < BLKMULT)
789 return(-1);
790 hd = (HD_USTAR *)blk;
791
792 /*

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

807/*
808 * ustar_rd()
809 * extract the values out of block already determined to be a ustar header.
810 * store the values in the ARCHD parameter.
811 * Return:
812 * 0
813 */
814
700{
701 register HD_USTAR *hd;
702
703 if (size < BLKMULT)
704 return(-1);
705 hd = (HD_USTAR *)blk;
706
707 /*

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

722/*
723 * ustar_rd()
724 * extract the values out of block already determined to be a ustar header.
725 * store the values in the ARCHD parameter.
726 * Return:
727 * 0
728 */
729
815#ifdef __STDC__
816int
817ustar_rd(register ARCHD *arcn, register char *buf)
730int
731ustar_rd(register ARCHD *arcn, register char *buf)
818#else
819int
820ustar_rd(arcn, buf)
821 register ARCHD *arcn;
822 register char *buf;
823#endif
824{
825 register HD_USTAR *hd;
826 register char *dest;
827 register int cnt = 0;
828 dev_t devmajor;
829 dev_t devminor;
830
831 /*

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

971 * are too long. Be careful of the term (last arg) to ul_oct, we only use
972 * '\0' for the termination character (this is different than picky tar)
973 * ASSUMED: space after header in header block is zero filled
974 * Return:
975 * 0 if file has data to be written after the header, 1 if file has NO
976 * data to write after the header, -1 if archive write failed
977 */
978
732{
733 register HD_USTAR *hd;
734 register char *dest;
735 register int cnt = 0;
736 dev_t devmajor;
737 dev_t devminor;
738
739 /*

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

879 * are too long. Be careful of the term (last arg) to ul_oct, we only use
880 * '\0' for the termination character (this is different than picky tar)
881 * ASSUMED: space after header in header block is zero filled
882 * Return:
883 * 0 if file has data to be written after the header, 1 if file has NO
884 * data to write after the header, -1 if archive write failed
885 */
886
979#ifdef __STDC__
980int
981ustar_wr(register ARCHD *arcn)
887int
888ustar_wr(register ARCHD *arcn)
982#else
983int
984ustar_wr(arcn)
985 register ARCHD *arcn;
986#endif
987{
988 register HD_USTAR *hd;
989 register char *pt;
990 char hdblk[sizeof(HD_USTAR)];
991
992 /*
993 * check for those file system types ustar cannot store
994 */

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

1159 * The split point is always at a /
1160 * Return
1161 * character pointer to split point (always the / that is to be removed
1162 * if the split is not needed, the points is set to the start of the file
1163 * name (it would violate the spec to split there). A NULL is returned if
1164 * the file name is too long
1165 */
1166
889{
890 register HD_USTAR *hd;
891 register char *pt;
892 char hdblk[sizeof(HD_USTAR)];
893
894 /*
895 * check for those file system types ustar cannot store
896 */

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

1061 * The split point is always at a /
1062 * Return
1063 * character pointer to split point (always the / that is to be removed
1064 * if the split is not needed, the points is set to the start of the file
1065 * name (it would violate the spec to split there). A NULL is returned if
1066 * the file name is too long
1067 */
1068
1167#ifdef __STDC__
1168static char *
1169name_split(register char *name, register int len)
1069static char *
1070name_split(register char *name, register int len)
1170#else
1171static char *
1172name_split(name, len)
1173 register char *name;
1174 register int len;
1175#endif
1176{
1177 register char *start;
1178
1179 /*
1180 * check to see if the file name is small enough to fit in the name
1181 * field. if so just return a pointer to the name.
1182 */
1183 if (len < TNMSZ)

--- 36 unchanged lines hidden ---
1071{
1072 register char *start;
1073
1074 /*
1075 * check to see if the file name is small enough to fit in the name
1076 * field. if so just return a pointer to the name.
1077 */
1078 if (len < TNMSZ)

--- 36 unchanged lines hidden ---