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