14b88c807SRodney W. Grimes /*- 24b88c807SRodney W. Grimes * Copyright (c) 1992 Keith Muller. 34b88c807SRodney W. Grimes * Copyright (c) 1992, 1993 44b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 54b88c807SRodney W. Grimes * 64b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 74b88c807SRodney W. Grimes * Keith Muller of the University of California, San Diego. 84b88c807SRodney W. Grimes * 94b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 104b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 114b88c807SRodney W. Grimes * are met: 124b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 134b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 144b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 154b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 164b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 174b88c807SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 184b88c807SRodney W. Grimes * must display the following acknowledgement: 194b88c807SRodney W. Grimes * This product includes software developed by the University of 204b88c807SRodney W. Grimes * California, Berkeley and its contributors. 214b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 224b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 234b88c807SRodney W. Grimes * without specific prior written permission. 244b88c807SRodney W. Grimes * 254b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 264b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 274b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 284b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 294b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 304b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 314b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 324b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 334b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 344b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 354b88c807SRodney W. Grimes * SUCH DAMAGE. 364b88c807SRodney W. Grimes * 374b88c807SRodney W. Grimes * @(#)tables.h 8.1 (Berkeley) 5/31/93 384b88c807SRodney W. Grimes */ 394b88c807SRodney W. Grimes 404b88c807SRodney W. Grimes /* 414b88c807SRodney W. Grimes * data structures and constants used by the different databases kept by pax 424b88c807SRodney W. Grimes */ 434b88c807SRodney W. Grimes 444b88c807SRodney W. Grimes /* 454b88c807SRodney W. Grimes * Hash Table Sizes MUST BE PRIME, if set too small performance suffers. 464b88c807SRodney W. Grimes * Probably safe to expect 500000 inodes per tape. Assuming good key 474b88c807SRodney W. Grimes * distribution (inodes) chains of under 50 long (worse case) is ok. 484b88c807SRodney W. Grimes */ 494b88c807SRodney W. Grimes #define L_TAB_SZ 2503 /* hard link hash table size */ 504b88c807SRodney W. Grimes #define F_TAB_SZ 50503 /* file time hash table size */ 514b88c807SRodney W. Grimes #define N_TAB_SZ 541 /* interactive rename hash table */ 524b88c807SRodney W. Grimes #define D_TAB_SZ 317 /* unique device mapping table */ 534b88c807SRodney W. Grimes #define A_TAB_SZ 317 /* ftree dir access time reset table */ 544b88c807SRodney W. Grimes #define MAXKEYLEN 64 /* max number of chars for hash */ 554b88c807SRodney W. Grimes 564b88c807SRodney W. Grimes /* 574b88c807SRodney W. Grimes * file hard link structure (hashed by dev/ino and chained) used to find the 584b88c807SRodney W. Grimes * hard links in a file system or with some archive formats (cpio) 594b88c807SRodney W. Grimes */ 604b88c807SRodney W. Grimes typedef struct hrdlnk { 614b88c807SRodney W. Grimes char *name; /* name of first file seen with this ino/dev */ 624b88c807SRodney W. Grimes dev_t dev; /* files device number */ 634b88c807SRodney W. Grimes ino_t ino; /* files inode number */ 644b88c807SRodney W. Grimes u_long nlink; /* expected link count */ 654b88c807SRodney W. Grimes struct hrdlnk *fow; 664b88c807SRodney W. Grimes } HRDLNK; 674b88c807SRodney W. Grimes 684b88c807SRodney W. Grimes /* 694b88c807SRodney W. Grimes * Archive write update file time table (the -u, -C flag), hashed by filename. 704b88c807SRodney W. Grimes * Filenames are stored in a scratch file at seek offset into the file. The 714b88c807SRodney W. Grimes * file time (mod time) and the file name length (for a quick check) are 724b88c807SRodney W. Grimes * stored in a hash table node. We were forced to use a scratch file because 734b88c807SRodney W. Grimes * with -u, the mtime for every node in the archive must always be available 744b88c807SRodney W. Grimes * to compare against (and this data can get REALLY large with big archives). 754b88c807SRodney W. Grimes * By being careful to read only when we have a good chance of a match, the 764b88c807SRodney W. Grimes * performance loss is not measurable (and the size of the archive we can 774b88c807SRodney W. Grimes * handle is greatly increased). 784b88c807SRodney W. Grimes */ 794b88c807SRodney W. Grimes typedef struct ftm { 804b88c807SRodney W. Grimes int namelen; /* file name length */ 814b88c807SRodney W. Grimes time_t mtime; /* files last modification time */ 824b88c807SRodney W. Grimes off_t seek; /* loacation in scratch file */ 834b88c807SRodney W. Grimes struct ftm *fow; 844b88c807SRodney W. Grimes } FTM; 854b88c807SRodney W. Grimes 864b88c807SRodney W. Grimes /* 874b88c807SRodney W. Grimes * Interactive rename table (-i flag), hashed by orig filename. 884b88c807SRodney W. Grimes * We assume this will not be a large table as this mapping data can only be 894b88c807SRodney W. Grimes * obtained through interactive input by the user. Nobody is going to type in 904b88c807SRodney W. Grimes * changes for 500000 files? We use chaining to resolve collisions. 914b88c807SRodney W. Grimes */ 924b88c807SRodney W. Grimes 934b88c807SRodney W. Grimes typedef struct namt { 944b88c807SRodney W. Grimes char *oname; /* old name */ 954b88c807SRodney W. Grimes char *nname; /* new name typed in by the user */ 964b88c807SRodney W. Grimes struct namt *fow; 974b88c807SRodney W. Grimes } NAMT; 984b88c807SRodney W. Grimes 994b88c807SRodney W. Grimes /* 1004b88c807SRodney W. Grimes * Unique device mapping tables. Some protocols (e.g. cpio) require that the 1014b88c807SRodney W. Grimes * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they 1024b88c807SRodney W. Grimes * are links to the same file. Appending to archives can break this. For those 1034b88c807SRodney W. Grimes * protocols that have this requirement we map c_dev to a unique value not seen 1044b88c807SRodney W. Grimes * in the archive when we append. We also try to handle inode truncation with 1054b88c807SRodney W. Grimes * this table. (When the inode field in the archive header are too small, we 1064b88c807SRodney W. Grimes * remap the dev on writes to remove accidental collisions). 1074b88c807SRodney W. Grimes * 1084b88c807SRodney W. Grimes * The list is hashed by device number using chain collision resolution. Off of 1094b88c807SRodney W. Grimes * each DEVT are linked the various remaps for this device based on those bits 1104b88c807SRodney W. Grimes * in the inode which were truncated. For example if we are just remapping to 1114b88c807SRodney W. Grimes * avoid a device number during an update append, off the DEVT we would have 1124b88c807SRodney W. Grimes * only a single DLIST that has a truncation id of 0 (no inode bits were 1134b88c807SRodney W. Grimes * stripped for this device so far). When we spot inode truncation we create 1144b88c807SRodney W. Grimes * a new mapping based on the set of bits in the inode which were stripped off. 1154b88c807SRodney W. Grimes * so if the top four bits of the inode are stripped and they have a pattern of 1164b88c807SRodney W. Grimes * 0110...... (where . are those bits not truncated) we would have a mapping 1174b88c807SRodney W. Grimes * assigned for all inodes that has the same 0110.... pattern (with this dev 1184b88c807SRodney W. Grimes * number of course). This keeps the mapping sparse and should be able to store 1194b88c807SRodney W. Grimes * close to the limit of files which can be represented by the optimal 1204b88c807SRodney W. Grimes * combination of dev and inode bits, and without creating a fouled up archive. 1214b88c807SRodney W. Grimes * Note we also remap truncated devs in the same way (an exercise for the 1224b88c807SRodney W. Grimes * dedicated reader; always wanted to say that...:) 1234b88c807SRodney W. Grimes */ 1244b88c807SRodney W. Grimes 1254b88c807SRodney W. Grimes typedef struct devt { 1264b88c807SRodney W. Grimes dev_t dev; /* the orig device number we now have to map */ 1274b88c807SRodney W. Grimes struct devt *fow; /* new device map list */ 1284b88c807SRodney W. Grimes struct dlist *list; /* map list based on inode truncation bits */ 1294b88c807SRodney W. Grimes } DEVT; 1304b88c807SRodney W. Grimes 1314b88c807SRodney W. Grimes typedef struct dlist { 1324b88c807SRodney W. Grimes ino_t trunc_bits; /* truncation pattern for a specific map */ 1334b88c807SRodney W. Grimes dev_t dev; /* the new device id we use */ 1344b88c807SRodney W. Grimes struct dlist *fow; 1354b88c807SRodney W. Grimes } DLIST; 1364b88c807SRodney W. Grimes 1374b88c807SRodney W. Grimes /* 1384b88c807SRodney W. Grimes * ftree directory access time reset table. When we are done with with a 1394b88c807SRodney W. Grimes * subtree we reset the access and mod time of the directory when the tflag is 1404b88c807SRodney W. Grimes * set. Not really explicitly specified in the pax spec, but easy and fast to 1414b88c807SRodney W. Grimes * do (and this may have even been intended in the spec, it is not clear). 1424b88c807SRodney W. Grimes * table is hashed by inode with chaining. 1434b88c807SRodney W. Grimes */ 1444b88c807SRodney W. Grimes 1454b88c807SRodney W. Grimes typedef struct atdir { 1464b88c807SRodney W. Grimes char *name; /* name of directory to reset */ 1474b88c807SRodney W. Grimes dev_t dev; /* dev and inode for fast lookup */ 1484b88c807SRodney W. Grimes ino_t ino; 1494b88c807SRodney W. Grimes time_t mtime; /* access and mod time to reset to */ 1504b88c807SRodney W. Grimes time_t atime; 1514b88c807SRodney W. Grimes struct atdir *fow; 1524b88c807SRodney W. Grimes } ATDIR; 1534b88c807SRodney W. Grimes 1544b88c807SRodney W. Grimes /* 1554b88c807SRodney W. Grimes * created directory time and mode storage entry. After pax is finished during 1564b88c807SRodney W. Grimes * extraction or copy, we must reset directory access modes and times that 1574b88c807SRodney W. Grimes * may have been modified after creation (they no longer have the specified 1584b88c807SRodney W. Grimes * times and/or modes). We must reset time in the reverse order of creation, 1594b88c807SRodney W. Grimes * because entries are added from the top of the file tree to the bottom. 1604b88c807SRodney W. Grimes * We MUST reset times from leaf to root (it will not work the other 1614b88c807SRodney W. Grimes * direction). Entries are recorded into a spool file to make reverse 1624b88c807SRodney W. Grimes * reading faster. 1634b88c807SRodney W. Grimes */ 1644b88c807SRodney W. Grimes 1654b88c807SRodney W. Grimes typedef struct dirdata { 1664b88c807SRodney W. Grimes int nlen; /* length of the directory name (includes \0) */ 1674b88c807SRodney W. Grimes off_t npos; /* position in file where this dir name starts */ 1684b88c807SRodney W. Grimes mode_t mode; /* file mode to restore */ 1694b88c807SRodney W. Grimes time_t mtime; /* mtime to set */ 1704b88c807SRodney W. Grimes time_t atime; /* atime to set */ 1714b88c807SRodney W. Grimes int frc_mode; /* do we force mode settings? */ 1724b88c807SRodney W. Grimes } DIRDATA; 173