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