Deleted Added
full compact
cpio.c (90110) cpio.c (90113)
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[] = "@(#)cpio.c 8.1 (Berkeley) 5/31/93";
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[] = "@(#)cpio.c 8.1 (Berkeley) 5/31/93";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/cpio.c 90110 2002-02-02 06:48:10Z imp $";
43 "$FreeBSD: head/bin/pax/cpio.c 90113 2002-02-02 07:07:59Z 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 "cpio.h"
55#include "extern.h"
56
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 "cpio.h"
55#include "extern.h"
56
57static int rd_nm(register ARCHD *, int);
58static int rd_ln_nm(register ARCHD *);
59static int com_rd(register ARCHD *);
57static int rd_nm(ARCHD *, int);
58static int rd_ln_nm(ARCHD *);
59static int com_rd(ARCHD *);
60
61/*
62 * Routines which support the different cpio versions
63 */
64
65static int swp_head; /* binary cpio header byte swap */
66
67/*

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

87 * passed the block, the in_sync flag (which tells us we are in resync
88 * mode; looking for a valid header), and cnt (which starts at zero)
89 * which is used to count the number of empty blocks we have seen so far.
90 * Return:
91 * 0 if a valid trailer, -1 if not a valid trailer,
92 */
93
94int
60
61/*
62 * Routines which support the different cpio versions
63 */
64
65static int swp_head; /* binary cpio header byte swap */
66
67/*

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

87 * passed the block, the in_sync flag (which tells us we are in resync
88 * mode; looking for a valid header), and cnt (which starts at zero)
89 * which is used to count the number of empty blocks we have seen so far.
90 * Return:
91 * 0 if a valid trailer, -1 if not a valid trailer,
92 */
93
94int
95cpio_trail(register ARCHD *arcn)
95cpio_trail(ARCHD *arcn)
96{
97 /*
98 * look for trailer id in file we are about to process
99 */
100 if ((strcmp(arcn->name, TRAILER) == 0) && (arcn->sb.st_size == 0))
101 return(0);
102 return(-1);
103}
104
105/*
106 * com_rd()
107 * operations common to all cpio read functions.
108 * Return:
109 * 0
110 */
111
112static int
96{
97 /*
98 * look for trailer id in file we are about to process
99 */
100 if ((strcmp(arcn->name, TRAILER) == 0) && (arcn->sb.st_size == 0))
101 return(0);
102 return(-1);
103}
104
105/*
106 * com_rd()
107 * operations common to all cpio read functions.
108 * Return:
109 * 0
110 */
111
112static int
113com_rd(register ARCHD *arcn)
113com_rd(ARCHD *arcn)
114{
115 arcn->skip = 0;
116 arcn->pat = NULL;
117 arcn->org_name = arcn->name;
118 switch(arcn->sb.st_mode & C_IFMT) {
119 case C_ISFIFO:
120 arcn->type = PAX_FIF;
121 break;

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

177/*
178 * rd_nam()
179 * read in the file name which follows the cpio header
180 * Return:
181 * 0 if ok, -1 otherwise
182 */
183
184static int
114{
115 arcn->skip = 0;
116 arcn->pat = NULL;
117 arcn->org_name = arcn->name;
118 switch(arcn->sb.st_mode & C_IFMT) {
119 case C_ISFIFO:
120 arcn->type = PAX_FIF;
121 break;

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

177/*
178 * rd_nam()
179 * read in the file name which follows the cpio header
180 * Return:
181 * 0 if ok, -1 otherwise
182 */
183
184static int
185rd_nm(register ARCHD *arcn, int nsz)
185rd_nm(ARCHD *arcn, int nsz)
186{
187 /*
188 * do not even try bogus values
189 */
190 if ((nsz == 0) || (nsz > sizeof(arcn->name))) {
191 paxwarn(1, "Cpio file name length %d is out of range", nsz);
192 return(-1);
193 }

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

207 * rd_ln_nm()
208 * read in the link name for a file with links. The link name is stored
209 * like file data (and is NOT \0 terminated!)
210 * Return:
211 * 0 if ok, -1 otherwise
212 */
213
214static int
186{
187 /*
188 * do not even try bogus values
189 */
190 if ((nsz == 0) || (nsz > sizeof(arcn->name))) {
191 paxwarn(1, "Cpio file name length %d is out of range", nsz);
192 return(-1);
193 }

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

207 * rd_ln_nm()
208 * read in the link name for a file with links. The link name is stored
209 * like file data (and is NOT \0 terminated!)
210 * Return:
211 * 0 if ok, -1 otherwise
212 */
213
214static int
215rd_ln_nm(register ARCHD *arcn)
215rd_ln_nm(ARCHD *arcn)
216{
217 /*
218 * check the length specified for bogus values
219 */
220 if ((arcn->sb.st_size == 0) ||
221 (arcn->sb.st_size >= sizeof(arcn->ln_name))) {
222# ifdef NET2_STAT
223 paxwarn(1, "Cpio link name length is invalid: %lu",

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

275 * cpio_rd()
276 * determine if a buffer is a byte oriented extended cpio archive entry.
277 * convert and store the values in the ARCHD parameter.
278 * Return:
279 * 0 if a valid header, -1 otherwise.
280 */
281
282int
216{
217 /*
218 * check the length specified for bogus values
219 */
220 if ((arcn->sb.st_size == 0) ||
221 (arcn->sb.st_size >= sizeof(arcn->ln_name))) {
222# ifdef NET2_STAT
223 paxwarn(1, "Cpio link name length is invalid: %lu",

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

275 * cpio_rd()
276 * determine if a buffer is a byte oriented extended cpio archive entry.
277 * convert and store the values in the ARCHD parameter.
278 * Return:
279 * 0 if a valid header, -1 otherwise.
280 */
281
282int
283cpio_rd(register ARCHD *arcn, register char *buf)
283cpio_rd(ARCHD *arcn, char *buf)
284{
284{
285 register int nsz;
286 register HD_CPIO *hd;
285 int nsz;
286 HD_CPIO *hd;
287
288 /*
289 * check that this is a valid header, if not return -1
290 */
291 if (cpio_id(buf, sizeof(HD_CPIO)) < 0)
292 return(-1);
293 hd = (HD_CPIO *)buf;
294

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

384 * copy the data in the ARCHD to buffer in extended byte oriented cpio
385 * format.
386 * Return
387 * 0 if file has data to be written after the header, 1 if file has NO
388 * data to write after the header, -1 if archive write failed
389 */
390
391int
287
288 /*
289 * check that this is a valid header, if not return -1
290 */
291 if (cpio_id(buf, sizeof(HD_CPIO)) < 0)
292 return(-1);
293 hd = (HD_CPIO *)buf;
294

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

384 * copy the data in the ARCHD to buffer in extended byte oriented cpio
385 * format.
386 * Return
387 * 0 if file has data to be written after the header, 1 if file has NO
388 * data to write after the header, -1 if archive write failed
389 */
390
391int
392cpio_wr(register ARCHD *arcn)
392cpio_wr(ARCHD *arcn)
393{
393{
394 register HD_CPIO *hd;
395 register int nsz;
394 HD_CPIO *hd;
395 int nsz;
396 char hdblk[sizeof(HD_CPIO)];
397
398 /*
399 * check and repair truncated device and inode fields in the header
400 */
401 if (map_dev(arcn, (u_long)CPIO_MASK, (u_long)CPIO_MASK) < 0)
402 return(-1);
403

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

562 * vcpio_rd()
563 * determine if a buffer is a system VR4 archive entry. (with/without CRC)
564 * convert and store the values in the ARCHD parameter.
565 * Return:
566 * 0 if a valid header, -1 otherwise.
567 */
568
569int
396 char hdblk[sizeof(HD_CPIO)];
397
398 /*
399 * check and repair truncated device and inode fields in the header
400 */
401 if (map_dev(arcn, (u_long)CPIO_MASK, (u_long)CPIO_MASK) < 0)
402 return(-1);
403

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

562 * vcpio_rd()
563 * determine if a buffer is a system VR4 archive entry. (with/without CRC)
564 * convert and store the values in the ARCHD parameter.
565 * Return:
566 * 0 if a valid header, -1 otherwise.
567 */
568
569int
570vcpio_rd(register ARCHD *arcn, register char *buf)
570vcpio_rd(ARCHD *arcn, char *buf)
571{
571{
572 register HD_VCPIO *hd;
572 HD_VCPIO *hd;
573 dev_t devminor;
574 dev_t devmajor;
573 dev_t devminor;
574 dev_t devmajor;
575 register int nsz;
575 int nsz;
576
577 /*
578 * during the id phase it was determined if we were using CRC, use the
579 * proper id routine.
580 */
581 if (docrc) {
582 if (crc_id(buf, sizeof(HD_VCPIO)) < 0)
583 return(-1);

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

695 * copy the data in the ARCHD to buffer in system VR4 cpio
696 * (with/without crc) format.
697 * Return
698 * 0 if file has data to be written after the header, 1 if file has
699 * NO data to write after the header, -1 if archive write failed
700 */
701
702int
576
577 /*
578 * during the id phase it was determined if we were using CRC, use the
579 * proper id routine.
580 */
581 if (docrc) {
582 if (crc_id(buf, sizeof(HD_VCPIO)) < 0)
583 return(-1);

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

695 * copy the data in the ARCHD to buffer in system VR4 cpio
696 * (with/without crc) format.
697 * Return
698 * 0 if file has data to be written after the header, 1 if file has
699 * NO data to write after the header, -1 if archive write failed
700 */
701
702int
703vcpio_wr(register ARCHD *arcn)
703vcpio_wr(ARCHD *arcn)
704{
704{
705 register HD_VCPIO *hd;
705 HD_VCPIO *hd;
706 unsigned int nsz;
707 char hdblk[sizeof(HD_VCPIO)];
708
709 /*
710 * check and repair truncated device and inode fields in the cpio
711 * header
712 */
713 if (map_dev(arcn, (u_long)VCPIO_MASK, (u_long)VCPIO_MASK) < 0)

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

880 * determine if a buffer is a old binary archive entry. (it may have byte
881 * swapped header) convert and store the values in the ARCHD parameter.
882 * This is a very old header format and should not really be used.
883 * Return:
884 * 0 if a valid header, -1 otherwise.
885 */
886
887int
706 unsigned int nsz;
707 char hdblk[sizeof(HD_VCPIO)];
708
709 /*
710 * check and repair truncated device and inode fields in the cpio
711 * header
712 */
713 if (map_dev(arcn, (u_long)VCPIO_MASK, (u_long)VCPIO_MASK) < 0)

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

880 * determine if a buffer is a old binary archive entry. (it may have byte
881 * swapped header) convert and store the values in the ARCHD parameter.
882 * This is a very old header format and should not really be used.
883 * Return:
884 * 0 if a valid header, -1 otherwise.
885 */
886
887int
888bcpio_rd(register ARCHD *arcn, register char *buf)
888bcpio_rd(ARCHD *arcn, char *buf)
889{
889{
890 register HD_BCPIO *hd;
891 register int nsz;
890 HD_BCPIO *hd;
891 int nsz;
892
893 /*
894 * check the header
895 */
896 if (bcpio_id(buf, sizeof(HD_BCPIO)) < 0)
897 return(-1);
898
899 arcn->pad = 0L;

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

995 * always check the conversion is ok. nobody in his their right mind
996 * should write an achive in this format...
997 * Return
998 * 0 if file has data to be written after the header, 1 if file has NO
999 * data to write after the header, -1 if archive write failed
1000 */
1001
1002int
892
893 /*
894 * check the header
895 */
896 if (bcpio_id(buf, sizeof(HD_BCPIO)) < 0)
897 return(-1);
898
899 arcn->pad = 0L;

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

995 * always check the conversion is ok. nobody in his their right mind
996 * should write an achive in this format...
997 * Return
998 * 0 if file has data to be written after the header, 1 if file has NO
999 * data to write after the header, -1 if archive write failed
1000 */
1001
1002int
1003bcpio_wr(register ARCHD *arcn)
1003bcpio_wr(ARCHD *arcn)
1004{
1004{
1005 register HD_BCPIO *hd;
1006 register int nsz;
1005 HD_BCPIO *hd;
1006 int nsz;
1007 char hdblk[sizeof(HD_BCPIO)];
1008 off_t t_offt;
1009 int t_int;
1010 time_t t_timet;
1011
1012 /*
1013 * check and repair truncated device and inode fields in the cpio
1014 * header

--- 143 unchanged lines hidden ---
1007 char hdblk[sizeof(HD_BCPIO)];
1008 off_t t_offt;
1009 int t_int;
1010 time_t t_timet;
1011
1012 /*
1013 * check and repair truncated device and inode fields in the cpio
1014 * header

--- 143 unchanged lines hidden ---