xref: /csrg-svn/bin/pax/cpio.h (revision 60676)
157116Smuller /*-
257116Smuller  * Copyright (c) 1992 Keith Muller.
3*60676Sbostic  * Copyright (c) 1992, 1993
4*60676Sbostic  *	The Regents of the University of California.  All rights reserved.
557116Smuller  *
657116Smuller  * This code is derived from software contributed to Berkeley by
757116Smuller  * Keith Muller of the University of California, San Diego.
857116Smuller  *
957116Smuller  * %sccs.include.redist.c%
1057116Smuller  *
11*60676Sbostic  *	@(#)cpio.h	8.1 (Berkeley) 05/31/93
1257116Smuller  */
1357116Smuller 
1457116Smuller /*
1557116Smuller  * Defines common to all versions of cpio
1657116Smuller  */
1757116Smuller #define TRAILER		"TRAILER!!!"	/* name in last archive record */
1857116Smuller 
1957116Smuller /*
2057116Smuller  * Header encoding of the different file types
2157116Smuller  */
2257116Smuller #define	C_ISDIR		 040000		/* Directory */
2357116Smuller #define	C_ISFIFO	 010000		/* FIFO */
2457116Smuller #define	C_ISREG		0100000		/* Regular file */
2557116Smuller #define	C_ISBLK		 060000		/* Block special file */
2657116Smuller #define	C_ISCHR		 020000		/* Character special file */
2757116Smuller #define	C_ISCTG		0110000		/* Reserved for contiguous files */
2857116Smuller #define	C_ISLNK		0120000		/* Reserved for symbolic links */
2957116Smuller #define	C_ISOCK		0140000		/* Reserved for sockets */
3057116Smuller #define C_IFMT		0170000		/* type of file */
3157116Smuller 
3257116Smuller /*
3357500Smuller  * Data Interchange Format - Extended cpio header format - POSIX 1003.1-1990
3457116Smuller  */
3557116Smuller typedef struct {
3657116Smuller 	char	c_magic[6];		/* magic cookie */
3757116Smuller 	char	c_dev[6];		/* device number */
3857116Smuller 	char	c_ino[6];		/* inode number */
3957116Smuller 	char	c_mode[6];		/* file type/access */
4057116Smuller 	char	c_uid[6];		/* owners uid */
4157116Smuller 	char	c_gid[6];		/* owners gid */
4257116Smuller 	char	c_nlink[6];		/* # of links at archive creation */
4357116Smuller 	char	c_rdev[6];		/* block/char major/minor # */
4457116Smuller 	char	c_mtime[11];		/* modification time */
4557116Smuller 	char	c_namesize[6];		/* length of pathname */
4657116Smuller 	char	c_filesize[11];		/* length of file in bytes */
4757116Smuller } HD_CPIO;
4857116Smuller 
4957116Smuller #define	MAGIC		070707		/* transportable archive id */
5057500Smuller 
5157500Smuller #ifdef _PAX_
5257500Smuller #define	AMAGIC		"070707"	/* ascii equivalent string of MAGIC */
5357116Smuller #define CPIO_MASK	0x3ffff		/* bits valid in the dev/ino fields */
5457116Smuller 					/* used for dev/inode remaps */
5557500Smuller #endif /* _PAX_ */
5657116Smuller 
5757116Smuller /*
5857500Smuller  * Binary cpio header structure
5957116Smuller  *
6057116Smuller  * CAUTION! CAUTION! CAUTION!
6157500Smuller  * Each field really represents a 16 bit short (NOT ASCII). Described as
6257116Smuller  * an array of chars in an attempt to improve portability!!
6357116Smuller  */
6457116Smuller typedef struct {
6557116Smuller 	u_char	h_magic[2];
6657116Smuller 	u_char	h_dev[2];
6757116Smuller 	u_char	h_ino[2];
6857116Smuller 	u_char	h_mode[2];
6957116Smuller 	u_char	h_uid[2];
7057116Smuller 	u_char	h_gid[2];
7157116Smuller 	u_char	h_nlink[2];
7257116Smuller 	u_char	h_rdev[2];
7357116Smuller 	u_char	h_mtime_1[2];
7457116Smuller 	u_char	h_mtime_2[2];
7557116Smuller 	u_char	h_namesize[2];
7657116Smuller 	u_char	h_filesize_1[2];
7757116Smuller 	u_char	h_filesize_2[2];
7857116Smuller } HD_BCPIO;
7957116Smuller 
8057500Smuller #ifdef _PAX_
8157116Smuller /*
8257500Smuller  * extraction and creation macros for binary cpio
8357116Smuller  */
8457116Smuller #define SHRT_EXT(ch)	((((unsigned)(ch)[0])<<8) | (((unsigned)(ch)[1])&0xff))
8557116Smuller #define RSHRT_EXT(ch)	((((unsigned)(ch)[1])<<8) | (((unsigned)(ch)[0])&0xff))
8657116Smuller #define CHR_WR_0(val)	((char)(((val) >> 24) & 0xff))
8757116Smuller #define CHR_WR_1(val)	((char)(((val) >> 16) & 0xff))
8857116Smuller #define CHR_WR_2(val)	((char)(((val) >> 8) & 0xff))
8957116Smuller #define CHR_WR_3(val)	((char)((val) & 0xff))
9057116Smuller 
9157116Smuller /*
9257500Smuller  * binary cpio masks and pads
9357116Smuller  */
9457116Smuller #define BCPIO_PAD(x)	((2 - ((x) & 1)) & 1)	/* pad to next 2 byte word */
9557116Smuller #define BCPIO_MASK	0xffff			/* mask for dev/ino fields */
9657500Smuller #endif /* _PAX_ */
9757116Smuller 
9857116Smuller /*
9957500Smuller  * System VR4 cpio header structure (with/without file data crc)
10057116Smuller  */
10157116Smuller typedef struct {
10257116Smuller 	char	c_magic[6];		/* magic cookie */
10357116Smuller 	char	c_ino[8];		/* inode number */
10457116Smuller 	char	c_mode[8];		/* file type/access */
10557116Smuller 	char	c_uid[8];		/* owners uid */
10657116Smuller 	char	c_gid[8];		/* owners gid */
10757116Smuller 	char	c_nlink[8];		/* # of links at archive creation */
10857116Smuller 	char	c_mtime[8];		/* modification time */
10957116Smuller 	char	c_filesize[8];		/* length of file in bytes */
11057116Smuller 	char	c_maj[8];		/* block/char major # */
11157116Smuller 	char	c_min[8];		/* block/char minor # */
11257116Smuller 	char	c_rmaj[8];		/* special file major # */
11357116Smuller 	char	c_rmin[8];		/* special file minor # */
11457116Smuller 	char	c_namesize[8];		/* length of pathname */
11557500Smuller 	char	c_chksum[8];		/* 0 OR CRC of bytes of FILE data */
11657116Smuller } HD_VCPIO;
11757116Smuller 
11857116Smuller #define	VMAGIC		070701		/* sVr4 new portable archive id */
11957500Smuller #define	VCMAGIC		070702		/* sVr4 new portable archive id CRC */
12057500Smuller #ifdef _PAX_
12157116Smuller #define	AVMAGIC		"070701"	/* ascii string of above */
12257116Smuller #define	AVCMAGIC	"070702"	/* ascii string of above */
12357500Smuller #define VCPIO_PAD(x)	((4 - ((x) & 3)) & 3)	/* pad to next 4 byte word */
12457116Smuller #define VCPIO_MASK	0xffffffff	/* mask for dev/ino fields */
12557500Smuller #endif /* _PAX_ */
126