1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1988,1997-1998,2001 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ifndef _ARCHIVES_H 32*7c478bd9Sstevel@tonic-gate #define _ARCHIVES_H 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.7 */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <tar.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 39*7c478bd9Sstevel@tonic-gate extern "C" { 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* Magic numbers */ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #define CMN_ASC 0x070701 /* Cpio Magic Number for ASCii header */ 45*7c478bd9Sstevel@tonic-gate #define CMN_BIN 070707 /* Cpio Magic Number for Binary header */ 46*7c478bd9Sstevel@tonic-gate #define CMN_BBS 0143561 /* Cpio Magic Number for Byte-Swap header */ 47*7c478bd9Sstevel@tonic-gate #define CMN_CRC 0x070702 /* Cpio Magic Number for CRC header */ 48*7c478bd9Sstevel@tonic-gate #define CMS_ASC "070701" /* Cpio Magic String for ASCii header */ 49*7c478bd9Sstevel@tonic-gate #define CMS_CHR "070707" /* Cpio Magic String for CHR (-c) header */ 50*7c478bd9Sstevel@tonic-gate #define CMS_CRC "070702" /* Cpio Magic String for CRC header */ 51*7c478bd9Sstevel@tonic-gate #define CMS_LEN 6 /* Cpio Magic String LENgth */ 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* Various header and field lengths */ 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #define CHRSZ 76 /* -c hdr size minus filename field */ 56*7c478bd9Sstevel@tonic-gate #define ASCSZ 110 /* ASC and CRC hdr size minus filename field */ 57*7c478bd9Sstevel@tonic-gate #define TARSZ 512 /* TAR hdr size */ 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #define HNAMLEN 256 /* maximum filename length for binary and -c headers */ 60*7c478bd9Sstevel@tonic-gate #define EXPNLEN 1024 /* maximum filename length for ASC and CRC headers */ 61*7c478bd9Sstevel@tonic-gate #define HTIMLEN 2 /* length of modification time field */ 62*7c478bd9Sstevel@tonic-gate #define HSIZLEN 2 /* length of file size field */ 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate /* cpio binary header definition */ 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate struct hdr_cpio { 67*7c478bd9Sstevel@tonic-gate short h_magic, /* magic number field */ 68*7c478bd9Sstevel@tonic-gate h_dev; /* file system of file */ 69*7c478bd9Sstevel@tonic-gate ushort_t h_ino, /* inode of file */ 70*7c478bd9Sstevel@tonic-gate h_mode, /* modes of file */ 71*7c478bd9Sstevel@tonic-gate h_uid, /* uid of file */ 72*7c478bd9Sstevel@tonic-gate h_gid; /* gid of file */ 73*7c478bd9Sstevel@tonic-gate short h_nlink, /* number of links to file */ 74*7c478bd9Sstevel@tonic-gate h_rdev, /* maj/min numbers for special files */ 75*7c478bd9Sstevel@tonic-gate h_mtime[HTIMLEN], /* modification time of file */ 76*7c478bd9Sstevel@tonic-gate h_namesize, /* length of filename */ 77*7c478bd9Sstevel@tonic-gate h_filesize[HSIZLEN]; /* size of file */ 78*7c478bd9Sstevel@tonic-gate char h_name[HNAMLEN]; /* filename */ 79*7c478bd9Sstevel@tonic-gate }; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* cpio ODC header format */ 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate struct c_hdr { 84*7c478bd9Sstevel@tonic-gate char c_magic[CMS_LEN], 85*7c478bd9Sstevel@tonic-gate c_dev[6], 86*7c478bd9Sstevel@tonic-gate c_ino[6], 87*7c478bd9Sstevel@tonic-gate c_mode[6], 88*7c478bd9Sstevel@tonic-gate c_uid[6], 89*7c478bd9Sstevel@tonic-gate c_gid[6], 90*7c478bd9Sstevel@tonic-gate c_nlink[6], 91*7c478bd9Sstevel@tonic-gate c_rdev[6], 92*7c478bd9Sstevel@tonic-gate c_mtime[11], 93*7c478bd9Sstevel@tonic-gate c_namesz[6], 94*7c478bd9Sstevel@tonic-gate c_filesz[11], 95*7c478bd9Sstevel@tonic-gate c_name[HNAMLEN]; 96*7c478bd9Sstevel@tonic-gate }; 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* -c and CRC header format */ 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate struct Exp_cpio_hdr { 101*7c478bd9Sstevel@tonic-gate char E_magic[CMS_LEN], 102*7c478bd9Sstevel@tonic-gate E_ino[8], 103*7c478bd9Sstevel@tonic-gate E_mode[8], 104*7c478bd9Sstevel@tonic-gate E_uid[8], 105*7c478bd9Sstevel@tonic-gate E_gid[8], 106*7c478bd9Sstevel@tonic-gate E_nlink[8], 107*7c478bd9Sstevel@tonic-gate E_mtime[8], 108*7c478bd9Sstevel@tonic-gate E_filesize[8], 109*7c478bd9Sstevel@tonic-gate E_maj[8], 110*7c478bd9Sstevel@tonic-gate E_min[8], 111*7c478bd9Sstevel@tonic-gate E_rmaj[8], 112*7c478bd9Sstevel@tonic-gate E_rmin[8], 113*7c478bd9Sstevel@tonic-gate E_namesize[8], 114*7c478bd9Sstevel@tonic-gate E_chksum[8], 115*7c478bd9Sstevel@tonic-gate E_name[EXPNLEN]; 116*7c478bd9Sstevel@tonic-gate }; 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* Tar header structure and format */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate #define TBLOCK 512 /* length of tar header and data blocks */ 121*7c478bd9Sstevel@tonic-gate #define TNAMLEN 100 /* maximum length for tar file names */ 122*7c478bd9Sstevel@tonic-gate #define TMODLEN 8 /* length of mode field */ 123*7c478bd9Sstevel@tonic-gate #define TUIDLEN 8 /* length of uid field */ 124*7c478bd9Sstevel@tonic-gate #define TGIDLEN 8 /* length of gid field */ 125*7c478bd9Sstevel@tonic-gate #define TSIZLEN 12 /* length of size field */ 126*7c478bd9Sstevel@tonic-gate #define TTIMLEN 12 /* length of modification time field */ 127*7c478bd9Sstevel@tonic-gate #define TCRCLEN 8 /* length of header checksum field */ 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate /* tar header definition */ 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate union tblock { 132*7c478bd9Sstevel@tonic-gate char dummy[TBLOCK]; 133*7c478bd9Sstevel@tonic-gate struct tar_hdr { 134*7c478bd9Sstevel@tonic-gate char t_name[TNAMLEN], /* name of file */ 135*7c478bd9Sstevel@tonic-gate t_mode[TMODLEN], /* mode of file */ 136*7c478bd9Sstevel@tonic-gate t_uid[TUIDLEN], /* uid of file */ 137*7c478bd9Sstevel@tonic-gate t_gid[TGIDLEN], /* gid of file */ 138*7c478bd9Sstevel@tonic-gate t_size[TSIZLEN], /* size of file in bytes */ 139*7c478bd9Sstevel@tonic-gate t_mtime[TTIMLEN], /* modification time of file */ 140*7c478bd9Sstevel@tonic-gate t_cksum[TCRCLEN], /* checksum of header */ 141*7c478bd9Sstevel@tonic-gate t_typeflag, 142*7c478bd9Sstevel@tonic-gate t_linkname[TNAMLEN], /* file this file linked with */ 143*7c478bd9Sstevel@tonic-gate t_magic[TMAGLEN], 144*7c478bd9Sstevel@tonic-gate t_version[TVERSLEN], 145*7c478bd9Sstevel@tonic-gate t_uname[32], 146*7c478bd9Sstevel@tonic-gate t_gname[32], 147*7c478bd9Sstevel@tonic-gate t_devmajor[8], 148*7c478bd9Sstevel@tonic-gate t_devminor[8], 149*7c478bd9Sstevel@tonic-gate t_prefix[155]; 150*7c478bd9Sstevel@tonic-gate } tbuf; 151*7c478bd9Sstevel@tonic-gate }; 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate /* volcopy tape label format and structure */ 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate #define VMAGLEN 8 156*7c478bd9Sstevel@tonic-gate #define VVOLLEN 6 157*7c478bd9Sstevel@tonic-gate #define VFILLEN 464 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate struct volcopy_label { 160*7c478bd9Sstevel@tonic-gate char v_magic[VMAGLEN], 161*7c478bd9Sstevel@tonic-gate v_volume[VVOLLEN], 162*7c478bd9Sstevel@tonic-gate v_reels, 163*7c478bd9Sstevel@tonic-gate v_reel; 164*7c478bd9Sstevel@tonic-gate int v_time, 165*7c478bd9Sstevel@tonic-gate v_length, 166*7c478bd9Sstevel@tonic-gate v_dens, 167*7c478bd9Sstevel@tonic-gate v_reelblks, /* u370 added field */ 168*7c478bd9Sstevel@tonic-gate v_blksize, /* u370 added field */ 169*7c478bd9Sstevel@tonic-gate v_nblocks; /* u370 added field */ 170*7c478bd9Sstevel@tonic-gate char v_fill[VFILLEN]; 171*7c478bd9Sstevel@tonic-gate int v_offset; /* used with -e and -reel options */ 172*7c478bd9Sstevel@tonic-gate int v_type; /* does tape have nblocks field? */ 173*7c478bd9Sstevel@tonic-gate }; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate /* 176*7c478bd9Sstevel@tonic-gate * Define archive formats for extended attributes. 177*7c478bd9Sstevel@tonic-gate * 178*7c478bd9Sstevel@tonic-gate * Extended attributes are stored in two pieces. 179*7c478bd9Sstevel@tonic-gate * 1. An attribute header which has information about 180*7c478bd9Sstevel@tonic-gate * what file the attribute is for and what the attribute 181*7c478bd9Sstevel@tonic-gate * is named. 182*7c478bd9Sstevel@tonic-gate * 2. The attribute record itself. Stored as a normal file type 183*7c478bd9Sstevel@tonic-gate * of entry. 184*7c478bd9Sstevel@tonic-gate * Both the header and attribute record have special modes/typeflags 185*7c478bd9Sstevel@tonic-gate * associated with them. 186*7c478bd9Sstevel@tonic-gate * 187*7c478bd9Sstevel@tonic-gate * The names of the header in the archive look like: 188*7c478bd9Sstevel@tonic-gate * /dev/null/attr.hdr 189*7c478bd9Sstevel@tonic-gate * 190*7c478bd9Sstevel@tonic-gate * The name of the attribute looks like: 191*7c478bd9Sstevel@tonic-gate * /dev/null/attr. 192*7c478bd9Sstevel@tonic-gate * 193*7c478bd9Sstevel@tonic-gate * This is done so that an archiver that doesn't understand these formats 194*7c478bd9Sstevel@tonic-gate * can just dispose of the attribute records unless the user chooses to 195*7c478bd9Sstevel@tonic-gate * rename them via cpio -r or pax -i 196*7c478bd9Sstevel@tonic-gate * 197*7c478bd9Sstevel@tonic-gate * The format is composed of a fixed size header followed 198*7c478bd9Sstevel@tonic-gate * by a variable sized xattr_buf. If the attribute is a hard link 199*7c478bd9Sstevel@tonic-gate * to another attribute, then another xattr_buf section is included 200*7c478bd9Sstevel@tonic-gate * for the link. 201*7c478bd9Sstevel@tonic-gate * 202*7c478bd9Sstevel@tonic-gate * The xattr_buf is used to define the necessary "pathing" steps 203*7c478bd9Sstevel@tonic-gate * to get to the extended attribute. This is necessary to support 204*7c478bd9Sstevel@tonic-gate * a fully recursive attribute model where an attribute may itself 205*7c478bd9Sstevel@tonic-gate * have an attribute. 206*7c478bd9Sstevel@tonic-gate * 207*7c478bd9Sstevel@tonic-gate * The basic layout looks like this. 208*7c478bd9Sstevel@tonic-gate * 209*7c478bd9Sstevel@tonic-gate * -------------------------------- 210*7c478bd9Sstevel@tonic-gate * | | 211*7c478bd9Sstevel@tonic-gate * | xattr_hdr | 212*7c478bd9Sstevel@tonic-gate * | | 213*7c478bd9Sstevel@tonic-gate * -------------------------------- 214*7c478bd9Sstevel@tonic-gate * -------------------------------- 215*7c478bd9Sstevel@tonic-gate * | | 216*7c478bd9Sstevel@tonic-gate * | xattr_buf | 217*7c478bd9Sstevel@tonic-gate * | | 218*7c478bd9Sstevel@tonic-gate * -------------------------------- 219*7c478bd9Sstevel@tonic-gate * -------------------------------- 220*7c478bd9Sstevel@tonic-gate * | | 221*7c478bd9Sstevel@tonic-gate * | (optional link info) | 222*7c478bd9Sstevel@tonic-gate * | | 223*7c478bd9Sstevel@tonic-gate * -------------------------------- 224*7c478bd9Sstevel@tonic-gate * -------------------------------- 225*7c478bd9Sstevel@tonic-gate * | | 226*7c478bd9Sstevel@tonic-gate * | attribute itself | 227*7c478bd9Sstevel@tonic-gate * | stored as normal tar | 228*7c478bd9Sstevel@tonic-gate * | or cpio data with | 229*7c478bd9Sstevel@tonic-gate * | special mode or | 230*7c478bd9Sstevel@tonic-gate * | typeflag | 231*7c478bd9Sstevel@tonic-gate * | | 232*7c478bd9Sstevel@tonic-gate * -------------------------------- 233*7c478bd9Sstevel@tonic-gate * 234*7c478bd9Sstevel@tonic-gate */ 235*7c478bd9Sstevel@tonic-gate #define XATTR_ARCH_VERS "1.0" 236*7c478bd9Sstevel@tonic-gate 237*7c478bd9Sstevel@tonic-gate /* 238*7c478bd9Sstevel@tonic-gate * extended attribute fixed header 239*7c478bd9Sstevel@tonic-gate * 240*7c478bd9Sstevel@tonic-gate * h_version format version. 241*7c478bd9Sstevel@tonic-gate * h_size size of header + variable sized data sections. 242*7c478bd9Sstevel@tonic-gate * h_component_len Length of entire pathing section. 243*7c478bd9Sstevel@tonic-gate * h_link_component_len Length of link component section. Again same definition 244*7c478bd9Sstevel@tonic-gate * as h_component_len. 245*7c478bd9Sstevel@tonic-gate */ 246*7c478bd9Sstevel@tonic-gate struct xattr_hdr { 247*7c478bd9Sstevel@tonic-gate char h_version[7]; 248*7c478bd9Sstevel@tonic-gate char h_size[10]; 249*7c478bd9Sstevel@tonic-gate char h_component_len[10]; /* total length of path component */ 250*7c478bd9Sstevel@tonic-gate char h_link_component_len[10]; 251*7c478bd9Sstevel@tonic-gate }; 252*7c478bd9Sstevel@tonic-gate 253*7c478bd9Sstevel@tonic-gate /* 254*7c478bd9Sstevel@tonic-gate * The name is encoded like this: 255*7c478bd9Sstevel@tonic-gate * filepathNULattrpathNUL[attrpathNULL]... 256*7c478bd9Sstevel@tonic-gate */ 257*7c478bd9Sstevel@tonic-gate struct xattr_buf { 258*7c478bd9Sstevel@tonic-gate char h_namesz[7]; /* length of h_names */ 259*7c478bd9Sstevel@tonic-gate char h_typeflag; /* actual typeflag of file being archived */ 260*7c478bd9Sstevel@tonic-gate char h_names[1]; /* filepathNULattrpathNUL... */ 261*7c478bd9Sstevel@tonic-gate }; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate /* 264*7c478bd9Sstevel@tonic-gate * Special values for tar archives 265*7c478bd9Sstevel@tonic-gate */ 266*7c478bd9Sstevel@tonic-gate 267*7c478bd9Sstevel@tonic-gate /* 268*7c478bd9Sstevel@tonic-gate * typeflag for tar archives. 269*7c478bd9Sstevel@tonic-gate */ 270*7c478bd9Sstevel@tonic-gate 271*7c478bd9Sstevel@tonic-gate /* 272*7c478bd9Sstevel@tonic-gate * Attribute hdr and attribute files have the following typeflag 273*7c478bd9Sstevel@tonic-gate */ 274*7c478bd9Sstevel@tonic-gate #define _XATTR_HDRTYPE 'E' 275*7c478bd9Sstevel@tonic-gate 276*7c478bd9Sstevel@tonic-gate /* 277*7c478bd9Sstevel@tonic-gate * For cpio archives the header and attribute have 278*7c478bd9Sstevel@tonic-gate * _XATTR_CPIO_MODE ORED into the mode field in both 279*7c478bd9Sstevel@tonic-gate * character and binary versions of the archive format 280*7c478bd9Sstevel@tonic-gate */ 281*7c478bd9Sstevel@tonic-gate #define _XATTR_CPIO_MODE 0xB000 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 284*7c478bd9Sstevel@tonic-gate } 285*7c478bd9Sstevel@tonic-gate #endif 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate #endif /* _ARCHIVES_H */ 288