msdosfs_vnops.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: msdosfs_vnops.c,v 1.1.2.2 2002/12/29 19:56:06 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 <sys/cdefs.h>
51 1.1.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.1.2.2 2002/12/29 19:56:06 thorpej Exp $");
52 1.1.2.2 thorpej
53 1.1.2.2 thorpej #include <sys/param.h>
54 1.1.2.2 thorpej #include <sys/systm.h>
55 1.1.2.2 thorpej #include <sys/namei.h>
56 1.1.2.2 thorpej #include <sys/resourcevar.h> /* defines plimit structure in proc struct */
57 1.1.2.2 thorpej #include <sys/kernel.h>
58 1.1.2.2 thorpej #include <sys/file.h> /* define FWRITE ... */
59 1.1.2.2 thorpej #include <sys/stat.h>
60 1.1.2.2 thorpej #include <sys/buf.h>
61 1.1.2.2 thorpej #include <sys/proc.h>
62 1.1.2.2 thorpej #include <sys/mount.h>
63 1.1.2.2 thorpej #include <sys/vnode.h>
64 1.1.2.2 thorpej #include <sys/signalvar.h>
65 1.1.2.2 thorpej #include <sys/malloc.h>
66 1.1.2.2 thorpej #include <sys/dirent.h>
67 1.1.2.2 thorpej #include <sys/lockf.h>
68 1.1.2.2 thorpej
69 1.1.2.2 thorpej #include <miscfs/genfs/genfs.h>
70 1.1.2.2 thorpej #include <miscfs/specfs/specdev.h> /* XXX */ /* defines v_rdev */
71 1.1.2.2 thorpej
72 1.1.2.2 thorpej #include <uvm/uvm_extern.h>
73 1.1.2.2 thorpej
74 1.1.2.2 thorpej #include <fs/msdosfs/bpb.h>
75 1.1.2.2 thorpej #include <fs/msdosfs/direntry.h>
76 1.1.2.2 thorpej #include <fs/msdosfs/denode.h>
77 1.1.2.2 thorpej #include <fs/msdosfs/msdosfsmount.h>
78 1.1.2.2 thorpej #include <fs/msdosfs/fat.h>
79 1.1.2.2 thorpej
80 1.1.2.2 thorpej /*
81 1.1.2.2 thorpej * Some general notes:
82 1.1.2.2 thorpej *
83 1.1.2.2 thorpej * In the ufs filesystem the inodes, superblocks, and indirect blocks are
84 1.1.2.2 thorpej * read/written using the vnode for the filesystem. Blocks that represent
85 1.1.2.2 thorpej * the contents of a file are read/written using the vnode for the file
86 1.1.2.2 thorpej * (including directories when they are read/written as files). This
87 1.1.2.2 thorpej * presents problems for the dos filesystem because data that should be in
88 1.1.2.2 thorpej * an inode (if dos had them) resides in the directory itself. Since we
89 1.1.2.2 thorpej * must update directory entries without the benefit of having the vnode
90 1.1.2.2 thorpej * for the directory we must use the vnode for the filesystem. This means
91 1.1.2.2 thorpej * that when a directory is actually read/written (via read, write, or
92 1.1.2.2 thorpej * readdir, or seek) we must use the vnode for the filesystem instead of
93 1.1.2.2 thorpej * the vnode for the directory as would happen in ufs. This is to insure we
94 1.1.2.2 thorpej * retrieve the correct block from the buffer cache since the hash value is
95 1.1.2.2 thorpej * based upon the vnode address and the desired block number.
96 1.1.2.2 thorpej */
97 1.1.2.2 thorpej
98 1.1.2.2 thorpej /*
99 1.1.2.2 thorpej * Create a regular file. On entry the directory to contain the file being
100 1.1.2.2 thorpej * created is locked. We must release before we return. We must also free
101 1.1.2.2 thorpej * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
102 1.1.2.2 thorpej * only if the SAVESTART bit in cn_flags is clear on success.
103 1.1.2.2 thorpej */
104 1.1.2.2 thorpej int
105 1.1.2.2 thorpej msdosfs_create(v)
106 1.1.2.2 thorpej void *v;
107 1.1.2.2 thorpej {
108 1.1.2.2 thorpej struct vop_create_args /* {
109 1.1.2.2 thorpej struct vnode *a_dvp;
110 1.1.2.2 thorpej struct vnode **a_vpp;
111 1.1.2.2 thorpej struct componentname *a_cnp;
112 1.1.2.2 thorpej struct vattr *a_vap;
113 1.1.2.2 thorpej } */ *ap = v;
114 1.1.2.2 thorpej struct componentname *cnp = ap->a_cnp;
115 1.1.2.2 thorpej struct denode ndirent;
116 1.1.2.2 thorpej struct denode *dep;
117 1.1.2.2 thorpej struct denode *pdep = VTODE(ap->a_dvp);
118 1.1.2.2 thorpej int error;
119 1.1.2.2 thorpej struct timespec ts;
120 1.1.2.2 thorpej
121 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
122 1.1.2.2 thorpej printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
123 1.1.2.2 thorpej #endif
124 1.1.2.2 thorpej
125 1.1.2.2 thorpej /*
126 1.1.2.2 thorpej * If this is the root directory and there is no space left we
127 1.1.2.2 thorpej * can't do anything. This is because the root directory can not
128 1.1.2.2 thorpej * change size.
129 1.1.2.2 thorpej */
130 1.1.2.2 thorpej if (pdep->de_StartCluster == MSDOSFSROOT
131 1.1.2.2 thorpej && pdep->de_fndoffset >= pdep->de_FileSize) {
132 1.1.2.2 thorpej error = ENOSPC;
133 1.1.2.2 thorpej goto bad;
134 1.1.2.2 thorpej }
135 1.1.2.2 thorpej
136 1.1.2.2 thorpej /*
137 1.1.2.2 thorpej * Create a directory entry for the file, then call createde() to
138 1.1.2.2 thorpej * have it installed. NOTE: DOS files are always executable. We
139 1.1.2.2 thorpej * use the absence of the owner write bit to make the file
140 1.1.2.2 thorpej * readonly.
141 1.1.2.2 thorpej */
142 1.1.2.2 thorpej #ifdef DIAGNOSTIC
143 1.1.2.2 thorpej if ((cnp->cn_flags & HASBUF) == 0)
144 1.1.2.2 thorpej panic("msdosfs_create: no name");
145 1.1.2.2 thorpej #endif
146 1.1.2.2 thorpej memset(&ndirent, 0, sizeof(ndirent));
147 1.1.2.2 thorpej if ((error = uniqdosname(pdep, cnp, ndirent.de_Name)) != 0)
148 1.1.2.2 thorpej goto bad;
149 1.1.2.2 thorpej
150 1.1.2.2 thorpej ndirent.de_Attributes = (ap->a_vap->va_mode & S_IWUSR) ?
151 1.1.2.2 thorpej ATTR_ARCHIVE : ATTR_ARCHIVE | ATTR_READONLY;
152 1.1.2.2 thorpej ndirent.de_StartCluster = 0;
153 1.1.2.2 thorpej ndirent.de_FileSize = 0;
154 1.1.2.2 thorpej ndirent.de_dev = pdep->de_dev;
155 1.1.2.2 thorpej ndirent.de_devvp = pdep->de_devvp;
156 1.1.2.2 thorpej ndirent.de_pmp = pdep->de_pmp;
157 1.1.2.2 thorpej ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
158 1.1.2.2 thorpej TIMEVAL_TO_TIMESPEC(&time, &ts);
159 1.1.2.2 thorpej DETIMES(&ndirent, &ts, &ts, &ts);
160 1.1.2.2 thorpej if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
161 1.1.2.2 thorpej goto bad;
162 1.1.2.2 thorpej if ((cnp->cn_flags & SAVESTART) == 0)
163 1.1.2.2 thorpej PNBUF_PUT(cnp->cn_pnbuf);
164 1.1.2.2 thorpej VN_KNOTE(ap->a_dvp, NOTE_WRITE);
165 1.1.2.2 thorpej vput(ap->a_dvp);
166 1.1.2.2 thorpej *ap->a_vpp = DETOV(dep);
167 1.1.2.2 thorpej return (0);
168 1.1.2.2 thorpej
169 1.1.2.2 thorpej bad:
170 1.1.2.2 thorpej PNBUF_PUT(cnp->cn_pnbuf);
171 1.1.2.2 thorpej vput(ap->a_dvp);
172 1.1.2.2 thorpej return (error);
173 1.1.2.2 thorpej }
174 1.1.2.2 thorpej
175 1.1.2.2 thorpej int
176 1.1.2.2 thorpej msdosfs_mknod(v)
177 1.1.2.2 thorpej void *v;
178 1.1.2.2 thorpej {
179 1.1.2.2 thorpej struct vop_mknod_args /* {
180 1.1.2.2 thorpej struct vnode *a_dvp;
181 1.1.2.2 thorpej struct vnode **a_vpp;
182 1.1.2.2 thorpej struct componentname *a_cnp;
183 1.1.2.2 thorpej struct vattr *a_vap;
184 1.1.2.2 thorpej } */ *ap = v;
185 1.1.2.2 thorpej
186 1.1.2.2 thorpej PNBUF_PUT(ap->a_cnp->cn_pnbuf);
187 1.1.2.2 thorpej vput(ap->a_dvp);
188 1.1.2.2 thorpej return (EINVAL);
189 1.1.2.2 thorpej }
190 1.1.2.2 thorpej
191 1.1.2.2 thorpej int
192 1.1.2.2 thorpej msdosfs_open(v)
193 1.1.2.2 thorpej void *v;
194 1.1.2.2 thorpej {
195 1.1.2.2 thorpej #if 0
196 1.1.2.2 thorpej struct vop_open_args /* {
197 1.1.2.2 thorpej struct vnode *a_vp;
198 1.1.2.2 thorpej int a_mode;
199 1.1.2.2 thorpej struct ucred *a_cred;
200 1.1.2.2 thorpej struct proc *a_p;
201 1.1.2.2 thorpej } */ *ap;
202 1.1.2.2 thorpej #endif
203 1.1.2.2 thorpej
204 1.1.2.2 thorpej return (0);
205 1.1.2.2 thorpej }
206 1.1.2.2 thorpej
207 1.1.2.2 thorpej int
208 1.1.2.2 thorpej msdosfs_close(v)
209 1.1.2.2 thorpej void *v;
210 1.1.2.2 thorpej {
211 1.1.2.2 thorpej struct vop_close_args /* {
212 1.1.2.2 thorpej struct vnode *a_vp;
213 1.1.2.2 thorpej int a_fflag;
214 1.1.2.2 thorpej struct ucred *a_cred;
215 1.1.2.2 thorpej struct proc *a_p;
216 1.1.2.2 thorpej } */ *ap = v;
217 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
218 1.1.2.2 thorpej struct denode *dep = VTODE(vp);
219 1.1.2.2 thorpej struct timespec ts;
220 1.1.2.2 thorpej
221 1.1.2.2 thorpej simple_lock(&vp->v_interlock);
222 1.1.2.2 thorpej if (vp->v_usecount > 1) {
223 1.1.2.2 thorpej TIMEVAL_TO_TIMESPEC(&time, &ts);
224 1.1.2.2 thorpej DETIMES(dep, &ts, &ts, &ts);
225 1.1.2.2 thorpej }
226 1.1.2.2 thorpej simple_unlock(&vp->v_interlock);
227 1.1.2.2 thorpej return (0);
228 1.1.2.2 thorpej }
229 1.1.2.2 thorpej
230 1.1.2.2 thorpej int
231 1.1.2.2 thorpej msdosfs_access(v)
232 1.1.2.2 thorpej void *v;
233 1.1.2.2 thorpej {
234 1.1.2.2 thorpej struct vop_access_args /* {
235 1.1.2.2 thorpej struct vnode *a_vp;
236 1.1.2.2 thorpej int a_mode;
237 1.1.2.2 thorpej struct ucred *a_cred;
238 1.1.2.2 thorpej struct proc *a_p;
239 1.1.2.2 thorpej } */ *ap = v;
240 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
241 1.1.2.2 thorpej struct denode *dep = VTODE(vp);
242 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
243 1.1.2.2 thorpej mode_t mode = ap->a_mode;
244 1.1.2.2 thorpej
245 1.1.2.2 thorpej /*
246 1.1.2.2 thorpej * Disallow write attempts on read-only file systems;
247 1.1.2.2 thorpej * unless the file is a socket, fifo, or a block or
248 1.1.2.2 thorpej * character device resident on the file system.
249 1.1.2.2 thorpej */
250 1.1.2.2 thorpej if (mode & VWRITE) {
251 1.1.2.2 thorpej switch (vp->v_type) {
252 1.1.2.2 thorpej case VDIR:
253 1.1.2.2 thorpej case VLNK:
254 1.1.2.2 thorpej case VREG:
255 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
256 1.1.2.2 thorpej return (EROFS);
257 1.1.2.2 thorpej default:
258 1.1.2.2 thorpej break;
259 1.1.2.2 thorpej }
260 1.1.2.2 thorpej }
261 1.1.2.2 thorpej
262 1.1.2.2 thorpej if ((dep->de_Attributes & ATTR_READONLY) == 0)
263 1.1.2.2 thorpej mode = S_IRWXU|S_IRWXG|S_IRWXO;
264 1.1.2.2 thorpej else
265 1.1.2.2 thorpej mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
266 1.1.2.2 thorpej return (vaccess(ap->a_vp->v_type, mode & pmp->pm_mask,
267 1.1.2.2 thorpej pmp->pm_uid, pmp->pm_gid, ap->a_mode, ap->a_cred));
268 1.1.2.2 thorpej }
269 1.1.2.2 thorpej
270 1.1.2.2 thorpej int
271 1.1.2.2 thorpej msdosfs_getattr(v)
272 1.1.2.2 thorpej void *v;
273 1.1.2.2 thorpej {
274 1.1.2.2 thorpej struct vop_getattr_args /* {
275 1.1.2.2 thorpej struct vnode *a_vp;
276 1.1.2.2 thorpej struct vattr *a_vap;
277 1.1.2.2 thorpej struct ucred *a_cred;
278 1.1.2.2 thorpej struct proc *a_p;
279 1.1.2.2 thorpej } */ *ap = v;
280 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
281 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
282 1.1.2.2 thorpej struct vattr *vap = ap->a_vap;
283 1.1.2.2 thorpej mode_t mode;
284 1.1.2.2 thorpej struct timespec ts;
285 1.1.2.2 thorpej u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
286 1.1.2.2 thorpej u_long fileid;
287 1.1.2.2 thorpej
288 1.1.2.2 thorpej TIMEVAL_TO_TIMESPEC(&time, &ts);
289 1.1.2.2 thorpej DETIMES(dep, &ts, &ts, &ts);
290 1.1.2.2 thorpej vap->va_fsid = dep->de_dev;
291 1.1.2.2 thorpej /*
292 1.1.2.2 thorpej * The following computation of the fileid must be the same as that
293 1.1.2.2 thorpej * used in msdosfs_readdir() to compute d_fileno. If not, pwd
294 1.1.2.2 thorpej * doesn't work.
295 1.1.2.2 thorpej */
296 1.1.2.2 thorpej if (dep->de_Attributes & ATTR_DIRECTORY) {
297 1.1.2.2 thorpej fileid = cntobn(pmp, dep->de_StartCluster) * dirsperblk;
298 1.1.2.2 thorpej if (dep->de_StartCluster == MSDOSFSROOT)
299 1.1.2.2 thorpej fileid = 1;
300 1.1.2.2 thorpej } else {
301 1.1.2.2 thorpej fileid = cntobn(pmp, dep->de_dirclust) * dirsperblk;
302 1.1.2.2 thorpej if (dep->de_dirclust == MSDOSFSROOT)
303 1.1.2.2 thorpej fileid = roottobn(pmp, 0) * dirsperblk;
304 1.1.2.2 thorpej fileid += dep->de_diroffset / sizeof(struct direntry);
305 1.1.2.2 thorpej }
306 1.1.2.2 thorpej vap->va_fileid = fileid;
307 1.1.2.2 thorpej if ((dep->de_Attributes & ATTR_READONLY) == 0)
308 1.1.2.2 thorpej mode = S_IRWXU|S_IRWXG|S_IRWXO;
309 1.1.2.2 thorpej else
310 1.1.2.2 thorpej mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
311 1.1.2.2 thorpej vap->va_mode = mode & pmp->pm_mask;
312 1.1.2.2 thorpej vap->va_uid = pmp->pm_uid;
313 1.1.2.2 thorpej vap->va_gid = pmp->pm_gid;
314 1.1.2.2 thorpej vap->va_nlink = 1;
315 1.1.2.2 thorpej vap->va_rdev = 0;
316 1.1.2.2 thorpej vap->va_size = ap->a_vp->v_size;
317 1.1.2.2 thorpej dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
318 1.1.2.2 thorpej if (dep->de_pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
319 1.1.2.2 thorpej dos2unixtime(dep->de_ADate, 0, 0, &vap->va_atime);
320 1.1.2.2 thorpej dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun, &vap->va_ctime);
321 1.1.2.2 thorpej } else {
322 1.1.2.2 thorpej vap->va_atime = vap->va_mtime;
323 1.1.2.2 thorpej vap->va_ctime = vap->va_mtime;
324 1.1.2.2 thorpej }
325 1.1.2.2 thorpej vap->va_flags = 0;
326 1.1.2.2 thorpej if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
327 1.1.2.2 thorpej vap->va_mode |= S_ARCH1;
328 1.1.2.2 thorpej vap->va_gen = 0;
329 1.1.2.2 thorpej vap->va_blocksize = pmp->pm_bpcluster;
330 1.1.2.2 thorpej vap->va_bytes =
331 1.1.2.2 thorpej (dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
332 1.1.2.2 thorpej vap->va_type = ap->a_vp->v_type;
333 1.1.2.2 thorpej return (0);
334 1.1.2.2 thorpej }
335 1.1.2.2 thorpej
336 1.1.2.2 thorpej int
337 1.1.2.2 thorpej msdosfs_setattr(v)
338 1.1.2.2 thorpej void *v;
339 1.1.2.2 thorpej {
340 1.1.2.2 thorpej struct vop_setattr_args /* {
341 1.1.2.2 thorpej struct vnode *a_vp;
342 1.1.2.2 thorpej struct vattr *a_vap;
343 1.1.2.2 thorpej struct ucred *a_cred;
344 1.1.2.2 thorpej struct proc *a_p;
345 1.1.2.2 thorpej } */ *ap = v;
346 1.1.2.2 thorpej int error = 0, de_changed = 0;
347 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
348 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
349 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
350 1.1.2.2 thorpej struct vattr *vap = ap->a_vap;
351 1.1.2.2 thorpej struct ucred *cred = ap->a_cred;
352 1.1.2.2 thorpej
353 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
354 1.1.2.2 thorpej printf("msdosfs_setattr(): vp %p, vap %p, cred %p, p %p\n",
355 1.1.2.2 thorpej ap->a_vp, vap, cred, ap->a_p);
356 1.1.2.2 thorpej #endif
357 1.1.2.2 thorpej /*
358 1.1.2.2 thorpej * Note we silently ignore uid or gid changes.
359 1.1.2.2 thorpej */
360 1.1.2.2 thorpej if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
361 1.1.2.2 thorpej (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
362 1.1.2.2 thorpej (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
363 1.1.2.2 thorpej (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL) ||
364 1.1.2.2 thorpej (vap->va_uid != VNOVAL && vap->va_uid != pmp->pm_uid) ||
365 1.1.2.2 thorpej (vap->va_gid != VNOVAL && vap->va_gid != pmp->pm_gid)) {
366 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
367 1.1.2.2 thorpej printf("msdosfs_setattr(): returning EINVAL\n");
368 1.1.2.2 thorpej printf(" va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
369 1.1.2.2 thorpej vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
370 1.1.2.2 thorpej printf(" va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
371 1.1.2.2 thorpej vap->va_blocksize, vap->va_rdev, (long long)vap->va_bytes, vap->va_gen);
372 1.1.2.2 thorpej #endif
373 1.1.2.2 thorpej return (EINVAL);
374 1.1.2.2 thorpej }
375 1.1.2.2 thorpej /*
376 1.1.2.2 thorpej * Silently ignore attributes modifications on directories.
377 1.1.2.2 thorpej */
378 1.1.2.2 thorpej if (ap->a_vp->v_type == VDIR)
379 1.1.2.2 thorpej return 0;
380 1.1.2.2 thorpej
381 1.1.2.2 thorpej if (vap->va_size != VNOVAL) {
382 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
383 1.1.2.2 thorpej return (EROFS);
384 1.1.2.2 thorpej error = detrunc(dep, (u_long)vap->va_size, 0, cred, ap->a_p);
385 1.1.2.2 thorpej if (error)
386 1.1.2.2 thorpej return (error);
387 1.1.2.2 thorpej de_changed = 1;
388 1.1.2.2 thorpej }
389 1.1.2.2 thorpej if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
390 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
391 1.1.2.2 thorpej return (EROFS);
392 1.1.2.2 thorpej if (cred->cr_uid != pmp->pm_uid &&
393 1.1.2.2 thorpej (error = suser(cred, &ap->a_p->p_acflag)) &&
394 1.1.2.2 thorpej ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
395 1.1.2.2 thorpej (error = VOP_ACCESS(ap->a_vp, VWRITE, cred, ap->a_p))))
396 1.1.2.2 thorpej return (error);
397 1.1.2.2 thorpej if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
398 1.1.2.2 thorpej vap->va_atime.tv_sec != VNOVAL)
399 1.1.2.2 thorpej unix2dostime(&vap->va_atime, &dep->de_ADate, NULL, NULL);
400 1.1.2.2 thorpej if (vap->va_mtime.tv_sec != VNOVAL)
401 1.1.2.2 thorpej unix2dostime(&vap->va_mtime, &dep->de_MDate, &dep->de_MTime, NULL);
402 1.1.2.2 thorpej dep->de_Attributes |= ATTR_ARCHIVE;
403 1.1.2.2 thorpej dep->de_flag |= DE_MODIFIED;
404 1.1.2.2 thorpej de_changed = 1;
405 1.1.2.2 thorpej }
406 1.1.2.2 thorpej /*
407 1.1.2.2 thorpej * DOS files only have the ability to have their writability
408 1.1.2.2 thorpej * attribute set, so we use the owner write bit to set the readonly
409 1.1.2.2 thorpej * attribute.
410 1.1.2.2 thorpej */
411 1.1.2.2 thorpej if (vap->va_mode != (mode_t)VNOVAL) {
412 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
413 1.1.2.2 thorpej return (EROFS);
414 1.1.2.2 thorpej if (cred->cr_uid != pmp->pm_uid &&
415 1.1.2.2 thorpej (error = suser(cred, &ap->a_p->p_acflag)))
416 1.1.2.2 thorpej return (error);
417 1.1.2.2 thorpej /* We ignore the read and execute bits. */
418 1.1.2.2 thorpej if (vap->va_mode & S_IWUSR)
419 1.1.2.2 thorpej dep->de_Attributes &= ~ATTR_READONLY;
420 1.1.2.2 thorpej else
421 1.1.2.2 thorpej dep->de_Attributes |= ATTR_READONLY;
422 1.1.2.2 thorpej dep->de_flag |= DE_MODIFIED;
423 1.1.2.2 thorpej de_changed = 1;
424 1.1.2.2 thorpej }
425 1.1.2.2 thorpej /*
426 1.1.2.2 thorpej * Allow the `archived' bit to be toggled.
427 1.1.2.2 thorpej */
428 1.1.2.2 thorpej if (vap->va_flags != VNOVAL) {
429 1.1.2.2 thorpej if (vp->v_mount->mnt_flag & MNT_RDONLY)
430 1.1.2.2 thorpej return (EROFS);
431 1.1.2.2 thorpej if (cred->cr_uid != pmp->pm_uid &&
432 1.1.2.2 thorpej (error = suser(cred, &ap->a_p->p_acflag)))
433 1.1.2.2 thorpej return (error);
434 1.1.2.2 thorpej if (vap->va_flags & SF_ARCHIVED)
435 1.1.2.2 thorpej dep->de_Attributes &= ~ATTR_ARCHIVE;
436 1.1.2.2 thorpej else
437 1.1.2.2 thorpej dep->de_Attributes |= ATTR_ARCHIVE;
438 1.1.2.2 thorpej dep->de_flag |= DE_MODIFIED;
439 1.1.2.2 thorpej de_changed = 1;
440 1.1.2.2 thorpej }
441 1.1.2.2 thorpej
442 1.1.2.2 thorpej if (de_changed) {
443 1.1.2.2 thorpej VN_KNOTE(vp, NOTE_ATTRIB);
444 1.1.2.2 thorpej return (deupdat(dep, 1));
445 1.1.2.2 thorpej } else
446 1.1.2.2 thorpej return (0);
447 1.1.2.2 thorpej }
448 1.1.2.2 thorpej
449 1.1.2.2 thorpej int
450 1.1.2.2 thorpej msdosfs_read(v)
451 1.1.2.2 thorpej void *v;
452 1.1.2.2 thorpej {
453 1.1.2.2 thorpej struct vop_read_args /* {
454 1.1.2.2 thorpej struct vnode *a_vp;
455 1.1.2.2 thorpej struct uio *a_uio;
456 1.1.2.2 thorpej int a_ioflag;
457 1.1.2.2 thorpej struct ucred *a_cred;
458 1.1.2.2 thorpej } */ *ap = v;
459 1.1.2.2 thorpej int error = 0;
460 1.1.2.2 thorpej int64_t diff;
461 1.1.2.2 thorpej int blsize;
462 1.1.2.2 thorpej long n;
463 1.1.2.2 thorpej long on;
464 1.1.2.2 thorpej daddr_t lbn;
465 1.1.2.2 thorpej void *win;
466 1.1.2.2 thorpej vsize_t bytelen;
467 1.1.2.2 thorpej struct buf *bp;
468 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
469 1.1.2.2 thorpej struct denode *dep = VTODE(vp);
470 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
471 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
472 1.1.2.2 thorpej
473 1.1.2.2 thorpej /*
474 1.1.2.2 thorpej * If they didn't ask for any data, then we are done.
475 1.1.2.2 thorpej */
476 1.1.2.2 thorpej
477 1.1.2.2 thorpej if (uio->uio_resid == 0)
478 1.1.2.2 thorpej return (0);
479 1.1.2.2 thorpej if (uio->uio_offset < 0)
480 1.1.2.2 thorpej return (EINVAL);
481 1.1.2.2 thorpej if (uio->uio_offset >= dep->de_FileSize)
482 1.1.2.2 thorpej return (0);
483 1.1.2.2 thorpej
484 1.1.2.2 thorpej if (vp->v_type == VREG) {
485 1.1.2.2 thorpej while (uio->uio_resid > 0) {
486 1.1.2.2 thorpej bytelen = MIN(dep->de_FileSize - uio->uio_offset,
487 1.1.2.2 thorpej uio->uio_resid);
488 1.1.2.2 thorpej
489 1.1.2.2 thorpej if (bytelen == 0)
490 1.1.2.2 thorpej break;
491 1.1.2.2 thorpej win = ubc_alloc(&vp->v_uobj, uio->uio_offset,
492 1.1.2.2 thorpej &bytelen, UBC_READ);
493 1.1.2.2 thorpej error = uiomove(win, bytelen, uio);
494 1.1.2.2 thorpej ubc_release(win, 0);
495 1.1.2.2 thorpej if (error)
496 1.1.2.2 thorpej break;
497 1.1.2.2 thorpej }
498 1.1.2.2 thorpej dep->de_flag |= DE_ACCESS;
499 1.1.2.2 thorpej goto out;
500 1.1.2.2 thorpej }
501 1.1.2.2 thorpej
502 1.1.2.2 thorpej /* this loop is only for directories now */
503 1.1.2.2 thorpej do {
504 1.1.2.2 thorpej lbn = de_cluster(pmp, uio->uio_offset);
505 1.1.2.2 thorpej on = uio->uio_offset & pmp->pm_crbomask;
506 1.1.2.2 thorpej n = MIN(pmp->pm_bpcluster - on, uio->uio_resid);
507 1.1.2.2 thorpej if (uio->uio_offset >= dep->de_FileSize)
508 1.1.2.2 thorpej return (0);
509 1.1.2.2 thorpej /* file size (and hence diff) may be up to 4GB */
510 1.1.2.2 thorpej diff = dep->de_FileSize - uio->uio_offset;
511 1.1.2.2 thorpej if (diff < n)
512 1.1.2.2 thorpej n = (long) diff;
513 1.1.2.2 thorpej
514 1.1.2.2 thorpej /* convert cluster # to block # */
515 1.1.2.2 thorpej error = pcbmap(dep, lbn, &lbn, 0, &blsize);
516 1.1.2.2 thorpej if (error)
517 1.1.2.2 thorpej return (error);
518 1.1.2.2 thorpej
519 1.1.2.2 thorpej /*
520 1.1.2.2 thorpej * If we are operating on a directory file then be sure to
521 1.1.2.2 thorpej * do i/o with the vnode for the filesystem instead of the
522 1.1.2.2 thorpej * vnode for the directory.
523 1.1.2.2 thorpej */
524 1.1.2.2 thorpej error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
525 1.1.2.2 thorpej n = MIN(n, pmp->pm_bpcluster - bp->b_resid);
526 1.1.2.2 thorpej if (error) {
527 1.1.2.2 thorpej brelse(bp);
528 1.1.2.2 thorpej return (error);
529 1.1.2.2 thorpej }
530 1.1.2.2 thorpej error = uiomove(bp->b_data + on, (int) n, uio);
531 1.1.2.2 thorpej brelse(bp);
532 1.1.2.2 thorpej } while (error == 0 && uio->uio_resid > 0 && n != 0);
533 1.1.2.2 thorpej
534 1.1.2.2 thorpej out:
535 1.1.2.2 thorpej if ((ap->a_ioflag & IO_SYNC) == IO_SYNC)
536 1.1.2.2 thorpej error = deupdat(dep, 1);
537 1.1.2.2 thorpej return (error);
538 1.1.2.2 thorpej }
539 1.1.2.2 thorpej
540 1.1.2.2 thorpej /*
541 1.1.2.2 thorpej * Write data to a file or directory.
542 1.1.2.2 thorpej */
543 1.1.2.2 thorpej int
544 1.1.2.2 thorpej msdosfs_write(v)
545 1.1.2.2 thorpej void *v;
546 1.1.2.2 thorpej {
547 1.1.2.2 thorpej struct vop_write_args /* {
548 1.1.2.2 thorpej struct vnode *a_vp;
549 1.1.2.2 thorpej struct uio *a_uio;
550 1.1.2.2 thorpej int a_ioflag;
551 1.1.2.2 thorpej struct ucred *a_cred;
552 1.1.2.2 thorpej } */ *ap = v;
553 1.1.2.2 thorpej int resid;
554 1.1.2.2 thorpej u_long osize;
555 1.1.2.2 thorpej int error = 0;
556 1.1.2.2 thorpej u_long count;
557 1.1.2.2 thorpej int ioflag = ap->a_ioflag;
558 1.1.2.2 thorpej void *win;
559 1.1.2.2 thorpej vsize_t bytelen;
560 1.1.2.2 thorpej off_t oldoff;
561 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
562 1.1.2.2 thorpej struct proc *p = uio->uio_procp;
563 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
564 1.1.2.2 thorpej struct denode *dep = VTODE(vp);
565 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
566 1.1.2.2 thorpej struct ucred *cred = ap->a_cred;
567 1.1.2.2 thorpej boolean_t async;
568 1.1.2.2 thorpej int extended=0;
569 1.1.2.2 thorpej
570 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
571 1.1.2.2 thorpej printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
572 1.1.2.2 thorpej vp, uio, ioflag, cred);
573 1.1.2.2 thorpej printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
574 1.1.2.2 thorpej dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
575 1.1.2.2 thorpej #endif
576 1.1.2.2 thorpej
577 1.1.2.2 thorpej switch (vp->v_type) {
578 1.1.2.2 thorpej case VREG:
579 1.1.2.2 thorpej if (ioflag & IO_APPEND)
580 1.1.2.2 thorpej uio->uio_offset = dep->de_FileSize;
581 1.1.2.2 thorpej break;
582 1.1.2.2 thorpej case VDIR:
583 1.1.2.2 thorpej return EISDIR;
584 1.1.2.2 thorpej default:
585 1.1.2.2 thorpej panic("msdosfs_write(): bad file type");
586 1.1.2.2 thorpej }
587 1.1.2.2 thorpej
588 1.1.2.2 thorpej if (uio->uio_offset < 0)
589 1.1.2.2 thorpej return (EINVAL);
590 1.1.2.2 thorpej
591 1.1.2.2 thorpej if (uio->uio_resid == 0)
592 1.1.2.2 thorpej return (0);
593 1.1.2.2 thorpej
594 1.1.2.2 thorpej /*
595 1.1.2.2 thorpej * If they've exceeded their filesize limit, tell them about it.
596 1.1.2.2 thorpej */
597 1.1.2.2 thorpej if (p &&
598 1.1.2.2 thorpej ((uio->uio_offset + uio->uio_resid) >
599 1.1.2.2 thorpej p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
600 1.1.2.2 thorpej psignal(p, SIGXFSZ);
601 1.1.2.2 thorpej return (EFBIG);
602 1.1.2.2 thorpej }
603 1.1.2.2 thorpej
604 1.1.2.2 thorpej /*
605 1.1.2.2 thorpej * If the offset we are starting the write at is beyond the end of
606 1.1.2.2 thorpej * the file, then they've done a seek. Unix filesystems allow
607 1.1.2.2 thorpej * files with holes in them, DOS doesn't so we must fill the hole
608 1.1.2.2 thorpej * with zeroed blocks.
609 1.1.2.2 thorpej */
610 1.1.2.2 thorpej if (uio->uio_offset > dep->de_FileSize) {
611 1.1.2.2 thorpej if ((error = deextend(dep, uio->uio_offset, cred)) != 0)
612 1.1.2.2 thorpej return (error);
613 1.1.2.2 thorpej }
614 1.1.2.2 thorpej
615 1.1.2.2 thorpej /*
616 1.1.2.2 thorpej * Remember some values in case the write fails.
617 1.1.2.2 thorpej */
618 1.1.2.2 thorpej async = vp->v_mount->mnt_flag & MNT_ASYNC;
619 1.1.2.2 thorpej resid = uio->uio_resid;
620 1.1.2.2 thorpej osize = dep->de_FileSize;
621 1.1.2.2 thorpej
622 1.1.2.2 thorpej /*
623 1.1.2.2 thorpej * If we write beyond the end of the file, extend it to its ultimate
624 1.1.2.2 thorpej * size ahead of the time to hopefully get a contiguous area.
625 1.1.2.2 thorpej */
626 1.1.2.2 thorpej if (uio->uio_offset + resid > osize) {
627 1.1.2.2 thorpej count = de_clcount(pmp, uio->uio_offset + resid) -
628 1.1.2.2 thorpej de_clcount(pmp, osize);
629 1.1.2.2 thorpej if ((error = extendfile(dep, count, NULL, NULL, 0)) &&
630 1.1.2.2 thorpej (error != ENOSPC || (ioflag & IO_UNIT)))
631 1.1.2.2 thorpej goto errexit;
632 1.1.2.2 thorpej }
633 1.1.2.2 thorpej
634 1.1.2.2 thorpej if (dep->de_FileSize < uio->uio_offset + resid) {
635 1.1.2.2 thorpej dep->de_FileSize = uio->uio_offset + resid;
636 1.1.2.2 thorpej uvm_vnp_setsize(vp, dep->de_FileSize);
637 1.1.2.2 thorpej extended = 1;
638 1.1.2.2 thorpej }
639 1.1.2.2 thorpej
640 1.1.2.2 thorpej do {
641 1.1.2.2 thorpej oldoff = uio->uio_offset;
642 1.1.2.2 thorpej bytelen = uio->uio_resid;
643 1.1.2.2 thorpej
644 1.1.2.2 thorpej win = ubc_alloc(&vp->v_uobj, oldoff, &bytelen, UBC_WRITE);
645 1.1.2.2 thorpej error = uiomove(win, bytelen, uio);
646 1.1.2.2 thorpej ubc_release(win, 0);
647 1.1.2.2 thorpej if (error) {
648 1.1.2.2 thorpej break;
649 1.1.2.2 thorpej }
650 1.1.2.2 thorpej
651 1.1.2.2 thorpej /*
652 1.1.2.2 thorpej * flush what we just wrote if necessary.
653 1.1.2.2 thorpej * XXXUBC simplistic async flushing.
654 1.1.2.2 thorpej */
655 1.1.2.2 thorpej
656 1.1.2.2 thorpej if (!async && oldoff >> 16 != uio->uio_offset >> 16) {
657 1.1.2.2 thorpej simple_lock(&vp->v_interlock);
658 1.1.2.2 thorpej error = VOP_PUTPAGES(vp, (oldoff >> 16) << 16,
659 1.1.2.2 thorpej (uio->uio_offset >> 16) << 16, PGO_CLEANIT);
660 1.1.2.2 thorpej }
661 1.1.2.2 thorpej } while (error == 0 && uio->uio_resid > 0);
662 1.1.2.2 thorpej if (error == 0 && ioflag & IO_SYNC) {
663 1.1.2.2 thorpej simple_lock(&vp->v_interlock);
664 1.1.2.2 thorpej error = VOP_PUTPAGES(vp, trunc_page(oldoff),
665 1.1.2.2 thorpej round_page(oldoff + bytelen), PGO_CLEANIT | PGO_SYNCIO);
666 1.1.2.2 thorpej }
667 1.1.2.2 thorpej dep->de_flag |= DE_UPDATE;
668 1.1.2.2 thorpej
669 1.1.2.2 thorpej /*
670 1.1.2.2 thorpej * If the write failed and they want us to, truncate the file back
671 1.1.2.2 thorpej * to the size it was before the write was attempted.
672 1.1.2.2 thorpej */
673 1.1.2.2 thorpej errexit:
674 1.1.2.2 thorpej if (resid > uio->uio_resid)
675 1.1.2.2 thorpej VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
676 1.1.2.2 thorpej if (error) {
677 1.1.2.2 thorpej detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
678 1.1.2.2 thorpej uio->uio_offset -= resid - uio->uio_resid;
679 1.1.2.2 thorpej uio->uio_resid = resid;
680 1.1.2.2 thorpej } else if ((ioflag & IO_SYNC) == IO_SYNC)
681 1.1.2.2 thorpej error = deupdat(dep, 1);
682 1.1.2.2 thorpej KASSERT(vp->v_size == dep->de_FileSize);
683 1.1.2.2 thorpej return (error);
684 1.1.2.2 thorpej }
685 1.1.2.2 thorpej
686 1.1.2.2 thorpej int
687 1.1.2.2 thorpej msdosfs_update(v)
688 1.1.2.2 thorpej void *v;
689 1.1.2.2 thorpej {
690 1.1.2.2 thorpej struct vop_update_args /* {
691 1.1.2.2 thorpej struct vnode *a_vp;
692 1.1.2.2 thorpej struct timespec *a_access;
693 1.1.2.2 thorpej struct timespec *a_modify;
694 1.1.2.2 thorpej int a_flags;
695 1.1.2.2 thorpej } */ *ap = v;
696 1.1.2.2 thorpej struct buf *bp;
697 1.1.2.2 thorpej struct direntry *dirp;
698 1.1.2.2 thorpej struct denode *dep;
699 1.1.2.2 thorpej int error;
700 1.1.2.2 thorpej struct timespec ts;
701 1.1.2.2 thorpej
702 1.1.2.2 thorpej if (ap->a_vp->v_mount->mnt_flag & MNT_RDONLY)
703 1.1.2.2 thorpej return (0);
704 1.1.2.2 thorpej dep = VTODE(ap->a_vp);
705 1.1.2.2 thorpej TIMEVAL_TO_TIMESPEC(&time, &ts);
706 1.1.2.2 thorpej DETIMES(dep,
707 1.1.2.2 thorpej ap->a_access ? ap->a_access : &ts,
708 1.1.2.2 thorpej ap->a_modify ? ap->a_modify : &ts, &ts);
709 1.1.2.2 thorpej if ((dep->de_flag & DE_MODIFIED) == 0)
710 1.1.2.2 thorpej return (0);
711 1.1.2.2 thorpej dep->de_flag &= ~DE_MODIFIED;
712 1.1.2.2 thorpej if (dep->de_Attributes & ATTR_DIRECTORY)
713 1.1.2.2 thorpej return (0);
714 1.1.2.2 thorpej if (dep->de_refcnt <= 0)
715 1.1.2.2 thorpej return (0);
716 1.1.2.2 thorpej error = readde(dep, &bp, &dirp);
717 1.1.2.2 thorpej if (error)
718 1.1.2.2 thorpej return (error);
719 1.1.2.2 thorpej DE_EXTERNALIZE(dirp, dep);
720 1.1.2.2 thorpej if (ap->a_flags & (UPDATE_WAIT|UPDATE_DIROP))
721 1.1.2.2 thorpej return (bwrite(bp));
722 1.1.2.2 thorpej else {
723 1.1.2.2 thorpej bdwrite(bp);
724 1.1.2.2 thorpej return (0);
725 1.1.2.2 thorpej }
726 1.1.2.2 thorpej }
727 1.1.2.2 thorpej
728 1.1.2.2 thorpej /*
729 1.1.2.2 thorpej * Flush the blocks of a file to disk.
730 1.1.2.2 thorpej *
731 1.1.2.2 thorpej * This function is worthless for vnodes that represent directories. Maybe we
732 1.1.2.2 thorpej * could just do a sync if they try an fsync on a directory file.
733 1.1.2.2 thorpej */
734 1.1.2.2 thorpej int
735 1.1.2.2 thorpej msdosfs_remove(v)
736 1.1.2.2 thorpej void *v;
737 1.1.2.2 thorpej {
738 1.1.2.2 thorpej struct vop_remove_args /* {
739 1.1.2.2 thorpej struct vnode *a_dvp;
740 1.1.2.2 thorpej struct vnode *a_vp;
741 1.1.2.2 thorpej struct componentname *a_cnp;
742 1.1.2.2 thorpej } */ *ap = v;
743 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
744 1.1.2.2 thorpej struct denode *ddep = VTODE(ap->a_dvp);
745 1.1.2.2 thorpej int error;
746 1.1.2.2 thorpej
747 1.1.2.2 thorpej if (ap->a_vp->v_type == VDIR)
748 1.1.2.2 thorpej error = EPERM;
749 1.1.2.2 thorpej else
750 1.1.2.2 thorpej error = removede(ddep, dep);
751 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
752 1.1.2.2 thorpej printf("msdosfs_remove(), dep %p, v_usecount %d\n",
753 1.1.2.2 thorpej dep, ap->a_vp->v_usecount);
754 1.1.2.2 thorpej #endif
755 1.1.2.2 thorpej VN_KNOTE(ap->a_vp, NOTE_DELETE);
756 1.1.2.2 thorpej VN_KNOTE(ap->a_dvp, NOTE_WRITE);
757 1.1.2.2 thorpej if (ddep == dep)
758 1.1.2.2 thorpej vrele(ap->a_vp);
759 1.1.2.2 thorpej else
760 1.1.2.2 thorpej vput(ap->a_vp); /* causes msdosfs_inactive() to be called
761 1.1.2.2 thorpej * via vrele() */
762 1.1.2.2 thorpej vput(ap->a_dvp);
763 1.1.2.2 thorpej return (error);
764 1.1.2.2 thorpej }
765 1.1.2.2 thorpej
766 1.1.2.2 thorpej /*
767 1.1.2.2 thorpej * DOS filesystems don't know what links are. But since we already called
768 1.1.2.2 thorpej * msdosfs_lookup() with create and lockparent, the parent is locked so we
769 1.1.2.2 thorpej * have to free it before we return the error.
770 1.1.2.2 thorpej */
771 1.1.2.2 thorpej int
772 1.1.2.2 thorpej msdosfs_link(v)
773 1.1.2.2 thorpej void *v;
774 1.1.2.2 thorpej {
775 1.1.2.2 thorpej struct vop_link_args /* {
776 1.1.2.2 thorpej struct vnode *a_dvp;
777 1.1.2.2 thorpej struct vnode *a_vp;
778 1.1.2.2 thorpej struct componentname *a_cnp;
779 1.1.2.2 thorpej } */ *ap = v;
780 1.1.2.2 thorpej
781 1.1.2.2 thorpej VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
782 1.1.2.2 thorpej vput(ap->a_dvp);
783 1.1.2.2 thorpej return (EOPNOTSUPP);
784 1.1.2.2 thorpej }
785 1.1.2.2 thorpej
786 1.1.2.2 thorpej /*
787 1.1.2.2 thorpej * Renames on files require moving the denode to a new hash queue since the
788 1.1.2.2 thorpej * denode's location is used to compute which hash queue to put the file
789 1.1.2.2 thorpej * in. Unless it is a rename in place. For example "mv a b".
790 1.1.2.2 thorpej *
791 1.1.2.2 thorpej * What follows is the basic algorithm:
792 1.1.2.2 thorpej *
793 1.1.2.2 thorpej * if (file move) {
794 1.1.2.2 thorpej * if (dest file exists) {
795 1.1.2.2 thorpej * remove dest file
796 1.1.2.2 thorpej * }
797 1.1.2.2 thorpej * if (dest and src in same directory) {
798 1.1.2.2 thorpej * rewrite name in existing directory slot
799 1.1.2.2 thorpej * } else {
800 1.1.2.2 thorpej * write new entry in dest directory
801 1.1.2.2 thorpej * update offset and dirclust in denode
802 1.1.2.2 thorpej * move denode to new hash chain
803 1.1.2.2 thorpej * clear old directory entry
804 1.1.2.2 thorpej * }
805 1.1.2.2 thorpej * } else {
806 1.1.2.2 thorpej * directory move
807 1.1.2.2 thorpej * if (dest directory exists) {
808 1.1.2.2 thorpej * if (dest is not empty) {
809 1.1.2.2 thorpej * return ENOTEMPTY
810 1.1.2.2 thorpej * }
811 1.1.2.2 thorpej * remove dest directory
812 1.1.2.2 thorpej * }
813 1.1.2.2 thorpej * if (dest and src in same directory) {
814 1.1.2.2 thorpej * rewrite name in existing entry
815 1.1.2.2 thorpej * } else {
816 1.1.2.2 thorpej * be sure dest is not a child of src directory
817 1.1.2.2 thorpej * write entry in dest directory
818 1.1.2.2 thorpej * update "." and ".." in moved directory
819 1.1.2.2 thorpej * update offset and dirclust in denode
820 1.1.2.2 thorpej * move denode to new hash chain
821 1.1.2.2 thorpej * clear old directory entry for moved directory
822 1.1.2.2 thorpej * }
823 1.1.2.2 thorpej * }
824 1.1.2.2 thorpej *
825 1.1.2.2 thorpej * On entry:
826 1.1.2.2 thorpej * source's parent directory is unlocked
827 1.1.2.2 thorpej * source file or directory is unlocked
828 1.1.2.2 thorpej * destination's parent directory is locked
829 1.1.2.2 thorpej * destination file or directory is locked if it exists
830 1.1.2.2 thorpej *
831 1.1.2.2 thorpej * On exit:
832 1.1.2.2 thorpej * all denodes should be released
833 1.1.2.2 thorpej *
834 1.1.2.2 thorpej * Notes:
835 1.1.2.2 thorpej * I'm not sure how the memory containing the pathnames pointed at by the
836 1.1.2.2 thorpej * componentname structures is freed, there may be some memory bleeding
837 1.1.2.2 thorpej * for each rename done.
838 1.1.2.2 thorpej */
839 1.1.2.2 thorpej int
840 1.1.2.2 thorpej msdosfs_rename(v)
841 1.1.2.2 thorpej void *v;
842 1.1.2.2 thorpej {
843 1.1.2.2 thorpej struct vop_rename_args /* {
844 1.1.2.2 thorpej struct vnode *a_fdvp;
845 1.1.2.2 thorpej struct vnode *a_fvp;
846 1.1.2.2 thorpej struct componentname *a_fcnp;
847 1.1.2.2 thorpej struct vnode *a_tdvp;
848 1.1.2.2 thorpej struct vnode *a_tvp;
849 1.1.2.2 thorpej struct componentname *a_tcnp;
850 1.1.2.2 thorpej } */ *ap = v;
851 1.1.2.2 thorpej struct vnode *tvp = ap->a_tvp;
852 1.1.2.2 thorpej struct vnode *tdvp = ap->a_tdvp;
853 1.1.2.2 thorpej struct vnode *fvp = ap->a_fvp;
854 1.1.2.2 thorpej struct vnode *fdvp = ap->a_fdvp;
855 1.1.2.2 thorpej struct componentname *tcnp = ap->a_tcnp;
856 1.1.2.2 thorpej struct componentname *fcnp = ap->a_fcnp;
857 1.1.2.2 thorpej struct proc *p = tcnp->cn_proc;
858 1.1.2.2 thorpej struct denode *ip, *xp, *dp, *zp;
859 1.1.2.2 thorpej u_char toname[11], oldname[11];
860 1.1.2.2 thorpej u_long from_diroffset, to_diroffset;
861 1.1.2.2 thorpej u_char to_count;
862 1.1.2.2 thorpej int doingdirectory = 0, newparent = 0;
863 1.1.2.2 thorpej int error;
864 1.1.2.2 thorpej u_long cn;
865 1.1.2.2 thorpej daddr_t bn;
866 1.1.2.2 thorpej struct msdosfsmount *pmp;
867 1.1.2.2 thorpej struct direntry *dotdotp;
868 1.1.2.2 thorpej struct buf *bp;
869 1.1.2.2 thorpej int fdvp_dorele = 0;
870 1.1.2.2 thorpej
871 1.1.2.2 thorpej pmp = VFSTOMSDOSFS(fdvp->v_mount);
872 1.1.2.2 thorpej
873 1.1.2.2 thorpej #ifdef DIAGNOSTIC
874 1.1.2.2 thorpej if ((tcnp->cn_flags & HASBUF) == 0 ||
875 1.1.2.2 thorpej (fcnp->cn_flags & HASBUF) == 0)
876 1.1.2.2 thorpej panic("msdosfs_rename: no name");
877 1.1.2.2 thorpej #endif
878 1.1.2.2 thorpej /*
879 1.1.2.2 thorpej * Check for cross-device rename.
880 1.1.2.2 thorpej */
881 1.1.2.2 thorpej if ((fvp->v_mount != tdvp->v_mount) ||
882 1.1.2.2 thorpej (tvp && (fvp->v_mount != tvp->v_mount))) {
883 1.1.2.2 thorpej error = EXDEV;
884 1.1.2.2 thorpej abortit:
885 1.1.2.2 thorpej VOP_ABORTOP(tdvp, tcnp);
886 1.1.2.2 thorpej if (tdvp == tvp)
887 1.1.2.2 thorpej vrele(tdvp);
888 1.1.2.2 thorpej else
889 1.1.2.2 thorpej vput(tdvp);
890 1.1.2.2 thorpej if (tvp)
891 1.1.2.2 thorpej vput(tvp);
892 1.1.2.2 thorpej VOP_ABORTOP(fdvp, fcnp);
893 1.1.2.2 thorpej vrele(fdvp);
894 1.1.2.2 thorpej vrele(fvp);
895 1.1.2.2 thorpej return (error);
896 1.1.2.2 thorpej }
897 1.1.2.2 thorpej
898 1.1.2.2 thorpej /*
899 1.1.2.2 thorpej * If source and dest are the same, do nothing.
900 1.1.2.2 thorpej */
901 1.1.2.2 thorpej if (tvp == fvp) {
902 1.1.2.2 thorpej error = 0;
903 1.1.2.2 thorpej goto abortit;
904 1.1.2.2 thorpej }
905 1.1.2.2 thorpej
906 1.1.2.2 thorpej /* */
907 1.1.2.2 thorpej if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
908 1.1.2.2 thorpej goto abortit;
909 1.1.2.2 thorpej dp = VTODE(fdvp);
910 1.1.2.2 thorpej ip = VTODE(fvp);
911 1.1.2.2 thorpej
912 1.1.2.2 thorpej /*
913 1.1.2.2 thorpej * Be sure we are not renaming ".", "..", or an alias of ".". This
914 1.1.2.2 thorpej * leads to a crippled directory tree. It's pretty tough to do a
915 1.1.2.2 thorpej * "ls" or "pwd" with the "." directory entry missing, and "cd .."
916 1.1.2.2 thorpej * doesn't work if the ".." entry is missing.
917 1.1.2.2 thorpej */
918 1.1.2.2 thorpej if (ip->de_Attributes & ATTR_DIRECTORY) {
919 1.1.2.2 thorpej /*
920 1.1.2.2 thorpej * Avoid ".", "..", and aliases of "." for obvious reasons.
921 1.1.2.2 thorpej */
922 1.1.2.2 thorpej if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
923 1.1.2.2 thorpej dp == ip ||
924 1.1.2.2 thorpej (fcnp->cn_flags & ISDOTDOT) ||
925 1.1.2.2 thorpej (tcnp->cn_flags & ISDOTDOT) ||
926 1.1.2.2 thorpej (ip->de_flag & DE_RENAME)) {
927 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
928 1.1.2.2 thorpej error = EINVAL;
929 1.1.2.2 thorpej goto abortit;
930 1.1.2.2 thorpej }
931 1.1.2.2 thorpej ip->de_flag |= DE_RENAME;
932 1.1.2.2 thorpej doingdirectory++;
933 1.1.2.2 thorpej }
934 1.1.2.2 thorpej VN_KNOTE(fdvp, NOTE_WRITE); /* XXXLUKEM/XXX: right place? */
935 1.1.2.2 thorpej
936 1.1.2.2 thorpej /*
937 1.1.2.2 thorpej * When the target exists, both the directory
938 1.1.2.2 thorpej * and target vnodes are returned locked.
939 1.1.2.2 thorpej */
940 1.1.2.2 thorpej dp = VTODE(tdvp);
941 1.1.2.2 thorpej xp = tvp ? VTODE(tvp) : NULL;
942 1.1.2.2 thorpej /*
943 1.1.2.2 thorpej * Remember direntry place to use for destination
944 1.1.2.2 thorpej */
945 1.1.2.2 thorpej to_diroffset = dp->de_fndoffset;
946 1.1.2.2 thorpej to_count = dp->de_fndcnt;
947 1.1.2.2 thorpej
948 1.1.2.2 thorpej /*
949 1.1.2.2 thorpej * If ".." must be changed (ie the directory gets a new
950 1.1.2.2 thorpej * parent) then the source directory must not be in the
951 1.1.2.2 thorpej * directory hierarchy above the target, as this would
952 1.1.2.2 thorpej * orphan everything below the source directory. Also
953 1.1.2.2 thorpej * the user must have write permission in the source so
954 1.1.2.2 thorpej * as to be able to change "..". We must repeat the call
955 1.1.2.2 thorpej * to namei, as the parent directory is unlocked by the
956 1.1.2.2 thorpej * call to doscheckpath().
957 1.1.2.2 thorpej */
958 1.1.2.2 thorpej error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, p);
959 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
960 1.1.2.2 thorpej if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
961 1.1.2.2 thorpej newparent = 1;
962 1.1.2.2 thorpej vrele(fdvp);
963 1.1.2.2 thorpej if (doingdirectory && newparent) {
964 1.1.2.2 thorpej if (error) /* write access check above */
965 1.1.2.2 thorpej goto bad;
966 1.1.2.2 thorpej if (xp != NULL)
967 1.1.2.2 thorpej vput(tvp);
968 1.1.2.2 thorpej /*
969 1.1.2.2 thorpej * doscheckpath() vput()'s dp,
970 1.1.2.2 thorpej * so we have to do a relookup afterwards
971 1.1.2.2 thorpej */
972 1.1.2.2 thorpej if ((error = doscheckpath(ip, dp)) != 0)
973 1.1.2.2 thorpej goto out;
974 1.1.2.2 thorpej if ((tcnp->cn_flags & SAVESTART) == 0)
975 1.1.2.2 thorpej panic("msdosfs_rename: lost to startdir");
976 1.1.2.2 thorpej if ((error = relookup(tdvp, &tvp, tcnp)) != 0)
977 1.1.2.2 thorpej goto out;
978 1.1.2.2 thorpej dp = VTODE(tdvp);
979 1.1.2.2 thorpej xp = tvp ? VTODE(tvp) : NULL;
980 1.1.2.2 thorpej }
981 1.1.2.2 thorpej
982 1.1.2.2 thorpej if (xp != NULL) {
983 1.1.2.2 thorpej /*
984 1.1.2.2 thorpej * Target must be empty if a directory and have no links
985 1.1.2.2 thorpej * to it. Also, ensure source and target are compatible
986 1.1.2.2 thorpej * (both directories, or both not directories).
987 1.1.2.2 thorpej */
988 1.1.2.2 thorpej if (xp->de_Attributes & ATTR_DIRECTORY) {
989 1.1.2.2 thorpej if (!dosdirempty(xp)) {
990 1.1.2.2 thorpej error = ENOTEMPTY;
991 1.1.2.2 thorpej goto bad;
992 1.1.2.2 thorpej }
993 1.1.2.2 thorpej if (!doingdirectory) {
994 1.1.2.2 thorpej error = ENOTDIR;
995 1.1.2.2 thorpej goto bad;
996 1.1.2.2 thorpej }
997 1.1.2.2 thorpej } else if (doingdirectory) {
998 1.1.2.2 thorpej error = EISDIR;
999 1.1.2.2 thorpej goto bad;
1000 1.1.2.2 thorpej }
1001 1.1.2.2 thorpej if ((error = removede(dp, xp)) != 0)
1002 1.1.2.2 thorpej goto bad;
1003 1.1.2.2 thorpej VN_KNOTE(tdvp, NOTE_WRITE);
1004 1.1.2.2 thorpej VN_KNOTE(tvp, NOTE_DELETE);
1005 1.1.2.2 thorpej cache_purge(tvp);
1006 1.1.2.2 thorpej vput(tvp);
1007 1.1.2.2 thorpej xp = NULL;
1008 1.1.2.2 thorpej }
1009 1.1.2.2 thorpej
1010 1.1.2.2 thorpej /*
1011 1.1.2.2 thorpej * Convert the filename in tcnp into a dos filename. We copy this
1012 1.1.2.2 thorpej * into the denode and directory entry for the destination
1013 1.1.2.2 thorpej * file/directory.
1014 1.1.2.2 thorpej */
1015 1.1.2.2 thorpej if ((error = uniqdosname(VTODE(tdvp), tcnp, toname)) != 0)
1016 1.1.2.2 thorpej goto abortit;
1017 1.1.2.2 thorpej
1018 1.1.2.2 thorpej /*
1019 1.1.2.2 thorpej * Since from wasn't locked at various places above,
1020 1.1.2.2 thorpej * have to do a relookup here.
1021 1.1.2.2 thorpej */
1022 1.1.2.2 thorpej fcnp->cn_flags &= ~MODMASK;
1023 1.1.2.2 thorpej fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1024 1.1.2.2 thorpej if ((fcnp->cn_flags & SAVESTART) == 0)
1025 1.1.2.2 thorpej panic("msdosfs_rename: lost from startdir");
1026 1.1.2.2 thorpej if (!newparent)
1027 1.1.2.2 thorpej VOP_UNLOCK(tdvp, 0);
1028 1.1.2.2 thorpej (void) relookup(fdvp, &fvp, fcnp);
1029 1.1.2.2 thorpej if (fvp == NULL) {
1030 1.1.2.2 thorpej /*
1031 1.1.2.2 thorpej * From name has disappeared.
1032 1.1.2.2 thorpej */
1033 1.1.2.2 thorpej if (doingdirectory)
1034 1.1.2.2 thorpej panic("rename: lost dir entry");
1035 1.1.2.2 thorpej vrele(ap->a_fvp);
1036 1.1.2.2 thorpej if (newparent)
1037 1.1.2.2 thorpej VOP_UNLOCK(tdvp, 0);
1038 1.1.2.2 thorpej vrele(tdvp);
1039 1.1.2.2 thorpej return 0;
1040 1.1.2.2 thorpej }
1041 1.1.2.2 thorpej fdvp_dorele = 1;
1042 1.1.2.2 thorpej xp = VTODE(fvp);
1043 1.1.2.2 thorpej zp = VTODE(fdvp);
1044 1.1.2.2 thorpej from_diroffset = zp->de_fndoffset;
1045 1.1.2.2 thorpej
1046 1.1.2.2 thorpej /*
1047 1.1.2.2 thorpej * Ensure that the directory entry still exists and has not
1048 1.1.2.2 thorpej * changed till now. If the source is a file the entry may
1049 1.1.2.2 thorpej * have been unlinked or renamed. In either case there is
1050 1.1.2.2 thorpej * no further work to be done. If the source is a directory
1051 1.1.2.2 thorpej * then it cannot have been rmdir'ed or renamed; this is
1052 1.1.2.2 thorpej * prohibited by the DE_RENAME flag.
1053 1.1.2.2 thorpej */
1054 1.1.2.2 thorpej if (xp != ip) {
1055 1.1.2.2 thorpej if (doingdirectory)
1056 1.1.2.2 thorpej panic("rename: lost dir entry");
1057 1.1.2.2 thorpej vrele(ap->a_fvp);
1058 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1059 1.1.2.2 thorpej if (newparent)
1060 1.1.2.2 thorpej VOP_UNLOCK(fdvp, 0);
1061 1.1.2.2 thorpej xp = NULL;
1062 1.1.2.2 thorpej } else {
1063 1.1.2.2 thorpej vrele(fvp);
1064 1.1.2.2 thorpej xp = NULL;
1065 1.1.2.2 thorpej
1066 1.1.2.2 thorpej /*
1067 1.1.2.2 thorpej * First write a new entry in the destination
1068 1.1.2.2 thorpej * directory and mark the entry in the source directory
1069 1.1.2.2 thorpej * as deleted. Then move the denode to the correct hash
1070 1.1.2.2 thorpej * chain for its new location in the filesystem. And, if
1071 1.1.2.2 thorpej * we moved a directory, then update its .. entry to point
1072 1.1.2.2 thorpej * to the new parent directory.
1073 1.1.2.2 thorpej */
1074 1.1.2.2 thorpej memcpy(oldname, ip->de_Name, 11);
1075 1.1.2.2 thorpej memcpy(ip->de_Name, toname, 11); /* update denode */
1076 1.1.2.2 thorpej dp->de_fndoffset = to_diroffset;
1077 1.1.2.2 thorpej dp->de_fndcnt = to_count;
1078 1.1.2.2 thorpej error = createde(ip, dp, (struct denode **)0, tcnp);
1079 1.1.2.2 thorpej if (error) {
1080 1.1.2.2 thorpej memcpy(ip->de_Name, oldname, 11);
1081 1.1.2.2 thorpej if (newparent)
1082 1.1.2.2 thorpej VOP_UNLOCK(fdvp, 0);
1083 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1084 1.1.2.2 thorpej goto bad;
1085 1.1.2.2 thorpej }
1086 1.1.2.2 thorpej ip->de_refcnt++;
1087 1.1.2.2 thorpej zp->de_fndoffset = from_diroffset;
1088 1.1.2.2 thorpej if ((error = removede(zp, ip)) != 0) {
1089 1.1.2.2 thorpej /* XXX should really panic here, fs is corrupt */
1090 1.1.2.2 thorpej if (newparent)
1091 1.1.2.2 thorpej VOP_UNLOCK(fdvp, 0);
1092 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1093 1.1.2.2 thorpej goto bad;
1094 1.1.2.2 thorpej }
1095 1.1.2.2 thorpej cache_purge(fvp);
1096 1.1.2.2 thorpej if (!doingdirectory) {
1097 1.1.2.2 thorpej error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1098 1.1.2.2 thorpej &ip->de_dirclust, 0);
1099 1.1.2.2 thorpej if (error) {
1100 1.1.2.2 thorpej /* XXX should really panic here, fs is corrupt */
1101 1.1.2.2 thorpej if (newparent)
1102 1.1.2.2 thorpej VOP_UNLOCK(fdvp, 0);
1103 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1104 1.1.2.2 thorpej goto bad;
1105 1.1.2.2 thorpej }
1106 1.1.2.2 thorpej ip->de_diroffset = to_diroffset;
1107 1.1.2.2 thorpej if (ip->de_dirclust != MSDOSFSROOT)
1108 1.1.2.2 thorpej ip->de_diroffset &= pmp->pm_crbomask;
1109 1.1.2.2 thorpej }
1110 1.1.2.2 thorpej reinsert(ip);
1111 1.1.2.2 thorpej if (newparent)
1112 1.1.2.2 thorpej VOP_UNLOCK(fdvp, 0);
1113 1.1.2.2 thorpej }
1114 1.1.2.2 thorpej
1115 1.1.2.2 thorpej /*
1116 1.1.2.2 thorpej * If we moved a directory to a new parent directory, then we must
1117 1.1.2.2 thorpej * fixup the ".." entry in the moved directory.
1118 1.1.2.2 thorpej */
1119 1.1.2.2 thorpej if (doingdirectory && newparent) {
1120 1.1.2.2 thorpej cn = ip->de_StartCluster;
1121 1.1.2.2 thorpej if (cn == MSDOSFSROOT) {
1122 1.1.2.2 thorpej /* this should never happen */
1123 1.1.2.2 thorpej panic("msdosfs_rename: updating .. in root directory?");
1124 1.1.2.2 thorpej } else
1125 1.1.2.2 thorpej bn = cntobn(pmp, cn);
1126 1.1.2.2 thorpej error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1127 1.1.2.2 thorpej NOCRED, &bp);
1128 1.1.2.2 thorpej if (error) {
1129 1.1.2.2 thorpej /* XXX should really panic here, fs is corrupt */
1130 1.1.2.2 thorpej brelse(bp);
1131 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1132 1.1.2.2 thorpej goto bad;
1133 1.1.2.2 thorpej }
1134 1.1.2.2 thorpej dotdotp = (struct direntry *)bp->b_data + 1;
1135 1.1.2.2 thorpej putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1136 1.1.2.2 thorpej if (FAT32(pmp)) {
1137 1.1.2.2 thorpej putushort(dotdotp->deHighClust,
1138 1.1.2.2 thorpej dp->de_StartCluster >> 16);
1139 1.1.2.2 thorpej }
1140 1.1.2.2 thorpej if ((error = bwrite(bp)) != 0) {
1141 1.1.2.2 thorpej /* XXX should really panic here, fs is corrupt */
1142 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1143 1.1.2.2 thorpej goto bad;
1144 1.1.2.2 thorpej }
1145 1.1.2.2 thorpej }
1146 1.1.2.2 thorpej
1147 1.1.2.2 thorpej VN_KNOTE(fvp, NOTE_RENAME);
1148 1.1.2.2 thorpej VOP_UNLOCK(fvp, 0);
1149 1.1.2.2 thorpej bad:
1150 1.1.2.2 thorpej if (xp)
1151 1.1.2.2 thorpej vput(tvp);
1152 1.1.2.2 thorpej vput(tdvp);
1153 1.1.2.2 thorpej out:
1154 1.1.2.2 thorpej ip->de_flag &= ~DE_RENAME;
1155 1.1.2.2 thorpej if (fdvp_dorele)
1156 1.1.2.2 thorpej vrele(fdvp);
1157 1.1.2.2 thorpej vrele(fvp);
1158 1.1.2.2 thorpej return (error);
1159 1.1.2.2 thorpej
1160 1.1.2.2 thorpej }
1161 1.1.2.2 thorpej
1162 1.1.2.2 thorpej struct {
1163 1.1.2.2 thorpej struct direntry dot;
1164 1.1.2.2 thorpej struct direntry dotdot;
1165 1.1.2.2 thorpej } dosdirtemplate = {
1166 1.1.2.2 thorpej { ". ", " ", /* the . entry */
1167 1.1.2.2 thorpej ATTR_DIRECTORY, /* file attribute */
1168 1.1.2.2 thorpej 0, /* reserved */
1169 1.1.2.2 thorpej 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1170 1.1.2.2 thorpej { 0, 0 }, /* access date */
1171 1.1.2.2 thorpej { 0, 0 }, /* high bits of start cluster */
1172 1.1.2.2 thorpej { 210, 4 }, { 210, 4 }, /* modify time & date */
1173 1.1.2.2 thorpej { 0, 0 }, /* startcluster */
1174 1.1.2.2 thorpej { 0, 0, 0, 0 } /* filesize */
1175 1.1.2.2 thorpej },
1176 1.1.2.2 thorpej { ".. ", " ", /* the .. entry */
1177 1.1.2.2 thorpej ATTR_DIRECTORY, /* file attribute */
1178 1.1.2.2 thorpej 0, /* reserved */
1179 1.1.2.2 thorpej 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1180 1.1.2.2 thorpej { 0, 0 }, /* access date */
1181 1.1.2.2 thorpej { 0, 0 }, /* high bits of start cluster */
1182 1.1.2.2 thorpej { 210, 4 }, { 210, 4 }, /* modify time & date */
1183 1.1.2.2 thorpej { 0, 0 }, /* startcluster */
1184 1.1.2.2 thorpej { 0, 0, 0, 0 } /* filesize */
1185 1.1.2.2 thorpej }
1186 1.1.2.2 thorpej };
1187 1.1.2.2 thorpej
1188 1.1.2.2 thorpej int
1189 1.1.2.2 thorpej msdosfs_mkdir(v)
1190 1.1.2.2 thorpej void *v;
1191 1.1.2.2 thorpej {
1192 1.1.2.2 thorpej struct vop_mkdir_args /* {
1193 1.1.2.2 thorpej struct vnode *a_dvp;
1194 1.1.2.2 thorpej struvt vnode **a_vpp;
1195 1.1.2.2 thorpej struvt componentname *a_cnp;
1196 1.1.2.2 thorpej struct vattr *a_vap;
1197 1.1.2.2 thorpej } */ *ap = v;
1198 1.1.2.2 thorpej struct componentname *cnp = ap->a_cnp;
1199 1.1.2.2 thorpej struct denode ndirent;
1200 1.1.2.2 thorpej struct denode *dep;
1201 1.1.2.2 thorpej struct denode *pdep = VTODE(ap->a_dvp);
1202 1.1.2.2 thorpej int error;
1203 1.1.2.2 thorpej int bn;
1204 1.1.2.2 thorpej u_long newcluster, pcl;
1205 1.1.2.2 thorpej struct direntry *denp;
1206 1.1.2.2 thorpej struct msdosfsmount *pmp = pdep->de_pmp;
1207 1.1.2.2 thorpej struct buf *bp;
1208 1.1.2.2 thorpej struct timespec ts;
1209 1.1.2.2 thorpej int async = pdep->de_pmp->pm_mountp->mnt_flag & MNT_ASYNC;
1210 1.1.2.2 thorpej
1211 1.1.2.2 thorpej /*
1212 1.1.2.2 thorpej * If this is the root directory and there is no space left we
1213 1.1.2.2 thorpej * can't do anything. This is because the root directory can not
1214 1.1.2.2 thorpej * change size.
1215 1.1.2.2 thorpej */
1216 1.1.2.2 thorpej if (pdep->de_StartCluster == MSDOSFSROOT
1217 1.1.2.2 thorpej && pdep->de_fndoffset >= pdep->de_FileSize) {
1218 1.1.2.2 thorpej error = ENOSPC;
1219 1.1.2.2 thorpej goto bad2;
1220 1.1.2.2 thorpej }
1221 1.1.2.2 thorpej
1222 1.1.2.2 thorpej /*
1223 1.1.2.2 thorpej * Allocate a cluster to hold the about to be created directory.
1224 1.1.2.2 thorpej */
1225 1.1.2.2 thorpej error = clusteralloc(pmp, 0, 1, &newcluster, NULL);
1226 1.1.2.2 thorpej if (error)
1227 1.1.2.2 thorpej goto bad2;
1228 1.1.2.2 thorpej
1229 1.1.2.2 thorpej memset(&ndirent, 0, sizeof(ndirent));
1230 1.1.2.2 thorpej ndirent.de_pmp = pmp;
1231 1.1.2.2 thorpej ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1232 1.1.2.2 thorpej TIMEVAL_TO_TIMESPEC(&time, &ts);
1233 1.1.2.2 thorpej DETIMES(&ndirent, &ts, &ts, &ts);
1234 1.1.2.2 thorpej
1235 1.1.2.2 thorpej /*
1236 1.1.2.2 thorpej * Now fill the cluster with the "." and ".." entries. And write
1237 1.1.2.2 thorpej * the cluster to disk. This way it is there for the parent
1238 1.1.2.2 thorpej * directory to be pointing at if there were a crash.
1239 1.1.2.2 thorpej */
1240 1.1.2.2 thorpej bn = cntobn(pmp, newcluster);
1241 1.1.2.2 thorpej /* always succeeds */
1242 1.1.2.2 thorpej bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0);
1243 1.1.2.2 thorpej memset(bp->b_data, 0, pmp->pm_bpcluster);
1244 1.1.2.2 thorpej memcpy(bp->b_data, &dosdirtemplate, sizeof dosdirtemplate);
1245 1.1.2.2 thorpej denp = (struct direntry *)bp->b_data;
1246 1.1.2.2 thorpej putushort(denp[0].deStartCluster, newcluster);
1247 1.1.2.2 thorpej putushort(denp[0].deCDate, ndirent.de_CDate);
1248 1.1.2.2 thorpej putushort(denp[0].deCTime, ndirent.de_CTime);
1249 1.1.2.2 thorpej denp[0].deCHundredth = ndirent.de_CHun;
1250 1.1.2.2 thorpej putushort(denp[0].deADate, ndirent.de_ADate);
1251 1.1.2.2 thorpej putushort(denp[0].deMDate, ndirent.de_MDate);
1252 1.1.2.2 thorpej putushort(denp[0].deMTime, ndirent.de_MTime);
1253 1.1.2.2 thorpej pcl = pdep->de_StartCluster;
1254 1.1.2.2 thorpej if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1255 1.1.2.2 thorpej pcl = 0;
1256 1.1.2.2 thorpej putushort(denp[1].deStartCluster, pcl);
1257 1.1.2.2 thorpej putushort(denp[1].deCDate, ndirent.de_CDate);
1258 1.1.2.2 thorpej putushort(denp[1].deCTime, ndirent.de_CTime);
1259 1.1.2.2 thorpej denp[1].deCHundredth = ndirent.de_CHun;
1260 1.1.2.2 thorpej putushort(denp[1].deADate, ndirent.de_ADate);
1261 1.1.2.2 thorpej putushort(denp[1].deMDate, ndirent.de_MDate);
1262 1.1.2.2 thorpej putushort(denp[1].deMTime, ndirent.de_MTime);
1263 1.1.2.2 thorpej if (FAT32(pmp)) {
1264 1.1.2.2 thorpej putushort(denp[0].deHighClust, newcluster >> 16);
1265 1.1.2.2 thorpej putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1266 1.1.2.2 thorpej }
1267 1.1.2.2 thorpej
1268 1.1.2.2 thorpej if (async)
1269 1.1.2.2 thorpej bdwrite(bp);
1270 1.1.2.2 thorpej else if ((error = bwrite(bp)) != 0)
1271 1.1.2.2 thorpej goto bad;
1272 1.1.2.2 thorpej
1273 1.1.2.2 thorpej /*
1274 1.1.2.2 thorpej * Now build up a directory entry pointing to the newly allocated
1275 1.1.2.2 thorpej * cluster. This will be written to an empty slot in the parent
1276 1.1.2.2 thorpej * directory.
1277 1.1.2.2 thorpej */
1278 1.1.2.2 thorpej #ifdef DIAGNOSTIC
1279 1.1.2.2 thorpej if ((cnp->cn_flags & HASBUF) == 0)
1280 1.1.2.2 thorpej panic("msdosfs_mkdir: no name");
1281 1.1.2.2 thorpej #endif
1282 1.1.2.2 thorpej if ((error = uniqdosname(pdep, cnp, ndirent.de_Name)) != 0)
1283 1.1.2.2 thorpej goto bad;
1284 1.1.2.2 thorpej
1285 1.1.2.2 thorpej ndirent.de_Attributes = ATTR_DIRECTORY;
1286 1.1.2.2 thorpej ndirent.de_StartCluster = newcluster;
1287 1.1.2.2 thorpej ndirent.de_FileSize = 0;
1288 1.1.2.2 thorpej ndirent.de_dev = pdep->de_dev;
1289 1.1.2.2 thorpej ndirent.de_devvp = pdep->de_devvp;
1290 1.1.2.2 thorpej if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
1291 1.1.2.2 thorpej goto bad;
1292 1.1.2.2 thorpej if ((cnp->cn_flags & SAVESTART) == 0)
1293 1.1.2.2 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1294 1.1.2.2 thorpej VN_KNOTE(ap->a_dvp, NOTE_WRITE | NOTE_LINK);
1295 1.1.2.2 thorpej vput(ap->a_dvp);
1296 1.1.2.2 thorpej *ap->a_vpp = DETOV(dep);
1297 1.1.2.2 thorpej return (0);
1298 1.1.2.2 thorpej
1299 1.1.2.2 thorpej bad:
1300 1.1.2.2 thorpej clusterfree(pmp, newcluster, NULL);
1301 1.1.2.2 thorpej bad2:
1302 1.1.2.2 thorpej PNBUF_PUT(cnp->cn_pnbuf);
1303 1.1.2.2 thorpej vput(ap->a_dvp);
1304 1.1.2.2 thorpej return (error);
1305 1.1.2.2 thorpej }
1306 1.1.2.2 thorpej
1307 1.1.2.2 thorpej int
1308 1.1.2.2 thorpej msdosfs_rmdir(v)
1309 1.1.2.2 thorpej void *v;
1310 1.1.2.2 thorpej {
1311 1.1.2.2 thorpej struct vop_rmdir_args /* {
1312 1.1.2.2 thorpej struct vnode *a_dvp;
1313 1.1.2.2 thorpej struct vnode *a_vp;
1314 1.1.2.2 thorpej struct componentname *a_cnp;
1315 1.1.2.2 thorpej } */ *ap = v;
1316 1.1.2.2 thorpej struct vnode *vp = ap->a_vp;
1317 1.1.2.2 thorpej struct vnode *dvp = ap->a_dvp;
1318 1.1.2.2 thorpej struct componentname *cnp = ap->a_cnp;
1319 1.1.2.2 thorpej struct denode *ip, *dp;
1320 1.1.2.2 thorpej int error;
1321 1.1.2.2 thorpej
1322 1.1.2.2 thorpej ip = VTODE(vp);
1323 1.1.2.2 thorpej dp = VTODE(dvp);
1324 1.1.2.2 thorpej /*
1325 1.1.2.2 thorpej * No rmdir "." please.
1326 1.1.2.2 thorpej */
1327 1.1.2.2 thorpej if (dp == ip) {
1328 1.1.2.2 thorpej vrele(dvp);
1329 1.1.2.2 thorpej vput(vp);
1330 1.1.2.2 thorpej return (EINVAL);
1331 1.1.2.2 thorpej }
1332 1.1.2.2 thorpej /*
1333 1.1.2.2 thorpej * Verify the directory is empty (and valid).
1334 1.1.2.2 thorpej * (Rmdir ".." won't be valid since
1335 1.1.2.2 thorpej * ".." will contain a reference to
1336 1.1.2.2 thorpej * the current directory and thus be
1337 1.1.2.2 thorpej * non-empty.)
1338 1.1.2.2 thorpej */
1339 1.1.2.2 thorpej error = 0;
1340 1.1.2.2 thorpej if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1341 1.1.2.2 thorpej error = ENOTEMPTY;
1342 1.1.2.2 thorpej goto out;
1343 1.1.2.2 thorpej }
1344 1.1.2.2 thorpej /*
1345 1.1.2.2 thorpej * Delete the entry from the directory. For dos filesystems this
1346 1.1.2.2 thorpej * gets rid of the directory entry on disk, the in memory copy
1347 1.1.2.2 thorpej * still exists but the de_refcnt is <= 0. This prevents it from
1348 1.1.2.2 thorpej * being found by deget(). When the vput() on dep is done we give
1349 1.1.2.2 thorpej * up access and eventually msdosfs_reclaim() will be called which
1350 1.1.2.2 thorpej * will remove it from the denode cache.
1351 1.1.2.2 thorpej */
1352 1.1.2.2 thorpej if ((error = removede(dp, ip)) != 0)
1353 1.1.2.2 thorpej goto out;
1354 1.1.2.2 thorpej /*
1355 1.1.2.2 thorpej * This is where we decrement the link count in the parent
1356 1.1.2.2 thorpej * directory. Since dos filesystems don't do this we just purge
1357 1.1.2.2 thorpej * the name cache and let go of the parent directory denode.
1358 1.1.2.2 thorpej */
1359 1.1.2.2 thorpej VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
1360 1.1.2.2 thorpej cache_purge(dvp);
1361 1.1.2.2 thorpej vput(dvp);
1362 1.1.2.2 thorpej dvp = NULL;
1363 1.1.2.2 thorpej /*
1364 1.1.2.2 thorpej * Truncate the directory that is being deleted.
1365 1.1.2.2 thorpej */
1366 1.1.2.2 thorpej error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, cnp->cn_proc);
1367 1.1.2.2 thorpej cache_purge(vp);
1368 1.1.2.2 thorpej out:
1369 1.1.2.2 thorpej VN_KNOTE(vp, NOTE_DELETE);
1370 1.1.2.2 thorpej if (dvp)
1371 1.1.2.2 thorpej vput(dvp);
1372 1.1.2.2 thorpej vput(vp);
1373 1.1.2.2 thorpej return (error);
1374 1.1.2.2 thorpej }
1375 1.1.2.2 thorpej
1376 1.1.2.2 thorpej /*
1377 1.1.2.2 thorpej * DOS filesystems don't know what symlinks are.
1378 1.1.2.2 thorpej */
1379 1.1.2.2 thorpej int
1380 1.1.2.2 thorpej msdosfs_symlink(v)
1381 1.1.2.2 thorpej void *v;
1382 1.1.2.2 thorpej {
1383 1.1.2.2 thorpej struct vop_symlink_args /* {
1384 1.1.2.2 thorpej struct vnode *a_dvp;
1385 1.1.2.2 thorpej struct vnode **a_vpp;
1386 1.1.2.2 thorpej struct componentname *a_cnp;
1387 1.1.2.2 thorpej struct vattr *a_vap;
1388 1.1.2.2 thorpej char *a_target;
1389 1.1.2.2 thorpej } */ *ap = v;
1390 1.1.2.2 thorpej
1391 1.1.2.2 thorpej VOP_ABORTOP(ap->a_dvp, ap->a_cnp);
1392 1.1.2.2 thorpej vput(ap->a_dvp);
1393 1.1.2.2 thorpej return (EOPNOTSUPP);
1394 1.1.2.2 thorpej }
1395 1.1.2.2 thorpej
1396 1.1.2.2 thorpej int
1397 1.1.2.2 thorpej msdosfs_readdir(v)
1398 1.1.2.2 thorpej void *v;
1399 1.1.2.2 thorpej {
1400 1.1.2.2 thorpej struct vop_readdir_args /* {
1401 1.1.2.2 thorpej struct vnode *a_vp;
1402 1.1.2.2 thorpej struct uio *a_uio;
1403 1.1.2.2 thorpej struct ucred *a_cred;
1404 1.1.2.2 thorpej int *a_eofflag;
1405 1.1.2.2 thorpej off_t **a_cookies;
1406 1.1.2.2 thorpej int *a_ncookies;
1407 1.1.2.2 thorpej } */ *ap = v;
1408 1.1.2.2 thorpej int error = 0;
1409 1.1.2.2 thorpej int diff;
1410 1.1.2.2 thorpej long n;
1411 1.1.2.2 thorpej int blsize;
1412 1.1.2.2 thorpej long on;
1413 1.1.2.2 thorpej long lost;
1414 1.1.2.2 thorpej long count;
1415 1.1.2.2 thorpej u_long cn;
1416 1.1.2.2 thorpej u_long fileno;
1417 1.1.2.2 thorpej u_long dirsperblk;
1418 1.1.2.2 thorpej long bias = 0;
1419 1.1.2.2 thorpej daddr_t bn, lbn;
1420 1.1.2.2 thorpej struct buf *bp;
1421 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
1422 1.1.2.2 thorpej struct msdosfsmount *pmp = dep->de_pmp;
1423 1.1.2.2 thorpej struct direntry *dentp;
1424 1.1.2.2 thorpej struct dirent dirbuf;
1425 1.1.2.2 thorpej struct uio *uio = ap->a_uio;
1426 1.1.2.2 thorpej off_t *cookies = NULL;
1427 1.1.2.2 thorpej int ncookies = 0, nc = 0;
1428 1.1.2.2 thorpej off_t offset, uio_off;
1429 1.1.2.2 thorpej int chksum = -1;
1430 1.1.2.2 thorpej
1431 1.1.2.2 thorpej #ifdef MSDOSFS_DEBUG
1432 1.1.2.2 thorpej printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1433 1.1.2.2 thorpej ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1434 1.1.2.2 thorpej #endif
1435 1.1.2.2 thorpej
1436 1.1.2.2 thorpej /*
1437 1.1.2.2 thorpej * msdosfs_readdir() won't operate properly on regular files since
1438 1.1.2.2 thorpej * it does i/o only with the filesystem vnode, and hence can
1439 1.1.2.2 thorpej * retrieve the wrong block from the buffer cache for a plain file.
1440 1.1.2.2 thorpej * So, fail attempts to readdir() on a plain file.
1441 1.1.2.2 thorpej */
1442 1.1.2.2 thorpej if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1443 1.1.2.2 thorpej return (ENOTDIR);
1444 1.1.2.2 thorpej
1445 1.1.2.2 thorpej /*
1446 1.1.2.2 thorpej * To be safe, initialize dirbuf
1447 1.1.2.2 thorpej */
1448 1.1.2.2 thorpej memset(dirbuf.d_name, 0, sizeof(dirbuf.d_name));
1449 1.1.2.2 thorpej
1450 1.1.2.2 thorpej /*
1451 1.1.2.2 thorpej * If the user buffer is smaller than the size of one dos directory
1452 1.1.2.2 thorpej * entry or the file offset is not a multiple of the size of a
1453 1.1.2.2 thorpej * directory entry, then we fail the read.
1454 1.1.2.2 thorpej */
1455 1.1.2.2 thorpej count = uio->uio_resid & ~(sizeof(struct direntry) - 1);
1456 1.1.2.2 thorpej offset = uio->uio_offset;
1457 1.1.2.2 thorpej if (count < sizeof(struct direntry) ||
1458 1.1.2.2 thorpej (offset & (sizeof(struct direntry) - 1)))
1459 1.1.2.2 thorpej return (EINVAL);
1460 1.1.2.2 thorpej lost = uio->uio_resid - count;
1461 1.1.2.2 thorpej uio->uio_resid = count;
1462 1.1.2.2 thorpej uio_off = uio->uio_offset;
1463 1.1.2.2 thorpej
1464 1.1.2.2 thorpej if (ap->a_ncookies) {
1465 1.1.2.2 thorpej nc = uio->uio_resid / 16;
1466 1.1.2.2 thorpej cookies = malloc(nc * sizeof (off_t), M_TEMP, M_WAITOK);
1467 1.1.2.2 thorpej *ap->a_cookies = cookies;
1468 1.1.2.2 thorpej }
1469 1.1.2.2 thorpej
1470 1.1.2.2 thorpej dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1471 1.1.2.2 thorpej
1472 1.1.2.2 thorpej /*
1473 1.1.2.2 thorpej * If they are reading from the root directory then, we simulate
1474 1.1.2.2 thorpej * the . and .. entries since these don't exist in the root
1475 1.1.2.2 thorpej * directory. We also set the offset bias to make up for having to
1476 1.1.2.2 thorpej * simulate these entries. By this I mean that at file offset 64 we
1477 1.1.2.2 thorpej * read the first entry in the root directory that lives on disk.
1478 1.1.2.2 thorpej */
1479 1.1.2.2 thorpej if (dep->de_StartCluster == MSDOSFSROOT
1480 1.1.2.2 thorpej || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1481 1.1.2.2 thorpej #if 0
1482 1.1.2.2 thorpej printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1483 1.1.2.2 thorpej offset);
1484 1.1.2.2 thorpej #endif
1485 1.1.2.2 thorpej bias = 2 * sizeof(struct direntry);
1486 1.1.2.2 thorpej if (offset < bias) {
1487 1.1.2.2 thorpej for (n = (int)offset / sizeof(struct direntry);
1488 1.1.2.2 thorpej n < 2; n++) {
1489 1.1.2.2 thorpej if (FAT32(pmp))
1490 1.1.2.2 thorpej dirbuf.d_fileno = cntobn(pmp,
1491 1.1.2.2 thorpej pmp->pm_rootdirblk)
1492 1.1.2.2 thorpej * dirsperblk;
1493 1.1.2.2 thorpej else
1494 1.1.2.2 thorpej dirbuf.d_fileno = 1;
1495 1.1.2.2 thorpej dirbuf.d_type = DT_DIR;
1496 1.1.2.2 thorpej switch (n) {
1497 1.1.2.2 thorpej case 0:
1498 1.1.2.2 thorpej dirbuf.d_namlen = 1;
1499 1.1.2.2 thorpej strcpy(dirbuf.d_name, ".");
1500 1.1.2.2 thorpej break;
1501 1.1.2.2 thorpej case 1:
1502 1.1.2.2 thorpej dirbuf.d_namlen = 2;
1503 1.1.2.2 thorpej strcpy(dirbuf.d_name, "..");
1504 1.1.2.2 thorpej break;
1505 1.1.2.2 thorpej }
1506 1.1.2.2 thorpej dirbuf.d_reclen = DIRENT_SIZE(&dirbuf);
1507 1.1.2.2 thorpej if (uio->uio_resid < dirbuf.d_reclen)
1508 1.1.2.2 thorpej goto out;
1509 1.1.2.2 thorpej error = uiomove((caddr_t) &dirbuf,
1510 1.1.2.2 thorpej dirbuf.d_reclen, uio);
1511 1.1.2.2 thorpej if (error)
1512 1.1.2.2 thorpej goto out;
1513 1.1.2.2 thorpej offset += sizeof(struct direntry);
1514 1.1.2.2 thorpej uio_off = offset;
1515 1.1.2.2 thorpej if (cookies) {
1516 1.1.2.2 thorpej *cookies++ = offset;
1517 1.1.2.2 thorpej ncookies++;
1518 1.1.2.2 thorpej if (ncookies >= nc)
1519 1.1.2.2 thorpej goto out;
1520 1.1.2.2 thorpej }
1521 1.1.2.2 thorpej }
1522 1.1.2.2 thorpej }
1523 1.1.2.2 thorpej }
1524 1.1.2.2 thorpej
1525 1.1.2.2 thorpej while (uio->uio_resid > 0) {
1526 1.1.2.2 thorpej lbn = de_cluster(pmp, offset - bias);
1527 1.1.2.2 thorpej on = (offset - bias) & pmp->pm_crbomask;
1528 1.1.2.2 thorpej n = MIN(pmp->pm_bpcluster - on, uio->uio_resid);
1529 1.1.2.2 thorpej diff = dep->de_FileSize - (offset - bias);
1530 1.1.2.2 thorpej if (diff <= 0)
1531 1.1.2.2 thorpej break;
1532 1.1.2.2 thorpej n = MIN(n, diff);
1533 1.1.2.2 thorpej if ((error = pcbmap(dep, lbn, &bn, &cn, &blsize)) != 0)
1534 1.1.2.2 thorpej break;
1535 1.1.2.2 thorpej error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1536 1.1.2.2 thorpej if (error) {
1537 1.1.2.2 thorpej brelse(bp);
1538 1.1.2.2 thorpej return (error);
1539 1.1.2.2 thorpej }
1540 1.1.2.2 thorpej n = MIN(n, blsize - bp->b_resid);
1541 1.1.2.2 thorpej
1542 1.1.2.2 thorpej /*
1543 1.1.2.2 thorpej * Convert from dos directory entries to fs-independent
1544 1.1.2.2 thorpej * directory entries.
1545 1.1.2.2 thorpej */
1546 1.1.2.2 thorpej for (dentp = (struct direntry *)(bp->b_data + on);
1547 1.1.2.2 thorpej (char *)dentp < bp->b_data + on + n;
1548 1.1.2.2 thorpej dentp++, offset += sizeof(struct direntry)) {
1549 1.1.2.2 thorpej #if 0
1550 1.1.2.2 thorpej
1551 1.1.2.2 thorpej printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1552 1.1.2.2 thorpej dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1553 1.1.2.2 thorpej #endif
1554 1.1.2.2 thorpej /*
1555 1.1.2.2 thorpej * If this is an unused entry, we can stop.
1556 1.1.2.2 thorpej */
1557 1.1.2.2 thorpej if (dentp->deName[0] == SLOT_EMPTY) {
1558 1.1.2.2 thorpej brelse(bp);
1559 1.1.2.2 thorpej goto out;
1560 1.1.2.2 thorpej }
1561 1.1.2.2 thorpej /*
1562 1.1.2.2 thorpej * Skip deleted entries.
1563 1.1.2.2 thorpej */
1564 1.1.2.2 thorpej if (dentp->deName[0] == SLOT_DELETED) {
1565 1.1.2.2 thorpej chksum = -1;
1566 1.1.2.2 thorpej continue;
1567 1.1.2.2 thorpej }
1568 1.1.2.2 thorpej
1569 1.1.2.2 thorpej /*
1570 1.1.2.2 thorpej * Handle Win95 long directory entries
1571 1.1.2.2 thorpej */
1572 1.1.2.2 thorpej if (dentp->deAttributes == ATTR_WIN95) {
1573 1.1.2.2 thorpej if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1574 1.1.2.2 thorpej continue;
1575 1.1.2.2 thorpej chksum = win2unixfn((struct winentry *)dentp, &dirbuf, chksum);
1576 1.1.2.2 thorpej continue;
1577 1.1.2.2 thorpej }
1578 1.1.2.2 thorpej
1579 1.1.2.2 thorpej /*
1580 1.1.2.2 thorpej * Skip volume labels
1581 1.1.2.2 thorpej */
1582 1.1.2.2 thorpej if (dentp->deAttributes & ATTR_VOLUME) {
1583 1.1.2.2 thorpej chksum = -1;
1584 1.1.2.2 thorpej continue;
1585 1.1.2.2 thorpej }
1586 1.1.2.2 thorpej /*
1587 1.1.2.2 thorpej * This computation of d_fileno must match
1588 1.1.2.2 thorpej * the computation of va_fileid in
1589 1.1.2.2 thorpej * msdosfs_getattr.
1590 1.1.2.2 thorpej */
1591 1.1.2.2 thorpej if (dentp->deAttributes & ATTR_DIRECTORY) {
1592 1.1.2.2 thorpej fileno = getushort(dentp->deStartCluster);
1593 1.1.2.2 thorpej if (FAT32(pmp))
1594 1.1.2.2 thorpej fileno |= getushort(dentp->deHighClust) << 16;
1595 1.1.2.2 thorpej /* if this is the root directory */
1596 1.1.2.2 thorpej if (fileno == MSDOSFSROOT)
1597 1.1.2.2 thorpej if (FAT32(pmp))
1598 1.1.2.2 thorpej fileno = cntobn(pmp,
1599 1.1.2.2 thorpej pmp->pm_rootdirblk)
1600 1.1.2.2 thorpej * dirsperblk;
1601 1.1.2.2 thorpej else
1602 1.1.2.2 thorpej fileno = 1;
1603 1.1.2.2 thorpej else
1604 1.1.2.2 thorpej fileno = cntobn(pmp, fileno) * dirsperblk;
1605 1.1.2.2 thorpej dirbuf.d_fileno = fileno;
1606 1.1.2.2 thorpej dirbuf.d_type = DT_DIR;
1607 1.1.2.2 thorpej } else {
1608 1.1.2.2 thorpej dirbuf.d_fileno = offset / sizeof(struct direntry);
1609 1.1.2.2 thorpej dirbuf.d_type = DT_REG;
1610 1.1.2.2 thorpej }
1611 1.1.2.2 thorpej if (chksum != winChksum(dentp->deName))
1612 1.1.2.2 thorpej dirbuf.d_namlen = dos2unixfn(dentp->deName,
1613 1.1.2.2 thorpej (u_char *)dirbuf.d_name,
1614 1.1.2.2 thorpej pmp->pm_flags & MSDOSFSMNT_SHORTNAME);
1615 1.1.2.2 thorpej else
1616 1.1.2.2 thorpej dirbuf.d_name[dirbuf.d_namlen] = 0;
1617 1.1.2.2 thorpej chksum = -1;
1618 1.1.2.2 thorpej dirbuf.d_reclen = DIRENT_SIZE(&dirbuf);
1619 1.1.2.2 thorpej if (uio->uio_resid < dirbuf.d_reclen) {
1620 1.1.2.2 thorpej brelse(bp);
1621 1.1.2.2 thorpej goto out;
1622 1.1.2.2 thorpej }
1623 1.1.2.2 thorpej error = uiomove((caddr_t) &dirbuf,
1624 1.1.2.2 thorpej dirbuf.d_reclen, uio);
1625 1.1.2.2 thorpej if (error) {
1626 1.1.2.2 thorpej brelse(bp);
1627 1.1.2.2 thorpej goto out;
1628 1.1.2.2 thorpej }
1629 1.1.2.2 thorpej uio_off = offset + sizeof(struct direntry);
1630 1.1.2.2 thorpej if (cookies) {
1631 1.1.2.2 thorpej *cookies++ = offset + sizeof(struct direntry);
1632 1.1.2.2 thorpej ncookies++;
1633 1.1.2.2 thorpej if (ncookies >= nc) {
1634 1.1.2.2 thorpej brelse(bp);
1635 1.1.2.2 thorpej goto out;
1636 1.1.2.2 thorpej }
1637 1.1.2.2 thorpej }
1638 1.1.2.2 thorpej }
1639 1.1.2.2 thorpej brelse(bp);
1640 1.1.2.2 thorpej }
1641 1.1.2.2 thorpej
1642 1.1.2.2 thorpej out:
1643 1.1.2.2 thorpej uio->uio_offset = uio_off;
1644 1.1.2.2 thorpej uio->uio_resid += lost;
1645 1.1.2.2 thorpej if (dep->de_FileSize - (offset - bias) <= 0)
1646 1.1.2.2 thorpej *ap->a_eofflag = 1;
1647 1.1.2.2 thorpej else
1648 1.1.2.2 thorpej *ap->a_eofflag = 0;
1649 1.1.2.2 thorpej
1650 1.1.2.2 thorpej if (ap->a_ncookies) {
1651 1.1.2.2 thorpej if (error) {
1652 1.1.2.2 thorpej free(*ap->a_cookies, M_TEMP);
1653 1.1.2.2 thorpej *ap->a_ncookies = 0;
1654 1.1.2.2 thorpej *ap->a_cookies = NULL;
1655 1.1.2.2 thorpej } else
1656 1.1.2.2 thorpej *ap->a_ncookies = ncookies;
1657 1.1.2.2 thorpej }
1658 1.1.2.2 thorpej return (error);
1659 1.1.2.2 thorpej }
1660 1.1.2.2 thorpej
1661 1.1.2.2 thorpej /*
1662 1.1.2.2 thorpej * DOS filesystems don't know what symlinks are.
1663 1.1.2.2 thorpej */
1664 1.1.2.2 thorpej int
1665 1.1.2.2 thorpej msdosfs_readlink(v)
1666 1.1.2.2 thorpej void *v;
1667 1.1.2.2 thorpej {
1668 1.1.2.2 thorpej #if 0
1669 1.1.2.2 thorpej struct vop_readlink_args /* {
1670 1.1.2.2 thorpej struct vnode *a_vp;
1671 1.1.2.2 thorpej struct uio *a_uio;
1672 1.1.2.2 thorpej struct ucred *a_cred;
1673 1.1.2.2 thorpej } */ *ap;
1674 1.1.2.2 thorpej #endif
1675 1.1.2.2 thorpej
1676 1.1.2.2 thorpej return (EINVAL);
1677 1.1.2.2 thorpej }
1678 1.1.2.2 thorpej
1679 1.1.2.2 thorpej /*
1680 1.1.2.2 thorpej * vp - address of vnode file the file
1681 1.1.2.2 thorpej * bn - which cluster we are interested in mapping to a filesystem block number.
1682 1.1.2.2 thorpej * vpp - returns the vnode for the block special file holding the filesystem
1683 1.1.2.2 thorpej * containing the file of interest
1684 1.1.2.2 thorpej * bnp - address of where to return the filesystem relative block number
1685 1.1.2.2 thorpej */
1686 1.1.2.2 thorpej int
1687 1.1.2.2 thorpej msdosfs_bmap(v)
1688 1.1.2.2 thorpej void *v;
1689 1.1.2.2 thorpej {
1690 1.1.2.2 thorpej struct vop_bmap_args /* {
1691 1.1.2.2 thorpej struct vnode *a_vp;
1692 1.1.2.2 thorpej daddr_t a_bn;
1693 1.1.2.2 thorpej struct vnode **a_vpp;
1694 1.1.2.2 thorpej daddr_t *a_bnp;
1695 1.1.2.2 thorpej int *a_runp;
1696 1.1.2.2 thorpej } */ *ap = v;
1697 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
1698 1.1.2.2 thorpej
1699 1.1.2.2 thorpej if (ap->a_vpp != NULL)
1700 1.1.2.2 thorpej *ap->a_vpp = dep->de_devvp;
1701 1.1.2.2 thorpej if (ap->a_bnp == NULL)
1702 1.1.2.2 thorpej return (0);
1703 1.1.2.2 thorpej if (ap->a_runp) {
1704 1.1.2.2 thorpej /*
1705 1.1.2.2 thorpej * Sequential clusters should be counted here.
1706 1.1.2.2 thorpej */
1707 1.1.2.2 thorpej *ap->a_runp = 0;
1708 1.1.2.2 thorpej }
1709 1.1.2.2 thorpej return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
1710 1.1.2.2 thorpej }
1711 1.1.2.2 thorpej
1712 1.1.2.2 thorpej int
1713 1.1.2.2 thorpej msdosfs_reallocblks(v)
1714 1.1.2.2 thorpej void *v;
1715 1.1.2.2 thorpej {
1716 1.1.2.2 thorpej #if 0
1717 1.1.2.2 thorpej struct vop_reallocblks_args /* {
1718 1.1.2.2 thorpej struct vnode *a_vp;
1719 1.1.2.2 thorpej struct cluster_save *a_buflist;
1720 1.1.2.2 thorpej } */ *ap = v;
1721 1.1.2.2 thorpej #endif
1722 1.1.2.2 thorpej
1723 1.1.2.2 thorpej /* Currently no support for clustering */ /* XXX */
1724 1.1.2.2 thorpej return (ENOSPC);
1725 1.1.2.2 thorpej }
1726 1.1.2.2 thorpej
1727 1.1.2.2 thorpej int
1728 1.1.2.2 thorpej msdosfs_strategy(v)
1729 1.1.2.2 thorpej void *v;
1730 1.1.2.2 thorpej {
1731 1.1.2.2 thorpej struct vop_strategy_args /* {
1732 1.1.2.2 thorpej struct buf *a_bp;
1733 1.1.2.2 thorpej } */ *ap = v;
1734 1.1.2.2 thorpej struct buf *bp = ap->a_bp;
1735 1.1.2.2 thorpej struct denode *dep = VTODE(bp->b_vp);
1736 1.1.2.2 thorpej struct vnode *vp;
1737 1.1.2.2 thorpej int error = 0;
1738 1.1.2.2 thorpej
1739 1.1.2.2 thorpej if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
1740 1.1.2.2 thorpej panic("msdosfs_strategy: spec");
1741 1.1.2.2 thorpej /*
1742 1.1.2.2 thorpej * If we don't already know the filesystem relative block number
1743 1.1.2.2 thorpej * then get it using pcbmap(). If pcbmap() returns the block
1744 1.1.2.2 thorpej * number as -1 then we've got a hole in the file. DOS filesystems
1745 1.1.2.2 thorpej * don't allow files with holes, so we shouldn't ever see this.
1746 1.1.2.2 thorpej */
1747 1.1.2.2 thorpej if (bp->b_blkno == bp->b_lblkno) {
1748 1.1.2.2 thorpej error = pcbmap(dep, de_bn2cn(dep->de_pmp, bp->b_lblkno),
1749 1.1.2.2 thorpej &bp->b_blkno, 0, 0);
1750 1.1.2.2 thorpej if (error)
1751 1.1.2.2 thorpej bp->b_blkno = -1;
1752 1.1.2.2 thorpej if (bp->b_blkno == -1)
1753 1.1.2.2 thorpej clrbuf(bp);
1754 1.1.2.2 thorpej }
1755 1.1.2.2 thorpej if (bp->b_blkno == -1) {
1756 1.1.2.2 thorpej biodone(bp);
1757 1.1.2.2 thorpej return (error);
1758 1.1.2.2 thorpej }
1759 1.1.2.2 thorpej
1760 1.1.2.2 thorpej /*
1761 1.1.2.2 thorpej * Read/write the block from/to the disk that contains the desired
1762 1.1.2.2 thorpej * file block.
1763 1.1.2.2 thorpej */
1764 1.1.2.2 thorpej
1765 1.1.2.2 thorpej vp = dep->de_devvp;
1766 1.1.2.2 thorpej bp->b_dev = vp->v_rdev;
1767 1.1.2.2 thorpej VOCALL(vp->v_op, VOFFSET(vop_strategy), ap);
1768 1.1.2.2 thorpej return (0);
1769 1.1.2.2 thorpej }
1770 1.1.2.2 thorpej
1771 1.1.2.2 thorpej int
1772 1.1.2.2 thorpej msdosfs_print(v)
1773 1.1.2.2 thorpej void *v;
1774 1.1.2.2 thorpej {
1775 1.1.2.2 thorpej struct vop_print_args /* {
1776 1.1.2.2 thorpej struct vnode *vp;
1777 1.1.2.2 thorpej } */ *ap = v;
1778 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
1779 1.1.2.2 thorpej
1780 1.1.2.2 thorpej printf(
1781 1.1.2.2 thorpej "tag VT_MSDOSFS, startcluster %ld, dircluster %ld, diroffset %ld ",
1782 1.1.2.2 thorpej dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1783 1.1.2.2 thorpej printf(" dev %d, %d ", major(dep->de_dev), minor(dep->de_dev));
1784 1.1.2.2 thorpej lockmgr_printinfo(&ap->a_vp->v_lock);
1785 1.1.2.2 thorpej printf("\n");
1786 1.1.2.2 thorpej return (0);
1787 1.1.2.2 thorpej }
1788 1.1.2.2 thorpej
1789 1.1.2.2 thorpej int
1790 1.1.2.2 thorpej msdosfs_advlock(v)
1791 1.1.2.2 thorpej void *v;
1792 1.1.2.2 thorpej {
1793 1.1.2.2 thorpej struct vop_advlock_args /* {
1794 1.1.2.2 thorpej struct vnode *a_vp;
1795 1.1.2.2 thorpej caddr_t a_id;
1796 1.1.2.2 thorpej int a_op;
1797 1.1.2.2 thorpej struct flock *a_fl;
1798 1.1.2.2 thorpej int a_flags;
1799 1.1.2.2 thorpej } */ *ap = v;
1800 1.1.2.2 thorpej struct denode *dep = VTODE(ap->a_vp);
1801 1.1.2.2 thorpej
1802 1.1.2.2 thorpej return lf_advlock(ap, &dep->de_lockf, dep->de_FileSize);
1803 1.1.2.2 thorpej }
1804 1.1.2.2 thorpej
1805 1.1.2.2 thorpej int
1806 1.1.2.2 thorpej msdosfs_pathconf(v)
1807 1.1.2.2 thorpej void *v;
1808 1.1.2.2 thorpej {
1809 1.1.2.2 thorpej struct vop_pathconf_args /* {
1810 1.1.2.2 thorpej struct vnode *a_vp;
1811 1.1.2.2 thorpej int a_name;
1812 1.1.2.2 thorpej register_t *a_retval;
1813 1.1.2.2 thorpej } */ *ap = v;
1814 1.1.2.2 thorpej struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1815 1.1.2.2 thorpej
1816 1.1.2.2 thorpej switch (ap->a_name) {
1817 1.1.2.2 thorpej case _PC_LINK_MAX:
1818 1.1.2.2 thorpej *ap->a_retval = 1;
1819 1.1.2.2 thorpej return (0);
1820 1.1.2.2 thorpej case _PC_NAME_MAX:
1821 1.1.2.2 thorpej *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1822 1.1.2.2 thorpej return (0);
1823 1.1.2.2 thorpej case _PC_PATH_MAX:
1824 1.1.2.2 thorpej *ap->a_retval = PATH_MAX;
1825 1.1.2.2 thorpej return (0);
1826 1.1.2.2 thorpej case _PC_CHOWN_RESTRICTED:
1827 1.1.2.2 thorpej *ap->a_retval = 1;
1828 1.1.2.2 thorpej return (0);
1829 1.1.2.2 thorpej case _PC_NO_TRUNC:
1830 1.1.2.2 thorpej *ap->a_retval = 0;
1831 1.1.2.2 thorpej return (0);
1832 1.1.2.2 thorpej case _PC_SYNC_IO:
1833 1.1.2.2 thorpej *ap->a_retval = 1;
1834 1.1.2.2 thorpej return (0);
1835 1.1.2.2 thorpej case _PC_FILESIZEBITS:
1836 1.1.2.2 thorpej *ap->a_retval = 32;
1837 1.1.2.2 thorpej return (0);
1838 1.1.2.2 thorpej default:
1839 1.1.2.2 thorpej return (EINVAL);
1840 1.1.2.2 thorpej }
1841 1.1.2.2 thorpej /* NOTREACHED */
1842 1.1.2.2 thorpej }
1843 1.1.2.2 thorpej
1844 1.1.2.2 thorpej /* Global vfs data structures for msdosfs */
1845 1.1.2.2 thorpej int (**msdosfs_vnodeop_p) __P((void *));
1846 1.1.2.2 thorpej const struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1847 1.1.2.2 thorpej { &vop_default_desc, vn_default_error },
1848 1.1.2.2 thorpej { &vop_lookup_desc, msdosfs_lookup }, /* lookup */
1849 1.1.2.2 thorpej { &vop_create_desc, msdosfs_create }, /* create */
1850 1.1.2.2 thorpej { &vop_mknod_desc, msdosfs_mknod }, /* mknod */
1851 1.1.2.2 thorpej { &vop_open_desc, msdosfs_open }, /* open */
1852 1.1.2.2 thorpej { &vop_close_desc, msdosfs_close }, /* close */
1853 1.1.2.2 thorpej { &vop_access_desc, msdosfs_access }, /* access */
1854 1.1.2.2 thorpej { &vop_getattr_desc, msdosfs_getattr }, /* getattr */
1855 1.1.2.2 thorpej { &vop_setattr_desc, msdosfs_setattr }, /* setattr */
1856 1.1.2.2 thorpej { &vop_read_desc, msdosfs_read }, /* read */
1857 1.1.2.2 thorpej { &vop_write_desc, msdosfs_write }, /* write */
1858 1.1.2.2 thorpej { &vop_lease_desc, msdosfs_lease_check }, /* lease */
1859 1.1.2.2 thorpej { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
1860 1.1.2.2 thorpej { &vop_ioctl_desc, msdosfs_ioctl }, /* ioctl */
1861 1.1.2.2 thorpej { &vop_poll_desc, msdosfs_poll }, /* poll */
1862 1.1.2.2 thorpej { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
1863 1.1.2.2 thorpej { &vop_revoke_desc, msdosfs_revoke }, /* revoke */
1864 1.1.2.2 thorpej { &vop_mmap_desc, msdosfs_mmap }, /* mmap */
1865 1.1.2.2 thorpej { &vop_fsync_desc, msdosfs_fsync }, /* fsync */
1866 1.1.2.2 thorpej { &vop_seek_desc, msdosfs_seek }, /* seek */
1867 1.1.2.2 thorpej { &vop_remove_desc, msdosfs_remove }, /* remove */
1868 1.1.2.2 thorpej { &vop_link_desc, msdosfs_link }, /* link */
1869 1.1.2.2 thorpej { &vop_rename_desc, msdosfs_rename }, /* rename */
1870 1.1.2.2 thorpej { &vop_mkdir_desc, msdosfs_mkdir }, /* mkdir */
1871 1.1.2.2 thorpej { &vop_rmdir_desc, msdosfs_rmdir }, /* rmdir */
1872 1.1.2.2 thorpej { &vop_symlink_desc, msdosfs_symlink }, /* symlink */
1873 1.1.2.2 thorpej { &vop_readdir_desc, msdosfs_readdir }, /* readdir */
1874 1.1.2.2 thorpej { &vop_readlink_desc, msdosfs_readlink }, /* readlink */
1875 1.1.2.2 thorpej { &vop_abortop_desc, msdosfs_abortop }, /* abortop */
1876 1.1.2.2 thorpej { &vop_inactive_desc, msdosfs_inactive }, /* inactive */
1877 1.1.2.2 thorpej { &vop_reclaim_desc, msdosfs_reclaim }, /* reclaim */
1878 1.1.2.2 thorpej { &vop_lock_desc, genfs_lock }, /* lock */
1879 1.1.2.2 thorpej { &vop_unlock_desc, genfs_unlock }, /* unlock */
1880 1.1.2.2 thorpej { &vop_bmap_desc, msdosfs_bmap }, /* bmap */
1881 1.1.2.2 thorpej { &vop_strategy_desc, msdosfs_strategy }, /* strategy */
1882 1.1.2.2 thorpej { &vop_print_desc, msdosfs_print }, /* print */
1883 1.1.2.2 thorpej { &vop_islocked_desc, genfs_islocked }, /* islocked */
1884 1.1.2.2 thorpej { &vop_pathconf_desc, msdosfs_pathconf }, /* pathconf */
1885 1.1.2.2 thorpej { &vop_advlock_desc, msdosfs_advlock }, /* advlock */
1886 1.1.2.2 thorpej { &vop_reallocblks_desc, msdosfs_reallocblks }, /* reallocblks */
1887 1.1.2.2 thorpej { &vop_update_desc, msdosfs_update }, /* update */
1888 1.1.2.2 thorpej { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1889 1.1.2.2 thorpej { &vop_getpages_desc, genfs_getpages }, /* getpages */
1890 1.1.2.2 thorpej { &vop_putpages_desc, genfs_putpages }, /* putpages */
1891 1.1.2.2 thorpej { NULL, NULL }
1892 1.1.2.2 thorpej };
1893 1.1.2.2 thorpej const struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1894 1.1.2.2 thorpej { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1895