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