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