1*8ce1f4ffSmsaitoh /* $NetBSD: tables.h,v 1.10 2007/04/29 20:23:34 msaitoh Exp $ */ 2b5b29542Sagc 3b5b29542Sagc /*- 4ed6ed8e6Sagc * Copyright (c) 1992 Keith Muller. 5b5b29542Sagc * Copyright (c) 1992, 1993 6b5b29542Sagc * The Regents of the University of California. All rights reserved. 7b5b29542Sagc * 8b5b29542Sagc * This code is derived from software contributed to Berkeley by 9b5b29542Sagc * Keith Muller of the University of California, San Diego. 10b5b29542Sagc * 11b5b29542Sagc * Redistribution and use in source and binary forms, with or without 12b5b29542Sagc * modification, are permitted provided that the following conditions 13b5b29542Sagc * are met: 14b5b29542Sagc * 1. Redistributions of source code must retain the above copyright 15b5b29542Sagc * notice, this list of conditions and the following disclaimer. 16b5b29542Sagc * 2. Redistributions in binary form must reproduce the above copyright 17b5b29542Sagc * notice, this list of conditions and the following disclaimer in the 18b5b29542Sagc * documentation and/or other materials provided with the distribution. 19b5b29542Sagc * 3. Neither the name of the University nor the names of its contributors 20b5b29542Sagc * may be used to endorse or promote products derived from this software 21b5b29542Sagc * without specific prior written permission. 22b5b29542Sagc * 23b5b29542Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24b5b29542Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25b5b29542Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26b5b29542Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27b5b29542Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28b5b29542Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29b5b29542Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30b5b29542Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31b5b29542Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32b5b29542Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33b5b29542Sagc * SUCH DAMAGE. 34b5b29542Sagc * 35b5b29542Sagc * @(#)tables.h 8.1 (Berkeley) 5/31/93 36b5b29542Sagc */ 3749f0ad86Scgd 388b35abe2Sjtc /* 398b35abe2Sjtc * data structures and constants used by the different databases kept by pax 408b35abe2Sjtc */ 418b35abe2Sjtc 428b35abe2Sjtc /* 438b35abe2Sjtc * Hash Table Sizes MUST BE PRIME, if set too small performance suffers. 448b35abe2Sjtc * Probably safe to expect 500000 inodes per tape. Assuming good key 458b35abe2Sjtc * distribution (inodes) chains of under 50 long (worse case) is ok. 468b35abe2Sjtc */ 478b35abe2Sjtc #define L_TAB_SZ 2503 /* hard link hash table size */ 488b35abe2Sjtc #define F_TAB_SZ 50503 /* file time hash table size */ 498b35abe2Sjtc #define N_TAB_SZ 541 /* interactive rename hash table */ 508b35abe2Sjtc #define D_TAB_SZ 317 /* unique device mapping table */ 518b35abe2Sjtc #define A_TAB_SZ 317 /* ftree dir access time reset table */ 528b35abe2Sjtc #define MAXKEYLEN 64 /* max number of chars for hash */ 538b35abe2Sjtc 548b35abe2Sjtc /* 558b35abe2Sjtc * file hard link structure (hashed by dev/ino and chained) used to find the 568b35abe2Sjtc * hard links in a file system or with some archive formats (cpio) 578b35abe2Sjtc */ 588b35abe2Sjtc typedef struct hrdlnk { 598b35abe2Sjtc char *name; /* name of first file seen with this ino/dev */ 608b35abe2Sjtc dev_t dev; /* files device number */ 618b35abe2Sjtc ino_t ino; /* files inode number */ 628b35abe2Sjtc u_long nlink; /* expected link count */ 638b35abe2Sjtc struct hrdlnk *fow; 648b35abe2Sjtc } HRDLNK; 658b35abe2Sjtc 668b35abe2Sjtc /* 678b35abe2Sjtc * Archive write update file time table (the -u, -C flag), hashed by filename. 688b35abe2Sjtc * Filenames are stored in a scratch file at seek offset into the file. The 698b35abe2Sjtc * file time (mod time) and the file name length (for a quick check) are 708b35abe2Sjtc * stored in a hash table node. We were forced to use a scratch file because 718b35abe2Sjtc * with -u, the mtime for every node in the archive must always be available 728b35abe2Sjtc * to compare against (and this data can get REALLY large with big archives). 738b35abe2Sjtc * By being careful to read only when we have a good chance of a match, the 748b35abe2Sjtc * performance loss is not measurable (and the size of the archive we can 758b35abe2Sjtc * handle is greatly increased). 768b35abe2Sjtc */ 778b35abe2Sjtc typedef struct ftm { 788b35abe2Sjtc int namelen; /* file name length */ 798b35abe2Sjtc time_t mtime; /* files last modification time */ 805b367875Schristos off_t seek; /* location in scratch file */ 818b35abe2Sjtc struct ftm *fow; 828b35abe2Sjtc } FTM; 838b35abe2Sjtc 848b35abe2Sjtc /* 858b35abe2Sjtc * Interactive rename table (-i flag), hashed by orig filename. 868b35abe2Sjtc * We assume this will not be a large table as this mapping data can only be 878b35abe2Sjtc * obtained through interactive input by the user. Nobody is going to type in 888b35abe2Sjtc * changes for 500000 files? We use chaining to resolve collisions. 898b35abe2Sjtc */ 908b35abe2Sjtc 918b35abe2Sjtc typedef struct namt { 928b35abe2Sjtc char *oname; /* old name */ 938b35abe2Sjtc char *nname; /* new name typed in by the user */ 948b35abe2Sjtc struct namt *fow; 958b35abe2Sjtc } NAMT; 968b35abe2Sjtc 978b35abe2Sjtc /* 988b35abe2Sjtc * Unique device mapping tables. Some protocols (e.g. cpio) require that the 998b35abe2Sjtc * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they 1008b35abe2Sjtc * are links to the same file. Appending to archives can break this. For those 1018b35abe2Sjtc * protocols that have this requirement we map c_dev to a unique value not seen 1028b35abe2Sjtc * in the archive when we append. We also try to handle inode truncation with 1038b35abe2Sjtc * this table. (When the inode field in the archive header are too small, we 1048b35abe2Sjtc * remap the dev on writes to remove accidental collisions). 1058b35abe2Sjtc * 1068b35abe2Sjtc * The list is hashed by device number using chain collision resolution. Off of 1078b35abe2Sjtc * each DEVT are linked the various remaps for this device based on those bits 1088b35abe2Sjtc * in the inode which were truncated. For example if we are just remapping to 1098b35abe2Sjtc * avoid a device number during an update append, off the DEVT we would have 1108b35abe2Sjtc * only a single DLIST that has a truncation id of 0 (no inode bits were 1118b35abe2Sjtc * stripped for this device so far). When we spot inode truncation we create 1128b35abe2Sjtc * a new mapping based on the set of bits in the inode which were stripped off. 1138b35abe2Sjtc * so if the top four bits of the inode are stripped and they have a pattern of 1148b35abe2Sjtc * 0110...... (where . are those bits not truncated) we would have a mapping 1158b35abe2Sjtc * assigned for all inodes that has the same 0110.... pattern (with this dev 1168b35abe2Sjtc * number of course). This keeps the mapping sparse and should be able to store 1178b35abe2Sjtc * close to the limit of files which can be represented by the optimal 1188b35abe2Sjtc * combination of dev and inode bits, and without creating a fouled up archive. 1198b35abe2Sjtc * Note we also remap truncated devs in the same way (an exercise for the 1208b35abe2Sjtc * dedicated reader; always wanted to say that...:) 1218b35abe2Sjtc */ 1228b35abe2Sjtc 1238b35abe2Sjtc typedef struct devt { 1248b35abe2Sjtc dev_t dev; /* the orig device number we now have to map */ 1258b35abe2Sjtc struct devt *fow; /* new device map list */ 1268b35abe2Sjtc struct dlist *list; /* map list based on inode truncation bits */ 1278b35abe2Sjtc } DEVT; 1288b35abe2Sjtc 1298b35abe2Sjtc typedef struct dlist { 1308b35abe2Sjtc ino_t trunc_bits; /* truncation pattern for a specific map */ 1318b35abe2Sjtc dev_t dev; /* the new device id we use */ 1328b35abe2Sjtc struct dlist *fow; 1338b35abe2Sjtc } DLIST; 1348b35abe2Sjtc 1358b35abe2Sjtc /* 136*8ce1f4ffSmsaitoh * ftree directory access time reset table. When we are done with a 1378b35abe2Sjtc * subtree we reset the access and mod time of the directory when the tflag is 1388b35abe2Sjtc * set. Not really explicitly specified in the pax spec, but easy and fast to 1398b35abe2Sjtc * do (and this may have even been intended in the spec, it is not clear). 1408b35abe2Sjtc * table is hashed by inode with chaining. 1418b35abe2Sjtc */ 1428b35abe2Sjtc 1438b35abe2Sjtc typedef struct atdir { 1448b35abe2Sjtc char *name; /* name of directory to reset */ 1458b35abe2Sjtc dev_t dev; /* dev and inode for fast lookup */ 1468b35abe2Sjtc ino_t ino; 1478b35abe2Sjtc time_t mtime; /* access and mod time to reset to */ 1488b35abe2Sjtc time_t atime; 1498b35abe2Sjtc struct atdir *fow; 1508b35abe2Sjtc } ATDIR; 1518b35abe2Sjtc 1528b35abe2Sjtc /* 1538b35abe2Sjtc * created directory time and mode storage entry. After pax is finished during 1548b35abe2Sjtc * extraction or copy, we must reset directory access modes and times that 1558b35abe2Sjtc * may have been modified after creation (they no longer have the specified 1568b35abe2Sjtc * times and/or modes). We must reset time in the reverse order of creation, 1578b35abe2Sjtc * because entries are added from the top of the file tree to the bottom. 1588b35abe2Sjtc * We MUST reset times from leaf to root (it will not work the other 1598b35abe2Sjtc * direction). Entries are recorded into a spool file to make reverse 1608b35abe2Sjtc * reading faster. 1618b35abe2Sjtc */ 1628b35abe2Sjtc 1638b35abe2Sjtc typedef struct dirdata { 1640317a206Sthorpej #ifdef DIRS_USE_FILE 1658b35abe2Sjtc int nlen; /* length of the directory name (includes \0) */ 1668b35abe2Sjtc off_t npos; /* position in file where this dir name starts */ 1670317a206Sthorpej #else 1680317a206Sthorpej char *name; /* file name */ 1690317a206Sthorpej struct dirdata *next; 1700317a206Sthorpej #endif 1718b35abe2Sjtc mode_t mode; /* file mode to restore */ 1728b35abe2Sjtc time_t mtime; /* mtime to set */ 1738b35abe2Sjtc time_t atime; /* atime to set */ 174b60cafe2Smrg long fflags; /* file flags to set */ 1758b35abe2Sjtc int frc_mode; /* do we force mode settings? */ 1768b35abe2Sjtc } DIRDATA; 177