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