1d684a8f3Smuller /*- 2d684a8f3Smuller * Copyright (c) 1992 Keith Muller. 3*3631e65bSbostic * Copyright (c) 1992, 1993 4*3631e65bSbostic * The Regents of the University of California. All rights reserved. 5d684a8f3Smuller * 6d684a8f3Smuller * This code is derived from software contributed to Berkeley by 7d684a8f3Smuller * Keith Muller of the University of California, San Diego. 8d684a8f3Smuller * 9d684a8f3Smuller * %sccs.include.redist.c% 10d684a8f3Smuller * 11*3631e65bSbostic * @(#)tables.h 8.1 (Berkeley) 05/31/93 12d684a8f3Smuller */ 13d684a8f3Smuller 14d684a8f3Smuller /* 15d684a8f3Smuller * data structures and constants used by the different databases kept by pax 16d684a8f3Smuller */ 17d684a8f3Smuller 18d684a8f3Smuller /* 19d684a8f3Smuller * Hash Table Sizes MUST BE PRIME, if set too small performance suffers. 20d684a8f3Smuller * Probably safe to expect 500000 inodes per tape. Assuming good key 21d684a8f3Smuller * distribution (inodes) chains of under 50 long (worse case) is ok. 22d684a8f3Smuller */ 23d684a8f3Smuller #define L_TAB_SZ 2503 /* hard link hash table size */ 24d684a8f3Smuller #define F_TAB_SZ 50503 /* file time hash table size */ 25d684a8f3Smuller #define N_TAB_SZ 541 /* interactive rename hash table */ 26d684a8f3Smuller #define D_TAB_SZ 317 /* unique device mapping table */ 27d684a8f3Smuller #define A_TAB_SZ 317 /* ftree dir access time reset table */ 28d684a8f3Smuller #define MAXKEYLEN 64 /* max number of chars for hash */ 29d684a8f3Smuller 30d684a8f3Smuller /* 31d684a8f3Smuller * file hard link structure (hashed by dev/ino and chained) used to find the 32d684a8f3Smuller * hard links in a file system or with some archive formats (cpio) 33d684a8f3Smuller */ 34d684a8f3Smuller typedef struct hrdlnk { 35d684a8f3Smuller char *name; /* name of first file seen with this ino/dev */ 36d684a8f3Smuller dev_t dev; /* files device number */ 37d684a8f3Smuller ino_t ino; /* files inode number */ 38d684a8f3Smuller u_long nlink; /* expected link count */ 39d684a8f3Smuller struct hrdlnk *fow; 40d684a8f3Smuller } HRDLNK; 41d684a8f3Smuller 42d684a8f3Smuller /* 43d684a8f3Smuller * Archive write update file time table (the -u, -C flag), hashed by filename. 44d684a8f3Smuller * Filenames are stored in a scratch file at seek offset into the file. The 45d684a8f3Smuller * file time (mod time) and the file name length (for a quick check) are 46d684a8f3Smuller * stored in a hash table node. We were forced to use a scratch file because 47d684a8f3Smuller * with -u, the mtime for every node in the archive must always be available 48d684a8f3Smuller * to compare against (and this data can get REALLY large with big archives). 49d684a8f3Smuller * By being careful to read only when we have a good chance of a match, the 50d684a8f3Smuller * performance loss is not measurable (and the size of the archive we can 51d684a8f3Smuller * handle is greatly increased). 52d684a8f3Smuller */ 53d684a8f3Smuller typedef struct ftm { 54d684a8f3Smuller int namelen; /* file name length */ 55d684a8f3Smuller time_t mtime; /* files last modification time */ 56d684a8f3Smuller off_t seek; /* loacation in scratch file */ 57d684a8f3Smuller struct ftm *fow; 58d684a8f3Smuller } FTM; 59d684a8f3Smuller 60d684a8f3Smuller /* 61d684a8f3Smuller * Interactive rename table (-i flag), hashed by orig filename. 62d684a8f3Smuller * We assume this will not be a large table as this mapping data can only be 63d684a8f3Smuller * obtained through interactive input by the user. Nobody is going to type in 64d684a8f3Smuller * changes for 500000 files? We use chaining to resolve collisions. 65d684a8f3Smuller */ 66d684a8f3Smuller 67d684a8f3Smuller typedef struct namt { 68d684a8f3Smuller char *oname; /* old name */ 69d684a8f3Smuller char *nname; /* new name typed in by the user */ 70d684a8f3Smuller struct namt *fow; 71d684a8f3Smuller } NAMT; 72d684a8f3Smuller 73d684a8f3Smuller /* 74d684a8f3Smuller * Unique device mapping tables. Some protocols (e.g. cpio) require that the 75d684a8f3Smuller * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they 76d684a8f3Smuller * are links to the same file. Appending to archives can break this. For those 77d684a8f3Smuller * protocols that have this requirement we map c_dev to a unique value not seen 78d684a8f3Smuller * in the archive when we append. We also try to handle inode truncation with 79d684a8f3Smuller * this table. (When the inode field in the archive header are too small, we 80d684a8f3Smuller * remap the dev on writes to remove accidental collisions). 81d684a8f3Smuller * 82d684a8f3Smuller * The list is hashed by device number using chain collision resolution. Off of 83d684a8f3Smuller * each DEVT are linked the various remaps for this device based on those bits 84d684a8f3Smuller * in the inode which were truncated. For example if we are just remapping to 85d684a8f3Smuller * avoid a device number during an update append, off the DEVT we would have 86d684a8f3Smuller * only a single DLIST that has a truncation id of 0 (no inode bits were 87d684a8f3Smuller * stripped for this device so far). When we spot inode truncation we create 88d684a8f3Smuller * a new mapping based on the set of bits in the inode which were stripped off. 89d684a8f3Smuller * so if the top four bits of the inode are stripped and they have a pattern of 90d684a8f3Smuller * 0110...... (where . are those bits not truncated) we would have a mapping 91d684a8f3Smuller * assigned for all inodes that has the same 0110.... pattern (with this dev 92d684a8f3Smuller * number of course). This keeps the mapping sparse and should be able to store 93d684a8f3Smuller * close to the limit of files which can be represented by the optimal 94d684a8f3Smuller * combination of dev and inode bits, and without creating a fouled up archive. 95d684a8f3Smuller * Note we also remap truncated devs in the same way (an exercise for the 96d684a8f3Smuller * dedicated reader; always wanted to say that...:) 97d684a8f3Smuller */ 98d684a8f3Smuller 99d684a8f3Smuller typedef struct devt { 100d684a8f3Smuller dev_t dev; /* the orig device number we now have to map */ 101d684a8f3Smuller struct devt *fow; /* new device map list */ 102d684a8f3Smuller struct dlist *list; /* map list based on inode truncation bits */ 103d684a8f3Smuller } DEVT; 104d684a8f3Smuller 105d684a8f3Smuller typedef struct dlist { 106d684a8f3Smuller ino_t trunc_bits; /* truncation pattern for a specific map */ 107d684a8f3Smuller dev_t dev; /* the new device id we use */ 108d684a8f3Smuller struct dlist *fow; 109d684a8f3Smuller } DLIST; 110d684a8f3Smuller 111d684a8f3Smuller /* 112d684a8f3Smuller * ftree directory access time reset table. When we are done with with a 113d684a8f3Smuller * subtree we reset the access and mod time of the directory when the tflag is 114d684a8f3Smuller * set. Not really explicitly specified in the pax spec, but easy and fast to 115d684a8f3Smuller * do (and this may have even been intended in the spec, it is not clear). 116d684a8f3Smuller * table is hashed by inode with chaining. 117d684a8f3Smuller */ 118d684a8f3Smuller 119d684a8f3Smuller typedef struct atdir { 120d684a8f3Smuller char *name; /* name of directory to reset */ 121d684a8f3Smuller dev_t dev; /* dev and inode for fast lookup */ 122d684a8f3Smuller ino_t ino; 123d684a8f3Smuller time_t mtime; /* access and mod time to reset to */ 124d684a8f3Smuller time_t atime; 125d684a8f3Smuller struct atdir *fow; 126d684a8f3Smuller } ATDIR; 127d684a8f3Smuller 128d684a8f3Smuller /* 129d684a8f3Smuller * created directory time and mode storage entry. After pax is finished during 130d684a8f3Smuller * extraction or copy, we must reset directory access modes and times that 131d684a8f3Smuller * may have been modified after creation (they no longer have the specified 132d684a8f3Smuller * times and/or modes). We must reset time in the reverse order of creation, 133d684a8f3Smuller * because entries are added from the top of the file tree to the bottom. 134d684a8f3Smuller * We MUST reset times from leaf to root (it will not work the other 135d684a8f3Smuller * direction). Entries are recorded into a spool file to make reverse 136d684a8f3Smuller * reading faster. 137d684a8f3Smuller */ 138d684a8f3Smuller 139d684a8f3Smuller typedef struct dirdata { 140d684a8f3Smuller int nlen; /* length of the directory name (includes \0) */ 141d684a8f3Smuller off_t npos; /* position in file where this dir name starts */ 142d684a8f3Smuller mode_t mode; /* file mode to restore */ 143d684a8f3Smuller time_t mtime; /* mtime to set */ 144d684a8f3Smuller time_t atime; /* atime to set */ 145d684a8f3Smuller int frc_mode; /* do we force mode settings? */ 146d684a8f3Smuller } DIRDATA; 147