00001 /*- 00002 * Copyright (c) 1992 Keith Muller. 00003 * Copyright (c) 1992, 1993 00004 * The Regents of the University of California. All rights reserved. 00005 * 00006 * This code is derived from software contributed to Berkeley by 00007 * Keith Muller of the University of California, San Diego. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 2. Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the distribution. 00017 * 4. Neither the name of the University nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * @(#)tables.h 8.1 (Berkeley) 5/31/93 00034 * $FreeBSD: src/bin/pax/tables.h,v 1.10 2004/04/06 20:06:48 markm Exp $ 00035 */ 00036 00037 /* 00038 * data structures and constants used by the different databases kept by pax 00039 */ 00040 00041 /* 00042 * Hash Table Sizes MUST BE PRIME, if set too small performance suffers. 00043 * Probably safe to expect 500000 inodes per tape. Assuming good key 00044 * distribution (inodes) chains of under 50 long (worse case) is ok. 00045 */ 00046 #define L_TAB_SZ 2503 /* hard link hash table size */ 00047 #define F_TAB_SZ 50503 /* file time hash table size */ 00048 #define N_TAB_SZ 541 /* interactive rename hash table */ 00049 #define D_TAB_SZ 317 /* unique device mapping table */ 00050 #define A_TAB_SZ 317 /* ftree dir access time reset table */ 00051 #define MAXKEYLEN 64 /* max number of chars for hash */ 00052 00053 /* 00054 * file hard link structure (hashed by dev/ino and chained) used to find the 00055 * hard links in a file system or with some archive formats (cpio) 00056 */ 00057 typedef struct hrdlnk { 00058 char *name; /* name of first file seen with this ino/dev */ 00059 dev_t dev; /* files device number */ 00060 ino_t ino; /* files inode number */ 00061 u_long nlink; /* expected link count */ 00062 struct hrdlnk *fow; 00063 } HRDLNK; 00064 00065 /* 00066 * Archive write update file time table (the -u, -C flag), hashed by filename. 00067 * Filenames are stored in a scratch file at seek offset into the file. The 00068 * file time (mod time) and the file name length (for a quick check) are 00069 * stored in a hash table node. We were forced to use a scratch file because 00070 * with -u, the mtime for every node in the archive must always be available 00071 * to compare against (and this data can get REALLY large with big archives). 00072 * By being careful to read only when we have a good chance of a match, the 00073 * performance loss is not measurable (and the size of the archive we can 00074 * handle is greatly increased). 00075 */ 00076 typedef struct ftm { 00077 int namelen; /* file name length */ 00078 time_t mtime; /* files last modification time */ 00079 off_t seek; /* location in scratch file */ 00080 struct ftm *fow; 00081 } FTM; 00082 00083 /* 00084 * Interactive rename table (-i flag), hashed by orig filename. 00085 * We assume this will not be a large table as this mapping data can only be 00086 * obtained through interactive input by the user. Nobody is going to type in 00087 * changes for 500000 files? We use chaining to resolve collisions. 00088 */ 00089 00090 typedef struct namt { 00091 char *oname; /* old name */ 00092 char *nname; /* new name typed in by the user */ 00093 struct namt *fow; 00094 } NAMT; 00095 00096 /* 00097 * Unique device mapping tables. Some protocols (e.g. cpio) require that the 00098 * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they 00099 * are links to the same file. Appending to archives can break this. For those 00100 * protocols that have this requirement we map c_dev to a unique value not seen 00101 * in the archive when we append. We also try to handle inode truncation with 00102 * this table. (When the inode field in the archive header are too small, we 00103 * remap the dev on writes to remove accidental collisions). 00104 * 00105 * The list is hashed by device number using chain collision resolution. Off of 00106 * each DEVT are linked the various remaps for this device based on those bits 00107 * in the inode which were truncated. For example if we are just remapping to 00108 * avoid a device number during an update append, off the DEVT we would have 00109 * only a single DLIST that has a truncation id of 0 (no inode bits were 00110 * stripped for this device so far). When we spot inode truncation we create 00111 * a new mapping based on the set of bits in the inode which were stripped off. 00112 * so if the top four bits of the inode are stripped and they have a pattern of 00113 * 0110...... (where . are those bits not truncated) we would have a mapping 00114 * assigned for all inodes that has the same 0110.... pattern (with this dev 00115 * number of course). This keeps the mapping sparse and should be able to store 00116 * close to the limit of files which can be represented by the optimal 00117 * combination of dev and inode bits, and without creating a fouled up archive. 00118 * Note we also remap truncated devs in the same way (an exercise for the 00119 * dedicated reader; always wanted to say that...:) 00120 */ 00121 00122 typedef struct devt { 00123 dev_t dev; /* the orig device number we now have to map */ 00124 struct devt *fow; /* new device map list */ 00125 struct dlist *list; /* map list based on inode truncation bits */ 00126 } DEVT; 00127 00128 typedef struct dlist { 00129 ino_t trunc_bits; /* truncation pattern for a specific map */ 00130 dev_t dev; /* the new device id we use */ 00131 struct dlist *fow; 00132 } DLIST; 00133 00134 /* 00135 * ftree directory access time reset table. When we are done with with a 00136 * subtree we reset the access and mod time of the directory when the tflag is 00137 * set. Not really explicitly specified in the pax spec, but easy and fast to 00138 * do (and this may have even been intended in the spec, it is not clear). 00139 * table is hashed by inode with chaining. 00140 */ 00141 00142 typedef struct atdir { 00143 char *name; /* name of directory to reset */ 00144 dev_t dev; /* dev and inode for fast lookup */ 00145 ino_t ino; 00146 time_t mtime; /* access and mod time to reset to */ 00147 time_t atime; 00148 struct atdir *fow; 00149 } ATDIR; 00150 00151 /* 00152 * created directory time and mode storage entry. After pax is finished during 00153 * extraction or copy, we must reset directory access modes and times that 00154 * may have been modified after creation (they no longer have the specified 00155 * times and/or modes). We must reset time in the reverse order of creation, 00156 * because entries are added from the top of the file tree to the bottom. 00157 * We MUST reset times from leaf to root (it will not work the other 00158 * direction). Entries are recorded into a spool file to make reverse 00159 * reading faster. 00160 */ 00161 00162 typedef struct dirdata { 00163 int nlen; /* length of the directory name (includes \0) */ 00164 off_t npos; /* position in file where this dir name starts */ 00165 mode_t mode; /* file mode to restore */ 00166 time_t mtime; /* mtime to set */ 00167 time_t atime; /* atime to set */ 00168 int frc_mode; /* do we force mode settings? */ 00169 } DIRDATA;
1.5.8