denode.h revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: denode.h,v 1.1.2.2 2002/12/29 19:55:57 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
5 1.1.2.2 thorpej * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
6 1.1.2.2 thorpej * All rights reserved.
7 1.1.2.2 thorpej * Original code by Paul Popelka (paulp (at) uts.amdahl.com) (see below).
8 1.1.2.2 thorpej *
9 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
11 1.1.2.2 thorpej * are met:
12 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
17 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 thorpej * must display the following acknowledgement:
19 1.1.2.2 thorpej * This product includes software developed by TooLs GmbH.
20 1.1.2.2 thorpej * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 1.1.2.2 thorpej * derived from this software without specific prior written permission.
22 1.1.2.2 thorpej *
23 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 1.1.2.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1.2.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1.2.2 thorpej * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 1.1.2.2 thorpej * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 1.1.2.2 thorpej * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 1.1.2.2 thorpej * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 1.1.2.2 thorpej * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 1.1.2.2 thorpej * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 1.1.2.2 thorpej * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1.2.2 thorpej */
34 1.1.2.2 thorpej /*
35 1.1.2.2 thorpej * Written by Paul Popelka (paulp (at) uts.amdahl.com)
36 1.1.2.2 thorpej *
37 1.1.2.2 thorpej * You can do anything you want with this software, just don't say you wrote
38 1.1.2.2 thorpej * it, and don't remove this notice.
39 1.1.2.2 thorpej *
40 1.1.2.2 thorpej * This software is provided "as is".
41 1.1.2.2 thorpej *
42 1.1.2.2 thorpej * The author supplies this software to be publicly redistributed on the
43 1.1.2.2 thorpej * understanding that the author is not responsible for the correct
44 1.1.2.2 thorpej * functioning of this software in any circumstances and is not liable for
45 1.1.2.2 thorpej * any damages caused by this software.
46 1.1.2.2 thorpej *
47 1.1.2.2 thorpej * October 1992
48 1.1.2.2 thorpej */
49 1.1.2.2 thorpej
50 1.1.2.2 thorpej #include <miscfs/genfs/genfs_node.h>
51 1.1.2.2 thorpej
52 1.1.2.2 thorpej /*
53 1.1.2.2 thorpej * This is the pc filesystem specific portion of the vnode structure.
54 1.1.2.2 thorpej *
55 1.1.2.2 thorpej * To describe a file uniquely the de_dirclust, de_diroffset, and
56 1.1.2.2 thorpej * de_StartCluster fields are used.
57 1.1.2.2 thorpej *
58 1.1.2.2 thorpej * de_dirclust contains the cluster number of the directory cluster
59 1.1.2.2 thorpej * containing the entry for a file or directory.
60 1.1.2.2 thorpej * de_diroffset is the index into the cluster for the entry describing
61 1.1.2.2 thorpej * a file or directory.
62 1.1.2.2 thorpej * de_StartCluster is the number of the first cluster of the file or directory.
63 1.1.2.2 thorpej *
64 1.1.2.2 thorpej * Now to describe the quirks of the pc filesystem.
65 1.1.2.2 thorpej * - Clusters 0 and 1 are reserved.
66 1.1.2.2 thorpej * - The first allocatable cluster is 2.
67 1.1.2.2 thorpej * - The root directory is of fixed size and all blocks that make it up
68 1.1.2.2 thorpej * are contiguous.
69 1.1.2.2 thorpej * - Cluster 0 refers to the root directory when it is found in the
70 1.1.2.2 thorpej * startcluster field of a directory entry that points to another directory.
71 1.1.2.2 thorpej * - Cluster 0 implies a 0 length file when found in the start cluster field
72 1.1.2.2 thorpej * of a directory entry that points to a file.
73 1.1.2.2 thorpej * - You can't use the cluster number 0 to derive the address of the root
74 1.1.2.2 thorpej * directory.
75 1.1.2.2 thorpej * - Multiple directory entries can point to a directory. The entry in the
76 1.1.2.2 thorpej * parent directory points to a child directory. Any directories in the
77 1.1.2.2 thorpej * child directory contain a ".." entry that points back to the parent.
78 1.1.2.2 thorpej * The child directory itself contains a "." entry that points to itself.
79 1.1.2.2 thorpej * - The root directory does not contain a "." or ".." entry.
80 1.1.2.2 thorpej * - Directory entries for directories are never changed once they are created
81 1.1.2.2 thorpej * (except when removed). The size stays 0, and the last modification time
82 1.1.2.2 thorpej * is never changed. This is because so many directory entries can point to
83 1.1.2.2 thorpej * the physical clusters that make up a directory. It would lead to an
84 1.1.2.2 thorpej * update nightmare.
85 1.1.2.2 thorpej * - The length field in a directory entry pointing to a directory contains 0
86 1.1.2.2 thorpej * (always). The only way to find the end of a directory is to follow the
87 1.1.2.2 thorpej * cluster chain until the "last cluster" marker is found.
88 1.1.2.2 thorpej *
89 1.1.2.2 thorpej * My extensions to make this house of cards work. These apply only to the in
90 1.1.2.2 thorpej * memory copy of the directory entry.
91 1.1.2.2 thorpej * - A reference count for each denode will be kept since dos doesn't keep such
92 1.1.2.2 thorpej * things.
93 1.1.2.2 thorpej */
94 1.1.2.2 thorpej
95 1.1.2.2 thorpej /*
96 1.1.2.2 thorpej * Internal pseudo-offset for (nonexistent) directory entry for the root
97 1.1.2.2 thorpej * dir in the root dir
98 1.1.2.2 thorpej */
99 1.1.2.2 thorpej #define MSDOSFSROOT_OFS 0x1fffffff
100 1.1.2.2 thorpej
101 1.1.2.2 thorpej /*
102 1.1.2.2 thorpej * The fat cache structure. fc_fsrcn is the filesystem relative cluster
103 1.1.2.2 thorpej * number that corresponds to the file relative cluster number in this
104 1.1.2.2 thorpej * structure (fc_frcn).
105 1.1.2.2 thorpej */
106 1.1.2.2 thorpej struct fatcache {
107 1.1.2.2 thorpej u_long fc_frcn; /* file relative cluster number */
108 1.1.2.2 thorpej u_long fc_fsrcn; /* filesystem relative cluster number */
109 1.1.2.2 thorpej };
110 1.1.2.2 thorpej
111 1.1.2.2 thorpej /*
112 1.1.2.2 thorpej * The fat entry cache as it stands helps make extending files a "quick"
113 1.1.2.2 thorpej * operation by avoiding having to scan the fat to discover the last
114 1.1.2.2 thorpej * cluster of the file. The cache also helps sequential reads by
115 1.1.2.2 thorpej * remembering the last cluster read from the file. This also prevents us
116 1.1.2.2 thorpej * from having to rescan the fat to find the next cluster to read. This
117 1.1.2.2 thorpej * cache is probably pretty worthless if a file is opened by multiple
118 1.1.2.2 thorpej * processes.
119 1.1.2.2 thorpej */
120 1.1.2.2 thorpej #define FC_SIZE 2 /* number of entries in the cache */
121 1.1.2.2 thorpej #define FC_LASTMAP 0 /* entry the last call to pcbmap() resolved
122 1.1.2.2 thorpej * to */
123 1.1.2.2 thorpej #define FC_LASTFC 1 /* entry for the last cluster in the file */
124 1.1.2.2 thorpej
125 1.1.2.2 thorpej #define FCE_EMPTY 0xffffffff /* doesn't represent an actual cluster # */
126 1.1.2.2 thorpej
127 1.1.2.2 thorpej /*
128 1.1.2.2 thorpej * Set a slot in the fat cache.
129 1.1.2.2 thorpej */
130 1.1.2.2 thorpej #define fc_setcache(dep, slot, frcn, fsrcn) \
131 1.1.2.2 thorpej (dep)->de_fc[slot].fc_frcn = frcn; \
132 1.1.2.2 thorpej (dep)->de_fc[slot].fc_fsrcn = fsrcn;
133 1.1.2.2 thorpej
134 1.1.2.2 thorpej /*
135 1.1.2.2 thorpej * This is the in memory variant of a dos directory entry. It is usually
136 1.1.2.2 thorpej * contained within a vnode.
137 1.1.2.2 thorpej */
138 1.1.2.2 thorpej struct denode {
139 1.1.2.2 thorpej struct genfs_node de_gnode;
140 1.1.2.2 thorpej LIST_ENTRY(denode) de_hash;
141 1.1.2.2 thorpej struct vnode *de_vnode; /* addr of vnode we are part of */
142 1.1.2.2 thorpej struct vnode *de_devvp; /* vnode of blk dev we live on */
143 1.1.2.2 thorpej u_long de_flag; /* flag bits */
144 1.1.2.2 thorpej dev_t de_dev; /* device where direntry lives */
145 1.1.2.2 thorpej u_long de_dirclust; /* cluster of the directory file containing this entry */
146 1.1.2.2 thorpej u_long de_diroffset; /* offset of this entry in the directory cluster */
147 1.1.2.2 thorpej u_long de_fndoffset; /* offset of found dir entry */
148 1.1.2.2 thorpej int de_fndcnt; /* number of slots before de_fndoffset */
149 1.1.2.2 thorpej long de_refcnt; /* reference count */
150 1.1.2.2 thorpej struct msdosfsmount *de_pmp; /* addr of our mount struct */
151 1.1.2.2 thorpej struct lockf *de_lockf; /* byte level lock list */
152 1.1.2.2 thorpej u_char de_Name[12]; /* name, from DOS directory entry */
153 1.1.2.2 thorpej u_char de_Attributes; /* attributes, from directory entry */
154 1.1.2.2 thorpej u_char de_CHun; /* Hundredth of second of CTime*/
155 1.1.2.2 thorpej u_short de_CTime; /* creation time */
156 1.1.2.2 thorpej u_short de_CDate; /* creation date */
157 1.1.2.2 thorpej u_short de_ADate; /* access date */
158 1.1.2.2 thorpej u_short de_MTime; /* modification time */
159 1.1.2.2 thorpej u_short de_MDate; /* modification date */
160 1.1.2.2 thorpej u_long de_StartCluster; /* starting cluster of file */
161 1.1.2.2 thorpej u_long de_FileSize; /* size of file in bytes */
162 1.1.2.2 thorpej struct fatcache de_fc[FC_SIZE]; /* fat cache */
163 1.1.2.2 thorpej };
164 1.1.2.2 thorpej
165 1.1.2.2 thorpej /*
166 1.1.2.2 thorpej * Values for the de_flag field of the denode.
167 1.1.2.2 thorpej */
168 1.1.2.2 thorpej #define DE_UPDATE 0x0001 /* Modification time update request. */
169 1.1.2.2 thorpej #define DE_CREATE 0x0002 /* Creation time update */
170 1.1.2.2 thorpej #define DE_ACCESS 0x0004 /* Access time update */
171 1.1.2.2 thorpej #define DE_MODIFIED 0x0008 /* Denode has been modified. */
172 1.1.2.2 thorpej #define DE_RENAME 0x0010 /* Denode is in the process of being renamed */
173 1.1.2.2 thorpej
174 1.1.2.2 thorpej /*
175 1.1.2.2 thorpej * Maximum filename length in Win95
176 1.1.2.2 thorpej * Note: Must be < sizeof(dirent.d_name)
177 1.1.2.2 thorpej */
178 1.1.2.2 thorpej #define WIN_MAXLEN 255
179 1.1.2.2 thorpej
180 1.1.2.2 thorpej /*
181 1.1.2.2 thorpej * Transfer directory entries between internal and external form.
182 1.1.2.2 thorpej * dep is a struct denode * (internal form),
183 1.1.2.2 thorpej * dp is a struct direntry * (external form).
184 1.1.2.2 thorpej */
185 1.1.2.2 thorpej #define DE_INTERNALIZE32(dep, dp) \
186 1.1.2.2 thorpej ((dep)->de_StartCluster |= getushort((dp)->deHighClust) << 16)
187 1.1.2.2 thorpej #define DE_INTERNALIZE(dep, dp) \
188 1.1.2.2 thorpej (memcpy((dep)->de_Name, (dp)->deName, 11), \
189 1.1.2.2 thorpej (dep)->de_Attributes = (dp)->deAttributes, \
190 1.1.2.2 thorpej (dep)->de_CHun = (dp)->deCHundredth, \
191 1.1.2.2 thorpej (dep)->de_CTime = getushort((dp)->deCTime), \
192 1.1.2.2 thorpej (dep)->de_CDate = getushort((dp)->deCDate), \
193 1.1.2.2 thorpej (dep)->de_ADate = getushort((dp)->deADate), \
194 1.1.2.2 thorpej (dep)->de_MTime = getushort((dp)->deMTime), \
195 1.1.2.2 thorpej (dep)->de_MDate = getushort((dp)->deMDate), \
196 1.1.2.2 thorpej (dep)->de_StartCluster = getushort((dp)->deStartCluster), \
197 1.1.2.2 thorpej (dep)->de_FileSize = getulong((dp)->deFileSize), \
198 1.1.2.2 thorpej (FAT32((dep)->de_pmp) ? DE_INTERNALIZE32((dep), (dp)) : 0))
199 1.1.2.2 thorpej
200 1.1.2.2 thorpej #define DE_EXTERNALIZE32(dp, dep) \
201 1.1.2.2 thorpej putushort((dp)->deHighClust, (dep)->de_StartCluster >> 16)
202 1.1.2.2 thorpej #define DE_EXTERNALIZE(dp, dep) \
203 1.1.2.2 thorpej (memcpy((dp)->deName, (dep)->de_Name, 11), \
204 1.1.2.2 thorpej (dp)->deAttributes = (dep)->de_Attributes, \
205 1.1.2.2 thorpej (dp)->deCHundredth = (dep)->de_CHun, \
206 1.1.2.2 thorpej putushort((dp)->deCTime, (dep)->de_CTime), \
207 1.1.2.2 thorpej putushort((dp)->deCDate, (dep)->de_CDate), \
208 1.1.2.2 thorpej putushort((dp)->deADate, (dep)->de_ADate), \
209 1.1.2.2 thorpej putushort((dp)->deMTime, (dep)->de_MTime), \
210 1.1.2.2 thorpej putushort((dp)->deMDate, (dep)->de_MDate), \
211 1.1.2.2 thorpej putushort((dp)->deStartCluster, (dep)->de_StartCluster), \
212 1.1.2.2 thorpej putulong((dp)->deFileSize, \
213 1.1.2.2 thorpej ((dep)->de_Attributes & ATTR_DIRECTORY) ? 0 : (dep)->de_FileSize), \
214 1.1.2.2 thorpej (FAT32((dep)->de_pmp) ? DE_EXTERNALIZE32((dp), (dep)) : 0))
215 1.1.2.2 thorpej
216 1.1.2.2 thorpej #define de_forw de_chain[0]
217 1.1.2.2 thorpej #define de_back de_chain[1]
218 1.1.2.2 thorpej
219 1.1.2.2 thorpej #ifdef _KERNEL
220 1.1.2.2 thorpej
221 1.1.2.2 thorpej #define VTODE(vp) ((struct denode *)(vp)->v_data)
222 1.1.2.2 thorpej #define DETOV(de) ((de)->de_vnode)
223 1.1.2.2 thorpej
224 1.1.2.2 thorpej #define DETIMES(dep, acc, mod, cre) \
225 1.1.2.2 thorpej if ((dep)->de_flag & (DE_UPDATE | DE_CREATE | DE_ACCESS)) { \
226 1.1.2.2 thorpej (dep)->de_flag |= DE_MODIFIED; \
227 1.1.2.2 thorpej if ((dep)->de_flag & DE_UPDATE) { \
228 1.1.2.2 thorpej unix2dostime((mod), &(dep)->de_MDate, &(dep)->de_MTime, NULL); \
229 1.1.2.2 thorpej (dep)->de_Attributes |= ATTR_ARCHIVE; \
230 1.1.2.2 thorpej } \
231 1.1.2.2 thorpej if (!((dep)->de_pmp->pm_flags & MSDOSFSMNT_NOWIN95)) { \
232 1.1.2.2 thorpej if ((dep)->de_flag & DE_ACCESS) \
233 1.1.2.2 thorpej unix2dostime((acc), &(dep)->de_ADate, NULL, NULL); \
234 1.1.2.2 thorpej if ((dep)->de_flag & DE_CREATE) \
235 1.1.2.2 thorpej unix2dostime((cre), &(dep)->de_CDate, &(dep)->de_CTime, &(dep)->de_CHun); \
236 1.1.2.2 thorpej } \
237 1.1.2.2 thorpej (dep)->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS); \
238 1.1.2.2 thorpej }
239 1.1.2.2 thorpej
240 1.1.2.2 thorpej /*
241 1.1.2.2 thorpej * This overlays the fid structure (see mount.h)
242 1.1.2.2 thorpej */
243 1.1.2.2 thorpej struct defid {
244 1.1.2.2 thorpej u_int16_t defid_len; /* length of structure */
245 1.1.2.2 thorpej u_int16_t defid_pad; /* force 4-byte alignment */
246 1.1.2.2 thorpej
247 1.1.2.2 thorpej u_int32_t defid_dirclust; /* cluster this dir entry came from */
248 1.1.2.2 thorpej u_int32_t defid_dirofs; /* offset of entry within the cluster */
249 1.1.2.2 thorpej #if 0
250 1.1.2.2 thorpej u_int32_t defid_gen; /* generation number */
251 1.1.2.2 thorpej #endif
252 1.1.2.2 thorpej };
253 1.1.2.2 thorpej
254 1.1.2.2 thorpej /*
255 1.1.2.2 thorpej * Prototypes for MSDOSFS vnode operations
256 1.1.2.2 thorpej */
257 1.1.2.2 thorpej int msdosfs_lookup __P((void *));
258 1.1.2.2 thorpej int msdosfs_create __P((void *));
259 1.1.2.2 thorpej int msdosfs_mknod __P((void *));
260 1.1.2.2 thorpej int msdosfs_open __P((void *));
261 1.1.2.2 thorpej int msdosfs_close __P((void *));
262 1.1.2.2 thorpej int msdosfs_access __P((void *));
263 1.1.2.2 thorpej int msdosfs_getattr __P((void *));
264 1.1.2.2 thorpej int msdosfs_setattr __P((void *));
265 1.1.2.2 thorpej int msdosfs_read __P((void *));
266 1.1.2.2 thorpej int msdosfs_write __P((void *));
267 1.1.2.2 thorpej #define msdosfs_lease_check genfs_lease_check
268 1.1.2.2 thorpej #define msdosfs_ioctl genfs_enoioctl
269 1.1.2.2 thorpej #define msdosfs_poll genfs_poll
270 1.1.2.2 thorpej #define msdosfs_revoke genfs_revoke
271 1.1.2.2 thorpej #define msdosfs_mmap genfs_mmap
272 1.1.2.2 thorpej #define msdosfs_fsync genfs_fsync
273 1.1.2.2 thorpej #define msdosfs_seek genfs_seek
274 1.1.2.2 thorpej int msdosfs_remove __P((void *));
275 1.1.2.2 thorpej int msdosfs_link __P((void *));
276 1.1.2.2 thorpej int msdosfs_rename __P((void *));
277 1.1.2.2 thorpej int msdosfs_mkdir __P((void *));
278 1.1.2.2 thorpej int msdosfs_rmdir __P((void *));
279 1.1.2.2 thorpej int msdosfs_symlink __P((void *));
280 1.1.2.2 thorpej int msdosfs_readdir __P((void *));
281 1.1.2.2 thorpej int msdosfs_readlink __P((void *));
282 1.1.2.2 thorpej #define msdosfs_abortop genfs_abortop
283 1.1.2.2 thorpej int msdosfs_inactive __P((void *));
284 1.1.2.2 thorpej int msdosfs_reclaim __P((void *));
285 1.1.2.2 thorpej int msdosfs_bmap __P((void *));
286 1.1.2.2 thorpej int msdosfs_strategy __P((void *));
287 1.1.2.2 thorpej int msdosfs_print __P((void *));
288 1.1.2.2 thorpej int msdosfs_advlock __P((void *));
289 1.1.2.2 thorpej int msdosfs_reallocblks __P((void *));
290 1.1.2.2 thorpej int msdosfs_pathconf __P((void *));
291 1.1.2.2 thorpej int msdosfs_update __P((void *));
292 1.1.2.2 thorpej
293 1.1.2.2 thorpej /*
294 1.1.2.2 thorpej * Internal service routine prototypes.
295 1.1.2.2 thorpej */
296 1.1.2.2 thorpej int createde __P((struct denode *, struct denode *, struct denode **, struct componentname *));
297 1.1.2.2 thorpej int deextend __P((struct denode *, u_long, struct ucred *));
298 1.1.2.2 thorpej int deget __P((struct msdosfsmount *, u_long, u_long, struct denode **));
299 1.1.2.2 thorpej int detrunc __P((struct denode *, u_long, int, struct ucred *, struct proc *));
300 1.1.2.2 thorpej int deupdat __P((struct denode *, int));
301 1.1.2.2 thorpej int doscheckpath __P((struct denode *, struct denode *));
302 1.1.2.2 thorpej int dosdirempty __P((struct denode *));
303 1.1.2.2 thorpej int readde __P((struct denode *, struct buf **, struct direntry **));
304 1.1.2.2 thorpej int readep __P((struct msdosfsmount *, u_long, u_long, struct buf **, struct direntry **));
305 1.1.2.2 thorpej void reinsert __P((struct denode *));
306 1.1.2.2 thorpej int removede __P((struct denode *, struct denode *));
307 1.1.2.2 thorpej int uniqdosname __P((struct denode *, struct componentname *, u_char *));
308 1.1.2.2 thorpej int findwin95 __P((struct denode *));
309 1.1.2.2 thorpej int msdosfs_gop_alloc __P((struct vnode *, off_t, off_t, int, struct ucred *));
310 1.1.2.2 thorpej #endif /* _KERNEL */
311