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