14b88c807SRodney W. Grimes /*- 2*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*8a16b7a1SPedro F. Giffuni * 44b88c807SRodney W. Grimes * Copyright (c) 1992 Keith Muller. 54b88c807SRodney W. Grimes * Copyright (c) 1992, 1993 64b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 74b88c807SRodney W. Grimes * 84b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 94b88c807SRodney W. Grimes * Keith Muller of the University of California, San Diego. 104b88c807SRodney W. Grimes * 114b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 124b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 134b88c807SRodney W. Grimes * are met: 144b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 154b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 164b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 174b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 184b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 19fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 204b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 214b88c807SRodney W. Grimes * without specific prior written permission. 224b88c807SRodney W. Grimes * 234b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 244b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 254b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 264b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 274b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 284b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 294b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 304b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 314b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 324b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 334b88c807SRodney W. Grimes * SUCH DAMAGE. 344b88c807SRodney W. Grimes */ 354b88c807SRodney W. Grimes 364b88c807SRodney W. Grimes /* 374b88c807SRodney W. Grimes * Defines common to all versions of cpio 384b88c807SRodney W. Grimes */ 394b88c807SRodney W. Grimes #define TRAILER "TRAILER!!!" /* name in last archive record */ 404b88c807SRodney W. Grimes 414b88c807SRodney W. Grimes /* 424b88c807SRodney W. Grimes * Header encoding of the different file types 434b88c807SRodney W. Grimes */ 444b88c807SRodney W. Grimes #define C_ISDIR 040000 /* Directory */ 454b88c807SRodney W. Grimes #define C_ISFIFO 010000 /* FIFO */ 464b88c807SRodney W. Grimes #define C_ISREG 0100000 /* Regular file */ 474b88c807SRodney W. Grimes #define C_ISBLK 060000 /* Block special file */ 484b88c807SRodney W. Grimes #define C_ISCHR 020000 /* Character special file */ 494b88c807SRodney W. Grimes #define C_ISCTG 0110000 /* Reserved for contiguous files */ 504b88c807SRodney W. Grimes #define C_ISLNK 0120000 /* Reserved for symbolic links */ 514b88c807SRodney W. Grimes #define C_ISOCK 0140000 /* Reserved for sockets */ 524b88c807SRodney W. Grimes #define C_IFMT 0170000 /* type of file */ 534b88c807SRodney W. Grimes 544b88c807SRodney W. Grimes /* 554b88c807SRodney W. Grimes * Data Interchange Format - Extended cpio header format - POSIX 1003.1-1990 564b88c807SRodney W. Grimes */ 574b88c807SRodney W. Grimes typedef struct { 584b88c807SRodney W. Grimes char c_magic[6]; /* magic cookie */ 594b88c807SRodney W. Grimes char c_dev[6]; /* device number */ 604b88c807SRodney W. Grimes char c_ino[6]; /* inode number */ 614b88c807SRodney W. Grimes char c_mode[6]; /* file type/access */ 624b88c807SRodney W. Grimes char c_uid[6]; /* owners uid */ 634b88c807SRodney W. Grimes char c_gid[6]; /* owners gid */ 644b88c807SRodney W. Grimes char c_nlink[6]; /* # of links at archive creation */ 654b88c807SRodney W. Grimes char c_rdev[6]; /* block/char major/minor # */ 664b88c807SRodney W. Grimes char c_mtime[11]; /* modification time */ 674b88c807SRodney W. Grimes char c_namesize[6]; /* length of pathname */ 684b88c807SRodney W. Grimes char c_filesize[11]; /* length of file in bytes */ 69ff52ef95SWarner Losh } HD_CPIO __aligned(1); 704b88c807SRodney W. Grimes 714b88c807SRodney W. Grimes #define MAGIC 070707 /* transportable archive id */ 724b88c807SRodney W. Grimes 734b88c807SRodney W. Grimes #ifdef _PAX_ 744b88c807SRodney W. Grimes #define AMAGIC "070707" /* ascii equivalent string of MAGIC */ 754b88c807SRodney W. Grimes #define CPIO_MASK 0x3ffff /* bits valid in the dev/ino fields */ 764b88c807SRodney W. Grimes /* used for dev/inode remaps */ 774b88c807SRodney W. Grimes #endif /* _PAX_ */ 784b88c807SRodney W. Grimes 794b88c807SRodney W. Grimes /* 804b88c807SRodney W. Grimes * Binary cpio header structure 814b88c807SRodney W. Grimes * 824b88c807SRodney W. Grimes * CAUTION! CAUTION! CAUTION! 834b88c807SRodney W. Grimes * Each field really represents a 16 bit short (NOT ASCII). Described as 844b88c807SRodney W. Grimes * an array of chars in an attempt to improve portability!! 854b88c807SRodney W. Grimes */ 864b88c807SRodney W. Grimes typedef struct { 874b88c807SRodney W. Grimes u_char h_magic[2]; 884b88c807SRodney W. Grimes u_char h_dev[2]; 894b88c807SRodney W. Grimes u_char h_ino[2]; 904b88c807SRodney W. Grimes u_char h_mode[2]; 914b88c807SRodney W. Grimes u_char h_uid[2]; 924b88c807SRodney W. Grimes u_char h_gid[2]; 934b88c807SRodney W. Grimes u_char h_nlink[2]; 944b88c807SRodney W. Grimes u_char h_rdev[2]; 954b88c807SRodney W. Grimes u_char h_mtime_1[2]; 964b88c807SRodney W. Grimes u_char h_mtime_2[2]; 974b88c807SRodney W. Grimes u_char h_namesize[2]; 984b88c807SRodney W. Grimes u_char h_filesize_1[2]; 994b88c807SRodney W. Grimes u_char h_filesize_2[2]; 100ff52ef95SWarner Losh } HD_BCPIO __aligned(1); 1014b88c807SRodney W. Grimes 1024b88c807SRodney W. Grimes #ifdef _PAX_ 1034b88c807SRodney W. Grimes /* 1044b88c807SRodney W. Grimes * extraction and creation macros for binary cpio 1054b88c807SRodney W. Grimes */ 1064b88c807SRodney W. Grimes #define SHRT_EXT(ch) ((((unsigned)(ch)[0])<<8) | (((unsigned)(ch)[1])&0xff)) 1074b88c807SRodney W. Grimes #define RSHRT_EXT(ch) ((((unsigned)(ch)[1])<<8) | (((unsigned)(ch)[0])&0xff)) 1084b88c807SRodney W. Grimes #define CHR_WR_0(val) ((char)(((val) >> 24) & 0xff)) 1094b88c807SRodney W. Grimes #define CHR_WR_1(val) ((char)(((val) >> 16) & 0xff)) 1104b88c807SRodney W. Grimes #define CHR_WR_2(val) ((char)(((val) >> 8) & 0xff)) 1114b88c807SRodney W. Grimes #define CHR_WR_3(val) ((char)((val) & 0xff)) 1124b88c807SRodney W. Grimes 1134b88c807SRodney W. Grimes /* 1144b88c807SRodney W. Grimes * binary cpio masks and pads 1154b88c807SRodney W. Grimes */ 1164b88c807SRodney W. Grimes #define BCPIO_PAD(x) ((2 - ((x) & 1)) & 1) /* pad to next 2 byte word */ 1174b88c807SRodney W. Grimes #define BCPIO_MASK 0xffff /* mask for dev/ino fields */ 1184b88c807SRodney W. Grimes #endif /* _PAX_ */ 1194b88c807SRodney W. Grimes 1204b88c807SRodney W. Grimes /* 1214b88c807SRodney W. Grimes * System VR4 cpio header structure (with/without file data crc) 1224b88c807SRodney W. Grimes */ 1234b88c807SRodney W. Grimes typedef struct { 1244b88c807SRodney W. Grimes char c_magic[6]; /* magic cookie */ 1254b88c807SRodney W. Grimes char c_ino[8]; /* inode number */ 1264b88c807SRodney W. Grimes char c_mode[8]; /* file type/access */ 1274b88c807SRodney W. Grimes char c_uid[8]; /* owners uid */ 1284b88c807SRodney W. Grimes char c_gid[8]; /* owners gid */ 1294b88c807SRodney W. Grimes char c_nlink[8]; /* # of links at archive creation */ 1304b88c807SRodney W. Grimes char c_mtime[8]; /* modification time */ 1314b88c807SRodney W. Grimes char c_filesize[8]; /* length of file in bytes */ 1324b88c807SRodney W. Grimes char c_maj[8]; /* block/char major # */ 1334b88c807SRodney W. Grimes char c_min[8]; /* block/char minor # */ 1344b88c807SRodney W. Grimes char c_rmaj[8]; /* special file major # */ 1354b88c807SRodney W. Grimes char c_rmin[8]; /* special file minor # */ 1364b88c807SRodney W. Grimes char c_namesize[8]; /* length of pathname */ 1374b88c807SRodney W. Grimes char c_chksum[8]; /* 0 OR CRC of bytes of FILE data */ 138ff52ef95SWarner Losh } HD_VCPIO __aligned(1); 1394b88c807SRodney W. Grimes 1404b88c807SRodney W. Grimes #define VMAGIC 070701 /* sVr4 new portable archive id */ 1414b88c807SRodney W. Grimes #define VCMAGIC 070702 /* sVr4 new portable archive id CRC */ 1424b88c807SRodney W. Grimes #ifdef _PAX_ 1434b88c807SRodney W. Grimes #define AVMAGIC "070701" /* ascii string of above */ 1444b88c807SRodney W. Grimes #define AVCMAGIC "070702" /* ascii string of above */ 1454b88c807SRodney W. Grimes #define VCPIO_PAD(x) ((4 - ((x) & 3)) & 3) /* pad to next 4 byte word */ 1464b88c807SRodney W. Grimes #define VCPIO_MASK 0xffffffff /* mask for dev/ino fields */ 1474b88c807SRodney W. Grimes #endif /* _PAX_ */ 148