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