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