file_cmds-321.40.3.tar.gz
[apple/file_cmds.git] / pax / tables.h
1 /* $OpenBSD: tables.h,v 1.8 2006/08/05 23:05:13 ray Exp $ */
2 /* $NetBSD: tables.h,v 1.3 1995/03/21 09:07:47 cgd Exp $ */
3
4 /*-
5 * Copyright (c) 1992 Keith Muller.
6 * Copyright (c) 1992, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * This code is derived from software contributed to Berkeley by
10 * Keith Muller of the University of California, San Diego.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)tables.h 8.1 (Berkeley) 5/31/93
37 */
38
39 #ifndef _TABLES_H_
40 #define _TABLES_H_
41
42 /*
43 * data structures and constants used by the different databases kept by pax
44 */
45
46 /*
47 * Hash Table Sizes MUST BE PRIME, if set too small performance suffers.
48 * Probably safe to expect 500000 inodes per tape. Assuming good key
49 * distribution (inodes) chains of under 50 long (worst case) is ok.
50 */
51 #define L_TAB_SZ 2503 /* hard link hash table size */
52 #define F_TAB_SZ 50503 /* file time hash table size */
53 #define N_TAB_SZ 541 /* interactive rename hash table */
54 #define D_TAB_SZ 317 /* unique device mapping table */
55 #define A_TAB_SZ 317 /* ftree dir access time reset table */
56 #define MAXKEYLEN 64 /* max number of chars for hash */
57 #define DIRP_SIZE 64 /* initial size of created dir table */
58
59 /*
60 * file hard link structure (hashed by dev/ino and chained) used to find the
61 * hard links in a file system or with some archive formats (cpio)
62 */
63 typedef struct hrdlnk {
64 char *name; /* name of first file seen with this ino/dev */
65 dev_t dev; /* files device number */
66 ino_t ino; /* files inode number */
67 u_long nlink; /* expected link count */
68 struct hrdlnk *fow;
69 } HRDLNK;
70
71 /*
72 * Archive write update file time table (the -u, -C flag), hashed by filename.
73 * Filenames are stored in a scratch file at seek offset into the file. The
74 * file time (mod time) and the file name length (for a quick check) are
75 * stored in a hash table node. We were forced to use a scratch file because
76 * with -u, the mtime for every node in the archive must always be available
77 * to compare against (and this data can get REALLY large with big archives).
78 * By being careful to read only when we have a good chance of a match, the
79 * performance loss is not measurable (and the size of the archive we can
80 * handle is greatly increased).
81 */
82 typedef struct ftm {
83 int namelen; /* file name length */
84 time_t mtime; /* files last modification time */
85 off_t seek; /* location in scratch file */
86 struct ftm *fow;
87 } FTM;
88
89 /*
90 * Interactive rename table (-i flag), hashed by orig filename.
91 * We assume this will not be a large table as this mapping data can only be
92 * obtained through interactive input by the user. Nobody is going to type in
93 * changes for 500000 files? We use chaining to resolve collisions.
94 */
95
96 typedef struct namt {
97 char *oname; /* old name */
98 char *nname; /* new name typed in by the user */
99 struct namt *fow;
100 } NAMT;
101
102 /*
103 * Unique device mapping tables. Some protocols (e.g. cpio) require that the
104 * <c_dev,c_ino> pair will uniquely identify a file in an archive unless they
105 * are links to the same file. Appending to archives can break this. For those
106 * protocols that have this requirement we map c_dev to a unique value not seen
107 * in the archive when we append. We also try to handle inode truncation with
108 * this table. (When the inode field in the archive header are too small, we
109 * remap the dev on writes to remove accidental collisions).
110 *
111 * The list is hashed by device number using chain collision resolution. Off of
112 * each DEVT are linked the various remaps for this device based on those bits
113 * in the inode which were truncated. For example if we are just remapping to
114 * avoid a device number during an update append, off the DEVT we would have
115 * only a single DLIST that has a truncation id of 0 (no inode bits were
116 * stripped for this device so far). When we spot inode truncation we create
117 * a new mapping based on the set of bits in the inode which were stripped off.
118 * so if the top four bits of the inode are stripped and they have a pattern of
119 * 0110...... (where . are those bits not truncated) we would have a mapping
120 * assigned for all inodes that has the same 0110.... pattern (with this dev
121 * number of course). This keeps the mapping sparse and should be able to store
122 * close to the limit of files which can be represented by the optimal
123 * combination of dev and inode bits, and without creating a fouled up archive.
124 * Note we also remap truncated devs in the same way (an exercise for the
125 * dedicated reader; always wanted to say that...:)
126 */
127
128 typedef struct devt {
129 dev_t dev; /* the orig device number we now have to map */
130 struct devt *fow; /* new device map list */
131 struct dlist *list; /* map list based on inode truncation bits */
132 } DEVT;
133
134 typedef struct dlist {
135 ino_t trunc_bits; /* truncation pattern for a specific map */
136 dev_t dev; /* the new device id we use */
137 struct dlist *fow;
138 } DLIST;
139
140 /*
141 * ftree directory access time reset table. When we are done with a
142 * subtree we reset the access and mod time of the directory when the tflag is
143 * set. Not really explicitly specified in the pax spec, but easy and fast to
144 * do (and this may have even been intended in the spec, it is not clear).
145 * table is hashed by inode with chaining.
146 */
147
148 typedef struct atdir {
149 char *name; /* name of directory to reset */
150 dev_t dev; /* dev and inode for fast lookup */
151 ino_t ino;
152 time_t mtime; /* access and mod time to reset to */
153 time_t atime;
154 struct atdir *fow;
155 } ATDIR;
156
157 /*
158 * created directory time and mode storage entry. After pax is finished during
159 * extraction or copy, we must reset directory access modes and times that
160 * may have been modified after creation (they no longer have the specified
161 * times and/or modes). We must reset time in the reverse order of creation,
162 * because entries are added from the top of the file tree to the bottom.
163 * We MUST reset times from leaf to root (it will not work the other
164 * direction).
165 */
166
167 typedef struct dirdata {
168 char *name; /* file name */
169 time_t mtime; /* mtime to set */
170 time_t atime; /* atime to set */
171 u_int16_t mode; /* file mode to restore */
172 u_int16_t frc_mode; /* do we force mode settings? */
173 } DIRDATA;
174
175 #endif /* _TABLES_H_ */