proc->thread stage 4: rework the VFS and DEVICE subsystems to take thread
[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 $ */
dadab5e9 2/* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vnops.c,v 1.5 2003/06/25 03:56:01 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 }
dadab5e9 498 error = detrunc(dep, vap->va_size, 0, cred, 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;
608 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
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,
616 &rablock, &rasize, 1, NOCRED, &bp);
617 } else {
618 error = bread(vp, lbn, blsize, NOCRED, &bp);
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;
670 struct ucred *cred = ap->a_cred;
dadab5e9 671 struct proc *p = td->td_proc;
984263bc
MD
672
673#ifdef MSDOSFS_DEBUG
674 printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
675 vp, uio, ioflag, cred);
676 printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
677 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
678#endif
679
680 switch (vp->v_type) {
681 case VREG:
682 if (ioflag & IO_APPEND)
683 uio->uio_offset = dep->de_FileSize;
684 thisvp = vp;
685 break;
686 case VDIR:
687 return EISDIR;
688 default:
689 panic("msdosfs_write(): bad file type");
690 }
691
692 if (uio->uio_offset < 0)
693 return (EFBIG);
694
695 if (uio->uio_resid == 0)
696 return (0);
697
698 /*
699 * If they've exceeded their filesize limit, tell them about it.
700 */
701 if (p &&
702 ((uoff_t)uio->uio_offset + uio->uio_resid >
703 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
704 psignal(p, SIGXFSZ);
705 return (EFBIG);
706 }
707
708 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
709 return (EFBIG);
710
711 /*
712 * If the offset we are starting the write at is beyond the end of
713 * the file, then they've done a seek. Unix filesystems allow
714 * files with holes in them, DOS doesn't so we must fill the hole
715 * with zeroed blocks.
716 */
717 if (uio->uio_offset > dep->de_FileSize) {
718 error = deextend(dep, uio->uio_offset, cred);
719 if (error)
720 return (error);
721 }
722
723 /*
724 * Remember some values in case the write fails.
725 */
726 resid = uio->uio_resid;
727 osize = dep->de_FileSize;
728
729 /*
730 * If we write beyond the end of the file, extend it to its ultimate
731 * size ahead of the time to hopefully get a contiguous area.
732 */
733 if (uio->uio_offset + resid > osize) {
734 count = de_clcount(pmp, uio->uio_offset + resid) -
735 de_clcount(pmp, osize);
736 error = extendfile(dep, count, NULL, NULL, 0);
737 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
738 goto errexit;
739 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
740 } else
741 lastcn = de_clcount(pmp, osize) - 1;
742
743 do {
744 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
745 error = ENOSPC;
746 break;
747 }
748
749 croffset = uio->uio_offset & pmp->pm_crbomask;
750 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
751 if (uio->uio_offset + n > dep->de_FileSize) {
752 dep->de_FileSize = uio->uio_offset + n;
753 /* The object size needs to be set before buffer is allocated */
754 vnode_pager_setsize(vp, dep->de_FileSize);
755 }
756
757 bn = de_cluster(pmp, uio->uio_offset);
758 if ((uio->uio_offset & pmp->pm_crbomask) == 0
759 && (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
760 > de_cluster(pmp, uio->uio_offset)
761 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
762 /*
763 * If either the whole cluster gets written,
764 * or we write the cluster from its start beyond EOF,
765 * then no need to read data from disk.
766 */
767 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
768 clrbuf(bp);
769 /*
770 * Do the bmap now, since pcbmap needs buffers
771 * for the fat table. (see msdosfs_strategy)
772 */
773 if (bp->b_blkno == bp->b_lblkno) {
774 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno,
775 0, 0);
776 if (error)
777 bp->b_blkno = -1;
778 }
779 if (bp->b_blkno == -1) {
780 brelse(bp);
781 if (!error)
782 error = EIO; /* XXX */
783 break;
784 }
785 } else {
786 /*
787 * The block we need to write into exists, so read it in.
788 */
789 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
790 if (error) {
791 brelse(bp);
792 break;
793 }
794 }
795
796 /*
797 * Should these vnode_pager_* functions be done on dir
798 * files?
799 */
800
801 /*
802 * Copy the data from user space into the buf header.
803 */
804 error = uiomove(bp->b_data + croffset, n, uio);
805 if (error) {
806 brelse(bp);
807 break;
808 }
809
810 /*
811 * If they want this synchronous then write it and wait for
812 * it. Otherwise, if on a cluster boundary write it
813 * asynchronously so we can move on to the next block
814 * without delay. Otherwise do a delayed write because we
815 * may want to write somemore into the block later.
816 */
817 if (ioflag & IO_SYNC)
818 (void) bwrite(bp);
819 else if (n + croffset == pmp->pm_bpcluster)
820 bawrite(bp);
821 else
822 bdwrite(bp);
823 dep->de_flag |= DE_UPDATE;
824 } while (error == 0 && uio->uio_resid > 0);
825
826 /*
827 * If the write failed and they want us to, truncate the file back
828 * to the size it was before the write was attempted.
829 */
830errexit:
831 if (error) {
832 if (ioflag & IO_UNIT) {
833 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
834 uio->uio_offset -= resid - uio->uio_resid;
835 uio->uio_resid = resid;
836 } else {
837 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
838 if (uio->uio_resid != resid)
839 error = 0;
840 }
841 } else if (ioflag & IO_SYNC)
842 error = deupdat(dep, 1);
843 return (error);
844}
845
846/*
847 * Flush the blocks of a file to disk.
848 *
849 * This function is worthless for vnodes that represent directories. Maybe we
850 * could just do a sync if they try an fsync on a directory file.
851 */
852static int
853msdosfs_fsync(ap)
854 struct vop_fsync_args /* {
855 struct vnode *a_vp;
856 struct ucred *a_cred;
857 int a_waitfor;
dadab5e9 858 struct thread *a_td;
984263bc
MD
859 } */ *ap;
860{
861 struct vnode *vp = ap->a_vp;
862 int s;
863 struct buf *bp, *nbp;
864
865 /*
866 * Flush all dirty buffers associated with a vnode.
867 */
868loop:
869 s = splbio();
870 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
871 nbp = TAILQ_NEXT(bp, b_vnbufs);
872 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
873 continue;
874 if ((bp->b_flags & B_DELWRI) == 0)
875 panic("msdosfs_fsync: not dirty");
876 bremfree(bp);
877 splx(s);
878 (void) bwrite(bp);
879 goto loop;
880 }
881 while (vp->v_numoutput) {
882 vp->v_flag |= VBWAIT;
883 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "msdosfsn", 0);
884 }
885#ifdef DIAGNOSTIC
886 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
887 vprint("msdosfs_fsync: dirty", vp);
888 goto loop;
889 }
890#endif
891 splx(s);
892 return (deupdat(VTODE(vp), ap->a_waitfor == MNT_WAIT));
893}
894
895static int
896msdosfs_remove(ap)
897 struct vop_remove_args /* {
898 struct vnode *a_dvp;
899 struct vnode *a_vp;
900 struct componentname *a_cnp;
901 } */ *ap;
902{
903 struct denode *dep = VTODE(ap->a_vp);
904 struct denode *ddep = VTODE(ap->a_dvp);
905 int error;
906
907 if (ap->a_vp->v_type == VDIR)
908 error = EPERM;
909 else
910 error = removede(ddep, dep);
911#ifdef MSDOSFS_DEBUG
912 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
913#endif
914 return (error);
915}
916
917/*
918 * DOS filesystems don't know what links are. But since we already called
919 * msdosfs_lookup() with create and lockparent, the parent is locked so we
920 * have to free it before we return the error.
921 */
922static int
923msdosfs_link(ap)
924 struct vop_link_args /* {
925 struct vnode *a_tdvp;
926 struct vnode *a_vp;
927 struct componentname *a_cnp;
928 } */ *ap;
929{
930 return (EOPNOTSUPP);
931}
932
933/*
934 * Renames on files require moving the denode to a new hash queue since the
935 * denode's location is used to compute which hash queue to put the file
936 * in. Unless it is a rename in place. For example "mv a b".
937 *
938 * What follows is the basic algorithm:
939 *
940 * if (file move) {
941 * if (dest file exists) {
942 * remove dest file
943 * }
944 * if (dest and src in same directory) {
945 * rewrite name in existing directory slot
946 * } else {
947 * write new entry in dest directory
948 * update offset and dirclust in denode
949 * move denode to new hash chain
950 * clear old directory entry
951 * }
952 * } else {
953 * directory move
954 * if (dest directory exists) {
955 * if (dest is not empty) {
956 * return ENOTEMPTY
957 * }
958 * remove dest directory
959 * }
960 * if (dest and src in same directory) {
961 * rewrite name in existing entry
962 * } else {
963 * be sure dest is not a child of src directory
964 * write entry in dest directory
965 * update "." and ".." in moved directory
966 * clear old directory entry for moved directory
967 * }
968 * }
969 *
970 * On entry:
971 * source's parent directory is unlocked
972 * source file or directory is unlocked
973 * destination's parent directory is locked
974 * destination file or directory is locked if it exists
975 *
976 * On exit:
977 * all denodes should be released
978 *
979 * Notes:
980 * I'm not sure how the memory containing the pathnames pointed at by the
981 * componentname structures is freed, there may be some memory bleeding
982 * for each rename done.
983 */
984static int
985msdosfs_rename(ap)
986 struct vop_rename_args /* {
987 struct vnode *a_fdvp;
988 struct vnode *a_fvp;
989 struct componentname *a_fcnp;
990 struct vnode *a_tdvp;
991 struct vnode *a_tvp;
992 struct componentname *a_tcnp;
993 } */ *ap;
994{
995 struct vnode *tdvp = ap->a_tdvp;
996 struct vnode *fvp = ap->a_fvp;
997 struct vnode *fdvp = ap->a_fdvp;
998 struct vnode *tvp = ap->a_tvp;
999 struct componentname *tcnp = ap->a_tcnp;
1000 struct componentname *fcnp = ap->a_fcnp;
dadab5e9 1001 struct thread *td = fcnp->cn_td;
984263bc
MD
1002 struct denode *ip, *xp, *dp, *zp;
1003 u_char toname[11], oldname[11];
1004 u_long from_diroffset, to_diroffset;
1005 u_char to_count;
1006 int doingdirectory = 0, newparent = 0;
1007 int error;
1008 u_long cn;
1009 daddr_t bn;
1010 struct denode *fddep; /* from file's parent directory */
1011 struct msdosfsmount *pmp;
1012 struct direntry *dotdotp;
1013 struct buf *bp;
1014
1015 fddep = VTODE(ap->a_fdvp);
1016 pmp = fddep->de_pmp;
1017
1018 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1019
1020#ifdef DIAGNOSTIC
1021 if ((tcnp->cn_flags & HASBUF) == 0 ||
1022 (fcnp->cn_flags & HASBUF) == 0)
1023 panic("msdosfs_rename: no name");
1024#endif
1025 /*
1026 * Check for cross-device rename.
1027 */
1028 if ((fvp->v_mount != tdvp->v_mount) ||
1029 (tvp && (fvp->v_mount != tvp->v_mount))) {
1030 error = EXDEV;
1031abortit:
1032 if (tdvp == tvp)
1033 vrele(tdvp);
1034 else
1035 vput(tdvp);
1036 if (tvp)
1037 vput(tvp);
1038 vrele(fdvp);
1039 vrele(fvp);
1040 return (error);
1041 }
1042
1043 /*
1044 * If source and dest are the same, do nothing.
1045 */
1046 if (tvp == fvp) {
1047 error = 0;
1048 goto abortit;
1049 }
1050
dadab5e9 1051 error = vn_lock(fvp, LK_EXCLUSIVE, td);
984263bc
MD
1052 if (error)
1053 goto abortit;
1054 dp = VTODE(fdvp);
1055 ip = VTODE(fvp);
1056
1057 /*
1058 * Be sure we are not renaming ".", "..", or an alias of ".". This
1059 * leads to a crippled directory tree. It's pretty tough to do a
1060 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
1061 * doesn't work if the ".." entry is missing.
1062 */
1063 if (ip->de_Attributes & ATTR_DIRECTORY) {
1064 /*
1065 * Avoid ".", "..", and aliases of "." for obvious reasons.
1066 */
1067 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1068 dp == ip ||
1069 (fcnp->cn_flags & ISDOTDOT) ||
1070 (tcnp->cn_flags & ISDOTDOT) ||
1071 (ip->de_flag & DE_RENAME)) {
dadab5e9 1072 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1073 error = EINVAL;
1074 goto abortit;
1075 }
1076 ip->de_flag |= DE_RENAME;
1077 doingdirectory++;
1078 }
1079
1080 /*
1081 * When the target exists, both the directory
1082 * and target vnodes are returned locked.
1083 */
1084 dp = VTODE(tdvp);
1085 xp = tvp ? VTODE(tvp) : NULL;
1086 /*
1087 * Remember direntry place to use for destination
1088 */
1089 to_diroffset = dp->de_fndoffset;
1090 to_count = dp->de_fndcnt;
1091
1092 /*
1093 * If ".." must be changed (ie the directory gets a new
1094 * parent) then the source directory must not be in the
1095 * directory heirarchy above the target, as this would
1096 * orphan everything below the source directory. Also
1097 * the user must have write permission in the source so
1098 * as to be able to change "..". We must repeat the call
1099 * to namei, as the parent directory is unlocked by the
1100 * call to doscheckpath().
1101 */
dadab5e9
MD
1102 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_td);
1103 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1104 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1105 newparent = 1;
1106 if (doingdirectory && newparent) {
1107 if (error) /* write access check above */
1108 goto bad;
1109 if (xp != NULL)
1110 vput(tvp);
1111 /*
1112 * doscheckpath() vput()'s dp,
1113 * so we have to do a relookup afterwards
1114 */
1115 error = doscheckpath(ip, dp);
1116 if (error)
1117 goto out;
1118 if ((tcnp->cn_flags & SAVESTART) == 0)
1119 panic("msdosfs_rename: lost to startdir");
1120 error = relookup(tdvp, &tvp, tcnp);
1121 if (error)
1122 goto out;
1123 dp = VTODE(tdvp);
1124 xp = tvp ? VTODE(tvp) : NULL;
1125 }
1126
1127 if (xp != NULL) {
1128 /*
1129 * Target must be empty if a directory and have no links
1130 * to it. Also, ensure source and target are compatible
1131 * (both directories, or both not directories).
1132 */
1133 if (xp->de_Attributes & ATTR_DIRECTORY) {
1134 if (!dosdirempty(xp)) {
1135 error = ENOTEMPTY;
1136 goto bad;
1137 }
1138 if (!doingdirectory) {
1139 error = ENOTDIR;
1140 goto bad;
1141 }
1142 cache_purge(tdvp);
1143 } else if (doingdirectory) {
1144 error = EISDIR;
1145 goto bad;
1146 }
1147 error = removede(dp, xp);
1148 if (error)
1149 goto bad;
1150 vput(tvp);
1151 xp = NULL;
1152 }
1153
1154 /*
1155 * Convert the filename in tcnp into a dos filename. We copy this
1156 * into the denode and directory entry for the destination
1157 * file/directory.
1158 */
1159 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1160 if (error)
1161 goto abortit;
1162
1163 /*
1164 * Since from wasn't locked at various places above,
1165 * have to do a relookup here.
1166 */
1167 fcnp->cn_flags &= ~MODMASK;
1168 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1169 if ((fcnp->cn_flags & SAVESTART) == 0)
1170 panic("msdosfs_rename: lost from startdir");
1171 if (!newparent)
dadab5e9 1172 VOP_UNLOCK(tdvp, 0, td);
984263bc
MD
1173 if (relookup(fdvp, &fvp, fcnp) == 0)
1174 vrele(fdvp);
1175 if (fvp == NULL) {
1176 /*
1177 * From name has disappeared.
1178 */
1179 if (doingdirectory)
1180 panic("rename: lost dir entry");
1181 vrele(ap->a_fvp);
1182 if (newparent)
dadab5e9 1183 VOP_UNLOCK(tdvp, 0, td);
984263bc
MD
1184 vrele(tdvp);
1185 return 0;
1186 }
1187 xp = VTODE(fvp);
1188 zp = VTODE(fdvp);
1189 from_diroffset = zp->de_fndoffset;
1190
1191 /*
1192 * Ensure that the directory entry still exists and has not
1193 * changed till now. If the source is a file the entry may
1194 * have been unlinked or renamed. In either case there is
1195 * no further work to be done. If the source is a directory
1196 * then it cannot have been rmdir'ed or renamed; this is
1197 * prohibited by the DE_RENAME flag.
1198 */
1199 if (xp != ip) {
1200 if (doingdirectory)
1201 panic("rename: lost dir entry");
1202 vrele(ap->a_fvp);
dadab5e9 1203 VOP_UNLOCK(fvp, 0, td);
984263bc 1204 if (newparent)
dadab5e9 1205 VOP_UNLOCK(fdvp, 0, td);
984263bc
MD
1206 xp = NULL;
1207 } else {
1208 vrele(fvp);
1209 xp = NULL;
1210
1211 /*
1212 * First write a new entry in the destination
1213 * directory and mark the entry in the source directory
1214 * as deleted. Then move the denode to the correct hash
1215 * chain for its new location in the filesystem. And, if
1216 * we moved a directory, then update its .. entry to point
1217 * to the new parent directory.
1218 */
1219 bcopy(ip->de_Name, oldname, 11);
1220 bcopy(toname, ip->de_Name, 11); /* update denode */
1221 dp->de_fndoffset = to_diroffset;
1222 dp->de_fndcnt = to_count;
1223 error = createde(ip, dp, (struct denode **)0, tcnp);
1224 if (error) {
1225 bcopy(oldname, ip->de_Name, 11);
1226 if (newparent)
dadab5e9
MD
1227 VOP_UNLOCK(fdvp, 0, td);
1228 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1229 goto bad;
1230 }
1231 ip->de_refcnt++;
1232 zp->de_fndoffset = from_diroffset;
1233 error = removede(zp, ip);
1234 if (error) {
1235 /* XXX should really panic here, fs is corrupt */
1236 if (newparent)
dadab5e9
MD
1237 VOP_UNLOCK(fdvp, 0, td);
1238 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1239 goto bad;
1240 }
1241 if (!doingdirectory) {
1242 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1243 &ip->de_dirclust, 0);
1244 if (error) {
1245 /* XXX should really panic here, fs is corrupt */
1246 if (newparent)
dadab5e9
MD
1247 VOP_UNLOCK(fdvp, 0, td);
1248 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1249 goto bad;
1250 }
1251 if (ip->de_dirclust == MSDOSFSROOT)
1252 ip->de_diroffset = to_diroffset;
1253 else
1254 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1255 }
1256 reinsert(ip);
1257 if (newparent)
dadab5e9 1258 VOP_UNLOCK(fdvp, 0, td);
984263bc
MD
1259 }
1260
1261 /*
1262 * If we moved a directory to a new parent directory, then we must
1263 * fixup the ".." entry in the moved directory.
1264 */
1265 if (doingdirectory && newparent) {
1266 cn = ip->de_StartCluster;
1267 if (cn == MSDOSFSROOT) {
1268 /* this should never happen */
1269 panic("msdosfs_rename(): updating .. in root directory?");
1270 } else
1271 bn = cntobn(pmp, cn);
1272 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1273 NOCRED, &bp);
1274 if (error) {
1275 /* XXX should really panic here, fs is corrupt */
1276 brelse(bp);
dadab5e9 1277 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1278 goto bad;
1279 }
1280 dotdotp = (struct direntry *)bp->b_data + 1;
1281 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1282 if (FAT32(pmp))
1283 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1284 error = bwrite(bp);
1285 if (error) {
1286 /* XXX should really panic here, fs is corrupt */
dadab5e9 1287 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1288 goto bad;
1289 }
1290 }
1291
dadab5e9 1292 VOP_UNLOCK(fvp, 0, td);
984263bc
MD
1293bad:
1294 if (xp)
1295 vput(tvp);
1296 vput(tdvp);
1297out:
1298 ip->de_flag &= ~DE_RENAME;
1299 vrele(fdvp);
1300 vrele(fvp);
1301 return (error);
1302
1303}
1304
1305static struct {
1306 struct direntry dot;
1307 struct direntry dotdot;
1308} dosdirtemplate = {
1309 { ". ", " ", /* the . entry */
1310 ATTR_DIRECTORY, /* file attribute */
1311 0, /* reserved */
1312 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1313 { 0, 0 }, /* access date */
1314 { 0, 0 }, /* high bits of start cluster */
1315 { 210, 4 }, { 210, 4 }, /* modify time & date */
1316 { 0, 0 }, /* startcluster */
1317 { 0, 0, 0, 0 } /* filesize */
1318 },
1319 { ".. ", " ", /* the .. entry */
1320 ATTR_DIRECTORY, /* file attribute */
1321 0, /* reserved */
1322 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1323 { 0, 0 }, /* access date */
1324 { 0, 0 }, /* high bits of start cluster */
1325 { 210, 4 }, { 210, 4 }, /* modify time & date */
1326 { 0, 0 }, /* startcluster */
1327 { 0, 0, 0, 0 } /* filesize */
1328 }
1329};
1330
1331static int
1332msdosfs_mkdir(ap)
1333 struct vop_mkdir_args /* {
1334 struct vnode *a_dvp;
1335 struvt vnode **a_vpp;
1336 struvt componentname *a_cnp;
1337 struct vattr *a_vap;
1338 } */ *ap;
1339{
1340 struct componentname *cnp = ap->a_cnp;
1341 struct denode *dep;
1342 struct denode *pdep = VTODE(ap->a_dvp);
1343 struct direntry *denp;
1344 struct msdosfsmount *pmp = pdep->de_pmp;
1345 struct buf *bp;
1346 u_long newcluster, pcl;
1347 int bn;
1348 int error;
1349 struct denode ndirent;
1350 struct timespec ts;
1351
1352 /*
1353 * If this is the root directory and there is no space left we
1354 * can't do anything. This is because the root directory can not
1355 * change size.
1356 */
1357 if (pdep->de_StartCluster == MSDOSFSROOT
1358 && pdep->de_fndoffset >= pdep->de_FileSize) {
1359 error = ENOSPC;
1360 goto bad2;
1361 }
1362
1363 /*
1364 * Allocate a cluster to hold the about to be created directory.
1365 */
1366 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1367 if (error)
1368 goto bad2;
1369
1370 bzero(&ndirent, sizeof(ndirent));
1371 ndirent.de_pmp = pmp;
1372 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1373 getnanotime(&ts);
1374 DETIMES(&ndirent, &ts, &ts, &ts);
1375
1376 /*
1377 * Now fill the cluster with the "." and ".." entries. And write
1378 * the cluster to disk. This way it is there for the parent
1379 * directory to be pointing at if there were a crash.
1380 */
1381 bn = cntobn(pmp, newcluster);
1382 /* always succeeds */
1383 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0);
1384 bzero(bp->b_data, pmp->pm_bpcluster);
1385 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1386 denp = (struct direntry *)bp->b_data;
1387 putushort(denp[0].deStartCluster, newcluster);
1388 putushort(denp[0].deCDate, ndirent.de_CDate);
1389 putushort(denp[0].deCTime, ndirent.de_CTime);
1390 denp[0].deCHundredth = ndirent.de_CHun;
1391 putushort(denp[0].deADate, ndirent.de_ADate);
1392 putushort(denp[0].deMDate, ndirent.de_MDate);
1393 putushort(denp[0].deMTime, ndirent.de_MTime);
1394 pcl = pdep->de_StartCluster;
1395 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1396 pcl = 0;
1397 putushort(denp[1].deStartCluster, pcl);
1398 putushort(denp[1].deCDate, ndirent.de_CDate);
1399 putushort(denp[1].deCTime, ndirent.de_CTime);
1400 denp[1].deCHundredth = ndirent.de_CHun;
1401 putushort(denp[1].deADate, ndirent.de_ADate);
1402 putushort(denp[1].deMDate, ndirent.de_MDate);
1403 putushort(denp[1].deMTime, ndirent.de_MTime);
1404 if (FAT32(pmp)) {
1405 putushort(denp[0].deHighClust, newcluster >> 16);
1406 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1407 }
1408
1409 error = bwrite(bp);
1410 if (error)
1411 goto bad;
1412
1413 /*
1414 * Now build up a directory entry pointing to the newly allocated
1415 * cluster. This will be written to an empty slot in the parent
1416 * directory.
1417 */
1418#ifdef DIAGNOSTIC
1419 if ((cnp->cn_flags & HASBUF) == 0)
1420 panic("msdosfs_mkdir: no name");
1421#endif
1422 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1423 if (error)
1424 goto bad;
1425
1426 ndirent.de_Attributes = ATTR_DIRECTORY;
1427 ndirent.de_LowerCase = 0;
1428 ndirent.de_StartCluster = newcluster;
1429 ndirent.de_FileSize = 0;
1430 ndirent.de_dev = pdep->de_dev;
1431 ndirent.de_devvp = pdep->de_devvp;
1432 error = createde(&ndirent, pdep, &dep, cnp);
1433 if (error)
1434 goto bad;
1435 *ap->a_vpp = DETOV(dep);
1436 return (0);
1437
1438bad:
1439 clusterfree(pmp, newcluster, NULL);
1440bad2:
1441 return (error);
1442}
1443
1444static int
1445msdosfs_rmdir(ap)
1446 struct vop_rmdir_args /* {
1447 struct vnode *a_dvp;
1448 struct vnode *a_vp;
1449 struct componentname *a_cnp;
1450 } */ *ap;
1451{
dadab5e9
MD
1452 struct vnode *vp = ap->a_vp;
1453 struct vnode *dvp = ap->a_dvp;
1454 struct componentname *cnp = ap->a_cnp;
1455 struct denode *ip, *dp;
1456 struct thread *td = cnp->cn_td;
984263bc
MD
1457 int error;
1458
1459 ip = VTODE(vp);
1460 dp = VTODE(dvp);
1461
1462 /*
1463 * Verify the directory is empty (and valid).
1464 * (Rmdir ".." won't be valid since
1465 * ".." will contain a reference to
1466 * the current directory and thus be
1467 * non-empty.)
1468 */
1469 error = 0;
1470 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1471 error = ENOTEMPTY;
1472 goto out;
1473 }
1474 /*
1475 * Delete the entry from the directory. For dos filesystems this
1476 * gets rid of the directory entry on disk, the in memory copy
1477 * still exists but the de_refcnt is <= 0. This prevents it from
1478 * being found by deget(). When the vput() on dep is done we give
1479 * up access and eventually msdosfs_reclaim() will be called which
1480 * will remove it from the denode cache.
1481 */
1482 error = removede(dp, ip);
1483 if (error)
1484 goto out;
1485 /*
1486 * This is where we decrement the link count in the parent
1487 * directory. Since dos filesystems don't do this we just purge
1488 * the name cache.
1489 */
1490 cache_purge(dvp);
dadab5e9 1491 VOP_UNLOCK(dvp, 0, td);
984263bc
MD
1492 /*
1493 * Truncate the directory that is being deleted.
1494 */
dadab5e9 1495 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, td);
984263bc
MD
1496 cache_purge(vp);
1497
dadab5e9 1498 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
984263bc
MD
1499out:
1500 return (error);
1501}
1502
1503/*
1504 * DOS filesystems don't know what symlinks are.
1505 */
1506static int
1507msdosfs_symlink(ap)
1508 struct vop_symlink_args /* {
1509 struct vnode *a_dvp;
1510 struct vnode **a_vpp;
1511 struct componentname *a_cnp;
1512 struct vattr *a_vap;
1513 char *a_target;
1514 } */ *ap;
1515{
1516 return (EOPNOTSUPP);
1517}
1518
1519static int
1520msdosfs_readdir(ap)
1521 struct vop_readdir_args /* {
1522 struct vnode *a_vp;
1523 struct uio *a_uio;
1524 struct ucred *a_cred;
1525 int *a_eofflag;
1526 int *a_ncookies;
1527 u_long **a_cookies;
1528 } */ *ap;
1529{
1530 int error = 0;
1531 int diff;
1532 long n;
1533 int blsize;
1534 long on;
1535 u_long cn;
1536 u_long fileno;
1537 u_long dirsperblk;
1538 long bias = 0;
1539 daddr_t bn, lbn;
1540 struct buf *bp;
1541 struct denode *dep = VTODE(ap->a_vp);
1542 struct msdosfsmount *pmp = dep->de_pmp;
1543 struct direntry *dentp;
1544 struct dirent dirbuf;
1545 struct uio *uio = ap->a_uio;
1546 u_long *cookies = NULL;
1547 int ncookies = 0;
1548 off_t offset, off;
1549 int chksum = -1;
1550
1551#ifdef MSDOSFS_DEBUG
1552 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1553 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1554#endif
1555
1556 /*
1557 * msdosfs_readdir() won't operate properly on regular files since
1558 * it does i/o only with the the filesystem vnode, and hence can
1559 * retrieve the wrong block from the buffer cache for a plain file.
1560 * So, fail attempts to readdir() on a plain file.
1561 */
1562 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1563 return (ENOTDIR);
1564
1565 /*
1566 * To be safe, initialize dirbuf
1567 */
1568 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1569
1570 /*
1571 * If the user buffer is smaller than the size of one dos directory
1572 * entry or the file offset is not a multiple of the size of a
1573 * directory entry, then we fail the read.
1574 */
1575 off = offset = uio->uio_offset;
1576 if (uio->uio_resid < sizeof(struct direntry) ||
1577 (offset & (sizeof(struct direntry) - 1)))
1578 return (EINVAL);
1579
1580 if (ap->a_ncookies) {
1581 ncookies = uio->uio_resid / 16;
1582 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1583 M_WAITOK);
1584 *ap->a_cookies = cookies;
1585 *ap->a_ncookies = ncookies;
1586 }
1587
1588 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1589
1590 /*
1591 * If they are reading from the root directory then, we simulate
1592 * the . and .. entries since these don't exist in the root
1593 * directory. We also set the offset bias to make up for having to
1594 * simulate these entries. By this I mean that at file offset 64 we
1595 * read the first entry in the root directory that lives on disk.
1596 */
1597 if (dep->de_StartCluster == MSDOSFSROOT
1598 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1599#if 0
1600 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1601 offset);
1602#endif
1603 bias = 2 * sizeof(struct direntry);
1604 if (offset < bias) {
1605 for (n = (int)offset / sizeof(struct direntry);
1606 n < 2; n++) {
1607 if (FAT32(pmp))
1608 dirbuf.d_fileno = cntobn(pmp,
1609 pmp->pm_rootdirblk)
1610 * dirsperblk;
1611 else
1612 dirbuf.d_fileno = 1;
1613 dirbuf.d_type = DT_DIR;
1614 switch (n) {
1615 case 0:
1616 dirbuf.d_namlen = 1;
1617 strcpy(dirbuf.d_name, ".");
1618 break;
1619 case 1:
1620 dirbuf.d_namlen = 2;
1621 strcpy(dirbuf.d_name, "..");
1622 break;
1623 }
1624 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1625 if (uio->uio_resid < dirbuf.d_reclen)
1626 goto out;
1627 error = uiomove((caddr_t) &dirbuf,
1628 dirbuf.d_reclen, uio);
1629 if (error)
1630 goto out;
1631 offset += sizeof(struct direntry);
1632 off = offset;
1633 if (cookies) {
1634 *cookies++ = offset;
1635 if (--ncookies <= 0)
1636 goto out;
1637 }
1638 }
1639 }
1640 }
1641
1642 off = offset;
1643 while (uio->uio_resid > 0) {
1644 lbn = de_cluster(pmp, offset - bias);
1645 on = (offset - bias) & pmp->pm_crbomask;
1646 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1647 diff = dep->de_FileSize - (offset - bias);
1648 if (diff <= 0)
1649 break;
1650 n = min(n, diff);
1651 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1652 if (error)
1653 break;
1654 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1655 if (error) {
1656 brelse(bp);
1657 return (error);
1658 }
1659 n = min(n, blsize - bp->b_resid);
1660
1661 /*
1662 * Convert from dos directory entries to fs-independent
1663 * directory entries.
1664 */
1665 for (dentp = (struct direntry *)(bp->b_data + on);
1666 (char *)dentp < bp->b_data + on + n;
1667 dentp++, offset += sizeof(struct direntry)) {
1668#if 0
1669 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1670 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1671#endif
1672 /*
1673 * If this is an unused entry, we can stop.
1674 */
1675 if (dentp->deName[0] == SLOT_EMPTY) {
1676 brelse(bp);
1677 goto out;
1678 }
1679 /*
1680 * Skip deleted entries.
1681 */
1682 if (dentp->deName[0] == SLOT_DELETED) {
1683 chksum = -1;
1684 continue;
1685 }
1686
1687 /*
1688 * Handle Win95 long directory entries
1689 */
1690 if (dentp->deAttributes == ATTR_WIN95) {
1691 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1692 continue;
1693 chksum = win2unixfn((struct winentry *)dentp,
1694 &dirbuf, chksum,
1695 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1696 pmp->pm_u2w);
1697 continue;
1698 }
1699
1700 /*
1701 * Skip volume labels
1702 */
1703 if (dentp->deAttributes & ATTR_VOLUME) {
1704 chksum = -1;
1705 continue;
1706 }
1707 /*
1708 * This computation of d_fileno must match
1709 * the computation of va_fileid in
1710 * msdosfs_getattr.
1711 */
1712 if (dentp->deAttributes & ATTR_DIRECTORY) {
1713 fileno = getushort(dentp->deStartCluster);
1714 if (FAT32(pmp))
1715 fileno |= getushort(dentp->deHighClust) << 16;
1716 /* if this is the root directory */
1717 if (fileno == MSDOSFSROOT)
1718 if (FAT32(pmp))
1719 fileno = cntobn(pmp,
1720 pmp->pm_rootdirblk)
1721 * dirsperblk;
1722 else
1723 fileno = 1;
1724 else
1725 fileno = cntobn(pmp, fileno) * dirsperblk;
1726 dirbuf.d_fileno = fileno;
1727 dirbuf.d_type = DT_DIR;
1728 } else {
1729 dirbuf.d_fileno = offset / sizeof(struct direntry);
1730 dirbuf.d_type = DT_REG;
1731 }
1732 if (chksum != winChksum(dentp->deName))
1733 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1734 (u_char *)dirbuf.d_name,
1735 dentp->deLowerCase |
1736 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1737 (LCASE_BASE | LCASE_EXT) : 0),
1738 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1739 pmp->pm_d2u,
1740 pmp->pm_flags & MSDOSFSMNT_ULTABLE,
1741 pmp->pm_ul);
1742 else
1743 dirbuf.d_name[dirbuf.d_namlen] = 0;
1744 chksum = -1;
1745 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1746 if (uio->uio_resid < dirbuf.d_reclen) {
1747 brelse(bp);
1748 goto out;
1749 }
1750 error = uiomove((caddr_t) &dirbuf,
1751 dirbuf.d_reclen, uio);
1752 if (error) {
1753 brelse(bp);
1754 goto out;
1755 }
1756 if (cookies) {
1757 *cookies++ = offset + sizeof(struct direntry);
1758 if (--ncookies <= 0) {
1759 brelse(bp);
1760 goto out;
1761 }
1762 }
1763 off = offset + sizeof(struct direntry);
1764 }
1765 brelse(bp);
1766 }
1767out:
1768 /* Subtract unused cookies */
1769 if (ap->a_ncookies)
1770 *ap->a_ncookies -= ncookies;
1771
1772 uio->uio_offset = off;
1773
1774 /*
1775 * Set the eofflag (NFS uses it)
1776 */
1777 if (ap->a_eofflag) {
1778 if (dep->de_FileSize - (offset - bias) <= 0)
1779 *ap->a_eofflag = 1;
1780 else
1781 *ap->a_eofflag = 0;
1782 }
1783 return (error);
1784}
1785
1786/*
1787 * vp - address of vnode file the file
1788 * bn - which cluster we are interested in mapping to a filesystem block number.
1789 * vpp - returns the vnode for the block special file holding the filesystem
1790 * containing the file of interest
1791 * bnp - address of where to return the filesystem relative block number
1792 */
1793static int
1794msdosfs_bmap(ap)
1795 struct vop_bmap_args /* {
1796 struct vnode *a_vp;
1797 daddr_t a_bn;
1798 struct vnode **a_vpp;
1799 daddr_t *a_bnp;
1800 int *a_runp;
1801 int *a_runb;
1802 } */ *ap;
1803{
1804 struct denode *dep = VTODE(ap->a_vp);
1805
1806 if (ap->a_vpp != NULL)
1807 *ap->a_vpp = dep->de_devvp;
1808 if (ap->a_bnp == NULL)
1809 return (0);
1810 if (ap->a_runp) {
1811 /*
1812 * Sequential clusters should be counted here.
1813 */
1814 *ap->a_runp = 0;
1815 }
1816 if (ap->a_runb) {
1817 *ap->a_runb = 0;
1818 }
1819 return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
1820}
1821
1822static int
1823msdosfs_strategy(ap)
1824 struct vop_strategy_args /* {
1825 struct vnode *a_vp;
1826 struct buf *a_bp;
1827 } */ *ap;
1828{
1829 struct buf *bp = ap->a_bp;
1830 struct denode *dep = VTODE(bp->b_vp);
1831 struct vnode *vp;
1832 int error = 0;
1833
1834 if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
1835 panic("msdosfs_strategy: spec");
1836 /*
1837 * If we don't already know the filesystem relative block number
1838 * then get it using pcbmap(). If pcbmap() returns the block
1839 * number as -1 then we've got a hole in the file. DOS filesystems
1840 * don't allow files with holes, so we shouldn't ever see this.
1841 */
1842 if (bp->b_blkno == bp->b_lblkno) {
1843 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0, 0);
1844 if (error) {
1845 bp->b_error = error;
1846 bp->b_flags |= B_ERROR;
1847 biodone(bp);
1848 return (error);
1849 }
1850 if ((long)bp->b_blkno == -1)
1851 vfs_bio_clrbuf(bp);
1852 }
1853 if (bp->b_blkno == -1) {
1854 biodone(bp);
1855 return (0);
1856 }
1857 /*
1858 * Read/write the block from/to the disk that contains the desired
1859 * file block.
1860 */
1861 vp = dep->de_devvp;
1862 bp->b_dev = vp->v_rdev;
1863 VOP_STRATEGY(vp, bp);
1864 return (0);
1865}
1866
1867static int
1868msdosfs_print(ap)
1869 struct vop_print_args /* {
1870 struct vnode *vp;
1871 } */ *ap;
1872{
1873 struct denode *dep = VTODE(ap->a_vp);
1874
1875 printf(
1876 "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ",
1877 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1878 printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev));
1879 lockmgr_printinfo(&dep->de_lock);
1880 printf("\n");
1881 return (0);
1882}
1883
1884static int
1885msdosfs_pathconf(ap)
1886 struct vop_pathconf_args /* {
1887 struct vnode *a_vp;
1888 int a_name;
1889 int *a_retval;
1890 } */ *ap;
1891{
1892 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1893
1894 switch (ap->a_name) {
1895 case _PC_LINK_MAX:
1896 *ap->a_retval = 1;
1897 return (0);
1898 case _PC_NAME_MAX:
1899 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1900 return (0);
1901 case _PC_PATH_MAX:
1902 *ap->a_retval = PATH_MAX;
1903 return (0);
1904 case _PC_CHOWN_RESTRICTED:
1905 *ap->a_retval = 1;
1906 return (0);
1907 case _PC_NO_TRUNC:
1908 *ap->a_retval = 0;
1909 return (0);
1910 default:
1911 return (EINVAL);
1912 }
1913 /* NOTREACHED */
1914}
1915
1916/*
1917 * get page routine
1918 *
1919 * XXX By default, wimp out... note that a_offset is ignored (and always
1920 * XXX has been).
1921 */
1922int
1923msdosfs_getpages(ap)
1924 struct vop_getpages_args *ap;
1925{
1926 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
1927 ap->a_reqpage);
1928}
1929
1930/*
1931 * put page routine
1932 *
1933 * XXX By default, wimp out... note that a_offset is ignored (and always
1934 * XXX has been).
1935 */
1936int
1937msdosfs_putpages(ap)
1938 struct vop_putpages_args *ap;
1939{
1940 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
1941 ap->a_sync, ap->a_rtvals);
1942}
1943
1944/* Global vfs data structures for msdosfs */
1945vop_t **msdosfs_vnodeop_p;
1946static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1947 { &vop_default_desc, (vop_t *) vop_defaultop },
1948 { &vop_access_desc, (vop_t *) msdosfs_access },
1949 { &vop_bmap_desc, (vop_t *) msdosfs_bmap },
1950 { &vop_cachedlookup_desc, (vop_t *) msdosfs_lookup },
1951 { &vop_close_desc, (vop_t *) msdosfs_close },
1952 { &vop_create_desc, (vop_t *) msdosfs_create },
1953 { &vop_fsync_desc, (vop_t *) msdosfs_fsync },
1954 { &vop_getattr_desc, (vop_t *) msdosfs_getattr },
1955 { &vop_inactive_desc, (vop_t *) msdosfs_inactive },
1956 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
1957 { &vop_link_desc, (vop_t *) msdosfs_link },
1958 { &vop_lock_desc, (vop_t *) vop_stdlock },
1959 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
1960 { &vop_mkdir_desc, (vop_t *) msdosfs_mkdir },
1961 { &vop_mknod_desc, (vop_t *) msdosfs_mknod },
1962 { &vop_pathconf_desc, (vop_t *) msdosfs_pathconf },
1963 { &vop_print_desc, (vop_t *) msdosfs_print },
1964 { &vop_read_desc, (vop_t *) msdosfs_read },
1965 { &vop_readdir_desc, (vop_t *) msdosfs_readdir },
1966 { &vop_reclaim_desc, (vop_t *) msdosfs_reclaim },
1967 { &vop_remove_desc, (vop_t *) msdosfs_remove },
1968 { &vop_rename_desc, (vop_t *) msdosfs_rename },
1969 { &vop_rmdir_desc, (vop_t *) msdosfs_rmdir },
1970 { &vop_setattr_desc, (vop_t *) msdosfs_setattr },
1971 { &vop_strategy_desc, (vop_t *) msdosfs_strategy },
1972 { &vop_symlink_desc, (vop_t *) msdosfs_symlink },
1973 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
1974 { &vop_write_desc, (vop_t *) msdosfs_write },
1975 { &vop_getpages_desc, (vop_t *) msdosfs_getpages },
1976 { &vop_putpages_desc, (vop_t *) msdosfs_putpages },
1977 { NULL, NULL }
1978};
1979static struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1980 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1981
1982VNODEOP_SET(msdosfs_vnodeop_opv_desc);