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