1 /* $FreeBSD: src/sys/msdosfs/msdosfs_vnops.c,v 1.95.2.4 2003/06/13 15:05:47 trhodes Exp $ */
2 /* $DragonFly: src/sys/vfs/msdosfs/msdosfs_vnops.c,v 1.3 2003/06/19 01:55:06 dillon Exp $ */
3 /* $NetBSD: msdosfs_vnops.c,v 1.68 1998/02/10 14:10:04 mrg Exp $ */
6 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
7 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
9 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
37 * Written by Paul Popelka (paulp@uts.amdahl.com)
39 * You can do anything you want with this software, just don't say you wrote
40 * it, and don't remove this notice.
42 * This software is provided "as is".
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.
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/namei.h>
55 #include <sys/resourcevar.h> /* defines plimit structure in proc struct */
56 #include <sys/kernel.h>
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>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_zone.h>
70 #include <vm/vnode_pager.h>
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>
80 #define DOS_FILESIZE_MAX 0xffffffff
83 * Prototypes for MSDOSFS vnode operations
85 static int msdosfs_create __P((struct vop_create_args *));
86 static int msdosfs_mknod __P((struct vop_mknod_args *));
87 static int msdosfs_close __P((struct vop_close_args *));
88 static int msdosfs_access __P((struct vop_access_args *));
89 static int msdosfs_getattr __P((struct vop_getattr_args *));
90 static int msdosfs_setattr __P((struct vop_setattr_args *));
91 static int msdosfs_read __P((struct vop_read_args *));
92 static int msdosfs_write __P((struct vop_write_args *));
93 static int msdosfs_fsync __P((struct vop_fsync_args *));
94 static int msdosfs_remove __P((struct vop_remove_args *));
95 static int msdosfs_link __P((struct vop_link_args *));
96 static int msdosfs_rename __P((struct vop_rename_args *));
97 static int msdosfs_mkdir __P((struct vop_mkdir_args *));
98 static int msdosfs_rmdir __P((struct vop_rmdir_args *));
99 static int msdosfs_symlink __P((struct vop_symlink_args *));
100 static int msdosfs_readdir __P((struct vop_readdir_args *));
101 static int msdosfs_bmap __P((struct vop_bmap_args *));
102 static int msdosfs_strategy __P((struct vop_strategy_args *));
103 static int msdosfs_print __P((struct vop_print_args *));
104 static int msdosfs_pathconf __P((struct vop_pathconf_args *ap));
105 static int msdosfs_getpages __P((struct vop_getpages_args *));
106 static int msdosfs_putpages __P((struct vop_putpages_args *));
109 * Some general notes:
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.
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.
134 struct vop_create_args /* {
136 struct vnode **a_vpp;
137 struct componentname *a_cnp;
141 struct componentname *cnp = ap->a_cnp;
142 struct denode ndirent;
144 struct denode *pdep = VTODE(ap->a_dvp);
149 printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
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
157 if (pdep->de_StartCluster == MSDOSFSROOT
158 && pdep->de_fndoffset >= pdep->de_FileSize) {
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
170 if ((cnp->cn_flags & HASBUF) == 0)
171 panic("msdosfs_create: no name");
173 bzero(&ndirent, sizeof(ndirent));
174 error = uniqdosname(pdep, cnp, ndirent.de_Name);
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;
188 DETIMES(&ndirent, &ts, &ts, &ts);
189 error = createde(&ndirent, pdep, &dep, cnp);
192 *ap->a_vpp = DETOV(dep);
201 struct vop_mknod_args /* {
203 struct vnode **a_vpp;
204 struct componentname *a_cnp;
209 switch (ap->a_vap->va_type) {
211 return (msdosfs_mkdir((struct vop_mkdir_args *)ap));
215 return (msdosfs_create((struct vop_create_args *)ap));
226 struct vop_close_args /* {
229 struct ucred *a_cred;
233 struct vnode *vp = ap->a_vp;
234 struct denode *dep = VTODE(vp);
237 simple_lock(&vp->v_interlock);
238 if (vp->v_usecount > 1) {
240 DETIMES(dep, &ts, &ts, &ts);
242 simple_unlock(&vp->v_interlock);
248 struct vop_access_args /* {
251 struct ucred *a_cred;
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;
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;
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.
273 switch (vp->v_type) {
277 if (vp->v_mount->mnt_flag & MNT_RDONLY)
285 /* User id 0 always gets access. */
286 if (cred->cr_uid == 0)
291 /* Otherwise, check the owner. */
292 if (cred->cr_uid == pmp->pm_uid) {
299 return (file_mode & mask) == mask ? 0 : EACCES;
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) {
311 return (file_mode & mask) == mask ? 0 : EACCES;
314 /* Otherwise, check everyone else. */
321 return (file_mode & mask) == mask ? 0 : EACCES;
326 struct vop_getattr_args /* {
329 struct ucred *a_cred;
333 struct denode *dep = VTODE(ap->a_vp);
334 struct msdosfsmount *pmp = dep->de_pmp;
335 struct vattr *vap = ap->a_vap;
338 u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
342 DETIMES(dep, &ts, &ts, &ts);
343 vap->va_fsid = dev2udev(dep->de_dev);
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
349 if (dep->de_Attributes & ATTR_DIRECTORY) {
350 fileid = cntobn(pmp, dep->de_StartCluster) * dirsperblk;
351 if (dep->de_StartCluster == MSDOSFSROOT)
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);
359 vap->va_fileid = fileid;
360 if ((dep->de_Attributes & ATTR_READONLY) == 0)
361 mode = S_IRWXU|S_IRWXG|S_IRWXO;
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;
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);
375 vap->va_atime = vap->va_mtime;
376 vap->va_ctime = vap->va_mtime;
379 if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
380 vap->va_flags |= SF_ARCHIVED;
382 vap->va_blocksize = pmp->pm_bpcluster;
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;
392 struct vop_setattr_args /* {
395 struct ucred *a_cred;
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;
407 printf("msdosfs_setattr(): vp %p, vap %p, cred %p, p %p\n",
408 ap->a_vp, vap, cred, ap->a_p);
412 * Check for unsettable attributes.
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)) {
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);
429 if (vap->va_flags != VNOVAL) {
430 if (vp->v_mount->mnt_flag & MNT_RDONLY)
432 if (cred->cr_uid != pmp->pm_uid &&
433 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
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
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.
447 if (cred->cr_uid != 0) {
448 if (vap->va_flags & SF_SETTABLE)
451 if (vap->va_flags & ~SF_ARCHIVED)
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;
460 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
464 if (vp->v_mount->mnt_flag & MNT_RDONLY)
467 if (uid == (uid_t)VNOVAL)
470 if (gid == (gid_t)VNOVAL)
472 if ((cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
473 (gid != pmp->pm_gid && !groupmember(gid, cred))) &&
474 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
476 if (uid != pmp->pm_uid || gid != pmp->pm_gid)
480 if (vap->va_size != VNOVAL) {
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.
486 switch (vp->v_type) {
492 if (vp->v_mount->mnt_flag & MNT_RDONLY)
498 error = detrunc(dep, vap->va_size, 0, cred, ap->a_p);
502 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
503 if (vp->v_mount->mnt_flag & MNT_RDONLY)
505 if (cred->cr_uid != pmp->pm_uid &&
506 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)) &&
507 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
508 (error = VOP_ACCESS(ap->a_vp, VWRITE, cred, ap->a_p))))
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,
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);
522 dep->de_Attributes |= ATTR_ARCHIVE;
523 dep->de_flag |= DE_MODIFIED;
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
531 if (vap->va_mode != (mode_t)VNOVAL) {
532 if (vp->v_mount->mnt_flag & MNT_RDONLY)
534 if (cred->cr_uid != pmp->pm_uid &&
535 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
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;
542 dep->de_Attributes |= ATTR_READONLY;
543 dep->de_Attributes |= ATTR_ARCHIVE;
544 dep->de_flag |= DE_MODIFIED;
547 return (deupdat(dep, 1));
552 struct vop_read_args /* {
556 struct ucred *a_cred;
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;
576 if (uio->uio_offset < 0)
579 if ((uoff_t)uio->uio_offset > DOS_FILESIZE_MAX)
582 * If they didn't ask for any data, then we are done.
584 orig_resid = uio->uio_resid;
588 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
590 isadir = dep->de_Attributes & ATTR_DIRECTORY;
592 if (uio->uio_offset >= dep->de_FileSize)
594 lbn = de_cluster(pmp, uio->uio_offset);
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.
601 /* convert cluster # to block # */
602 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
603 if (error == E2BIG) {
608 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
610 blsize = pmp->pm_bpcluster;
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);
618 error = bread(vp, lbn, blsize, NOCRED, &bp);
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;
631 diff = blsize - bp->b_resid;
634 error = uiomove(bp->b_data + on, (int) n, uio);
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;
644 * Write data to a file or directory.
648 struct vop_write_args /* {
652 struct ucred *a_cred;
663 int ioflag = ap->a_ioflag;
664 struct uio *uio = ap->a_uio;
665 struct proc *p = uio->uio_procp;
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;
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);
679 switch (vp->v_type) {
681 if (ioflag & IO_APPEND)
682 uio->uio_offset = dep->de_FileSize;
688 panic("msdosfs_write(): bad file type");
691 if (uio->uio_offset < 0)
694 if (uio->uio_resid == 0)
698 * If they've exceeded their filesize limit, tell them about it.
701 ((uoff_t)uio->uio_offset + uio->uio_resid >
702 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
707 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
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.
716 if (uio->uio_offset > dep->de_FileSize) {
717 error = deextend(dep, uio->uio_offset, cred);
723 * Remember some values in case the write fails.
725 resid = uio->uio_resid;
726 osize = dep->de_FileSize;
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.
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)))
738 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
740 lastcn = de_clcount(pmp, osize) - 1;
743 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
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);
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)) {
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.
766 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
769 * Do the bmap now, since pcbmap needs buffers
770 * for the fat table. (see msdosfs_strategy)
772 if (bp->b_blkno == bp->b_lblkno) {
773 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno,
778 if (bp->b_blkno == -1) {
781 error = EIO; /* XXX */
786 * The block we need to write into exists, so read it in.
788 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
796 * Should these vnode_pager_* functions be done on dir
801 * Copy the data from user space into the buf header.
803 error = uiomove(bp->b_data + croffset, n, uio);
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.
816 if (ioflag & IO_SYNC)
818 else if (n + croffset == pmp->pm_bpcluster)
822 dep->de_flag |= DE_UPDATE;
823 } while (error == 0 && uio->uio_resid > 0);
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.
831 if (ioflag & IO_UNIT) {
832 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
833 uio->uio_offset -= resid - uio->uio_resid;
834 uio->uio_resid = resid;
836 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
837 if (uio->uio_resid != resid)
840 } else if (ioflag & IO_SYNC)
841 error = deupdat(dep, 1);
846 * Flush the blocks of a file to disk.
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.
853 struct vop_fsync_args /* {
855 struct ucred *a_cred;
860 struct vnode *vp = ap->a_vp;
862 struct buf *bp, *nbp;
865 * Flush all dirty buffers associated with a vnode.
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))
873 if ((bp->b_flags & B_DELWRI) == 0)
874 panic("msdosfs_fsync: not dirty");
880 while (vp->v_numoutput) {
881 vp->v_flag |= VBWAIT;
882 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "msdosfsn", 0);
885 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
886 vprint("msdosfs_fsync: dirty", vp);
891 return (deupdat(VTODE(vp), ap->a_waitfor == MNT_WAIT));
896 struct vop_remove_args /* {
899 struct componentname *a_cnp;
902 struct denode *dep = VTODE(ap->a_vp);
903 struct denode *ddep = VTODE(ap->a_dvp);
906 if (ap->a_vp->v_type == VDIR)
909 error = removede(ddep, dep);
911 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
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.
923 struct vop_link_args /* {
924 struct vnode *a_tdvp;
926 struct componentname *a_cnp;
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".
937 * What follows is the basic algorithm:
940 * if (dest file exists) {
943 * if (dest and src in same directory) {
944 * rewrite name in existing directory slot
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
953 * if (dest directory exists) {
954 * if (dest is not empty) {
957 * remove dest directory
959 * if (dest and src in same directory) {
960 * rewrite name in existing entry
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
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
976 * all denodes should be released
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.
985 struct vop_rename_args /* {
986 struct vnode *a_fdvp;
988 struct componentname *a_fcnp;
989 struct vnode *a_tdvp;
991 struct componentname *a_tcnp;
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;
1000 struct proc *p = fcnp->cn_proc;
1001 struct denode *ip, *xp, *dp, *zp;
1002 u_char toname[11], oldname[11];
1003 u_long from_diroffset, to_diroffset;
1005 int doingdirectory = 0, newparent = 0;
1009 struct denode *fddep; /* from file's parent directory */
1010 struct msdosfsmount *pmp;
1011 struct direntry *dotdotp;
1014 fddep = VTODE(ap->a_fdvp);
1015 pmp = fddep->de_pmp;
1017 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1020 if ((tcnp->cn_flags & HASBUF) == 0 ||
1021 (fcnp->cn_flags & HASBUF) == 0)
1022 panic("msdosfs_rename: no name");
1025 * Check for cross-device rename.
1027 if ((fvp->v_mount != tdvp->v_mount) ||
1028 (tvp && (fvp->v_mount != tvp->v_mount))) {
1043 * If source and dest are the same, do nothing.
1050 error = vn_lock(fvp, LK_EXCLUSIVE, p);
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.
1062 if (ip->de_Attributes & ATTR_DIRECTORY) {
1064 * Avoid ".", "..", and aliases of "." for obvious reasons.
1066 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1068 (fcnp->cn_flags & ISDOTDOT) ||
1069 (tcnp->cn_flags & ISDOTDOT) ||
1070 (ip->de_flag & DE_RENAME)) {
1071 VOP_UNLOCK(fvp, 0, p);
1075 ip->de_flag |= DE_RENAME;
1080 * When the target exists, both the directory
1081 * and target vnodes are returned locked.
1084 xp = tvp ? VTODE(tvp) : NULL;
1086 * Remember direntry place to use for destination
1088 to_diroffset = dp->de_fndoffset;
1089 to_count = dp->de_fndcnt;
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().
1101 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc);
1102 VOP_UNLOCK(fvp, 0, p);
1103 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1105 if (doingdirectory && newparent) {
1106 if (error) /* write access check above */
1111 * doscheckpath() vput()'s dp,
1112 * so we have to do a relookup afterwards
1114 error = doscheckpath(ip, dp);
1117 if ((tcnp->cn_flags & SAVESTART) == 0)
1118 panic("msdosfs_rename: lost to startdir");
1119 error = relookup(tdvp, &tvp, tcnp);
1123 xp = tvp ? VTODE(tvp) : NULL;
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).
1132 if (xp->de_Attributes & ATTR_DIRECTORY) {
1133 if (!dosdirempty(xp)) {
1137 if (!doingdirectory) {
1142 } else if (doingdirectory) {
1146 error = removede(dp, xp);
1154 * Convert the filename in tcnp into a dos filename. We copy this
1155 * into the denode and directory entry for the destination
1158 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1163 * Since from wasn't locked at various places above,
1164 * have to do a relookup here.
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");
1171 VOP_UNLOCK(tdvp, 0, p);
1172 if (relookup(fdvp, &fvp, fcnp) == 0)
1176 * From name has disappeared.
1179 panic("rename: lost dir entry");
1182 VOP_UNLOCK(tdvp, 0, p);
1188 from_diroffset = zp->de_fndoffset;
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.
1200 panic("rename: lost dir entry");
1202 VOP_UNLOCK(fvp, 0, p);
1204 VOP_UNLOCK(fdvp, 0, p);
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.
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);
1224 bcopy(oldname, ip->de_Name, 11);
1226 VOP_UNLOCK(fdvp, 0, p);
1227 VOP_UNLOCK(fvp, 0, p);
1231 zp->de_fndoffset = from_diroffset;
1232 error = removede(zp, ip);
1234 /* XXX should really panic here, fs is corrupt */
1236 VOP_UNLOCK(fdvp, 0, p);
1237 VOP_UNLOCK(fvp, 0, p);
1240 if (!doingdirectory) {
1241 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1242 &ip->de_dirclust, 0);
1244 /* XXX should really panic here, fs is corrupt */
1246 VOP_UNLOCK(fdvp, 0, p);
1247 VOP_UNLOCK(fvp, 0, p);
1250 if (ip->de_dirclust == MSDOSFSROOT)
1251 ip->de_diroffset = to_diroffset;
1253 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1257 VOP_UNLOCK(fdvp, 0, p);
1261 * If we moved a directory to a new parent directory, then we must
1262 * fixup the ".." entry in the moved directory.
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?");
1270 bn = cntobn(pmp, cn);
1271 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1274 /* XXX should really panic here, fs is corrupt */
1276 VOP_UNLOCK(fvp, 0, p);
1279 dotdotp = (struct direntry *)bp->b_data + 1;
1280 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1282 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1285 /* XXX should really panic here, fs is corrupt */
1286 VOP_UNLOCK(fvp, 0, p);
1291 VOP_UNLOCK(fvp, 0, p);
1297 ip->de_flag &= ~DE_RENAME;
1305 struct direntry dot;
1306 struct direntry dotdot;
1307 } dosdirtemplate = {
1308 { ". ", " ", /* the . entry */
1309 ATTR_DIRECTORY, /* file attribute */
1311 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1312 { 0, 0 }, /* access date */
1313 { 0, 0 }, /* high bits of start cluster */
1314 { 210, 4 }, { 210, 4 }, /* modify time & date */
1315 { 0, 0 }, /* startcluster */
1316 { 0, 0, 0, 0 } /* filesize */
1318 { ".. ", " ", /* the .. entry */
1319 ATTR_DIRECTORY, /* file attribute */
1321 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1322 { 0, 0 }, /* access date */
1323 { 0, 0 }, /* high bits of start cluster */
1324 { 210, 4 }, { 210, 4 }, /* modify time & date */
1325 { 0, 0 }, /* startcluster */
1326 { 0, 0, 0, 0 } /* filesize */
1332 struct vop_mkdir_args /* {
1333 struct vnode *a_dvp;
1334 struvt vnode **a_vpp;
1335 struvt componentname *a_cnp;
1336 struct vattr *a_vap;
1339 struct componentname *cnp = ap->a_cnp;
1341 struct denode *pdep = VTODE(ap->a_dvp);
1342 struct direntry *denp;
1343 struct msdosfsmount *pmp = pdep->de_pmp;
1345 u_long newcluster, pcl;
1348 struct denode ndirent;
1352 * If this is the root directory and there is no space left we
1353 * can't do anything. This is because the root directory can not
1356 if (pdep->de_StartCluster == MSDOSFSROOT
1357 && pdep->de_fndoffset >= pdep->de_FileSize) {
1363 * Allocate a cluster to hold the about to be created directory.
1365 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1369 bzero(&ndirent, sizeof(ndirent));
1370 ndirent.de_pmp = pmp;
1371 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1373 DETIMES(&ndirent, &ts, &ts, &ts);
1376 * Now fill the cluster with the "." and ".." entries. And write
1377 * the cluster to disk. This way it is there for the parent
1378 * directory to be pointing at if there were a crash.
1380 bn = cntobn(pmp, newcluster);
1381 /* always succeeds */
1382 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0);
1383 bzero(bp->b_data, pmp->pm_bpcluster);
1384 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1385 denp = (struct direntry *)bp->b_data;
1386 putushort(denp[0].deStartCluster, newcluster);
1387 putushort(denp[0].deCDate, ndirent.de_CDate);
1388 putushort(denp[0].deCTime, ndirent.de_CTime);
1389 denp[0].deCHundredth = ndirent.de_CHun;
1390 putushort(denp[0].deADate, ndirent.de_ADate);
1391 putushort(denp[0].deMDate, ndirent.de_MDate);
1392 putushort(denp[0].deMTime, ndirent.de_MTime);
1393 pcl = pdep->de_StartCluster;
1394 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1396 putushort(denp[1].deStartCluster, pcl);
1397 putushort(denp[1].deCDate, ndirent.de_CDate);
1398 putushort(denp[1].deCTime, ndirent.de_CTime);
1399 denp[1].deCHundredth = ndirent.de_CHun;
1400 putushort(denp[1].deADate, ndirent.de_ADate);
1401 putushort(denp[1].deMDate, ndirent.de_MDate);
1402 putushort(denp[1].deMTime, ndirent.de_MTime);
1404 putushort(denp[0].deHighClust, newcluster >> 16);
1405 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1413 * Now build up a directory entry pointing to the newly allocated
1414 * cluster. This will be written to an empty slot in the parent
1418 if ((cnp->cn_flags & HASBUF) == 0)
1419 panic("msdosfs_mkdir: no name");
1421 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1425 ndirent.de_Attributes = ATTR_DIRECTORY;
1426 ndirent.de_LowerCase = 0;
1427 ndirent.de_StartCluster = newcluster;
1428 ndirent.de_FileSize = 0;
1429 ndirent.de_dev = pdep->de_dev;
1430 ndirent.de_devvp = pdep->de_devvp;
1431 error = createde(&ndirent, pdep, &dep, cnp);
1434 *ap->a_vpp = DETOV(dep);
1438 clusterfree(pmp, newcluster, NULL);
1445 struct vop_rmdir_args /* {
1446 struct vnode *a_dvp;
1448 struct componentname *a_cnp;
1451 register struct vnode *vp = ap->a_vp;
1452 register struct vnode *dvp = ap->a_dvp;
1453 register struct componentname *cnp = ap->a_cnp;
1454 register struct denode *ip, *dp;
1455 struct proc *p = cnp->cn_proc;
1462 * Verify the directory is empty (and valid).
1463 * (Rmdir ".." won't be valid since
1464 * ".." will contain a reference to
1465 * the current directory and thus be
1469 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1474 * Delete the entry from the directory. For dos filesystems this
1475 * gets rid of the directory entry on disk, the in memory copy
1476 * still exists but the de_refcnt is <= 0. This prevents it from
1477 * being found by deget(). When the vput() on dep is done we give
1478 * up access and eventually msdosfs_reclaim() will be called which
1479 * will remove it from the denode cache.
1481 error = removede(dp, ip);
1485 * This is where we decrement the link count in the parent
1486 * directory. Since dos filesystems don't do this we just purge
1490 VOP_UNLOCK(dvp, 0, p);
1492 * Truncate the directory that is being deleted.
1494 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, p);
1497 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
1503 * DOS filesystems don't know what symlinks are.
1507 struct vop_symlink_args /* {
1508 struct vnode *a_dvp;
1509 struct vnode **a_vpp;
1510 struct componentname *a_cnp;
1511 struct vattr *a_vap;
1515 return (EOPNOTSUPP);
1520 struct vop_readdir_args /* {
1523 struct ucred *a_cred;
1540 struct denode *dep = VTODE(ap->a_vp);
1541 struct msdosfsmount *pmp = dep->de_pmp;
1542 struct direntry *dentp;
1543 struct dirent dirbuf;
1544 struct uio *uio = ap->a_uio;
1545 u_long *cookies = NULL;
1550 #ifdef MSDOSFS_DEBUG
1551 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1552 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1556 * msdosfs_readdir() won't operate properly on regular files since
1557 * it does i/o only with the the filesystem vnode, and hence can
1558 * retrieve the wrong block from the buffer cache for a plain file.
1559 * So, fail attempts to readdir() on a plain file.
1561 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1565 * To be safe, initialize dirbuf
1567 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1570 * If the user buffer is smaller than the size of one dos directory
1571 * entry or the file offset is not a multiple of the size of a
1572 * directory entry, then we fail the read.
1574 off = offset = uio->uio_offset;
1575 if (uio->uio_resid < sizeof(struct direntry) ||
1576 (offset & (sizeof(struct direntry) - 1)))
1579 if (ap->a_ncookies) {
1580 ncookies = uio->uio_resid / 16;
1581 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1583 *ap->a_cookies = cookies;
1584 *ap->a_ncookies = ncookies;
1587 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1590 * If they are reading from the root directory then, we simulate
1591 * the . and .. entries since these don't exist in the root
1592 * directory. We also set the offset bias to make up for having to
1593 * simulate these entries. By this I mean that at file offset 64 we
1594 * read the first entry in the root directory that lives on disk.
1596 if (dep->de_StartCluster == MSDOSFSROOT
1597 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1599 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1602 bias = 2 * sizeof(struct direntry);
1603 if (offset < bias) {
1604 for (n = (int)offset / sizeof(struct direntry);
1607 dirbuf.d_fileno = cntobn(pmp,
1611 dirbuf.d_fileno = 1;
1612 dirbuf.d_type = DT_DIR;
1615 dirbuf.d_namlen = 1;
1616 strcpy(dirbuf.d_name, ".");
1619 dirbuf.d_namlen = 2;
1620 strcpy(dirbuf.d_name, "..");
1623 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1624 if (uio->uio_resid < dirbuf.d_reclen)
1626 error = uiomove((caddr_t) &dirbuf,
1627 dirbuf.d_reclen, uio);
1630 offset += sizeof(struct direntry);
1633 *cookies++ = offset;
1634 if (--ncookies <= 0)
1642 while (uio->uio_resid > 0) {
1643 lbn = de_cluster(pmp, offset - bias);
1644 on = (offset - bias) & pmp->pm_crbomask;
1645 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1646 diff = dep->de_FileSize - (offset - bias);
1650 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1653 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1658 n = min(n, blsize - bp->b_resid);
1661 * Convert from dos directory entries to fs-independent
1662 * directory entries.
1664 for (dentp = (struct direntry *)(bp->b_data + on);
1665 (char *)dentp < bp->b_data + on + n;
1666 dentp++, offset += sizeof(struct direntry)) {
1668 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1669 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1672 * If this is an unused entry, we can stop.
1674 if (dentp->deName[0] == SLOT_EMPTY) {
1679 * Skip deleted entries.
1681 if (dentp->deName[0] == SLOT_DELETED) {
1687 * Handle Win95 long directory entries
1689 if (dentp->deAttributes == ATTR_WIN95) {
1690 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1692 chksum = win2unixfn((struct winentry *)dentp,
1694 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1700 * Skip volume labels
1702 if (dentp->deAttributes & ATTR_VOLUME) {
1707 * This computation of d_fileno must match
1708 * the computation of va_fileid in
1711 if (dentp->deAttributes & ATTR_DIRECTORY) {
1712 fileno = getushort(dentp->deStartCluster);
1714 fileno |= getushort(dentp->deHighClust) << 16;
1715 /* if this is the root directory */
1716 if (fileno == MSDOSFSROOT)
1718 fileno = cntobn(pmp,
1724 fileno = cntobn(pmp, fileno) * dirsperblk;
1725 dirbuf.d_fileno = fileno;
1726 dirbuf.d_type = DT_DIR;
1728 dirbuf.d_fileno = offset / sizeof(struct direntry);
1729 dirbuf.d_type = DT_REG;
1731 if (chksum != winChksum(dentp->deName))
1732 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1733 (u_char *)dirbuf.d_name,
1734 dentp->deLowerCase |
1735 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1736 (LCASE_BASE | LCASE_EXT) : 0),
1737 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1739 pmp->pm_flags & MSDOSFSMNT_ULTABLE,
1742 dirbuf.d_name[dirbuf.d_namlen] = 0;
1744 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1745 if (uio->uio_resid < dirbuf.d_reclen) {
1749 error = uiomove((caddr_t) &dirbuf,
1750 dirbuf.d_reclen, uio);
1756 *cookies++ = offset + sizeof(struct direntry);
1757 if (--ncookies <= 0) {
1762 off = offset + sizeof(struct direntry);
1767 /* Subtract unused cookies */
1769 *ap->a_ncookies -= ncookies;
1771 uio->uio_offset = off;
1774 * Set the eofflag (NFS uses it)
1776 if (ap->a_eofflag) {
1777 if (dep->de_FileSize - (offset - bias) <= 0)
1786 * vp - address of vnode file the file
1787 * bn - which cluster we are interested in mapping to a filesystem block number.
1788 * vpp - returns the vnode for the block special file holding the filesystem
1789 * containing the file of interest
1790 * bnp - address of where to return the filesystem relative block number
1794 struct vop_bmap_args /* {
1797 struct vnode **a_vpp;
1803 struct denode *dep = VTODE(ap->a_vp);
1805 if (ap->a_vpp != NULL)
1806 *ap->a_vpp = dep->de_devvp;
1807 if (ap->a_bnp == NULL)
1811 * Sequential clusters should be counted here.
1818 return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
1822 msdosfs_strategy(ap)
1823 struct vop_strategy_args /* {
1828 struct buf *bp = ap->a_bp;
1829 struct denode *dep = VTODE(bp->b_vp);
1833 if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
1834 panic("msdosfs_strategy: spec");
1836 * If we don't already know the filesystem relative block number
1837 * then get it using pcbmap(). If pcbmap() returns the block
1838 * number as -1 then we've got a hole in the file. DOS filesystems
1839 * don't allow files with holes, so we shouldn't ever see this.
1841 if (bp->b_blkno == bp->b_lblkno) {
1842 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0, 0);
1844 bp->b_error = error;
1845 bp->b_flags |= B_ERROR;
1849 if ((long)bp->b_blkno == -1)
1852 if (bp->b_blkno == -1) {
1857 * Read/write the block from/to the disk that contains the desired
1861 bp->b_dev = vp->v_rdev;
1862 VOP_STRATEGY(vp, bp);
1868 struct vop_print_args /* {
1872 struct denode *dep = VTODE(ap->a_vp);
1875 "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ",
1876 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1877 printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev));
1878 lockmgr_printinfo(&dep->de_lock);
1884 msdosfs_pathconf(ap)
1885 struct vop_pathconf_args /* {
1891 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1893 switch (ap->a_name) {
1898 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1901 *ap->a_retval = PATH_MAX;
1903 case _PC_CHOWN_RESTRICTED:
1918 * XXX By default, wimp out... note that a_offset is ignored (and always
1922 msdosfs_getpages(ap)
1923 struct vop_getpages_args *ap;
1925 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
1932 * XXX By default, wimp out... note that a_offset is ignored (and always
1936 msdosfs_putpages(ap)
1937 struct vop_putpages_args *ap;
1939 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
1940 ap->a_sync, ap->a_rtvals);
1943 /* Global vfs data structures for msdosfs */
1944 vop_t **msdosfs_vnodeop_p;
1945 static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1946 { &vop_default_desc, (vop_t *) vop_defaultop },
1947 { &vop_access_desc, (vop_t *) msdosfs_access },
1948 { &vop_bmap_desc, (vop_t *) msdosfs_bmap },
1949 { &vop_cachedlookup_desc, (vop_t *) msdosfs_lookup },
1950 { &vop_close_desc, (vop_t *) msdosfs_close },
1951 { &vop_create_desc, (vop_t *) msdosfs_create },
1952 { &vop_fsync_desc, (vop_t *) msdosfs_fsync },
1953 { &vop_getattr_desc, (vop_t *) msdosfs_getattr },
1954 { &vop_inactive_desc, (vop_t *) msdosfs_inactive },
1955 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
1956 { &vop_link_desc, (vop_t *) msdosfs_link },
1957 { &vop_lock_desc, (vop_t *) vop_stdlock },
1958 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
1959 { &vop_mkdir_desc, (vop_t *) msdosfs_mkdir },
1960 { &vop_mknod_desc, (vop_t *) msdosfs_mknod },
1961 { &vop_pathconf_desc, (vop_t *) msdosfs_pathconf },
1962 { &vop_print_desc, (vop_t *) msdosfs_print },
1963 { &vop_read_desc, (vop_t *) msdosfs_read },
1964 { &vop_readdir_desc, (vop_t *) msdosfs_readdir },
1965 { &vop_reclaim_desc, (vop_t *) msdosfs_reclaim },
1966 { &vop_remove_desc, (vop_t *) msdosfs_remove },
1967 { &vop_rename_desc, (vop_t *) msdosfs_rename },
1968 { &vop_rmdir_desc, (vop_t *) msdosfs_rmdir },
1969 { &vop_setattr_desc, (vop_t *) msdosfs_setattr },
1970 { &vop_strategy_desc, (vop_t *) msdosfs_strategy },
1971 { &vop_symlink_desc, (vop_t *) msdosfs_symlink },
1972 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
1973 { &vop_write_desc, (vop_t *) msdosfs_write },
1974 { &vop_getpages_desc, (vop_t *) msdosfs_getpages },
1975 { &vop_putpages_desc, (vop_t *) msdosfs_putpages },
1978 static struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1979 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1981 VNODEOP_SET(msdosfs_vnodeop_opv_desc);