Deleted Added
full compact
denode.h (28787) denode.h (30513)
1/* $Id: denode.h,v 1.12 1997/02/26 14:23:09 bde Exp $ */
1/* $Id: denode.h,v 1.13 1997/08/26 07:32:36 phk Exp $ */
2/* $NetBSD: denode.h,v 1.8 1994/08/21 18:43:49 ws Exp $ */
3
4/*-
5 * Copyright (C) 1994 Wolfgang Solfrank.
6 * Copyright (C) 1994 TooLs GmbH.
7 * All rights reserved.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
37 *
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
40 *
41 * This software is provided "as is".
42 *
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
47 *
48 * October 1992
49 */
50
51/*
52 * This is the pc filesystem specific portion of the vnode structure.
53 *
54 * To describe a file uniquely the de_dirclust, de_diroffset, and
55 * de_StartCluster fields are used.
56 *
57 * de_dirclust contains the cluster number of the directory cluster
58 * containing the entry for a file or directory.
59 * de_diroffset is the index into the cluster for the entry describing
60 * a file or directory.
61 * de_StartCluster is the number of the first cluster of the file or directory.
62 *
63 * Now to describe the quirks of the pc filesystem.
64 * - Clusters 0 and 1 are reserved.
65 * - The first allocatable cluster is 2.
66 * - The root directory is of fixed size and all blocks that make it up
67 * are contiguous.
68 * - Cluster 0 refers to the root directory when it is found in the
69 * startcluster field of a directory entry that points to another directory.
70 * - Cluster 0 implies a 0 length file when found in the start cluster field
71 * of a directory entry that points to a file.
72 * - You can't use the cluster number 0 to derive the address of the root
73 * directory.
74 * - Multiple directory entries can point to a directory. The entry in the
75 * parent directory points to a child directory. Any directories in the
76 * child directory contain a ".." entry that points back to the parent.
77 * The child directory itself contains a "." entry that points to itself.
78 * - The root directory does not contain a "." or ".." entry.
79 * - Directory entries for directories are never changed once they are created
80 * (except when removed). The size stays 0, and the last modification time
81 * is never changed. This is because so many directory entries can point to
82 * the physical clusters that make up a directory. It would lead to an
83 * update nightmare.
84 * - The length field in a directory entry pointing to a directory contains 0
85 * (always). The only way to find the end of a directory is to follow the
86 * cluster chain until the "last cluster" marker is found.
87 *
88 * My extensions to make this house of cards work. These apply only to the in
89 * memory copy of the directory entry.
90 * - A reference count for each denode will be kept since dos doesn't keep such
91 * things.
92 */
93
94/*
95 * Internal pseudo-offset for (nonexistent) directory entry for the root
96 * dir in the root dir
97 */
98#define MSDOSFSROOT_OFS 0x1fffffff
99
100/*
101 * The fat cache structure. fc_fsrcn is the filesystem relative cluster
102 * number that corresponds to the file relative cluster number in this
103 * structure (fc_frcn).
104 */
105struct fatcache {
106 u_short fc_frcn; /* file relative cluster number */
107 u_short fc_fsrcn; /* filesystem relative cluster number */
108};
109
110/*
111 * The fat entry cache as it stands helps make extending files a "quick"
112 * operation by avoiding having to scan the fat to discover the last
113 * cluster of the file. The cache also helps sequential reads by
114 * remembering the last cluster read from the file. This also prevents us
115 * from having to rescan the fat to find the next cluster to read. This
116 * cache is probably pretty worthless if a file is opened by multiple
117 * processes.
118 */
119#define FC_SIZE 2 /* number of entries in the cache */
120#define FC_LASTMAP 0 /* entry the last call to pcbmap() resolved
121 * to */
122#define FC_LASTFC 1 /* entry for the last cluster in the file */
123
124#define FCE_EMPTY 0xffff /* doesn't represent an actual cluster # */
125
126/*
127 * Set a slot in the fat cache.
128 */
129#define fc_setcache(dep, slot, frcn, fsrcn) \
130 (dep)->de_fc[slot].fc_frcn = frcn; \
131 (dep)->de_fc[slot].fc_fsrcn = fsrcn;
132
133/*
134 * This is the in memory variant of a dos directory entry. It is usually
135 * contained within a vnode.
136 */
137struct denode {
2/* $NetBSD: denode.h,v 1.8 1994/08/21 18:43:49 ws Exp $ */
3
4/*-
5 * Copyright (C) 1994 Wolfgang Solfrank.
6 * Copyright (C) 1994 TooLs GmbH.
7 * All rights reserved.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
37 *
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
40 *
41 * This software is provided "as is".
42 *
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
47 *
48 * October 1992
49 */
50
51/*
52 * This is the pc filesystem specific portion of the vnode structure.
53 *
54 * To describe a file uniquely the de_dirclust, de_diroffset, and
55 * de_StartCluster fields are used.
56 *
57 * de_dirclust contains the cluster number of the directory cluster
58 * containing the entry for a file or directory.
59 * de_diroffset is the index into the cluster for the entry describing
60 * a file or directory.
61 * de_StartCluster is the number of the first cluster of the file or directory.
62 *
63 * Now to describe the quirks of the pc filesystem.
64 * - Clusters 0 and 1 are reserved.
65 * - The first allocatable cluster is 2.
66 * - The root directory is of fixed size and all blocks that make it up
67 * are contiguous.
68 * - Cluster 0 refers to the root directory when it is found in the
69 * startcluster field of a directory entry that points to another directory.
70 * - Cluster 0 implies a 0 length file when found in the start cluster field
71 * of a directory entry that points to a file.
72 * - You can't use the cluster number 0 to derive the address of the root
73 * directory.
74 * - Multiple directory entries can point to a directory. The entry in the
75 * parent directory points to a child directory. Any directories in the
76 * child directory contain a ".." entry that points back to the parent.
77 * The child directory itself contains a "." entry that points to itself.
78 * - The root directory does not contain a "." or ".." entry.
79 * - Directory entries for directories are never changed once they are created
80 * (except when removed). The size stays 0, and the last modification time
81 * is never changed. This is because so many directory entries can point to
82 * the physical clusters that make up a directory. It would lead to an
83 * update nightmare.
84 * - The length field in a directory entry pointing to a directory contains 0
85 * (always). The only way to find the end of a directory is to follow the
86 * cluster chain until the "last cluster" marker is found.
87 *
88 * My extensions to make this house of cards work. These apply only to the in
89 * memory copy of the directory entry.
90 * - A reference count for each denode will be kept since dos doesn't keep such
91 * things.
92 */
93
94/*
95 * Internal pseudo-offset for (nonexistent) directory entry for the root
96 * dir in the root dir
97 */
98#define MSDOSFSROOT_OFS 0x1fffffff
99
100/*
101 * The fat cache structure. fc_fsrcn is the filesystem relative cluster
102 * number that corresponds to the file relative cluster number in this
103 * structure (fc_frcn).
104 */
105struct fatcache {
106 u_short fc_frcn; /* file relative cluster number */
107 u_short fc_fsrcn; /* filesystem relative cluster number */
108};
109
110/*
111 * The fat entry cache as it stands helps make extending files a "quick"
112 * operation by avoiding having to scan the fat to discover the last
113 * cluster of the file. The cache also helps sequential reads by
114 * remembering the last cluster read from the file. This also prevents us
115 * from having to rescan the fat to find the next cluster to read. This
116 * cache is probably pretty worthless if a file is opened by multiple
117 * processes.
118 */
119#define FC_SIZE 2 /* number of entries in the cache */
120#define FC_LASTMAP 0 /* entry the last call to pcbmap() resolved
121 * to */
122#define FC_LASTFC 1 /* entry for the last cluster in the file */
123
124#define FCE_EMPTY 0xffff /* doesn't represent an actual cluster # */
125
126/*
127 * Set a slot in the fat cache.
128 */
129#define fc_setcache(dep, slot, frcn, fsrcn) \
130 (dep)->de_fc[slot].fc_frcn = frcn; \
131 (dep)->de_fc[slot].fc_fsrcn = fsrcn;
132
133/*
134 * This is the in memory variant of a dos directory entry. It is usually
135 * contained within a vnode.
136 */
137struct denode {
138 struct lock de_lock; /* denode lock >Keep this first< */
138 struct denode *de_next; /* Hash chain forward */
139 struct denode **de_prev; /* Hash chain back */
140 struct vnode *de_vnode; /* addr of vnode we are part of */
141 struct vnode *de_devvp; /* vnode of blk dev we live on */
142 u_long de_flag; /* flag bits */
143 dev_t de_dev; /* device where direntry lives */
144 u_long de_dirclust; /* cluster of the directory file containing this entry */
145 u_long de_diroffset; /* ordinal of this entry in the directory */
146 u_long de_fndclust; /* cluster of found dir entry */
147 u_long de_fndoffset; /* offset of found dir entry */
148 long de_refcnt; /* reference count */
149 struct msdosfsmount *de_pmp; /* addr of our mount struct */
150 struct lockf *de_lockf; /* byte level lock list */
139 struct denode *de_next; /* Hash chain forward */
140 struct denode **de_prev; /* Hash chain back */
141 struct vnode *de_vnode; /* addr of vnode we are part of */
142 struct vnode *de_devvp; /* vnode of blk dev we live on */
143 u_long de_flag; /* flag bits */
144 dev_t de_dev; /* device where direntry lives */
145 u_long de_dirclust; /* cluster of the directory file containing this entry */
146 u_long de_diroffset; /* ordinal of this entry in the directory */
147 u_long de_fndclust; /* cluster of found dir entry */
148 u_long de_fndoffset; /* offset of found dir entry */
149 long de_refcnt; /* reference count */
150 struct msdosfsmount *de_pmp; /* addr of our mount struct */
151 struct lockf *de_lockf; /* byte level lock list */
151 struct lock de_lock; /* denode lock */
152 /* the next two fields must be contiguous in memory... */
153 u_char de_Name[8]; /* name, from directory entry */
154 u_char de_Extension[3]; /* extension, from directory entry */
155 u_char de_Attributes; /* attributes, from directory entry */
156 u_short de_Time; /* creation time */
157 u_short de_Date; /* creation date */
158 u_short de_StartCluster; /* starting cluster of file */
159 u_long de_FileSize; /* size of file in bytes */
160 struct fatcache de_fc[FC_SIZE]; /* fat cache */
161 u_quad_t de_modrev; /* Revision level for lease. */
162};
163
164/*
165 * Values for the de_flag field of the denode.
166 */
167#define DE_UPDATE 0x0004 /* modification time update request */
168#define DE_MODIFIED 0x0080 /* denode has been modified, but DE_UPDATE
169 * isn't set */
170
171/*
172 * Transfer directory entries between internal and external form.
173 * dep is a struct denode * (internal form),
174 * dp is a struct direntry * (external form).
175 */
176#define DE_INTERNALIZE(dep, dp) \
177 (bcopy((dp)->deName, (dep)->de_Name, 11), \
178 (dep)->de_Attributes = (dp)->deAttributes, \
179 (dep)->de_Time = getushort((dp)->deTime), \
180 (dep)->de_Date = getushort((dp)->deDate), \
181 (dep)->de_StartCluster = getushort((dp)->deStartCluster), \
182 (dep)->de_FileSize = getulong((dp)->deFileSize))
183
184#define DE_EXTERNALIZE(dp, dep) \
185 (bcopy((dep)->de_Name, (dp)->deName, 11), \
186 bzero((dp)->deReserved, 10), \
187 (dp)->deAttributes = (dep)->de_Attributes, \
188 putushort((dp)->deTime, (dep)->de_Time), \
189 putushort((dp)->deDate, (dep)->de_Date), \
190 putushort((dp)->deStartCluster, (dep)->de_StartCluster), \
191 putulong((dp)->deFileSize, (dep)->de_FileSize))
192
193#define de_forw de_chain[0]
194#define de_back de_chain[1]
195
196#ifdef KERNEL
197
198#define VTODE(vp) ((struct denode *)(vp)->v_data)
199#define DETOV(de) ((de)->de_vnode)
200
201#define DE_TIMES(dep, t) \
202 if ((dep)->de_flag & DE_UPDATE) { \
203 if (!((dep)->de_Attributes & ATTR_DIRECTORY)) { \
204 struct timespec DE_TIMES_ts; \
205 (dep)->de_flag |= DE_MODIFIED; \
206 TIMEVAL_TO_TIMESPEC((t), &DE_TIMES_ts); \
207 unix2dostime(&DE_TIMES_ts, &(dep)->de_Date, \
208 &(dep)->de_Time); \
209 (dep)->de_Attributes |= ATTR_ARCHIVE; \
210 } \
211 (dep)->de_flag &= ~DE_UPDATE; \
212 }
213
214/*
215 * This overlays the fid structure (see mount.h)
216 */
217struct defid {
218 u_short defid_len; /* length of structure */
219 u_short defid_pad; /* force long alignment */
220
221 u_long defid_dirclust; /* cluster this dir entry came from */
222 u_long defid_dirofs; /* index of entry within the cluster */
223
224 /* u_long defid_gen; generation number */
225};
226
227extern vop_t **msdosfs_vnodeop_p;
228
229int msdosfs_lookup __P((struct vop_cachedlookup_args *));
230int msdosfs_inactive __P((struct vop_inactive_args *));
231int msdosfs_reclaim __P((struct vop_reclaim_args *));
232
233/*
234 * Internal service routine prototypes.
235 */
236int deget __P((struct msdosfsmount * pmp, u_long dirclust, u_long diroffset, struct direntry * direntptr, struct denode ** depp));
237#endif /* KERNEL */
152 /* the next two fields must be contiguous in memory... */
153 u_char de_Name[8]; /* name, from directory entry */
154 u_char de_Extension[3]; /* extension, from directory entry */
155 u_char de_Attributes; /* attributes, from directory entry */
156 u_short de_Time; /* creation time */
157 u_short de_Date; /* creation date */
158 u_short de_StartCluster; /* starting cluster of file */
159 u_long de_FileSize; /* size of file in bytes */
160 struct fatcache de_fc[FC_SIZE]; /* fat cache */
161 u_quad_t de_modrev; /* Revision level for lease. */
162};
163
164/*
165 * Values for the de_flag field of the denode.
166 */
167#define DE_UPDATE 0x0004 /* modification time update request */
168#define DE_MODIFIED 0x0080 /* denode has been modified, but DE_UPDATE
169 * isn't set */
170
171/*
172 * Transfer directory entries between internal and external form.
173 * dep is a struct denode * (internal form),
174 * dp is a struct direntry * (external form).
175 */
176#define DE_INTERNALIZE(dep, dp) \
177 (bcopy((dp)->deName, (dep)->de_Name, 11), \
178 (dep)->de_Attributes = (dp)->deAttributes, \
179 (dep)->de_Time = getushort((dp)->deTime), \
180 (dep)->de_Date = getushort((dp)->deDate), \
181 (dep)->de_StartCluster = getushort((dp)->deStartCluster), \
182 (dep)->de_FileSize = getulong((dp)->deFileSize))
183
184#define DE_EXTERNALIZE(dp, dep) \
185 (bcopy((dep)->de_Name, (dp)->deName, 11), \
186 bzero((dp)->deReserved, 10), \
187 (dp)->deAttributes = (dep)->de_Attributes, \
188 putushort((dp)->deTime, (dep)->de_Time), \
189 putushort((dp)->deDate, (dep)->de_Date), \
190 putushort((dp)->deStartCluster, (dep)->de_StartCluster), \
191 putulong((dp)->deFileSize, (dep)->de_FileSize))
192
193#define de_forw de_chain[0]
194#define de_back de_chain[1]
195
196#ifdef KERNEL
197
198#define VTODE(vp) ((struct denode *)(vp)->v_data)
199#define DETOV(de) ((de)->de_vnode)
200
201#define DE_TIMES(dep, t) \
202 if ((dep)->de_flag & DE_UPDATE) { \
203 if (!((dep)->de_Attributes & ATTR_DIRECTORY)) { \
204 struct timespec DE_TIMES_ts; \
205 (dep)->de_flag |= DE_MODIFIED; \
206 TIMEVAL_TO_TIMESPEC((t), &DE_TIMES_ts); \
207 unix2dostime(&DE_TIMES_ts, &(dep)->de_Date, \
208 &(dep)->de_Time); \
209 (dep)->de_Attributes |= ATTR_ARCHIVE; \
210 } \
211 (dep)->de_flag &= ~DE_UPDATE; \
212 }
213
214/*
215 * This overlays the fid structure (see mount.h)
216 */
217struct defid {
218 u_short defid_len; /* length of structure */
219 u_short defid_pad; /* force long alignment */
220
221 u_long defid_dirclust; /* cluster this dir entry came from */
222 u_long defid_dirofs; /* index of entry within the cluster */
223
224 /* u_long defid_gen; generation number */
225};
226
227extern vop_t **msdosfs_vnodeop_p;
228
229int msdosfs_lookup __P((struct vop_cachedlookup_args *));
230int msdosfs_inactive __P((struct vop_inactive_args *));
231int msdosfs_reclaim __P((struct vop_reclaim_args *));
232
233/*
234 * Internal service routine prototypes.
235 */
236int deget __P((struct msdosfsmount * pmp, u_long dirclust, u_long diroffset, struct direntry * direntptr, struct denode ** depp));
237#endif /* KERNEL */