cpio.h revision 1.1 1 1.1 jtc /*-
2 1.1 jtc * Copyright (c) 1992 Keith Muller.
3 1.1 jtc * Copyright (c) 1992, 1993
4 1.1 jtc * The Regents of the University of California. All rights reserved.
5 1.1 jtc *
6 1.1 jtc * This code is derived from software contributed to Berkeley by
7 1.1 jtc * Keith Muller of the University of California, San Diego.
8 1.1 jtc *
9 1.1 jtc * Redistribution and use in source and binary forms, with or without
10 1.1 jtc * modification, are permitted provided that the following conditions
11 1.1 jtc * are met:
12 1.1 jtc * 1. Redistributions of source code must retain the above copyright
13 1.1 jtc * notice, this list of conditions and the following disclaimer.
14 1.1 jtc * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 jtc * notice, this list of conditions and the following disclaimer in the
16 1.1 jtc * documentation and/or other materials provided with the distribution.
17 1.1 jtc * 3. All advertising materials mentioning features or use of this software
18 1.1 jtc * must display the following acknowledgement:
19 1.1 jtc * This product includes software developed by the University of
20 1.1 jtc * California, Berkeley and its contributors.
21 1.1 jtc * 4. Neither the name of the University nor the names of its contributors
22 1.1 jtc * may be used to endorse or promote products derived from this software
23 1.1 jtc * without specific prior written permission.
24 1.1 jtc *
25 1.1 jtc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 jtc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 jtc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 jtc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 jtc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 jtc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 jtc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 jtc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 jtc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 jtc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 jtc * SUCH DAMAGE.
36 1.1 jtc *
37 1.1 jtc * @(#)cpio.h 8.1 (Berkeley) 5/31/93
38 1.1 jtc */
39 1.1 jtc
40 1.1 jtc /*
41 1.1 jtc * Defines common to all versions of cpio
42 1.1 jtc */
43 1.1 jtc #define TRAILER "TRAILER!!!" /* name in last archive record */
44 1.1 jtc
45 1.1 jtc /*
46 1.1 jtc * Header encoding of the different file types
47 1.1 jtc */
48 1.1 jtc #define C_ISDIR 040000 /* Directory */
49 1.1 jtc #define C_ISFIFO 010000 /* FIFO */
50 1.1 jtc #define C_ISREG 0100000 /* Regular file */
51 1.1 jtc #define C_ISBLK 060000 /* Block special file */
52 1.1 jtc #define C_ISCHR 020000 /* Character special file */
53 1.1 jtc #define C_ISCTG 0110000 /* Reserved for contiguous files */
54 1.1 jtc #define C_ISLNK 0120000 /* Reserved for symbolic links */
55 1.1 jtc #define C_ISOCK 0140000 /* Reserved for sockets */
56 1.1 jtc #define C_IFMT 0170000 /* type of file */
57 1.1 jtc
58 1.1 jtc /*
59 1.1 jtc * Data Interchange Format - Extended cpio header format - POSIX 1003.1-1990
60 1.1 jtc */
61 1.1 jtc typedef struct {
62 1.1 jtc char c_magic[6]; /* magic cookie */
63 1.1 jtc char c_dev[6]; /* device number */
64 1.1 jtc char c_ino[6]; /* inode number */
65 1.1 jtc char c_mode[6]; /* file type/access */
66 1.1 jtc char c_uid[6]; /* owners uid */
67 1.1 jtc char c_gid[6]; /* owners gid */
68 1.1 jtc char c_nlink[6]; /* # of links at archive creation */
69 1.1 jtc char c_rdev[6]; /* block/char major/minor # */
70 1.1 jtc char c_mtime[11]; /* modification time */
71 1.1 jtc char c_namesize[6]; /* length of pathname */
72 1.1 jtc char c_filesize[11]; /* length of file in bytes */
73 1.1 jtc } HD_CPIO;
74 1.1 jtc
75 1.1 jtc #define MAGIC 070707 /* transportable archive id */
76 1.1 jtc
77 1.1 jtc #ifdef _PAX_
78 1.1 jtc #define AMAGIC "070707" /* ascii equivalent string of MAGIC */
79 1.1 jtc #define CPIO_MASK 0x3ffff /* bits valid in the dev/ino fields */
80 1.1 jtc /* used for dev/inode remaps */
81 1.1 jtc #endif /* _PAX_ */
82 1.1 jtc
83 1.1 jtc /*
84 1.1 jtc * Binary cpio header structure
85 1.1 jtc *
86 1.1 jtc * CAUTION! CAUTION! CAUTION!
87 1.1 jtc * Each field really represents a 16 bit short (NOT ASCII). Described as
88 1.1 jtc * an array of chars in an attempt to improve portability!!
89 1.1 jtc */
90 1.1 jtc typedef struct {
91 1.1 jtc u_char h_magic[2];
92 1.1 jtc u_char h_dev[2];
93 1.1 jtc u_char h_ino[2];
94 1.1 jtc u_char h_mode[2];
95 1.1 jtc u_char h_uid[2];
96 1.1 jtc u_char h_gid[2];
97 1.1 jtc u_char h_nlink[2];
98 1.1 jtc u_char h_rdev[2];
99 1.1 jtc u_char h_mtime_1[2];
100 1.1 jtc u_char h_mtime_2[2];
101 1.1 jtc u_char h_namesize[2];
102 1.1 jtc u_char h_filesize_1[2];
103 1.1 jtc u_char h_filesize_2[2];
104 1.1 jtc } HD_BCPIO;
105 1.1 jtc
106 1.1 jtc #ifdef _PAX_
107 1.1 jtc /*
108 1.1 jtc * extraction and creation macros for binary cpio
109 1.1 jtc */
110 1.1 jtc #define SHRT_EXT(ch) ((((unsigned)(ch)[0])<<8) | (((unsigned)(ch)[1])&0xff))
111 1.1 jtc #define RSHRT_EXT(ch) ((((unsigned)(ch)[1])<<8) | (((unsigned)(ch)[0])&0xff))
112 1.1 jtc #define CHR_WR_0(val) ((char)(((val) >> 24) & 0xff))
113 1.1 jtc #define CHR_WR_1(val) ((char)(((val) >> 16) & 0xff))
114 1.1 jtc #define CHR_WR_2(val) ((char)(((val) >> 8) & 0xff))
115 1.1 jtc #define CHR_WR_3(val) ((char)((val) & 0xff))
116 1.1 jtc
117 1.1 jtc /*
118 1.1 jtc * binary cpio masks and pads
119 1.1 jtc */
120 1.1 jtc #define BCPIO_PAD(x) ((2 - ((x) & 1)) & 1) /* pad to next 2 byte word */
121 1.1 jtc #define BCPIO_MASK 0xffff /* mask for dev/ino fields */
122 1.1 jtc #endif /* _PAX_ */
123 1.1 jtc
124 1.1 jtc /*
125 1.1 jtc * System VR4 cpio header structure (with/without file data crc)
126 1.1 jtc */
127 1.1 jtc typedef struct {
128 1.1 jtc char c_magic[6]; /* magic cookie */
129 1.1 jtc char c_ino[8]; /* inode number */
130 1.1 jtc char c_mode[8]; /* file type/access */
131 1.1 jtc char c_uid[8]; /* owners uid */
132 1.1 jtc char c_gid[8]; /* owners gid */
133 1.1 jtc char c_nlink[8]; /* # of links at archive creation */
134 1.1 jtc char c_mtime[8]; /* modification time */
135 1.1 jtc char c_filesize[8]; /* length of file in bytes */
136 1.1 jtc char c_maj[8]; /* block/char major # */
137 1.1 jtc char c_min[8]; /* block/char minor # */
138 1.1 jtc char c_rmaj[8]; /* special file major # */
139 1.1 jtc char c_rmin[8]; /* special file minor # */
140 1.1 jtc char c_namesize[8]; /* length of pathname */
141 1.1 jtc char c_chksum[8]; /* 0 OR CRC of bytes of FILE data */
142 1.1 jtc } HD_VCPIO;
143 1.1 jtc
144 1.1 jtc #define VMAGIC 070701 /* sVr4 new portable archive id */
145 1.1 jtc #define VCMAGIC 070702 /* sVr4 new portable archive id CRC */
146 1.1 jtc #ifdef _PAX_
147 1.1 jtc #define AVMAGIC "070701" /* ascii string of above */
148 1.1 jtc #define AVCMAGIC "070702" /* ascii string of above */
149 1.1 jtc #define VCPIO_PAD(x) ((4 - ((x) & 3)) & 3) /* pad to next 4 byte word */
150 1.1 jtc #define VCPIO_MASK 0xffffffff /* mask for dev/ino fields */
151 1.1 jtc #endif /* _PAX_ */
152