tables.h revision 8855
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1992 Keith Muller. 31556Srgrimes * Copyright (c) 1992, 1993 41556Srgrimes * The Regents of the University of California. All rights reserved. 51556Srgrimes * 61556Srgrimes * This code is derived from software contributed to Berkeley by 71556Srgrimes * Keith Muller of the University of California, San Diego. 81556Srgrimes * 91556Srgrimes * Redistribution and use in source and binary forms, with or without 101556Srgrimes * modification, are permitted provided that the following conditions 111556Srgrimes * are met: 121556Srgrimes * 1. Redistributions of source code must retain the above copyright 131556Srgrimes * notice, this list of conditions and the following disclaimer. 141556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 151556Srgrimes * notice, this list of conditions and the following disclaimer in the 161556Srgrimes * documentation and/or other materials provided with the distribution. 171556Srgrimes * 3. All advertising materials mentioning features or use of this software 181556Srgrimes * must display the following acknowledgement: 191556Srgrimes * This product includes software developed by the University of 201556Srgrimes * California, Berkeley and its contributors. 211556Srgrimes * 4. Neither the name of the University nor the names of its contributors 221556Srgrimes * may be used to endorse or promote products derived from this software 231556Srgrimes * without specific prior written permission. 241556Srgrimes * 251556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 261556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 271556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 281556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 331556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 341556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 351556Srgrimes * SUCH DAMAGE. 361556Srgrimes * 371556Srgrimes * @(#)tables.h 8.1 (Berkeley) 5/31/93 388855Srgrimes * $Id: tables.h,v 1.2 1994/09/24 02:56:35 davidg Exp $ 391556Srgrimes */ 401556Srgrimes 411556Srgrimes/* 421556Srgrimes * data structures and constants used by the different databases kept by pax 431556Srgrimes */ 441556Srgrimes 451556Srgrimes/* 461556Srgrimes * Hash Table Sizes MUST BE PRIME, if set too small performance suffers. 471556Srgrimes * Probably safe to expect 500000 inodes per tape. Assuming good key 481556Srgrimes * distribution (inodes) chains of under 50 long (worse case) is ok. 491556Srgrimes */ 501556Srgrimes#define L_TAB_SZ 2503 /* hard link hash table size */ 511556Srgrimes#define F_TAB_SZ 50503 /* file time hash table size */ 521556Srgrimes#define N_TAB_SZ 541 /* interactive rename hash table */ 531556Srgrimes#define D_TAB_SZ 317 /* unique device mapping table */ 541556Srgrimes#define A_TAB_SZ 317 /* ftree dir access time reset table */ 551556Srgrimes#define MAXKEYLEN 64 /* max number of chars for hash */ 561556Srgrimes 571556Srgrimes/* 581556Srgrimes * file hard link structure (hashed by dev/ino and chained) used to find the 591556Srgrimes * hard links in a file system or with some archive formats (cpio) 601556Srgrimes */ 611556Srgrimestypedef struct hrdlnk { 621556Srgrimes char *name; /* name of first file seen with this ino/dev */ 631556Srgrimes dev_t dev; /* files device number */ 641556Srgrimes ino_t ino; /* files inode number */ 651556Srgrimes u_long nlink; /* expected link count */ 661556Srgrimes struct hrdlnk *fow; 671556Srgrimes} HRDLNK; 681556Srgrimes 691556Srgrimes/* 701556Srgrimes * Archive write update file time table (the -u, -C flag), hashed by filename. 711556Srgrimes * Filenames are stored in a scratch file at seek offset into the file. The 721556Srgrimes * file time (mod time) and the file name length (for a quick check) are 731556Srgrimes * stored in a hash table node. We were forced to use a scratch file because 741556Srgrimes * with -u, the mtime for every node in the archive must always be available 751556Srgrimes * to compare against (and this data can get REALLY large with big archives). 761556Srgrimes * By being careful to read only when we have a good chance of a match, the 771556Srgrimes * performance loss is not measurable (and the size of the archive we can 781556Srgrimes * handle is greatly increased). 791556Srgrimes */ 801556Srgrimestypedef struct ftm { 811556Srgrimes int namelen; /* file name length */ 821556Srgrimes time_t mtime; /* files last modification time */ 831556Srgrimes off_t seek; /* loacation in scratch file */ 841556Srgrimes struct ftm *fow; 851556Srgrimes} FTM; 861556Srgrimes 871556Srgrimes/* 881556Srgrimes * Interactive rename table (-i flag), hashed by orig filename. 891556Srgrimes * We assume this will not be a large table as this mapping data can only be 901556Srgrimes * obtained through interactive input by the user. Nobody is going to type in 911556Srgrimes * changes for 500000 files? We use chaining to resolve collisions. 921556Srgrimes */ 931556Srgrimes 941556Srgrimestypedef struct namt { 951556Srgrimes char *oname; /* old name */ 961556Srgrimes char *nname; /* new name typed in by the user */ 971556Srgrimes struct namt *fow; 981556Srgrimes} NAMT; 991556Srgrimes 1001556Srgrimes/* 1011556Srgrimes * Unique device mapping tables. Some protocols (e.g. cpio) require that the 1021556Srgrimes * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they 1031556Srgrimes * are links to the same file. Appending to archives can break this. For those 1041556Srgrimes * protocols that have this requirement we map c_dev to a unique value not seen 1051556Srgrimes * in the archive when we append. We also try to handle inode truncation with 1061556Srgrimes * this table. (When the inode field in the archive header are too small, we 1071556Srgrimes * remap the dev on writes to remove accidental collisions). 1081556Srgrimes * 1098855Srgrimes * The list is hashed by device number using chain collision resolution. Off of 1101556Srgrimes * each DEVT are linked the various remaps for this device based on those bits 1111556Srgrimes * in the inode which were truncated. For example if we are just remapping to 1121556Srgrimes * avoid a device number during an update append, off the DEVT we would have 1131556Srgrimes * only a single DLIST that has a truncation id of 0 (no inode bits were 1141556Srgrimes * stripped for this device so far). When we spot inode truncation we create 1151556Srgrimes * a new mapping based on the set of bits in the inode which were stripped off. 1161556Srgrimes * so if the top four bits of the inode are stripped and they have a pattern of 1171556Srgrimes * 0110...... (where . are those bits not truncated) we would have a mapping 1181556Srgrimes * assigned for all inodes that has the same 0110.... pattern (with this dev 1191556Srgrimes * number of course). This keeps the mapping sparse and should be able to store 1201556Srgrimes * close to the limit of files which can be represented by the optimal 1211556Srgrimes * combination of dev and inode bits, and without creating a fouled up archive. 1221556Srgrimes * Note we also remap truncated devs in the same way (an exercise for the 1231556Srgrimes * dedicated reader; always wanted to say that...:) 1241556Srgrimes */ 1251556Srgrimes 1261556Srgrimestypedef struct devt { 1271556Srgrimes dev_t dev; /* the orig device number we now have to map */ 1281556Srgrimes struct devt *fow; /* new device map list */ 1291556Srgrimes struct dlist *list; /* map list based on inode truncation bits */ 1301556Srgrimes} DEVT; 1311556Srgrimes 1321556Srgrimestypedef struct dlist { 1331556Srgrimes ino_t trunc_bits; /* truncation pattern for a specific map */ 1341556Srgrimes dev_t dev; /* the new device id we use */ 1351556Srgrimes struct dlist *fow; 1361556Srgrimes} DLIST; 1371556Srgrimes 1381556Srgrimes/* 1391556Srgrimes * ftree directory access time reset table. When we are done with with a 1401556Srgrimes * subtree we reset the access and mod time of the directory when the tflag is 1411556Srgrimes * set. Not really explicitly specified in the pax spec, but easy and fast to 1421556Srgrimes * do (and this may have even been intended in the spec, it is not clear). 1431556Srgrimes * table is hashed by inode with chaining. 1441556Srgrimes */ 1451556Srgrimes 1461556Srgrimestypedef struct atdir { 1471556Srgrimes char *name; /* name of directory to reset */ 1481556Srgrimes dev_t dev; /* dev and inode for fast lookup */ 1491556Srgrimes ino_t ino; 1501556Srgrimes time_t mtime; /* access and mod time to reset to */ 1511556Srgrimes time_t atime; 1521556Srgrimes struct atdir *fow; 1531556Srgrimes} ATDIR; 1541556Srgrimes 1551556Srgrimes/* 1561556Srgrimes * created directory time and mode storage entry. After pax is finished during 1571556Srgrimes * extraction or copy, we must reset directory access modes and times that 1581556Srgrimes * may have been modified after creation (they no longer have the specified 1591556Srgrimes * times and/or modes). We must reset time in the reverse order of creation, 1601556Srgrimes * because entries are added from the top of the file tree to the bottom. 1611556Srgrimes * We MUST reset times from leaf to root (it will not work the other 1621556Srgrimes * direction). Entries are recorded into a spool file to make reverse 1631556Srgrimes * reading faster. 1641556Srgrimes */ 1651556Srgrimes 1661556Srgrimestypedef struct dirdata { 1671556Srgrimes int nlen; /* length of the directory name (includes \0) */ 1681556Srgrimes off_t npos; /* position in file where this dir name starts */ 1691556Srgrimes mode_t mode; /* file mode to restore */ 1701556Srgrimes time_t mtime; /* mtime to set */ 1711556Srgrimes time_t atime; /* atime to set */ 1721556Srgrimes int frc_mode; /* do we force mode settings? */ 1731556Srgrimes} DIRDATA; 174