1 /* @(#)star.h 1.151 20/07/08 Copyright 1985, 1995-2020 J. Schilling */ 2 /* 3 * Copyright (c) 1985, 1995-2020 J. Schilling 4 */ 5 /* 6 * The contents of this file are subject to the terms of the 7 * Common Development and Distribution License, Version 1.0 only 8 * (the "License"). You may not use this file except in compliance 9 * with the License. 10 * 11 * See the file CDDL.Schily.txt in this distribution for details. 12 * A copy of the CDDL is also available via the Internet at 13 * http://www.opensource.org/licenses/cddl1.txt 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file CDDL.Schily.txt from this distribution. 17 */ 18 19 #ifndef _STAR_H 20 #define _STAR_H 21 22 #include <schily/utypes.h> 23 #include <schily/time.h> 24 #include <schily/types.h> 25 #include <schily/limits.h> 26 #include "pathname.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 /* 33 * Be careful not to overflow off_t when computing tarblocks() 34 */ 35 #define tarblocks(s) (((s) / TBLOCK) + (((s)%TBLOCK)?1:0)) 36 #define tarsize(s) (tarblocks(s) * TBLOCK) 37 38 /* 39 * Defines for header type recognition 40 * N.B. these must kept in sync with hdrtxt[] in header.c 41 */ 42 #define H_SWAPPED(t) ((-1)*(t)) 43 #define H_ISSWAPPED(t) ((t) < H_UNDEF) 44 #define H_TYPE(t) ((int)(H_ISSWAPPED(t) ? ((-1)*(t)):(t))) 45 #define H_UNDEF 0 46 #define H_TARMIN 1 /* Lowest TAR type # */ 47 #define H_TAR 1 /* tar unbekanntes format */ 48 #define H_V7TAR 2 /* UNIX V7 format (1978 ???) */ 49 #define H_OTAR 3 /* tar altes BSD format (1978 ???) */ 50 #define H_STAR 4 /* altes star format (1985) */ 51 #define H_GNUTAR 5 /* gnu tar format (1989) */ 52 #define H_USTAR 6 /* ieee 1003.1-1988 format (1987 ff.) */ 53 #define H_XSTAR 7 /* extended 1003.1-1988 format (1994) */ 54 #define H_XUSTAR 8 /* ext 1003.1-1988 fmt w/o "tar" sign. (1998) */ 55 #define H_EXUSTAR 9 /* ext 1003.1-2001 fmt w/o "tar" sign. (2001) */ 56 #define H_PAX 10 /* ieee 1003.1-2001 ext. ustar format (PAX) */ 57 #define H_EPAX 11 /* ieee 1003.1-2001 ext. ustar format + xhdr */ 58 #define H_SUNTAR 12 /* Sun's tar implementaion from Solaris 7/8/9 */ 59 #define H_TARMAX 12 /* Highest TAR type # */ 60 #define H_RES13 13 /* Reserved */ 61 #define H_RES14 14 /* Reserved */ 62 #define H_BAR 15 /* SUN bar format */ 63 #define H_CPIO_BASE 16 /* cpio Basis */ 64 #define H_CPIO_BIN 16 /* cpio Bin�r */ 65 #define H_CPIO_CHR 17 /* cpio -Hodc POSIX format */ 66 #define H_CPIO_ODC 18 /* cpio -Hodc POSIX format 256 char filename */ 67 #define H_CPIO_NBIN 19 /* cpio neu Bin�r */ 68 #define H_CPIO_CRC 20 /* cpio crc Bin�r */ 69 #define H_CPIO_ASC 21 /* cpio -c ascii expanded maj/min */ 70 #define H_CPIO_ACRC 22 /* cpio -Hcrc ascii expanded maj/min */ 71 #define H_CPIO_MAX 22 /* cpio Ende */ 72 #define H_MAX_ARCH 22 /* Highest possible # */ 73 74 /* 75 * Interface types 76 */ 77 #define I_TAR 1 /* tar, ustar, star */ 78 #define I_PAX 2 /* pax, spax */ 79 #define I_CPIO 3 /* cpio */ 80 81 /* 82 * Program types 83 */ 84 #define P_STAR 1 /* star, ustar */ 85 #define P_SUNTAR 2 /* suntar */ 86 #define P_GNUTAR 3 /* gnutar */ 87 #define P_PAX 10 /* pax, spax */ 88 #define P_CPIO 20 /* cpio, scpio */ 89 90 /* 91 * Return codes from compression type checker. 92 */ 93 #define C_NONE 0 /* Not compressed or unknown compression */ 94 #define C_PACK 1 /* Compr. with 'pack', unpack with 'gzip' */ 95 #define C_GZIP 2 /* Compr. with 'gzip', unpack with 'gzip' */ 96 #define C_LZW 3 /* Compr. with 'lzw', unpack with 'gzip' */ 97 #define C_FREEZE 4 /* Compr. with 'freeze', unpack with 'gzip' */ 98 #define C_LZH 5 /* Compr. with 'SCO LZH', unpack with 'gzip' */ 99 #define C_PKZIP 6 /* Compr. with 'pkzip', unpack with 'gzip' */ 100 #define C_BZIP2 7 /* Compr. with 'bzip2', unpack with 'bzip2' */ 101 #define C_LZO 8 /* Compr. with 'lzop', unpack with 'lzop' */ 102 #define C_7Z 9 /* Compr. with 'p7zip', unpack with 'p7zip' */ 103 #define C_XZ 10 /* Compr. with 'xz', unpack with 'xz' */ 104 #define C_LZIP 11 /* Compr. with 'lzip', unpack with 'lzip' */ 105 #define C_ZSTD 12 /* Compr. with 'zstd', unpack with 'zstd' */ 106 #define C_LZMA 13 /* Compr. with 'lzma', unpack with 'lzma' */ 107 #define C_FREEZE2 14 /* Compr. with 'freeze2', unpack w. 'freeze' */ 108 #define C_MAX 14 109 110 /* 111 * Transfer direction types for utf8_init() 112 */ 113 #define S_CREATE 1 114 #define S_EXTRACT 2 115 116 /* 117 * Header size values 118 */ 119 #define TAR_HDRSZ TBLOCK /* TAR header size */ 120 #define BAR_HDRSZ TBLOCK /* Sun bar header size */ 121 #define CPIOBIN_HDRSZ 26 /* cpio Bin�r (default) CPIO header size */ 122 #define CPIOODC_HDRSZ 76 /* cpio -Hodc POSIX format header size */ 123 #define CPIOCRC_HDRSZ 110 /* cpio -c ascii / cpio -Hcrc header size */ 124 125 /* 126 * POSIX.1-1988 field size values and magic. 127 */ 128 #define TBLOCK 512 129 #define NAMSIZ 100 130 #define PFXSIZ 155 131 132 #define TMODLEN 8 133 #define TUIDLEN 8 134 #define TGIDLEN 8 135 #define TSIZLEN 12 136 #define TMTMLEN 12 137 #define TCKSLEN 8 138 139 #define TMAGIC "ustar" /* ustar magic */ 140 #define TMAGLEN 6 /* "ustar" including NULL byte */ 141 #define TVERSION "00" 142 #define TVERSLEN 2 143 #define TUNMLEN 32 144 #define TGNMLEN 32 145 #define TDEVLEN 8 146 147 /* 148 * The maximum number that we may handle with a 32 bit int 149 */ 150 #define MAXINT32 0x7FFFFFFFL 151 152 /* 153 * Large file summit: max size of a non-large file (2 GB - 2 Bytes) 154 */ 155 #define MAXNONLARGEFILE (MAXINT32 - 1) 156 157 /* 158 * Max POSIX.1-1988 limit for numeric 12 byte fields such as size/mtime 159 */ 160 #ifdef USE_LONGLONG 161 #define MAXOCTAL11 077777777777ULL 162 #else 163 #define MAXOCTAL11 MAXINT32 164 #endif 165 166 /* 167 * Max POSIX.1-1988 limit for numeric 8 byte fields such as uid/gid/dev 168 */ 169 #define MAXOCTAL7 07777777 170 171 /* 172 * Pre POSIX.1-1988 limit for numeric 8 byte fields such as uid/gid/dev 173 */ 174 #define MAXOCTAL6 0777777 175 176 /* 177 * Non POSIX.1-1988 limit used by HP-UX tar for 8 byte devmajor/devminor 178 */ 179 #define MAXOCTAL8 077777777 180 181 182 /* 183 * POSIX.1-1988 typeflag values 184 */ 185 #define REGTYPE '0' 186 #define AREGTYPE '\0' 187 #define LNKTYPE '1' 188 #define SYMTYPE '2' 189 #define CHRTYPE '3' 190 #define BLKTYPE '4' 191 #define DIRTYPE '5' 192 #define FIFOTYPE '6' 193 #define CONTTYPE '7' 194 195 /* 196 * POSIX.1-2001 typeflag extensions. 197 * POSIX.1-2001 calls the extended USTAR format PAX although it is definitely 198 * derived from and based on USTAR. The reason may be that POSIX.1-2001 199 * calls the tar program outdated and lists the pax program as the successor. 200 */ 201 #define LF_GHDR 'g' /* POSIX.1-2001 global extended header */ 202 #define LF_XHDR 'x' /* POSIX.1-2001 extended header */ 203 204 /* 205 * star/gnu/Sun tar extensions: 206 */ 207 /* 208 * Note that the standards committee allows only capital A through 209 * capital Z for user-defined expansion. This means that defining something 210 * as, say '8' is a *bad* idea. 211 */ 212 213 #define LF_ACL 'A' /* Solaris Access Control List */ 214 #define LF_DUMPDIR 'D' /* This is a dir entry that contains */ 215 /* the names of files that were in */ 216 /* the dir at the time the dump was made */ 217 218 #define LF_EXTATTR 'E' /* Solaris Extended Attribute File */ 219 #define LF_META 'I' /* Inode (metadata only) no file content */ 220 #define LF_LONGLINK 'K' /* Identifies the NEXT file on the tape */ 221 /* as having a long linkname */ 222 223 #define LF_LONGNAME 'L' /* Identifies the NEXT file on the tape */ 224 /* as having a long name. */ 225 226 #define LF_MULTIVOL 'M' /* This is the continuation */ 227 /* of a file that began on another volume */ 228 229 #define LF_NAMES 'N' /* For storing filenames that didn't */ 230 /* fit in 100 characters */ 231 232 #define LF_SPARSE 'S' /* This is for sparse files */ 233 #define LF_VOLHDR 'V' /* This file is a tape/volume header */ 234 /* Ignore it on extraction */ 235 #define LF_VU_XHDR 'X' /* POSIX.1-2001 xtended (VU version) */ 236 237 /* 238 * Definitions for the t_mode field 239 */ 240 #define TSUID 04000 /* Set UID on execution */ 241 #define TSGID 02000 /* Set GID on execution */ 242 #define TSVTX 01000 /* On directories, restricted deletion flag */ 243 #define TUREAD 00400 /* Read by owner */ 244 #define TUWRITE 00200 /* Write by owner special */ 245 #define TUEXEC 00100 /* Execute/search by owner */ 246 #define TGREAD 00040 /* Read by group */ 247 #define TGWRITE 00020 /* Write by group */ 248 #define TGEXEC 00010 /* Execute/search by group */ 249 #define TOREAD 00004 /* Read by other */ 250 #define TOWRITE 00002 /* Write by other */ 251 #define TOEXEC 00001 /* Execute/search by other */ 252 253 #define TALLMODES 07777 /* The low 12 bits mentioned in the standard */ 254 255 #define S_IRWALL (S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP | S_IROTH|S_IWOTH) 256 257 /* 258 * This is the ustar (Posix 1003.1) header. 259 */ 260 struct header { 261 char t_name[NAMSIZ]; /* 0 Dateiname */ 262 char t_mode[8]; /* 100 Zugriffsrechte */ 263 char t_uid[8]; /* 108 Benutzernummer */ 264 char t_gid[8]; /* 116 Benutzergruppe */ 265 char t_size[12]; /* 124 Dateigroesze */ 266 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 267 char t_chksum[8]; /* 148 Checksumme */ 268 Uchar t_typeflag; /* 156 Typ der Datei */ 269 char t_linkname[NAMSIZ]; /* 157 Zielname des Links */ 270 char t_magic[TMAGLEN]; /* 257 "ustar" */ 271 char t_version[TVERSLEN]; /* 263 Version v. star */ 272 char t_uname[TUNMLEN]; /* 265 Benutzername */ 273 char t_gname[TGNMLEN]; /* 297 Gruppenname */ 274 char t_devmajor[8]; /* 329 Major bei Geraeten */ 275 char t_devminor[8]; /* 337 Minor bei Geraeten */ 276 char t_prefix[PFXSIZ]; /* 345 Prefix fuer t_name */ 277 /* 500 Ende */ 278 char t_mfill[12]; /* 500 Filler bis 512 */ 279 }; 280 281 /* 282 * This is the ustar (Posix 1003.1) header with extended name arrays. 283 * Extended name arrays are needed to avoid compiler warnings for the code 284 * that deals with 100/155 byte names that are not null terminated. 285 */ 286 struct name_header { 287 char t_name[NAMSIZ+1]; /* 0 Dateiname */ 288 char t_res1[7]; /* 101 Reserved: t_mode Rest */ 289 char t_uid[8]; /* 108 Benutzernummer */ 290 char t_gid[8]; /* 116 Benutzergruppe */ 291 char t_size[12]; /* 124 Dateigroesze */ 292 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 293 char t_chksum[8]; /* 148 Checksumme */ 294 Uchar t_typeflag; /* 156 Typ der Datei */ 295 char t_linkname[NAMSIZ+1]; /* 157 Zielname des Links */ 296 char t_res2[TMAGLEN-1]; /* 258 Reserved: t_magic Rest */ 297 char t_version[TVERSLEN]; /* 263 Version v. star */ 298 char t_uname[TUNMLEN]; /* 265 Benutzername */ 299 char t_gname[TGNMLEN]; /* 297 Gruppenname */ 300 char t_devmajor[8]; /* 329 Major bei Geraeten */ 301 char t_devminor[8]; /* 337 Minor bei Geraeten */ 302 char t_prefix[PFXSIZ+1]; /* 345 Prefix fuer t_name */ 303 /* 501 Ende */ 304 char t_res3[11]; /* 501 Filler bis 512 */ 305 }; 306 307 /* 308 * star header specific definitions 309 */ 310 #define STMAGIC "tar" /* star magic */ 311 #define STMAGLEN 4 /* "tar" including NULL byte */ 312 #define STVERSION '1' /* current star version */ 313 314 #define STUNMLEN 16 /* star user name length */ 315 #define STGNMLEN 15 /* star group name length */ 316 317 /* 318 * This is the old (pre Posix 1003.1-1988) star header defined in 1985. 319 */ 320 struct star_header { 321 char t_name[NAMSIZ]; /* 0 Dateiname */ 322 char t_mode[8]; /* 100 Zugriffsrechte */ 323 char t_uid[8]; /* 108 Benutzernummer */ 324 char t_gid[8]; /* 116 Benutzergruppe */ 325 char t_size[12]; /* 124 Dateigroesze */ 326 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 327 char t_chksum[8]; /* 148 Checksumme */ 328 Uchar t_linkflag; /* 156 Linktyp der Datei */ 329 char t_linkname[NAMSIZ]; /* 157 Zielname des Links */ 330 /* --- Ende historisches TAR */ 331 /* --- Anfang star Erweiterungen */ 332 char t_vers; /* 257 Version v. star */ 333 char t_filetype[8]; /* 258 Interner Dateityp */ 334 char t_type[12]; /* 266 Dateityp (UNIX) */ 335 #ifdef no_minor_bits_in_rdev 336 char t_rdev[12]; /* 278 Major/Minor bei Geraeten */ 337 #else 338 char t_rdev[11]; /* 278 Major/Minor bei Geraeten */ 339 char t_devminorbits; /* 298 Anzahl d. Minor Bits in t_rdev */ 340 #endif 341 char t_atime[12]; /* 290 Zeit d. letzten Zugriffs */ 342 char t_ctime[12]; /* 302 Zeit d. letzten Statusaend. */ 343 char t_uname[STUNMLEN]; /* 314 Benutzername */ 344 char t_gname[STGNMLEN]; /* 330 Gruppenname */ 345 char t_prefix[PFXSIZ]; /* 345 Prefix fuer t_name */ 346 char t_mfill[8]; /* 500 Filler bis magic */ 347 char t_magic[4]; /* 508 "tar" */ 348 }; 349 350 /* 351 * This is the new (post Posix 1003.1-1988) xstar header defined in 1994. 352 * 353 * t_prefix[130] is garanteed to be '\0' to prevent ustar compliant 354 * implementations from failing. 355 * t_mfill & t_xmagic need to be zero for a 100% ustar compliant 356 * implementation, so setting t_xmagic to "tar" should 357 * be avoided in the future. 358 * 359 * A different method to recognise this format is to verify that 360 * t_prefix[130] is equal to '\0' and 361 * t_atime[0]/t_ctime[0] is an octal number and 362 * t_atime[11] is equal to ' ' and 363 * t_ctime[11] is equal to ' '. 364 * 365 * Note that t_atime[11]/t_ctime[11] may be changed in future. 366 */ 367 struct xstar_header { 368 char t_name[NAMSIZ]; /* 0 Dateiname */ 369 char t_mode[8]; /* 100 Zugriffsrechte */ 370 char t_uid[8]; /* 108 Benutzernummer */ 371 char t_gid[8]; /* 116 Benutzergruppe */ 372 char t_size[12]; /* 124 Dateigroesze */ 373 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 374 char t_chksum[8]; /* 148 Checksumme */ 375 Uchar t_typeflag; /* 156 Typ der Datei */ 376 char t_linkname[NAMSIZ]; /* 157 Zielname des Links */ 377 char t_magic[TMAGLEN]; /* 257 "ustar" */ 378 char t_version[TVERSLEN]; /* 263 Version v. star */ 379 char t_uname[TUNMLEN]; /* 265 Benutzername */ 380 char t_gname[TGNMLEN]; /* 297 Gruppenname */ 381 char t_devmajor[8]; /* 329 Major bei Geraeten */ 382 char t_devminor[8]; /* 337 Minor bei Geraeten */ 383 char t_prefix[131]; /* 345 Prefix fuer t_name */ 384 char t_atime[12]; /* 476 Zeit d. letzten Zugriffs */ 385 char t_ctime[12]; /* 488 Zeit d. letzten Statusaend. */ 386 char t_mfill[8]; /* 500 Filler bis magic */ 387 char t_xmagic[4]; /* 508 "tar" */ 388 }; 389 390 struct sparse { 391 char t_offset[12]; 392 char t_numbytes[12]; 393 }; 394 395 #define SPARSE_EXT_HDR 21 396 #define SPARSE_IN_HDR 4 397 #define SIH SPARSE_IN_HDR 398 #define SEH SPARSE_EXT_HDR 399 400 struct xstar_in_header { 401 char t_fill[345]; /* 0 Everything before t_prefix */ 402 char t_prefix[1]; /* 345 Prefix fuer t_name */ 403 char t_fill2; /* 346 */ 404 char t_fill3[8]; /* 347 */ 405 char t_isextended; /* 355 */ 406 struct sparse t_sp[SIH]; /* 356 8 x 12 */ 407 char t_realsize[12]; /* 452 Echte Gr��e bei sparse Dateien */ 408 char t_offset[12]; /* 464 Offset f�r Multivol cont. Dateien */ 409 char t_atime[12]; /* 476 Zeit d. letzten Zugriffs */ 410 char t_ctime[12]; /* 488 Zeit d. letzten Statusaend. */ 411 char t_mfill[8]; /* 500 Filler bis magic */ 412 char t_xmagic[4]; /* 508 "tar" */ 413 }; 414 415 struct xstar_ext_header { 416 struct sparse t_sp[SEH]; 417 char t_isextended; 418 }; 419 420 typedef struct { 421 off_t sp_offset; 422 off_t sp_numbytes; 423 } sp_t; 424 425 /* 426 * gnu tar header specific definitions 427 */ 428 429 #define GMAGIC "ustar " /* gnu tar magic */ 430 #define GMAGLEN 8 /* "ustar" two blanks and a NULL */ 431 432 /* 433 * This is the GNUtar header defined in 1989. 434 * 435 * The nonstandard stuff could not be found in in the first pubslished versions 436 * of the program. The first version I am aware of, is a program called SUGtar 437 * published at the Sun User Group meeting in december 1987, a different 438 * publishing of the same program which has been originally written by 439 * John Gilmore was called PDtar. In 1987 PDtar/SUGtar was implementing a true 440 * subset of the 1987 POSIX-1003 draft (missing only the long name splitting). 441 * 442 * FSF people then later added t_atime... making GNU tar non POSIX compliant. 443 * When FSF added the sparse file handling stuff, this was done in a way that 444 * even violates any tar document available since the late 1970's. 445 * 446 * GNU tar is not tar... 447 */ 448 struct gnu_header { 449 char t_name[NAMSIZ]; /* 0 Dateiname */ 450 char t_mode[8]; /* 100 Zugriffsrechte */ 451 char t_uid[8]; /* 108 Benutzernummer */ 452 char t_gid[8]; /* 116 Benutzergruppe */ 453 char t_size[12]; /* 124 Dateigroesze */ 454 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 455 char t_chksum[8]; /* 148 Checksumme */ 456 Uchar t_linkflag; /* 156 Typ der Datei */ 457 char t_linkname[NAMSIZ]; /* 157 Zielname des Links */ 458 char t_magic[8]; /* 257 "ustar" */ 459 char t_uname[TUNMLEN]; /* 265 Benutzername */ 460 char t_gname[TGNMLEN]; /* 297 Gruppenname */ 461 char t_devmajor[8]; /* 329 Major bei Geraeten */ 462 char t_devminor[8]; /* 337 Minor bei Geraeten */ 463 464 /* 465 * Jay Fenlason (hack@ai.mit.edu) 466 * these following fields were added by JF for gnu 467 * and are NOT standard 468 */ 469 char t_atime[12]; /* 345 */ 470 char t_ctime[12]; /* 357 */ 471 char t_offset[12]; /* 369 */ 472 char t_longnames[4]; /* 381 */ 473 /* 474 * for the rest see struct gnu_in_header 475 */ 476 }; 477 478 struct gnu_in_header { 479 char t_fill[386]; 480 struct sparse t_sp[SIH]; /* 386 4 sparse structures (2 x 12 bytes) */ 481 char t_isextended; /* 482 an extended header follows */ 482 char t_realsize[12]; /* 483 true size of the sparse file */ 483 }; 484 485 struct gnu_extended_header { 486 struct sparse t_sp[SEH]; /* 0 21 sparse structures (2 x 12 bytes) */ 487 char t_isextended; /* 504 another extended header follows */ 488 }; 489 490 #undef SIH 491 #undef SEH 492 493 /* 494 * This is the Sun tar header used on SunOS-5.x. 495 */ 496 struct suntar_header { 497 char t_name[NAMSIZ]; /* 0 Dateiname */ 498 char t_mode[8]; /* 100 Zugriffsrechte */ 499 char t_uid[8]; /* 108 Benutzernummer */ 500 char t_gid[8]; /* 116 Benutzergruppe */ 501 char t_size[12]; /* 124 Dateigroesze */ 502 char t_mtime[12]; /* 136 Zeit d. letzten Aenderung */ 503 char t_chksum[8]; /* 148 Checksumme */ 504 Uchar t_typeflag; /* 156 Typ der Datei */ 505 char t_linkname[NAMSIZ]; /* 157 Zielname des Links */ 506 char t_magic[TMAGLEN]; /* 257 "ustar" */ 507 char t_version[TVERSLEN]; /* 263 Version v. star */ 508 char t_uname[TUNMLEN]; /* 265 Benutzername */ 509 char t_gname[TGNMLEN]; /* 297 Gruppenname */ 510 char t_devmajor[8]; /* 329 Major bei Geraeten */ 511 char t_devminor[8]; /* 337 Minor bei Geraeten */ 512 char t_prefix[PFXSIZ]; /* 345 Prefix fuer t_name */ 513 514 /* Sun Erweiterungen: */ 515 char t_extno; /* 500 extent #, null if not split */ 516 char t_extotal; /* 501 total # of extents */ 517 char t_efsize[10]; /* 502 size of entire file */ 518 }; 519 520 521 #define BAR_UNSPEC '\0' /* XXX Volheader ??? */ 522 #define BAR_REGTYPE '0' 523 #define BAR_LNKTYPE '1' 524 #define BAR_SYMTYPE '2' 525 #define BAR_SPECIAL '3' 526 527 #define BAR_VOLHEAD "V" /* The BAR Volume "magic" */ 528 529 /* 530 * The Sun BAR header format as introduced with the Roadrunner Intel machines 531 * 532 * All header parts marked with "*VH" are set only in the volheader 533 * and zero on any other headers. 534 */ 535 struct bar_header { 536 char mode[8]; /* 0 file type and mode (top bit masked) */ 537 char uid[8]; /* 8 Benutzernummer */ 538 char gid[8]; /* 16 Benutzergruppe */ 539 char size[12]; /* 24 Dateigroesze */ 540 char mtime[12]; /* 36 Zeit d. letzten Aenderung */ 541 char t_chksum[8]; /* 48 Checksumme */ 542 char rdev[8]; /* 56 Major/Minor bei Geraeten */ 543 Uchar linkflag; /* 64 Linktyp der Datei */ 544 char bar_magic[2]; /* 65 *VH xxx */ 545 char volume_num[4]; /* 67 *VH Volume Nummer */ 546 char compressed; /* 71 *VH Compress Flag */ 547 char date[12]; /* 72 *VH Aktuelles Datum YYMMDDhhmm */ 548 char start_of_name[1]; /* 84 Dateiname */ 549 }; 550 551 typedef union hblock { 552 char dummy[TBLOCK]; 553 long ldummy[TBLOCK/sizeof (long)]; /* force long alignement */ 554 struct star_header dbuf; 555 struct star_header star_dbuf; 556 struct xstar_header xstar_dbuf; 557 struct xstar_in_header xstar_in_dbuf; 558 struct xstar_ext_header xstar_ext_dbuf; 559 struct header ustar_dbuf; 560 struct name_header ndbuf; 561 struct gnu_header gnu_dbuf; 562 struct gnu_in_header gnu_in_dbuf; 563 struct gnu_extended_header gnu_ext_dbuf; 564 struct suntar_header suntar_dbuf; 565 struct bar_header bar_dbuf; 566 } TCB; 567 568 /* 569 * Used for internal extended file attribute processing 570 */ 571 typedef struct star_xattr { 572 char *name; /* The name of the attribute */ 573 void *value; /* The asociated value */ 574 size_t value_len; /* The size of the attribute value */ 575 } star_xattr_t; 576 577 /* 578 * Our internal OS independant structure to hold file metadata. 579 * 580 * Some remarks to the different file type structure members: 581 * 582 * f_xftype The new tar general (x-tended) file type. 583 * This includes values XT_LINK XT_SPARSE XT_LONGNAME ... 584 * 585 * f_rxftype The 'real' general file type. 586 * Doesn't include XT_LINK XT_SPARSE XT_LONGNAME ... 587 * This is the 'real' file type and close to what has been 588 * set up in getinfo(). 589 * 590 * f_filetype The coarse file type classification (star 1985 header) 591 * 592 * f_typeflag The file type flag used in the POSIX.1-1988 TAR header 593 * 594 * f_type The OS specific file type (e.g. UNIX st_mode & S_IFMT) 595 */ 596 typedef struct { 597 TCB *f_tcb; 598 char *f_sname; /* Zeiger auf den kurzen stat Dateinamen */ 599 char *f_name; /* Zeiger auf den langen Dateinamen */ 600 Ulong f_namelen; /* L�nge des Dateinamens */ 601 char *f_lname; /* Zeiger auf den langen Linknamen */ 602 Ulong f_lnamelen; /* L�nge des Linknamens */ 603 char *f_uname; /* User name oder NULL Pointer */ 604 Ulong f_umaxlen; /* Maximale L�nge des Usernamens */ 605 char *f_gname; /* Group name oder NULL Pointer */ 606 Ulong f_gmaxlen; /* Maximale L�nge des Gruppennamens */ 607 char *f_dir; /* Directory Inhalt */ 608 ino_t *f_dirinos; /* Inode Liste fuer Directory Inhalt */ 609 size_t f_dirlen; /* Extended strlen(f_dir)+1 */ 610 size_t f_dirents; /* # der Directory Eintraege */ 611 dev_t f_dev; /* Geraet auf dem sich d. Datei befindet */ 612 major_t f_devmaj; /* Major von f_dev */ 613 minor_t f_devmin; /* Minor bei f_dev */ 614 int f_devminorbits; /* Anzahl d. Minor Bits in f_dev */ 615 ino_t f_ino; /* Dateinummer */ 616 nlink_t f_nlink; /* Anzahl der Links */ 617 mode_t f_mode; /* Zugriffsrechte (TAR Bit Werte) */ 618 uid_t f_uid; /* Benutzernummer */ 619 gid_t f_gid; /* Benutzergruppe */ 620 off_t f_size; /* Dateigroesze */ 621 off_t f_rsize; /* Dateigroesze auf Band */ 622 off_t f_contoffset; /* Offset f�r Multivol cont. Dateien */ 623 Ullong f_llsize; /* Dateigroesze wenn off_t zu kein */ 624 Ulong f_flags; /* Bearbeitungshinweise */ 625 Ulong f_xflags; /* Flags f�r x-header */ 626 Ulong f_xftype; /* Header Dateityp (neu generell) */ 627 Ulong f_rxftype; /* Echter Dateityp (neu generell) */ 628 Ulong f_filetype; /* Typ der Datei (star alt) */ 629 Uchar f_typeflag; /* Kopie aus TAR Header */ 630 mode_t f_type; /* Dateityp aus UNIX struct stat */ 631 #ifdef NEW_RDEV 632 dev_t f_rdev; /* Major/Minor bei Geraeten */ 633 major_t f_rdevmaj; /* Major bei Geraeten */ 634 minor_t f_rdevmin; /* Minor bei Geraeten */ 635 #else 636 Ulong f_rdev; /* Major/Minor bei Geraeten */ 637 Ulong f_rdevmaj; /* Major bei Geraeten */ 638 Ulong f_rdevmin; /* Minor bei Geraeten */ 639 #endif 640 time_t f_atime; /* Zeit d. letzten Zugriffs */ 641 long f_ansec; /* nsec Teil " */ 642 time_t f_mtime; /* Zeit d. letzten Aenderung */ 643 long f_mnsec; /* nsec Teil " */ 644 time_t f_ctime; /* Zeit d. letzten Statusaend. */ 645 long f_cnsec; /* nsec Teil " */ 646 long f_timeres; /* Time stamp resolution */ 647 Ulong f_fflags; /* File flags */ 648 #ifdef USE_ACL 649 #ifdef HAVE_ST_ACLCNT 650 int f_aclcnt; 651 #endif 652 char *f_acl_access; /* POSIX Draft Access Control List */ 653 char *f_acl_default; /* POSIX Draft Default ACL */ 654 char *f_acl_ace; /* NFSv4 Access Control List */ 655 #endif 656 #ifdef USE_XATTR 657 star_xattr_t *f_xattr; /* Extended File Attributes */ 658 #endif 659 /* 660 * These two members must be last, so we are able to copy everything 661 * before, e.g. for the options -newest and -newest-file. 662 */ 663 pathstore_t f_pname; /* Verwaltung f�r f_name */ 664 pathstore_t f_plname; /* Verwaltung f�r f_lname */ 665 666 } FINFO; 667 668 /* 669 * We use offsetof(FINFO, f_pname) to compute the size of the first part 670 * of FINFO that may be copied without breaking things. This is needed for 671 * e.g. the options -newest and -newest-file. 672 */ 673 #ifndef offsetof 674 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 675 #endif 676 677 #define init_finfo(fip) (fip)->f_flags = 0, (fip)->f_xflags = 0 678 679 /* 680 * Used with f_flags 681 */ 682 #define F_LONGNAME 0x01 /* Langer Name passt nicht in Header */ 683 #define F_LONGLINK 0x02 /* Langer Linkname passt nicht in Header */ 684 #define F_SPLIT_NAME 0x04 /* Langer Name wurde gesplitted */ 685 #define F_HAS_NAME 0x08 /* Langer Name in f_name/f_lname soll bl. */ 686 #define F_SPARSE 0x10 /* Datei enth�lt L�cher */ 687 #define F_TCB_BUF 0x20 /* TCB ist/war vom Buffer alloziert */ 688 #define F_ADDSLASH 0x40 /* Langer Name ben�tigt Slash am Ende */ 689 #define F_NSECS 0x80 /* stat() liefert Nanosekunden */ 690 #define F_NODUMP 0x100 /* Datei hat OS spezifisches NODUMP flag */ 691 #define F_EXTRACT 0x200 /* Bearbeitung im 'extract' Modus */ 692 #define F_CRC 0x400 /* CPIO CRC f�r Datei berechnen */ 693 #define F_BAD_SIZE 0x1000 /* Bad size data detected */ 694 #define F_BAD_META 0x2000 /* Bad meta data detected */ 695 #define F_BAD_UID 0x4000 /* Bad uid value detected */ 696 #define F_BAD_GID 0x8000 /* Bad gid value detected */ 697 #define F_SP_EXTENDED 0x10000 /* Extended sparse area found */ 698 #define F_SP_SKIPPED 0x20000 /* Extended sparse area already skipped */ 699 #define F_FORCE_ADD 0x40000 /* Force take_file() to add the file */ 700 #define F_SAME 0x80000 /* Same symlink of special found */ 701 #define F_DATA_SKIPPED 0x100000 /* The data part of the file was skipped */ 702 #define F_BAD_ACL 0x200000 /* Unsupported ACL encoding type */ 703 #define F_ALL_HOLE 0x400000 /* File is sparse, one hole with no data */ 704 705 /* 706 * Used with f_xflags 707 */ 708 #define XF_ATIME 0x0001 /* Zeit d. letzten Zugriffs */ 709 #define XF_CTIME 0x0002 /* Zeit d. letzten Statusaend. */ 710 #define XF_MTIME 0x0004 /* Zeit d. letzten Aenderung */ 711 #define XF_COMMENT 0x0008 /* Beliebiger Kommentar */ 712 #define XF_UID 0x0010 /* Benutzernummer */ 713 #define XF_UNAME 0x0020 /* Langer Benutzername */ 714 #define XF_GID 0x0040 /* Benutzergruppe */ 715 #define XF_GNAME 0x0080 /* Langer Benutzergruppenname */ 716 #define XF_PATH 0x0100 /* Langer Name */ 717 #define XF_LINKPATH 0x0200 /* Langer Link Name */ 718 /* Dateigr��e auf Band (f_rsize) */ 719 #define XF_SIZE 0x0400 /* Dateigr��e wenn > 8 GB */ 720 #define XF_CHARSET 0x0800 /* Zeichensatz f�r Dateiinhalte */ 721 722 #define XF_DEVMAJOR 0x1000 /* Major bei Ger�ten */ 723 #define XF_DEVMINOR 0x2000 /* Major bei Ger�ten */ 724 #define XF_FSDEVMAJOR 0x4000 /* Major Filesys */ 725 #define XF_FSDEVMINOR 0x8000 /* Major Filesys */ 726 727 #define XF_ACL_ACCESS 0x04000 /* POSIX Draft Access Control List */ 728 #define XF_ACL_DEFAULT 0x08000 /* POSIX Draft Default ACL */ 729 #define XF_ACL_ACE 0x10000 /* NFSv4 Access Control List */ 730 731 #define XF_FFLAGS 0x20000 /* File flags */ 732 /* Echte Dateigr��e (f_size) */ 733 #define XF_REALSIZE 0x40000 /* Dateigr��e wenn > 8 GB */ 734 #define XF_OFFSET 0x80000 /* Multi Volume Offset */ 735 #define XF_XATTR 0x100000 /* Extended Attributes */ 736 737 #define XF_NOTIME 0x10000000 /* Keine extended Zeiten */ 738 #define XF_BINARY 0x20000000 /* Binary path/usr/group in x-header */ 739 740 /* 741 * All Extended header tags that are covered by POSIX.1-2001 742 */ 743 #define XF_POSIX (XF_ATIME|XF_CTIME|XF_MTIME|XF_COMMENT|\ 744 XF_UID|XF_UNAME|XF_GID|XF_GNAME|\ 745 XF_PATH|XF_LINKPATH|XF_SIZE|XF_CHARSET) 746 747 /* 748 * Used with f_filetype 749 * 750 * This is optimised for the old star (1986) extensions that were the first 751 * tar extensions which allowed to archive files different from regular files, 752 * directories and symbolic links. 753 */ 754 #define F_SPEC 0 /* Anything not mentioned below */ 755 #define F_FILE 1 /* A reguar file */ 756 #define F_SLINK 2 /* A symbolic link */ 757 #define F_DIR 3 /* A directory */ 758 759 #define is_special(i) ((i)->f_filetype == F_SPEC) 760 #define is_file(i) ((i)->f_filetype == F_FILE) 761 #define is_symlink(i) ((i)->f_filetype == F_SLINK) 762 #define is_dir(i) ((i)->f_filetype == F_DIR) 763 764 #define is_cont(i) ((i)->f_xftype == XT_CONT) 765 #define is_bdev(i) ((i)->f_xftype == XT_BLK) 766 #define is_cdev(i) ((i)->f_xftype == XT_CHR) 767 #define is_dev(i) (is_bdev(i) || is_cdev(i)) 768 #define is_fifo(i) ((i)->f_xftype == XT_FIFO) 769 #define is_door(i) ((i)->f_xftype == XT_DOOR) 770 #define is_link(i) ((i)->f_xftype == XT_LINK) 771 #define fis_link(i) ((i)->f_rxftype == XT_LINK) /* Filetype unknown */ 772 #define is_volhdr(i) ((i)->f_xftype == XT_VOLHDR) 773 #define is_sparse(i) ((i)->f_xftype == XT_SPARSE) 774 #define is_multivol(i) ((i)->f_xftype == XT_MULTIVOL) 775 #define is_whiteout(i) ((i)->f_xftype == XT_WHT) 776 #define is_meta(i) ((i)->f_xftype == XT_META) 777 #define fis_meta(i) ((i)->f_rxftype == XT_META) /* Really "regular" */ 778 779 #define is_a_file(i) (is_file(i) || is_cont(i)) 780 /* 781 * Defines for bad stat.st_mode, stat.st_uid and stat.st_gid 782 */ 783 #define _BAD_MODE ((mode_t)-1) 784 #define _BAD_UID ((gid_t)-1) 785 #define _BAD_GID ((gid_t)-1) 786 787 /* 788 * The global info structure holds volume header related information 789 */ 790 typedef struct { 791 char *label; /* Volume label */ 792 char *hostname; /* Hostname where the dump is from */ 793 char *filesys; /* Mount point of the dump */ 794 char *cwd; /* Working directory if != filesys */ 795 char *device; /* Device for mount point */ 796 char *release; /* Release string from creating tar */ 797 int archtype; /* Archive type from 'g'lobal header */ 798 int dumptype; /* Dump type see below */ 799 int dumplevel; /* Level of this dump */ 800 int reflevel; /* Level this dump refers to */ 801 struct timespec dumpdate; /* Date of this dump */ 802 struct timespec refdate; /* Date this dump refers to */ 803 int volno; /* Volume number starting with 1 */ 804 Ullong tapesize; /* Tape size in 512 byte units */ 805 Ullong blockoff; /* 512 byte based offset within all */ 806 int blocksize; /* Block size in 512 byte units */ 807 Int32_t gflags; 808 } GINFO; 809 810 /* 811 * Defines for dumptype 812 */ 813 #define DT_UNKN -1 /* DT_UNKNOWN used in BSD <dirent.h> */ 814 #define DT_NONE 0 815 #define DT_PARTIAL 1 816 #define DT_FULL 2 817 818 /* 819 * Defines for gflags 820 */ 821 #define GF_LABEL 0x0001 822 #define GF_HOSTNAME 0x0002 823 #define GF_FILESYS 0x0004 824 #define GF_CWD 0x0008 825 #define GF_DEVICE 0x0010 826 #define GF_RELEASE 0x0020 827 #define GF_ARCHTYPE 0x0040 828 #define GF_DUMPTYPE 0x0080 829 #define GF_DUMPLEVEL 0x0100 830 #define GF_REFLEVEL 0x0200 831 #define GF_DUMPDATE 0x0400 832 #define GF_REFDATE 0x0800 833 #define GF_VOLNO 0x1000 834 #define GF_BLOCKOFF 0x2000 835 #define GF_BLOCKSIZE 0x4000 836 #define GF_TAPESIZE 0x8000 837 #define GF_MINIT 0x10000000 /* Structure initialized from media */ 838 #define GF_NOALLOC 0x20000000 /* Strings in struct not allocated */ 839 840 841 #ifdef isdigit 842 #undef isdigit /* Needed for HP-UX */ 843 #endif 844 #define isdigit(c) ((c) >= '0' && (c) <= '9') 845 #ifdef isoctal 846 #undef isoctal /* Needed if aclutils.h is present */ 847 #endif 848 #define isoctal(c) ((c) >= '0' && (c) <= '7') 849 #ifdef isupper 850 #undef isupper /* Needed for HP-UX */ 851 #endif 852 #define isupper(c) ((c) >= 'A' && (c) <= 'Z') 853 #ifdef toupper 854 #undef toupper /* Needed if aclutils.h is present */ 855 #endif 856 #define toupper(c) (isupper(c) ? (c) : (c) - ('a' - 'A')) 857 /* 858 * Needed for QNX 859 */ 860 #ifdef max 861 #undef max 862 #endif 863 #ifdef min 864 #undef min 865 #endif 866 #define max(a, b) ((a) < (b) ? (b) : (a)) 867 #define min(a, b) ((a) < (b) ? (a) : (b)) 868 869 870 struct star_stats { 871 int s_staterrs; /* Could not stat(2) file */ 872 #ifdef USE_ACL 873 int s_getaclerrs; /* Could not get ACL for file */ 874 #endif 875 int s_openerrs; /* Open/Create error for file */ 876 int s_rwerrs; /* Read/Write error from file */ 877 int s_sizeerrs; /* File changed size */ 878 int s_misslinks; /* Missing links to file */ 879 int s_toolong; /* File name too long */ 880 int s_toobig; /* File does not fit on one tape */ 881 int s_isspecial; /* File is special - not dumped */ 882 #ifdef USE_XATTR 883 int s_getxattr; /* get xattr for file failed */ 884 #endif 885 int s_chdir; /* chdir() failed */ 886 int s_iconv; /* iconv() failed */ 887 int s_id; /* uid/gid range error */ 888 int s_time; /* time range error */ 889 /* 890 * Extract only.... 891 */ 892 int s_settime; /* utimes() on file failed */ 893 int s_setmodes; /* chmod() on file failed */ 894 int s_security; /* skipped for security reasons */ 895 int s_lsecurity; /* link skipped for security reasons */ 896 int s_samefile; /* skipped from/to are identical */ 897 #ifdef USE_ACL 898 int s_badacl; /* ACL could not be converted */ 899 int s_setacl; /* set ACL for file failed */ 900 #endif 901 #ifdef USE_XATTR 902 int s_setxattr; /* set xattr for file failed */ 903 #endif 904 int s_restore; /* other incremental restore specific */ 905 int s_compress; /* compress specific failures */ 906 int s_hardeof; /* Hard EOF on input */ 907 int s_substerrs; /* Problems while executing -s/from/to/ */ 908 int s_selinuxerrs; /* Problems setting SEL security context */ 909 }; 910 911 extern struct star_stats xstats; 912 913 914 #include <schily/param.h> 915 916 #if !defined(PATH_MAX) && defined(MAXPATHLEN) 917 #define PATH_MAX MAXPATHLEN 918 #endif 919 920 #ifndef PATH_MAX 921 #define PATH_MAX 1024 922 #endif 923 924 /* 925 * Make sure that regardless what the OS defines, star reserves 926 * space for 1024 chars in filenames. 927 */ 928 #if PATH_MAX < 1024 929 #undef PATH_MAX 930 #define PATH_MAX 1024 931 #endif 932 933 /* 934 * Hack to do debugging with larger values of PATH_MAX. 935 */ 936 #if MY_PATH_MAX > PATH_MAX 937 #undef PATH_MAX 938 #define PATH_MAX MY_PATH_MAX 939 #endif 940 941 #ifdef HAVE_LARGEFILES 942 /* 943 * XXX Hack until fseeko()/ftello() are available everywhere or until 944 * XXX we know a secure way to let autoconf ckeck for fseeko()/ftello() 945 * XXX without defining FILE_OFFSETBITS to 64 in confdefs.h 946 */ 947 #define fseek fseeko 948 #define ftell ftello 949 #endif 950 951 #if !(defined(USE_XATTR) && \ 952 defined(HAVE_LISTXATTR) && defined(HAVE_GETXATTR)) 953 #undef USE_SELINUX 954 #endif 955 #if !defined(HAVE_SELINUX_SELINUX_H) || !defined(HAVE_IS_SELINUX_ENABLED) 956 #undef USE_SELINUX 957 #endif 958 #ifdef USE_SELINUX 959 #include <selinux/selinux.h> 960 #endif 961 962 extern char *bigbuf; 963 extern long bigsize; 964 extern long bufsize; 965 966 #ifdef __cplusplus 967 } 968 #endif 969 970 #endif /* _STAR_H */ 971