msdosfs_vnops.c revision 1.79.4.1 1 /* $NetBSD: msdosfs_vnops.c,v 1.79.4.1 2012/04/06 17:40:20 riz 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.79.4.1 2012/04/06 17:40:20 riz 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_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 vput(ap->a_dvp);
159 *ap->a_vpp = DETOV(dep);
160 return (0);
161
162 bad:
163 fstrans_done(ap->a_dvp->v_mount);
164 vput(ap->a_dvp);
165 return (error);
166 }
167
168 int
169 msdosfs_close(void *v)
170 {
171 struct vop_close_args /* {
172 struct vnode *a_vp;
173 int a_fflag;
174 kauth_cred_t a_cred;
175 } */ *ap = v;
176 struct vnode *vp = ap->a_vp;
177 struct denode *dep = VTODE(vp);
178
179 fstrans_start(vp->v_mount, FSTRANS_SHARED);
180 mutex_enter(vp->v_interlock);
181 if (vp->v_usecount > 1)
182 DETIMES(dep, NULL, NULL, NULL, dep->de_pmp->pm_gmtoff);
183 mutex_exit(vp->v_interlock);
184 fstrans_done(vp->v_mount);
185 return (0);
186 }
187
188 static int
189 msdosfs_check_possible(struct vnode *vp, struct denode *dep, mode_t mode)
190 {
191
192 /*
193 * Disallow write attempts on read-only file systems;
194 * unless the file is a socket, fifo, or a block or
195 * character device resident on the file system.
196 */
197 if (mode & VWRITE) {
198 switch (vp->v_type) {
199 case VDIR:
200 case VLNK:
201 case VREG:
202 if (vp->v_mount->mnt_flag & MNT_RDONLY)
203 return (EROFS);
204 default:
205 break;
206 }
207 }
208
209 return 0;
210 }
211
212 static int
213 msdosfs_check_permitted(struct vnode *vp, struct denode *dep, mode_t mode,
214 kauth_cred_t cred)
215 {
216 struct msdosfsmount *pmp = dep->de_pmp;
217 mode_t file_mode;
218
219 if ((dep->de_Attributes & ATTR_READONLY) == 0)
220 file_mode = S_IRWXU|S_IRWXG|S_IRWXO;
221 else
222 file_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
223
224 return genfs_can_access(vp->v_type,
225 file_mode & (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask),
226 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 = genfs_can_chtimes(ap->a_vp, vap->va_vaflags,
381 pmp->pm_uid, cred);
382 if (error)
383 goto bad;
384 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
385 vap->va_atime.tv_sec != VNOVAL)
386 unix2dostime(&vap->va_atime, pmp->pm_gmtoff, &dep->de_ADate, NULL, NULL);
387 if (vap->va_mtime.tv_sec != VNOVAL)
388 unix2dostime(&vap->va_mtime, pmp->pm_gmtoff, &dep->de_MDate, &dep->de_MTime, NULL);
389 dep->de_Attributes |= ATTR_ARCHIVE;
390 dep->de_flag |= DE_MODIFIED;
391 de_changed = 1;
392 }
393 /*
394 * DOS files only have the ability to have their writability
395 * attribute set, so we use the owner write bit to set the readonly
396 * attribute.
397 */
398 if (vap->va_mode != (mode_t)VNOVAL) {
399 if (vp->v_mount->mnt_flag & MNT_RDONLY) {
400 error = EROFS;
401 goto bad;
402 }
403 if (kauth_cred_geteuid(cred) != pmp->pm_uid &&
404 (error = kauth_authorize_generic(cred, KAUTH_GENERIC_ISSUSER,
405 NULL)))
406 goto bad;
407 /* We ignore the read and execute bits. */
408 if (vap->va_mode & S_IWUSR)
409 dep->de_Attributes &= ~ATTR_READONLY;
410 else
411 dep->de_Attributes |= ATTR_READONLY;
412 dep->de_flag |= DE_MODIFIED;
413 de_changed = 1;
414 }
415 /*
416 * Allow the `archived' bit to be toggled.
417 */
418 if (vap->va_flags != VNOVAL) {
419 if (vp->v_mount->mnt_flag & MNT_RDONLY) {
420 error = EROFS;
421 goto bad;
422 }
423 if (kauth_cred_geteuid(cred) != pmp->pm_uid &&
424 (error = kauth_authorize_generic(cred, KAUTH_GENERIC_ISSUSER,
425 NULL)))
426 goto bad;
427 if (vap->va_flags & SF_ARCHIVED)
428 dep->de_Attributes &= ~ATTR_ARCHIVE;
429 else
430 dep->de_Attributes |= ATTR_ARCHIVE;
431 dep->de_flag |= DE_MODIFIED;
432 de_changed = 1;
433 }
434
435 if (de_changed) {
436 VN_KNOTE(vp, NOTE_ATTRIB);
437 error = deupdat(dep, 1);
438 if (error)
439 goto bad;
440 }
441
442 bad:
443 fstrans_done(vp->v_mount);
444 return error;
445 }
446
447 int
448 msdosfs_read(void *v)
449 {
450 struct vop_read_args /* {
451 struct vnode *a_vp;
452 struct uio *a_uio;
453 int a_ioflag;
454 kauth_cred_t a_cred;
455 } */ *ap = v;
456 int error = 0;
457 int64_t diff;
458 int blsize;
459 long n;
460 long on;
461 daddr_t lbn;
462 vsize_t bytelen;
463 struct buf *bp;
464 struct vnode *vp = ap->a_vp;
465 struct denode *dep = VTODE(vp);
466 struct msdosfsmount *pmp = dep->de_pmp;
467 struct uio *uio = ap->a_uio;
468
469 /*
470 * If they didn't ask for any data, then we are done.
471 */
472
473 if (uio->uio_resid == 0)
474 return (0);
475 if (uio->uio_offset < 0)
476 return (EINVAL);
477 if (uio->uio_offset >= dep->de_FileSize)
478 return (0);
479
480 fstrans_start(vp->v_mount, FSTRANS_SHARED);
481 if (vp->v_type == VREG) {
482 const int advice = IO_ADV_DECODE(ap->a_ioflag);
483
484 while (uio->uio_resid > 0) {
485 bytelen = MIN(dep->de_FileSize - uio->uio_offset,
486 uio->uio_resid);
487
488 if (bytelen == 0)
489 break;
490 error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice,
491 UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp));
492 if (error)
493 break;
494 }
495 dep->de_flag |= DE_ACCESS;
496 goto out;
497 }
498
499 /* this loop is only for directories now */
500 do {
501 lbn = de_cluster(pmp, uio->uio_offset);
502 on = uio->uio_offset & pmp->pm_crbomask;
503 n = MIN(pmp->pm_bpcluster - on, uio->uio_resid);
504 if (uio->uio_offset >= dep->de_FileSize) {
505 fstrans_done(vp->v_mount);
506 return (0);
507 }
508 /* file size (and hence diff) may be up to 4GB */
509 diff = dep->de_FileSize - uio->uio_offset;
510 if (diff < n)
511 n = (long) diff;
512
513 /* convert cluster # to sector # */
514 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
515 if (error)
516 goto bad;
517
518 /*
519 * If we are operating on a directory file then be sure to
520 * do i/o with the vnode for the filesystem instead of the
521 * vnode for the directory.
522 */
523 error = bread(pmp->pm_devvp, de_bn2kb(pmp, lbn), blsize,
524 NOCRED, 0, &bp);
525 n = MIN(n, pmp->pm_bpcluster - bp->b_resid);
526 if (error) {
527 brelse(bp, 0);
528 goto bad;
529 }
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, PGO_CLEANIT);
657 }
658 } while (error == 0 && uio->uio_resid > 0);
659
660 /* set final size */
661 uvm_vnp_setsize(vp, dep->de_FileSize);
662 if (error == 0 && ioflag & IO_SYNC) {
663 mutex_enter(vp->v_interlock);
664 error = VOP_PUTPAGES(vp, trunc_page(oldoff),
665 round_page(oldoff + bytelen), PGO_CLEANIT | PGO_SYNCIO);
666 }
667 dep->de_flag |= DE_UPDATE;
668
669 /*
670 * If the write failed and they want us to, truncate the file back
671 * to the size it was before the write was attempted.
672 */
673 errexit:
674 if (resid > uio->uio_resid)
675 VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
676 if (error) {
677 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED);
678 uio->uio_offset -= resid - uio->uio_resid;
679 uio->uio_resid = resid;
680 } else if ((ioflag & IO_SYNC) == IO_SYNC)
681 error = deupdat(dep, 1);
682 fstrans_done(vp->v_mount);
683 KASSERT(vp->v_size == dep->de_FileSize);
684 return (error);
685 }
686
687 int
688 msdosfs_update(struct vnode *vp, const struct timespec *acc,
689 const struct timespec *mod, int flags)
690 {
691 struct buf *bp;
692 struct direntry *dirp;
693 struct denode *dep;
694 int error;
695
696 if (vp->v_mount->mnt_flag & MNT_RDONLY)
697 return (0);
698 dep = VTODE(vp);
699 DETIMES(dep, acc, mod, NULL, dep->de_pmp->pm_gmtoff);
700 if ((dep->de_flag & DE_MODIFIED) == 0)
701 return (0);
702 dep->de_flag &= ~DE_MODIFIED;
703 if (dep->de_Attributes & ATTR_DIRECTORY)
704 return (0);
705 if (dep->de_refcnt <= 0)
706 return (0);
707 error = readde(dep, &bp, &dirp);
708 if (error)
709 return (error);
710 DE_EXTERNALIZE(dirp, dep);
711 if (flags & (UPDATE_WAIT|UPDATE_DIROP))
712 return (bwrite(bp));
713 else {
714 bdwrite(bp);
715 return (0);
716 }
717 }
718
719 /*
720 * Flush the blocks of a file to disk.
721 *
722 * This function is worthless for vnodes that represent directories. Maybe we
723 * could just do a sync if they try an fsync on a directory file.
724 */
725 int
726 msdosfs_remove(void *v)
727 {
728 struct vop_remove_args /* {
729 struct vnode *a_dvp;
730 struct vnode *a_vp;
731 struct componentname *a_cnp;
732 } */ *ap = v;
733 struct denode *dep = VTODE(ap->a_vp);
734 struct denode *ddep = VTODE(ap->a_dvp);
735 int error;
736
737 fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
738 if (ap->a_vp->v_type == VDIR)
739 error = EPERM;
740 else
741 error = removede(ddep, dep);
742 #ifdef MSDOSFS_DEBUG
743 printf("msdosfs_remove(), dep %p, v_usecount %d\n",
744 dep, ap->a_vp->v_usecount);
745 #endif
746 VN_KNOTE(ap->a_vp, NOTE_DELETE);
747 VN_KNOTE(ap->a_dvp, NOTE_WRITE);
748 if (ddep == dep)
749 vrele(ap->a_vp);
750 else
751 vput(ap->a_vp); /* causes msdosfs_inactive() to be called
752 * via vrele() */
753 vput(ap->a_dvp);
754 fstrans_done(ap->a_dvp->v_mount);
755 return (error);
756 }
757
758 /*
759 * Renames on files require moving the denode to a new hash queue since the
760 * denode's location is used to compute which hash queue to put the file
761 * in. Unless it is a rename in place. For example "mv a b".
762 *
763 * What follows is the basic algorithm:
764 *
765 * if (file move) {
766 * if (dest file exists) {
767 * remove dest file
768 * }
769 * if (dest and src in same directory) {
770 * rewrite name in existing directory slot
771 * } else {
772 * write new entry in dest directory
773 * update offset and dirclust in denode
774 * move denode to new hash chain
775 * clear old directory entry
776 * }
777 * } else {
778 * directory move
779 * if (dest directory exists) {
780 * if (dest is not empty) {
781 * return ENOTEMPTY
782 * }
783 * remove dest directory
784 * }
785 * if (dest and src in same directory) {
786 * rewrite name in existing entry
787 * } else {
788 * be sure dest is not a child of src directory
789 * write entry in dest directory
790 * update "." and ".." in moved directory
791 * update offset and dirclust in denode
792 * move denode to new hash chain
793 * clear old directory entry for moved directory
794 * }
795 * }
796 *
797 * On entry:
798 * source's parent directory is unlocked
799 * source file or directory is unlocked
800 * destination's parent directory is locked
801 * destination file or directory is locked if it exists
802 *
803 * On exit:
804 * all denodes should be released
805 *
806 * Notes:
807 * I'm not sure how the memory containing the pathnames pointed at by the
808 * componentname structures is freed, there may be some memory bleeding
809 * for each rename done.
810 *
811 * --More-- Notes:
812 * This routine needs help. badly.
813 */
814 int
815 msdosfs_rename(void *v)
816 {
817 struct vop_rename_args /* {
818 struct vnode *a_fdvp;
819 struct vnode *a_fvp;
820 struct componentname *a_fcnp;
821 struct vnode *a_tdvp;
822 struct vnode *a_tvp;
823 struct componentname *a_tcnp;
824 } */ *ap = v;
825 struct vnode *tvp = ap->a_tvp;
826 struct vnode *tdvp = ap->a_tdvp;
827 struct vnode *fvp = ap->a_fvp;
828 struct vnode *fdvp = ap->a_fdvp;
829 struct componentname *tcnp = ap->a_tcnp;
830 struct componentname *fcnp = ap->a_fcnp;
831 struct denode *ip, *xp, *dp, *zp;
832 u_char toname[12], oldname[12];
833 u_long from_diroffset, to_diroffset;
834 u_char to_count;
835 int doingdirectory = 0, newparent = 0;
836 int error;
837 u_long cn;
838 daddr_t bn;
839 struct msdosfsmount *pmp;
840 struct direntry *dotdotp;
841 struct buf *bp;
842
843 pmp = VFSTOMSDOSFS(fdvp->v_mount);
844
845 /*
846 * Check for cross-device rename.
847 */
848 if ((fvp->v_mount != tdvp->v_mount) ||
849 (tvp && (fvp->v_mount != tvp->v_mount))) {
850 error = EXDEV;
851 abortit:
852 VOP_ABORTOP(tdvp, tcnp);
853 if (tdvp == tvp)
854 vrele(tdvp);
855 else
856 vput(tdvp);
857 if (tvp)
858 vput(tvp);
859 VOP_ABORTOP(fdvp, fcnp);
860 vrele(fdvp);
861 vrele(fvp);
862 return (error);
863 }
864
865 /*
866 * If source and dest are the same, do nothing.
867 */
868 if (tvp == fvp) {
869 error = 0;
870 goto abortit;
871 }
872
873 /*
874 * XXX: This can deadlock since we hold tdvp/tvp locked.
875 * But I'm not going to fix it now.
876 */
877 if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
878 goto abortit;
879 dp = VTODE(fdvp);
880 ip = VTODE(fvp);
881
882 /*
883 * Be sure we are not renaming ".", "..", or an alias of ".". This
884 * leads to a crippled directory tree. It's pretty tough to do a
885 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
886 * doesn't work if the ".." entry is missing.
887 */
888 if (ip->de_Attributes & ATTR_DIRECTORY) {
889 /*
890 * Avoid ".", "..", and aliases of "." for obvious reasons.
891 */
892 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
893 dp == ip ||
894 (fcnp->cn_flags & ISDOTDOT) ||
895 (tcnp->cn_flags & ISDOTDOT) ||
896 (ip->de_flag & DE_RENAME)) {
897 VOP_UNLOCK(fvp);
898 error = EINVAL;
899 goto abortit;
900 }
901 ip->de_flag |= DE_RENAME;
902 doingdirectory++;
903 }
904 VN_KNOTE(fdvp, NOTE_WRITE); /* XXXLUKEM/XXX: right place? */
905
906 fstrans_start(fdvp->v_mount, FSTRANS_SHARED);
907 /*
908 * When the target exists, both the directory
909 * and target vnodes are returned locked.
910 */
911 dp = VTODE(tdvp);
912 xp = tvp ? VTODE(tvp) : NULL;
913 /*
914 * Remember direntry place to use for destination
915 */
916 to_diroffset = dp->de_fndoffset;
917 to_count = dp->de_fndcnt;
918
919 /*
920 * If ".." must be changed (ie the directory gets a new
921 * parent) then the source directory must not be in the
922 * directory hierarchy above the target, as this would
923 * orphan everything below the source directory. Also
924 * the user must have write permission in the source so
925 * as to be able to change "..". We must repeat the call
926 * to namei, as the parent directory is unlocked by the
927 * call to doscheckpath().
928 */
929 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred);
930 VOP_UNLOCK(fvp);
931 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
932 newparent = 1;
933
934 if (doingdirectory && newparent) {
935 if (error) /* write access check above */
936 goto tdvpbad;
937 if (xp != NULL)
938 vput(tvp);
939 tvp = NULL;
940 /*
941 * doscheckpath() vput()'s tdvp (dp == VTODE(tdvp)),
942 * so we have to get an extra ref to it first, and
943 * because it's been unlocked we need to do a relookup
944 * afterwards in case tvp has changed.
945 */
946 vref(tdvp);
947 if ((error = doscheckpath(ip, dp)) != 0)
948 goto bad;
949 vn_lock(tdvp, LK_EXCLUSIVE | LK_RETRY);
950 if ((error = relookup(tdvp, &tvp, tcnp, 0)) != 0) {
951 VOP_UNLOCK(tdvp);
952 goto bad;
953 }
954 dp = VTODE(tdvp);
955 xp = tvp ? VTODE(tvp) : NULL;
956 }
957
958 if (xp != NULL) {
959 /*
960 * Target must be empty if a directory and have no links
961 * to it. Also, ensure source and target are compatible
962 * (both directories, or both not directories).
963 */
964 if (xp->de_Attributes & ATTR_DIRECTORY) {
965 if (!dosdirempty(xp)) {
966 error = ENOTEMPTY;
967 goto tdvpbad;
968 }
969 if (!doingdirectory) {
970 error = ENOTDIR;
971 goto tdvpbad;
972 }
973 } else if (doingdirectory) {
974 error = EISDIR;
975 goto tdvpbad;
976 }
977 if ((error = removede(dp, xp)) != 0)
978 goto tdvpbad;
979 VN_KNOTE(tdvp, NOTE_WRITE);
980 VN_KNOTE(tvp, NOTE_DELETE);
981 cache_purge(tvp);
982 vput(tvp);
983 tvp = NULL;
984 xp = NULL;
985 }
986
987 /*
988 * Convert the filename in tcnp into a dos filename. We copy this
989 * into the denode and directory entry for the destination
990 * file/directory.
991 */
992 if ((error = uniqdosname(VTODE(tdvp), tcnp, toname)) != 0) {
993 fstrans_done(fdvp->v_mount);
994 goto abortit;
995 }
996
997 /*
998 * Since from wasn't locked at various places above,
999 * have to do a relookup here.
1000 */
1001 fcnp->cn_flags &= ~MODMASK;
1002 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1003 VOP_UNLOCK(tdvp);
1004 vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY);
1005 if ((error = relookup(fdvp, &fvp, fcnp, 0))) {
1006 VOP_UNLOCK(fdvp);
1007 vrele(ap->a_fvp);
1008 vrele(tdvp);
1009 fstrans_done(fdvp->v_mount);
1010 return (error);
1011 }
1012 if (fvp == NULL) {
1013 /*
1014 * From name has disappeared.
1015 */
1016 if (doingdirectory)
1017 panic("rename: lost dir entry");
1018 vput(fdvp);
1019 vrele(ap->a_fvp);
1020 vrele(tdvp);
1021 fstrans_done(fdvp->v_mount);
1022 return 0;
1023 }
1024 VOP_UNLOCK(fdvp);
1025 xp = VTODE(fvp);
1026 zp = VTODE(fdvp);
1027 from_diroffset = zp->de_fndoffset;
1028
1029 /*
1030 * Ensure that the directory entry still exists and has not
1031 * changed till now. If the source is a file the entry may
1032 * have been unlinked or renamed. In either case there is
1033 * no further work to be done. If the source is a directory
1034 * then it cannot have been rmdir'ed or renamed; this is
1035 * prohibited by the DE_RENAME flag.
1036 */
1037 if (xp != ip) {
1038 if (doingdirectory)
1039 panic("rename: lost dir entry");
1040 vrele(ap->a_fvp);
1041 xp = NULL;
1042 } else {
1043 vrele(fvp);
1044 xp = NULL;
1045
1046 /*
1047 * First write a new entry in the destination
1048 * directory and mark the entry in the source directory
1049 * as deleted. Then move the denode to the correct hash
1050 * chain for its new location in the filesystem. And, if
1051 * we moved a directory, then update its .. entry to point
1052 * to the new parent directory.
1053 */
1054 memcpy(oldname, ip->de_Name, 11);
1055 memcpy(ip->de_Name, toname, 11); /* update denode */
1056 dp->de_fndoffset = to_diroffset;
1057 dp->de_fndcnt = to_count;
1058 error = createde(ip, dp, (struct denode **)0, tcnp);
1059 if (error) {
1060 memcpy(ip->de_Name, oldname, 11);
1061 VOP_UNLOCK(fvp);
1062 goto bad;
1063 }
1064 ip->de_refcnt++;
1065 zp->de_fndoffset = from_diroffset;
1066 if ((error = removede(zp, ip)) != 0) {
1067 /* XXX should really panic here, fs is corrupt */
1068 VOP_UNLOCK(fvp);
1069 goto bad;
1070 }
1071 cache_purge(fvp);
1072 if (!doingdirectory) {
1073 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1074 &ip->de_dirclust, 0);
1075 if (error) {
1076 /* XXX should really panic here, fs is corrupt */
1077 VOP_UNLOCK(fvp);
1078 goto bad;
1079 }
1080 ip->de_diroffset = to_diroffset;
1081 if (ip->de_dirclust != MSDOSFSROOT)
1082 ip->de_diroffset &= pmp->pm_crbomask;
1083 }
1084 reinsert(ip);
1085 }
1086
1087 /*
1088 * If we moved a directory to a new parent directory, then we must
1089 * fixup the ".." entry in the moved directory.
1090 */
1091 if (doingdirectory && newparent) {
1092 cn = ip->de_StartCluster;
1093 if (cn == MSDOSFSROOT) {
1094 /* this should never happen */
1095 panic("msdosfs_rename: updating .. in root directory?");
1096 } else
1097 bn = cntobn(pmp, cn);
1098 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn),
1099 pmp->pm_bpcluster, NOCRED, B_MODIFY, &bp);
1100 if (error) {
1101 /* XXX should really panic here, fs is corrupt */
1102 brelse(bp, 0);
1103 VOP_UNLOCK(fvp);
1104 goto bad;
1105 }
1106 dotdotp = (struct direntry *)bp->b_data + 1;
1107 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1108 if (FAT32(pmp)) {
1109 putushort(dotdotp->deHighClust,
1110 dp->de_StartCluster >> 16);
1111 } else {
1112 putushort(dotdotp->deHighClust, 0);
1113 }
1114 if ((error = bwrite(bp)) != 0) {
1115 /* XXX should really panic here, fs is corrupt */
1116 VOP_UNLOCK(fvp);
1117 goto bad;
1118 }
1119 }
1120
1121 VN_KNOTE(fvp, NOTE_RENAME);
1122 VOP_UNLOCK(fvp);
1123 bad:
1124 if (tvp)
1125 vput(tvp);
1126 vrele(tdvp);
1127 ip->de_flag &= ~DE_RENAME;
1128 vrele(fdvp);
1129 vrele(fvp);
1130 fstrans_done(fdvp->v_mount);
1131 return (error);
1132
1133 /* XXX: uuuh */
1134 tdvpbad:
1135 VOP_UNLOCK(tdvp);
1136 goto bad;
1137 }
1138
1139 static const struct {
1140 struct direntry dot;
1141 struct direntry dotdot;
1142 } dosdirtemplate = {
1143 { ". ", " ", /* the . entry */
1144 ATTR_DIRECTORY, /* file attribute */
1145 0, /* reserved */
1146 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1147 { 0, 0 }, /* access date */
1148 { 0, 0 }, /* high bits of start cluster */
1149 { 210, 4 }, { 210, 4 }, /* modify time & date */
1150 { 0, 0 }, /* startcluster */
1151 { 0, 0, 0, 0 } /* filesize */
1152 },
1153 { ".. ", " ", /* the .. entry */
1154 ATTR_DIRECTORY, /* file attribute */
1155 0, /* reserved */
1156 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1157 { 0, 0 }, /* access date */
1158 { 0, 0 }, /* high bits of start cluster */
1159 { 210, 4 }, { 210, 4 }, /* modify time & date */
1160 { 0, 0 }, /* startcluster */
1161 { 0, 0, 0, 0 } /* filesize */
1162 }
1163 };
1164
1165 int
1166 msdosfs_mkdir(void *v)
1167 {
1168 struct vop_mkdir_args /* {
1169 struct vnode *a_dvp;
1170 struvt vnode **a_vpp;
1171 struvt componentname *a_cnp;
1172 struct vattr *a_vap;
1173 } */ *ap = v;
1174 struct componentname *cnp = ap->a_cnp;
1175 struct denode ndirent;
1176 struct denode *dep;
1177 struct denode *pdep = VTODE(ap->a_dvp);
1178 int error;
1179 int bn;
1180 u_long newcluster, pcl;
1181 daddr_t lbn;
1182 struct direntry *denp;
1183 struct msdosfsmount *pmp = pdep->de_pmp;
1184 struct buf *bp;
1185 int async = pdep->de_pmp->pm_mountp->mnt_flag & MNT_ASYNC;
1186
1187 fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
1188 /*
1189 * If this is the root directory and there is no space left we
1190 * can't do anything. This is because the root directory can not
1191 * change size.
1192 */
1193 if (pdep->de_StartCluster == MSDOSFSROOT
1194 && pdep->de_fndoffset >= pdep->de_FileSize) {
1195 error = ENOSPC;
1196 goto bad2;
1197 }
1198
1199 /*
1200 * Allocate a cluster to hold the about to be created directory.
1201 */
1202 error = clusteralloc(pmp, 0, 1, &newcluster, NULL);
1203 if (error)
1204 goto bad2;
1205
1206 memset(&ndirent, 0, sizeof(ndirent));
1207 ndirent.de_pmp = pmp;
1208 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1209 DETIMES(&ndirent, NULL, NULL, NULL, pmp->pm_gmtoff);
1210
1211 /*
1212 * Now fill the cluster with the "." and ".." entries. And write
1213 * the cluster to disk. This way it is there for the parent
1214 * directory to be pointing at if there were a crash.
1215 */
1216 bn = cntobn(pmp, newcluster);
1217 lbn = de_bn2kb(pmp, bn);
1218 /* always succeeds */
1219 bp = getblk(pmp->pm_devvp, lbn, pmp->pm_bpcluster, 0, 0);
1220 memset(bp->b_data, 0, pmp->pm_bpcluster);
1221 memcpy(bp->b_data, &dosdirtemplate, sizeof dosdirtemplate);
1222 denp = (struct direntry *)bp->b_data;
1223 putushort(denp[0].deStartCluster, newcluster);
1224 putushort(denp[0].deCDate, ndirent.de_CDate);
1225 putushort(denp[0].deCTime, ndirent.de_CTime);
1226 denp[0].deCHundredth = ndirent.de_CHun;
1227 putushort(denp[0].deADate, ndirent.de_ADate);
1228 putushort(denp[0].deMDate, ndirent.de_MDate);
1229 putushort(denp[0].deMTime, ndirent.de_MTime);
1230 pcl = pdep->de_StartCluster;
1231 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1232 pcl = 0;
1233 putushort(denp[1].deStartCluster, pcl);
1234 putushort(denp[1].deCDate, ndirent.de_CDate);
1235 putushort(denp[1].deCTime, ndirent.de_CTime);
1236 denp[1].deCHundredth = ndirent.de_CHun;
1237 putushort(denp[1].deADate, ndirent.de_ADate);
1238 putushort(denp[1].deMDate, ndirent.de_MDate);
1239 putushort(denp[1].deMTime, ndirent.de_MTime);
1240 if (FAT32(pmp)) {
1241 putushort(denp[0].deHighClust, newcluster >> 16);
1242 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1243 } else {
1244 putushort(denp[0].deHighClust, 0);
1245 putushort(denp[1].deHighClust, 0);
1246 }
1247
1248 if (async)
1249 bdwrite(bp);
1250 else if ((error = bwrite(bp)) != 0)
1251 goto bad;
1252
1253 /*
1254 * Now build up a directory entry pointing to the newly allocated
1255 * cluster. This will be written to an empty slot in the parent
1256 * directory.
1257 */
1258 if ((error = uniqdosname(pdep, cnp, ndirent.de_Name)) != 0)
1259 goto bad;
1260
1261 ndirent.de_Attributes = ATTR_DIRECTORY;
1262 ndirent.de_StartCluster = newcluster;
1263 ndirent.de_FileSize = 0;
1264 ndirent.de_dev = pdep->de_dev;
1265 ndirent.de_devvp = pdep->de_devvp;
1266 if ((error = createde(&ndirent, pdep, &dep, cnp)) != 0)
1267 goto bad;
1268 VN_KNOTE(ap->a_dvp, NOTE_WRITE | NOTE_LINK);
1269 vput(ap->a_dvp);
1270 *ap->a_vpp = DETOV(dep);
1271 fstrans_done(ap->a_dvp->v_mount);
1272 return (0);
1273
1274 bad:
1275 clusterfree(pmp, newcluster, NULL);
1276 bad2:
1277 vput(ap->a_dvp);
1278 fstrans_done(ap->a_dvp->v_mount);
1279 return (error);
1280 }
1281
1282 int
1283 msdosfs_rmdir(void *v)
1284 {
1285 struct vop_rmdir_args /* {
1286 struct vnode *a_dvp;
1287 struct vnode *a_vp;
1288 struct componentname *a_cnp;
1289 } */ *ap = v;
1290 struct vnode *vp = ap->a_vp;
1291 struct vnode *dvp = ap->a_dvp;
1292 struct componentname *cnp = ap->a_cnp;
1293 struct denode *ip, *dp;
1294 int error;
1295
1296 ip = VTODE(vp);
1297 dp = VTODE(dvp);
1298 /*
1299 * No rmdir "." please.
1300 */
1301 if (dp == ip) {
1302 vrele(dvp);
1303 vput(vp);
1304 return (EINVAL);
1305 }
1306 fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
1307 /*
1308 * Verify the directory is empty (and valid).
1309 * (Rmdir ".." won't be valid since
1310 * ".." will contain a reference to
1311 * the current directory and thus be
1312 * non-empty.)
1313 */
1314 error = 0;
1315 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1316 error = ENOTEMPTY;
1317 goto out;
1318 }
1319 /*
1320 * Delete the entry from the directory. For dos filesystems this
1321 * gets rid of the directory entry on disk, the in memory copy
1322 * still exists but the de_refcnt is <= 0. This prevents it from
1323 * being found by deget(). When the vput() on dep is done we give
1324 * up access and eventually msdosfs_reclaim() will be called which
1325 * will remove it from the denode cache.
1326 */
1327 if ((error = removede(dp, ip)) != 0)
1328 goto out;
1329 /*
1330 * This is where we decrement the link count in the parent
1331 * directory. Since dos filesystems don't do this we just purge
1332 * the name cache and let go of the parent directory denode.
1333 */
1334 VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
1335 cache_purge(dvp);
1336 vput(dvp);
1337 dvp = NULL;
1338 /*
1339 * Truncate the directory that is being deleted.
1340 */
1341 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred);
1342 cache_purge(vp);
1343 out:
1344 VN_KNOTE(vp, NOTE_DELETE);
1345 if (dvp)
1346 vput(dvp);
1347 vput(vp);
1348 fstrans_done(ap->a_dvp->v_mount);
1349 return (error);
1350 }
1351
1352 int
1353 msdosfs_readdir(void *v)
1354 {
1355 struct vop_readdir_args /* {
1356 struct vnode *a_vp;
1357 struct uio *a_uio;
1358 kauth_cred_t a_cred;
1359 int *a_eofflag;
1360 off_t **a_cookies;
1361 int *a_ncookies;
1362 } */ *ap = v;
1363 int error = 0;
1364 int diff;
1365 long n;
1366 int blsize;
1367 long on;
1368 long lost;
1369 long count;
1370 u_long cn;
1371 ino_t fileno;
1372 u_long dirsperblk;
1373 long bias = 0;
1374 daddr_t bn, lbn;
1375 struct buf *bp;
1376 struct denode *dep = VTODE(ap->a_vp);
1377 struct msdosfsmount *pmp = dep->de_pmp;
1378 struct direntry *dentp;
1379 struct dirent *dirbuf;
1380 struct uio *uio = ap->a_uio;
1381 off_t *cookies = NULL;
1382 int ncookies = 0, nc = 0;
1383 off_t offset, uio_off;
1384 int chksum = -1;
1385
1386 #ifdef MSDOSFS_DEBUG
1387 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1388 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1389 #endif
1390
1391 /*
1392 * msdosfs_readdir() won't operate properly on regular files since
1393 * it does i/o only with the filesystem vnode, and hence can
1394 * retrieve the wrong block from the buffer cache for a plain file.
1395 * So, fail attempts to readdir() on a plain file.
1396 */
1397 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1398 return (ENOTDIR);
1399
1400 /*
1401 * If the user buffer is smaller than the size of one dos directory
1402 * entry or the file offset is not a multiple of the size of a
1403 * directory entry, then we fail the read.
1404 */
1405 count = uio->uio_resid & ~(sizeof(struct direntry) - 1);
1406 offset = uio->uio_offset;
1407 if (count < sizeof(struct direntry) ||
1408 (offset & (sizeof(struct direntry) - 1)))
1409 return (EINVAL);
1410 lost = uio->uio_resid - count;
1411 uio->uio_resid = count;
1412 uio_off = uio->uio_offset;
1413
1414 fstrans_start(ap->a_vp->v_mount, FSTRANS_SHARED);
1415
1416 /* Allocate a temporary dirent buffer. */
1417 dirbuf = malloc(sizeof(struct dirent), M_MSDOSFSTMP, M_WAITOK | M_ZERO);
1418
1419 if (ap->a_ncookies) {
1420 nc = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0);
1421 cookies = malloc(nc * sizeof (off_t), M_TEMP, M_WAITOK);
1422 *ap->a_cookies = cookies;
1423 }
1424
1425 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1426
1427 /*
1428 * If they are reading from the root directory then, we simulate
1429 * the . and .. entries since these don't exist in the root
1430 * directory. We also set the offset bias to make up for having to
1431 * simulate these entries. By this I mean that at file offset 64 we
1432 * read the first entry in the root directory that lives on disk.
1433 */
1434 if (dep->de_StartCluster == MSDOSFSROOT
1435 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1436 #if 0
1437 printf("msdosfs_readdir(): going after . or .. in root dir, "
1438 "offset %" PRIu64 "\n", offset);
1439 #endif
1440 bias = 2 * sizeof(struct direntry);
1441 if (offset < bias) {
1442 for (n = (int)offset / sizeof(struct direntry);
1443 n < 2; n++) {
1444 if (FAT32(pmp))
1445 dirbuf->d_fileno = cntobn(pmp,
1446 (ino_t)pmp->pm_rootdirblk)
1447 * dirsperblk;
1448 else
1449 dirbuf->d_fileno = 1;
1450 dirbuf->d_type = DT_DIR;
1451 switch (n) {
1452 case 0:
1453 dirbuf->d_namlen = 1;
1454 strlcpy(dirbuf->d_name, ".",
1455 sizeof(dirbuf->d_name));
1456 break;
1457 case 1:
1458 dirbuf->d_namlen = 2;
1459 strlcpy(dirbuf->d_name, "..",
1460 sizeof(dirbuf->d_name));
1461 break;
1462 }
1463 dirbuf->d_reclen = _DIRENT_SIZE(dirbuf);
1464 if (uio->uio_resid < dirbuf->d_reclen)
1465 goto out;
1466 error = uiomove(dirbuf, dirbuf->d_reclen, uio);
1467 if (error)
1468 goto out;
1469 offset += sizeof(struct direntry);
1470 uio_off = offset;
1471 if (cookies) {
1472 *cookies++ = offset;
1473 ncookies++;
1474 if (ncookies >= nc)
1475 goto out;
1476 }
1477 }
1478 }
1479 }
1480
1481 while (uio->uio_resid > 0) {
1482 lbn = de_cluster(pmp, offset - bias);
1483 on = (offset - bias) & pmp->pm_crbomask;
1484 n = MIN(pmp->pm_bpcluster - on, uio->uio_resid);
1485 diff = dep->de_FileSize - (offset - bias);
1486 if (diff <= 0)
1487 break;
1488 n = MIN(n, diff);
1489 if ((error = pcbmap(dep, lbn, &bn, &cn, &blsize)) != 0)
1490 break;
1491 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), blsize,
1492 NOCRED, 0, &bp);
1493 if (error) {
1494 brelse(bp, 0);
1495 goto bad;
1496 }
1497 n = MIN(n, blsize - bp->b_resid);
1498
1499 /*
1500 * Convert from dos directory entries to fs-independent
1501 * directory entries.
1502 */
1503 for (dentp = (struct direntry *)((char *)bp->b_data + on);
1504 (char *)dentp < (char *)bp->b_data + on + n;
1505 dentp++, offset += sizeof(struct direntry)) {
1506 #if 0
1507
1508 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1509 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1510 #endif
1511 /*
1512 * If this is an unused entry, we can stop.
1513 */
1514 if (dentp->deName[0] == SLOT_EMPTY) {
1515 brelse(bp, 0);
1516 goto out;
1517 }
1518 /*
1519 * Skip deleted entries.
1520 */
1521 if (dentp->deName[0] == SLOT_DELETED) {
1522 chksum = -1;
1523 continue;
1524 }
1525
1526 /*
1527 * Handle Win95 long directory entries
1528 */
1529 if (dentp->deAttributes == ATTR_WIN95) {
1530 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1531 continue;
1532 chksum = win2unixfn((struct winentry *)dentp,
1533 dirbuf, chksum);
1534 continue;
1535 }
1536
1537 /*
1538 * Skip volume labels
1539 */
1540 if (dentp->deAttributes & ATTR_VOLUME) {
1541 chksum = -1;
1542 continue;
1543 }
1544 /*
1545 * This computation of d_fileno must match
1546 * the computation of va_fileid in
1547 * msdosfs_getattr.
1548 */
1549 if (dentp->deAttributes & ATTR_DIRECTORY) {
1550 fileno = getushort(dentp->deStartCluster);
1551 if (FAT32(pmp))
1552 fileno |= ((ino_t)getushort(dentp->deHighClust)) << 16;
1553 /* if this is the root directory */
1554 if (fileno == MSDOSFSROOT)
1555 if (FAT32(pmp))
1556 fileno = cntobn(pmp,
1557 (ino_t)pmp->pm_rootdirblk)
1558 * dirsperblk;
1559 else
1560 fileno = 1;
1561 else
1562 fileno = cntobn(pmp, fileno) * dirsperblk;
1563 dirbuf->d_fileno = fileno;
1564 dirbuf->d_type = DT_DIR;
1565 } else {
1566 dirbuf->d_fileno =
1567 offset / sizeof(struct direntry);
1568 dirbuf->d_type = DT_REG;
1569 }
1570 if (chksum != winChksum(dentp->deName))
1571 dirbuf->d_namlen = dos2unixfn(dentp->deName,
1572 (u_char *)dirbuf->d_name,
1573 pmp->pm_flags & MSDOSFSMNT_SHORTNAME);
1574 else
1575 dirbuf->d_name[dirbuf->d_namlen] = 0;
1576 chksum = -1;
1577 dirbuf->d_reclen = _DIRENT_SIZE(dirbuf);
1578 if (uio->uio_resid < dirbuf->d_reclen) {
1579 brelse(bp, 0);
1580 goto out;
1581 }
1582 error = uiomove(dirbuf, dirbuf->d_reclen, uio);
1583 if (error) {
1584 brelse(bp, 0);
1585 goto out;
1586 }
1587 uio_off = offset + sizeof(struct direntry);
1588 if (cookies) {
1589 *cookies++ = offset + sizeof(struct direntry);
1590 ncookies++;
1591 if (ncookies >= nc) {
1592 brelse(bp, 0);
1593 goto out;
1594 }
1595 }
1596 }
1597 brelse(bp, 0);
1598 }
1599
1600 out:
1601 uio->uio_offset = uio_off;
1602 uio->uio_resid += lost;
1603 if (dep->de_FileSize - (offset - bias) <= 0)
1604 *ap->a_eofflag = 1;
1605 else
1606 *ap->a_eofflag = 0;
1607
1608 if (ap->a_ncookies) {
1609 if (error) {
1610 free(*ap->a_cookies, M_TEMP);
1611 *ap->a_ncookies = 0;
1612 *ap->a_cookies = NULL;
1613 } else
1614 *ap->a_ncookies = ncookies;
1615 }
1616
1617 bad:
1618 free(dirbuf, M_MSDOSFSTMP);
1619 fstrans_done(ap->a_vp->v_mount);
1620 return (error);
1621 }
1622
1623 /*
1624 * vp - address of vnode file the file
1625 * bn - which cluster we are interested in mapping to a filesystem block number.
1626 * vpp - returns the vnode for the block special file holding the filesystem
1627 * containing the file of interest
1628 * bnp - address of where to return the filesystem relative block number
1629 */
1630 int
1631 msdosfs_bmap(void *v)
1632 {
1633 struct vop_bmap_args /* {
1634 struct vnode *a_vp;
1635 daddr_t a_bn;
1636 struct vnode **a_vpp;
1637 daddr_t *a_bnp;
1638 int *a_runp;
1639 } */ *ap = v;
1640 struct denode *dep = VTODE(ap->a_vp);
1641 int run, maxrun;
1642 daddr_t runbn;
1643 int status;
1644
1645 if (ap->a_vpp != NULL)
1646 *ap->a_vpp = dep->de_devvp;
1647 if (ap->a_bnp == NULL)
1648 return (0);
1649 status = pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0);
1650
1651 /*
1652 * From FreeBSD:
1653 * A little kludgy, but we loop calling pcbmap until we
1654 * reach the end of the contiguous piece, or reach MAXPHYS.
1655 * Since it reduces disk I/Os, the "wasted" CPU is put to
1656 * good use (4 to 5 fold sequential read I/O improvement on USB
1657 * drives).
1658 */
1659 if (ap->a_runp != NULL) {
1660 /* taken from ufs_bmap */
1661 maxrun = ulmin(MAXPHYS / dep->de_pmp->pm_bpcluster - 1,
1662 dep->de_pmp->pm_maxcluster - ap->a_bn);
1663 for (run = 1; run <= maxrun; run++) {
1664 if (pcbmap(dep, ap->a_bn + run, &runbn, NULL, NULL)
1665 != 0 || runbn !=
1666 *ap->a_bnp + de_cn2bn(dep->de_pmp, run))
1667 break;
1668 }
1669 *ap->a_runp = run - 1;
1670 }
1671
1672 /*
1673 * We need to scale *ap->a_bnp by sector_size/DEV_BSIZE
1674 */
1675 *ap->a_bnp = de_bn2kb(dep->de_pmp, *ap->a_bnp);
1676 return status;
1677 }
1678
1679 int
1680 msdosfs_strategy(void *v)
1681 {
1682 struct vop_strategy_args /* {
1683 struct vnode *a_vp;
1684 struct buf *a_bp;
1685 } */ *ap = v;
1686 struct vnode *vp = ap->a_vp;
1687 struct buf *bp = ap->a_bp;
1688 struct denode *dep = VTODE(bp->b_vp);
1689 int error = 0;
1690
1691 if (vp->v_type == VBLK || vp->v_type == VCHR)
1692 panic("msdosfs_strategy: spec");
1693 /*
1694 * If we don't already know the filesystem relative block number
1695 * then get it using pcbmap(). If pcbmap() returns the block
1696 * number as -1 then we've got a hole in the file. DOS filesystems
1697 * don't allow files with holes, so we shouldn't ever see this.
1698 */
1699 if (bp->b_blkno == bp->b_lblkno) {
1700 error = pcbmap(dep, de_bn2cn(dep->de_pmp, bp->b_lblkno),
1701 &bp->b_blkno, 0, 0);
1702 if (error)
1703 bp->b_blkno = -1;
1704 if (bp->b_blkno == -1)
1705 clrbuf(bp);
1706 else
1707 bp->b_blkno = de_bn2kb(dep->de_pmp, bp->b_blkno);
1708 }
1709 if (bp->b_blkno == -1) {
1710 biodone(bp);
1711 return (error);
1712 }
1713
1714 /*
1715 * Read/write the block from/to the disk that contains the desired
1716 * file block.
1717 */
1718
1719 vp = dep->de_devvp;
1720 return (VOP_STRATEGY(vp, bp));
1721 }
1722
1723 int
1724 msdosfs_print(void *v)
1725 {
1726 struct vop_print_args /* {
1727 struct vnode *vp;
1728 } */ *ap = v;
1729 struct denode *dep = VTODE(ap->a_vp);
1730
1731 printf(
1732 "tag VT_MSDOSFS, startcluster %ld, dircluster %ld, diroffset %ld ",
1733 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1734 printf(" dev %llu, %llu ", (unsigned long long)major(dep->de_dev),
1735 (unsigned long long)minor(dep->de_dev));
1736 printf("\n");
1737 return (0);
1738 }
1739
1740 int
1741 msdosfs_advlock(void *v)
1742 {
1743 struct vop_advlock_args /* {
1744 struct vnode *a_vp;
1745 void *a_id;
1746 int a_op;
1747 struct flock *a_fl;
1748 int a_flags;
1749 } */ *ap = v;
1750 struct denode *dep = VTODE(ap->a_vp);
1751
1752 return lf_advlock(ap, &dep->de_lockf, dep->de_FileSize);
1753 }
1754
1755 int
1756 msdosfs_pathconf(void *v)
1757 {
1758 struct vop_pathconf_args /* {
1759 struct vnode *a_vp;
1760 int a_name;
1761 register_t *a_retval;
1762 } */ *ap = v;
1763
1764 switch (ap->a_name) {
1765 case _PC_LINK_MAX:
1766 *ap->a_retval = 1;
1767 return (0);
1768 case _PC_NAME_MAX:
1769 *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_namemax;
1770 return (0);
1771 case _PC_PATH_MAX:
1772 *ap->a_retval = PATH_MAX;
1773 return (0);
1774 case _PC_CHOWN_RESTRICTED:
1775 *ap->a_retval = 1;
1776 return (0);
1777 case _PC_NO_TRUNC:
1778 *ap->a_retval = 1;
1779 return (0);
1780 case _PC_SYNC_IO:
1781 *ap->a_retval = 1;
1782 return (0);
1783 case _PC_FILESIZEBITS:
1784 *ap->a_retval = 32;
1785 return (0);
1786 default:
1787 return (EINVAL);
1788 }
1789 /* NOTREACHED */
1790 }
1791
1792 int
1793 msdosfs_fsync(void *v)
1794 {
1795 struct vop_fsync_args /* {
1796 struct vnode *a_vp;
1797 kauth_cred_t a_cred;
1798 int a_flags;
1799 off_t offlo;
1800 off_t offhi;
1801 } */ *ap = v;
1802 struct vnode *vp = ap->a_vp;
1803 int wait;
1804 int error;
1805
1806 fstrans_start(vp->v_mount, FSTRANS_LAZY);
1807 wait = (ap->a_flags & FSYNC_WAIT) != 0;
1808 error = vflushbuf(vp, wait);
1809 if (error == 0 && (ap->a_flags & FSYNC_DATAONLY) == 0)
1810 error = msdosfs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
1811
1812 if (error == 0 && ap->a_flags & FSYNC_CACHE) {
1813 struct denode *dep = VTODE(vp);
1814 struct vnode *devvp = dep->de_devvp;
1815
1816 int l = 0;
1817 error = VOP_IOCTL(devvp, DIOCCACHESYNC, &l, FWRITE,
1818 curlwp->l_cred);
1819 }
1820 fstrans_done(vp->v_mount);
1821
1822 return (error);
1823 }
1824
1825 void
1826 msdosfs_detimes(struct denode *dep, const struct timespec *acc,
1827 const struct timespec *mod, const struct timespec *cre, int gmtoff)
1828 {
1829 struct timespec *ts = NULL, tsb;
1830
1831 KASSERT(dep->de_flag & (DE_UPDATE | DE_CREATE | DE_ACCESS));
1832 /* XXX just call getnanotime early and use result if needed? */
1833 dep->de_flag |= DE_MODIFIED;
1834 if (dep->de_flag & DE_UPDATE) {
1835 if (mod == NULL) {
1836 getnanotime(&tsb);
1837 mod = ts = &tsb;
1838 }
1839 unix2dostime(mod, gmtoff, &dep->de_MDate, &dep->de_MTime, NULL);
1840 dep->de_Attributes |= ATTR_ARCHIVE;
1841 }
1842 if ((dep->de_pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0) {
1843 if (dep->de_flag & DE_ACCESS) {
1844 if (acc == NULL)
1845 acc = ts == NULL ?
1846 (getnanotime(&tsb), ts = &tsb) : ts;
1847 unix2dostime(acc, gmtoff, &dep->de_ADate, NULL, NULL);
1848 }
1849 if (dep->de_flag & DE_CREATE) {
1850 if (cre == NULL)
1851 cre = ts == NULL ?
1852 (getnanotime(&tsb), ts = &tsb) : ts;
1853 unix2dostime(cre, gmtoff, &dep->de_CDate,
1854 &dep->de_CTime, &dep->de_CHun);
1855 }
1856 }
1857
1858 dep->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS);
1859 }
1860
1861 /* Global vfs data structures for msdosfs */
1862 int (**msdosfs_vnodeop_p)(void *);
1863 const struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1864 { &vop_default_desc, vn_default_error },
1865 { &vop_lookup_desc, msdosfs_lookup }, /* lookup */
1866 { &vop_create_desc, msdosfs_create }, /* create */
1867 { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */
1868 { &vop_open_desc, genfs_nullop }, /* open */
1869 { &vop_close_desc, msdosfs_close }, /* close */
1870 { &vop_access_desc, msdosfs_access }, /* access */
1871 { &vop_getattr_desc, msdosfs_getattr }, /* getattr */
1872 { &vop_setattr_desc, msdosfs_setattr }, /* setattr */
1873 { &vop_read_desc, msdosfs_read }, /* read */
1874 { &vop_write_desc, msdosfs_write }, /* write */
1875 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */
1876 { &vop_ioctl_desc, msdosfs_ioctl }, /* ioctl */
1877 { &vop_poll_desc, msdosfs_poll }, /* poll */
1878 { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
1879 { &vop_revoke_desc, msdosfs_revoke }, /* revoke */
1880 { &vop_mmap_desc, msdosfs_mmap }, /* mmap */
1881 { &vop_fsync_desc, msdosfs_fsync }, /* fsync */
1882 { &vop_seek_desc, msdosfs_seek }, /* seek */
1883 { &vop_remove_desc, msdosfs_remove }, /* remove */
1884 { &vop_link_desc, genfs_eopnotsupp }, /* link */
1885 { &vop_rename_desc, msdosfs_rename }, /* rename */
1886 { &vop_mkdir_desc, msdosfs_mkdir }, /* mkdir */
1887 { &vop_rmdir_desc, msdosfs_rmdir }, /* rmdir */
1888 { &vop_symlink_desc, genfs_eopnotsupp }, /* symlink */
1889 { &vop_readdir_desc, msdosfs_readdir }, /* readdir */
1890 { &vop_readlink_desc, genfs_einval }, /* readlink */
1891 { &vop_abortop_desc, msdosfs_abortop }, /* abortop */
1892 { &vop_inactive_desc, msdosfs_inactive }, /* inactive */
1893 { &vop_reclaim_desc, msdosfs_reclaim }, /* reclaim */
1894 { &vop_lock_desc, genfs_lock }, /* lock */
1895 { &vop_unlock_desc, genfs_unlock }, /* unlock */
1896 { &vop_bmap_desc, msdosfs_bmap }, /* bmap */
1897 { &vop_strategy_desc, msdosfs_strategy }, /* strategy */
1898 { &vop_print_desc, msdosfs_print }, /* print */
1899 { &vop_islocked_desc, genfs_islocked }, /* islocked */
1900 { &vop_pathconf_desc, msdosfs_pathconf }, /* pathconf */
1901 { &vop_advlock_desc, msdosfs_advlock }, /* advlock */
1902 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
1903 { &vop_getpages_desc, genfs_getpages }, /* getpages */
1904 { &vop_putpages_desc, genfs_putpages }, /* putpages */
1905 { NULL, NULL }
1906 };
1907 const struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1908 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1909