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