2 /* $NetBSD: msdosfs_vnops.c,v 1.68 1998/02/10 14:10:04 mrg Exp $ */
5 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
41 * This software is provided "as is".
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/namei.h>
54 #include <sys/resourcevar.h> /* defines plimit structure in proc struct */
55 #include <sys/kernel.h>
59 #include <sys/mount.h>
60 #include <sys/unistd.h>
61 #include <sys/vnode.h>
62 #include <sys/malloc.h>
63 #include <sys/dirent.h>
64 #include <sys/signalvar.h>
67 #include <vm/vm_extern.h>
68 #include <vm/vm_zone.h>
69 #include <vm/vnode_pager.h>
71 #include <msdosfs/bpb.h>
72 #include <msdosfs/direntry.h>
73 #include <msdosfs/denode.h>
74 #include <msdosfs/msdosfsmount.h>
75 #include <msdosfs/fat.h>
78 * Prototypes for MSDOSFS vnode operations
80 static int msdosfs_create __P((struct vop_create_args *));
81 static int msdosfs_mknod __P((struct vop_mknod_args *));
82 static int msdosfs_close __P((struct vop_close_args *));
83 static int msdosfs_access __P((struct vop_access_args *));
84 static int msdosfs_getattr __P((struct vop_getattr_args *));
85 static int msdosfs_setattr __P((struct vop_setattr_args *));
86 static int msdosfs_read __P((struct vop_read_args *));
87 static int msdosfs_write __P((struct vop_write_args *));
88 static int msdosfs_fsync __P((struct vop_fsync_args *));
89 static int msdosfs_remove __P((struct vop_remove_args *));
90 static int msdosfs_link __P((struct vop_link_args *));
91 static int msdosfs_rename __P((struct vop_rename_args *));
92 static int msdosfs_mkdir __P((struct vop_mkdir_args *));
93 static int msdosfs_rmdir __P((struct vop_rmdir_args *));
94 static int msdosfs_symlink __P((struct vop_symlink_args *));
95 static int msdosfs_readdir __P((struct vop_readdir_args *));
96 static int msdosfs_abortop __P((struct vop_abortop_args *));
97 static int msdosfs_bmap __P((struct vop_bmap_args *));
98 static int msdosfs_strategy __P((struct vop_strategy_args *));
99 static int msdosfs_print __P((struct vop_print_args *));
100 static int msdosfs_pathconf __P((struct vop_pathconf_args *ap));
101 static int msdosfs_getpages __P((struct vop_getpages_args *));
102 static int msdosfs_putpages __P((struct vop_putpages_args *));
105 * Some general notes:
107 * In the ufs filesystem the inodes, superblocks, and indirect blocks are
108 * read/written using the vnode for the filesystem. Blocks that represent
109 * the contents of a file are read/written using the vnode for the file
110 * (including directories when they are read/written as files). This
111 * presents problems for the dos filesystem because data that should be in
112 * an inode (if dos had them) resides in the directory itself. Since we
113 * must update directory entries without the benefit of having the vnode
114 * for the directory we must use the vnode for the filesystem. This means
115 * that when a directory is actually read/written (via read, write, or
116 * readdir, or seek) we must use the vnode for the filesystem instead of
117 * the vnode for the directory as would happen in ufs. This is to insure we
118 * retreive the correct block from the buffer cache since the hash value is
119 * based upon the vnode address and the desired block number.
123 * Create a regular file. On entry the directory to contain the file being
124 * created is locked. We must release before we return. We must also free
125 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
126 * only if the SAVESTART bit in cn_flags is clear on success.
130 struct vop_create_args /* {
132 struct vnode **a_vpp;
133 struct componentname *a_cnp;
137 struct componentname *cnp = ap->a_cnp;
138 struct denode ndirent;
140 struct denode *pdep = VTODE(ap->a_dvp);
145 printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
149 * If this is the root directory and there is no space left we
150 * can't do anything. This is because the root directory can not
153 if (pdep->de_StartCluster == MSDOSFSROOT
154 && pdep->de_fndoffset >= pdep->de_FileSize) {
160 * Create a directory entry for the file, then call createde() to
161 * have it installed. NOTE: DOS files are always executable. We
162 * use the absence of the owner write bit to make the file
166 if ((cnp->cn_flags & HASBUF) == 0)
167 panic("msdosfs_create: no name");
169 bzero(&ndirent, sizeof(ndirent));
170 error = uniqdosname(pdep, cnp, ndirent.de_Name);
174 ndirent.de_Attributes = (ap->a_vap->va_mode & VWRITE) ?
175 ATTR_ARCHIVE : ATTR_ARCHIVE | ATTR_READONLY;
176 ndirent.de_LowerCase = 0;
177 ndirent.de_StartCluster = 0;
178 ndirent.de_FileSize = 0;
179 ndirent.de_dev = pdep->de_dev;
180 ndirent.de_devvp = pdep->de_devvp;
181 ndirent.de_pmp = pdep->de_pmp;
182 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
184 DETIMES(&ndirent, &ts, &ts, &ts);
185 error = createde(&ndirent, pdep, &dep, cnp);
188 if ((cnp->cn_flags & SAVESTART) == 0)
189 zfree(namei_zone, cnp->cn_pnbuf);
190 *ap->a_vpp = DETOV(dep);
194 zfree(namei_zone, cnp->cn_pnbuf);
200 struct vop_mknod_args /* {
202 struct vnode **a_vpp;
203 struct componentname *a_cnp;
208 switch (ap->a_vap->va_type) {
210 return (msdosfs_mkdir((struct vop_mkdir_args *)ap));
214 return (msdosfs_create((struct vop_create_args *)ap));
218 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
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 unix2dostime(&vap->va_atime, &dep->de_ADate, NULL, NULL);
514 if (vap->va_mtime.tv_sec != VNOVAL)
515 unix2dostime(&vap->va_mtime, &dep->de_MDate, &dep->de_MTime, NULL);
516 dep->de_Attributes |= ATTR_ARCHIVE;
517 dep->de_flag |= DE_MODIFIED;
521 * DOS files only have the ability to have their writability
522 * attribute set, so we use the owner write bit to set the readonly
525 if (vap->va_mode != (mode_t)VNOVAL) {
526 if (vp->v_mount->mnt_flag & MNT_RDONLY)
528 if (cred->cr_uid != pmp->pm_uid &&
529 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
531 if (vp->v_type != VDIR) {
532 /* We ignore the read and execute bits. */
533 if (vap->va_mode & VWRITE)
534 dep->de_Attributes &= ~ATTR_READONLY;
536 dep->de_Attributes |= ATTR_READONLY;
537 dep->de_flag |= DE_MODIFIED;
540 return (deupdat(dep, 1));
545 struct vop_read_args /* {
549 struct ucred *a_cred;
564 struct vnode *vp = ap->a_vp;
565 struct denode *dep = VTODE(vp);
566 struct msdosfsmount *pmp = dep->de_pmp;
567 struct uio *uio = ap->a_uio;
569 if (uio->uio_offset < 0)
573 * If they didn't ask for any data, then we are done.
575 orig_resid = uio->uio_resid;
579 seqcount = ap->a_ioflag >> 16;
581 isadir = dep->de_Attributes & ATTR_DIRECTORY;
583 lbn = de_cluster(pmp, uio->uio_offset);
584 on = uio->uio_offset & pmp->pm_crbomask;
585 n = min((u_long) (pmp->pm_bpcluster - on), uio->uio_resid);
586 diff = dep->de_FileSize - uio->uio_offset;
591 /* convert cluster # to block # if a directory */
593 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
598 * If we are operating on a directory file then be sure to
599 * do i/o with the vnode for the filesystem instead of the
600 * vnode for the directory.
603 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
607 de_cn2off(pmp, rablock) < dep->de_FileSize) {
608 rasize = pmp->pm_bpcluster;
609 error = breadn(vp, lbn, pmp->pm_bpcluster,
610 &rablock, &rasize, 1, NOCRED, &bp);
612 error = bread(vp, lbn, pmp->pm_bpcluster,
616 n = min(n, pmp->pm_bpcluster - bp->b_resid);
621 error = uiomove(bp->b_data + on, (int) n, uio);
623 } while (error == 0 && uio->uio_resid > 0 && n != 0);
624 if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
625 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
626 dep->de_flag |= DE_ACCESS;
631 * Write data to a file or directory.
635 struct vop_write_args /* {
639 struct ucred *a_cred;
650 int ioflag = ap->a_ioflag;
651 struct uio *uio = ap->a_uio;
652 struct proc *p = uio->uio_procp;
653 struct vnode *vp = ap->a_vp;
654 struct vnode *thisvp;
655 struct denode *dep = VTODE(vp);
656 struct msdosfsmount *pmp = dep->de_pmp;
657 struct ucred *cred = ap->a_cred;
660 printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
661 vp, uio, ioflag, cred);
662 printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
663 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
666 switch (vp->v_type) {
668 if (ioflag & IO_APPEND)
669 uio->uio_offset = dep->de_FileSize;
675 panic("msdosfs_write(): bad file type");
678 if (uio->uio_offset < 0)
681 if (uio->uio_resid == 0)
685 * If they've exceeded their filesize limit, tell them about it.
688 ((uio->uio_offset + uio->uio_resid) >
689 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
695 * If the offset we are starting the write at is beyond the end of
696 * the file, then they've done a seek. Unix filesystems allow
697 * files with holes in them, DOS doesn't so we must fill the hole
698 * with zeroed blocks.
700 if (uio->uio_offset > dep->de_FileSize) {
701 error = deextend(dep, uio->uio_offset, cred);
707 * Remember some values in case the write fails.
709 resid = uio->uio_resid;
710 osize = dep->de_FileSize;
713 * If we write beyond the end of the file, extend it to its ultimate
714 * size ahead of the time to hopefully get a contiguous area.
716 if (uio->uio_offset + resid > osize) {
717 count = de_clcount(pmp, uio->uio_offset + resid) -
718 de_clcount(pmp, osize);
719 error = extendfile(dep, count, NULL, NULL, 0);
720 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
722 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
724 lastcn = de_clcount(pmp, osize) - 1;
727 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
732 croffset = uio->uio_offset & pmp->pm_crbomask;
733 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
734 if (uio->uio_offset + n > dep->de_FileSize) {
735 dep->de_FileSize = uio->uio_offset + n;
736 /* The object size needs to be set before buffer is allocated */
737 vnode_pager_setsize(vp, dep->de_FileSize);
740 bn = de_cluster(pmp, uio->uio_offset);
741 if ((uio->uio_offset & pmp->pm_crbomask) == 0
742 && (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
743 > de_cluster(pmp, uio->uio_offset)
744 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
746 * If either the whole cluster gets written,
747 * or we write the cluster from its start beyond EOF,
748 * then no need to read data from disk.
750 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
753 * Do the bmap now, since pcbmap needs buffers
754 * for the fat table. (see msdosfs_strategy)
756 if (bp->b_blkno == bp->b_lblkno) {
757 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno,
762 if (bp->b_blkno == -1) {
765 error = EIO; /* XXX */
770 * The block we need to write into exists, so read it in.
772 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
780 * Should these vnode_pager_* functions be done on dir
785 * Copy the data from user space into the buf header.
787 error = uiomove(bp->b_data + croffset, n, uio);
790 * If they want this synchronous then write it and wait for
791 * it. Otherwise, if on a cluster boundary write it
792 * asynchronously so we can move on to the next block
793 * without delay. Otherwise do a delayed write because we
794 * may want to write somemore into the block later.
796 if (ioflag & IO_SYNC)
798 else if (n + croffset == pmp->pm_bpcluster)
802 dep->de_flag |= DE_UPDATE;
803 } while (error == 0 && uio->uio_resid > 0);
806 * If the write failed and they want us to, truncate the file back
807 * to the size it was before the write was attempted.
811 if (ioflag & IO_UNIT) {
812 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
813 uio->uio_offset -= resid - uio->uio_resid;
814 uio->uio_resid = resid;
816 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
817 if (uio->uio_resid != resid)
820 } else if (ioflag & IO_SYNC)
821 error = deupdat(dep, 1);
826 * Flush the blocks of a file to disk.
828 * This function is worthless for vnodes that represent directories. Maybe we
829 * could just do a sync if they try an fsync on a directory file.
833 struct vop_fsync_args /* {
835 struct ucred *a_cred;
840 struct vnode *vp = ap->a_vp;
842 struct buf *bp, *nbp;
845 * Flush all dirty buffers associated with a vnode.
849 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
850 nbp = TAILQ_NEXT(bp, b_vnbufs);
851 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
853 if ((bp->b_flags & B_DELWRI) == 0)
854 panic("msdosfs_fsync: not dirty");
860 while (vp->v_numoutput) {
861 vp->v_flag |= VBWAIT;
862 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "msdosfsn", 0);
865 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
866 vprint("msdosfs_fsync: dirty", vp);
871 return (deupdat(VTODE(vp), ap->a_waitfor == MNT_WAIT));
876 struct vop_remove_args /* {
879 struct componentname *a_cnp;
882 struct denode *dep = VTODE(ap->a_vp);
883 struct denode *ddep = VTODE(ap->a_dvp);
886 if (ap->a_vp->v_type == VDIR)
889 error = removede(ddep, dep);
891 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
897 * DOS filesystems don't know what links are. But since we already called
898 * msdosfs_lookup() with create and lockparent, the parent is locked so we
899 * have to free it before we return the error.
903 struct vop_link_args /* {
904 struct vnode *a_tdvp;
906 struct componentname *a_cnp;
909 VOP_ABORTOP(ap->a_tdvp, ap->a_cnp);
914 * Renames on files require moving the denode to a new hash queue since the
915 * denode's location is used to compute which hash queue to put the file
916 * in. Unless it is a rename in place. For example "mv a b".
918 * What follows is the basic algorithm:
921 * if (dest file exists) {
924 * if (dest and src in same directory) {
925 * rewrite name in existing directory slot
927 * write new entry in dest directory
928 * update offset and dirclust in denode
929 * move denode to new hash chain
930 * clear old directory entry
934 * if (dest directory exists) {
935 * if (dest is not empty) {
938 * remove dest directory
940 * if (dest and src in same directory) {
941 * rewrite name in existing entry
943 * be sure dest is not a child of src directory
944 * write entry in dest directory
945 * update "." and ".." in moved directory
946 * clear old directory entry for moved directory
951 * source's parent directory is unlocked
952 * source file or directory is unlocked
953 * destination's parent directory is locked
954 * destination file or directory is locked if it exists
957 * all denodes should be released
960 * I'm not sure how the memory containing the pathnames pointed at by the
961 * componentname structures is freed, there may be some memory bleeding
962 * for each rename done.
966 struct vop_rename_args /* {
967 struct vnode *a_fdvp;
969 struct componentname *a_fcnp;
970 struct vnode *a_tdvp;
972 struct componentname *a_tcnp;
975 struct vnode *tdvp = ap->a_tdvp;
976 struct vnode *fvp = ap->a_fvp;
977 struct vnode *fdvp = ap->a_fdvp;
978 struct vnode *tvp = ap->a_tvp;
979 struct componentname *tcnp = ap->a_tcnp;
980 struct componentname *fcnp = ap->a_fcnp;
981 struct proc *p = fcnp->cn_proc;
982 struct denode *ip, *xp, *dp, *zp;
983 u_char toname[11], oldname[11];
984 u_long from_diroffset, to_diroffset;
986 int doingdirectory = 0, newparent = 0;
990 struct denode *fddep; /* from file's parent directory */
991 struct denode *fdep; /* from file or directory */
992 struct denode *tddep; /* to file's parent directory */
993 struct denode *tdep; /* to file or directory */
994 struct msdosfsmount *pmp;
995 struct direntry *dotdotp;
998 fddep = VTODE(ap->a_fdvp);
999 fdep = VTODE(ap->a_fvp);
1000 tddep = VTODE(ap->a_tdvp);
1001 tdep = tvp ? VTODE(tvp) : NULL;
1002 pmp = fddep->de_pmp;
1004 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1007 if ((tcnp->cn_flags & HASBUF) == 0 ||
1008 (fcnp->cn_flags & HASBUF) == 0)
1009 panic("msdosfs_rename: no name");
1012 * Check for cross-device rename.
1014 if ((fvp->v_mount != tdvp->v_mount) ||
1015 (tvp && (fvp->v_mount != tvp->v_mount))) {
1018 VOP_ABORTOP(tdvp, tcnp);
1025 VOP_ABORTOP(fdvp, fcnp);
1032 * If source and dest are the same, do nothing.
1039 error = vn_lock(fvp, LK_EXCLUSIVE, p);
1046 * Be sure we are not renaming ".", "..", or an alias of ".". This
1047 * leads to a crippled directory tree. It's pretty tough to do a
1048 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
1049 * doesn't work if the ".." entry is missing.
1051 if (ip->de_Attributes & ATTR_DIRECTORY) {
1053 * Avoid ".", "..", and aliases of "." for obvious reasons.
1055 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1057 (fcnp->cn_flags & ISDOTDOT) ||
1058 (tcnp->cn_flags & ISDOTDOT) ||
1059 (ip->de_flag & DE_RENAME)) {
1060 VOP_UNLOCK(fvp, 0, p);
1064 ip->de_flag |= DE_RENAME;
1069 * When the target exists, both the directory
1070 * and target vnodes are returned locked.
1073 xp = tvp ? VTODE(tvp) : NULL;
1075 * Remember direntry place to use for destination
1077 to_diroffset = dp->de_fndoffset;
1078 to_count = dp->de_fndcnt;
1081 * If ".." must be changed (ie the directory gets a new
1082 * parent) then the source directory must not be in the
1083 * directory heirarchy above the target, as this would
1084 * orphan everything below the source directory. Also
1085 * the user must have write permission in the source so
1086 * as to be able to change "..". We must repeat the call
1087 * to namei, as the parent directory is unlocked by the
1088 * call to doscheckpath().
1090 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc);
1091 VOP_UNLOCK(fvp, 0, p);
1092 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1095 if (doingdirectory && newparent) {
1096 if (error) /* write access check above */
1101 * doscheckpath() vput()'s dp,
1102 * so we have to do a relookup afterwards
1104 error = doscheckpath(ip, dp);
1107 if ((tcnp->cn_flags & SAVESTART) == 0)
1108 panic("msdosfs_rename: lost to startdir");
1109 error = relookup(tdvp, &tvp, tcnp);
1113 xp = tvp ? VTODE(tvp) : NULL;
1118 * Target must be empty if a directory and have no links
1119 * to it. Also, ensure source and target are compatible
1120 * (both directories, or both not directories).
1122 if (xp->de_Attributes & ATTR_DIRECTORY) {
1123 if (!dosdirempty(xp)) {
1127 if (!doingdirectory) {
1132 } else if (doingdirectory) {
1136 error = removede(dp, xp);
1144 * Convert the filename in tcnp into a dos filename. We copy this
1145 * into the denode and directory entry for the destination
1148 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1153 * Since from wasn't locked at various places above,
1154 * have to do a relookup here.
1156 fcnp->cn_flags &= ~MODMASK;
1157 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1158 if ((fcnp->cn_flags & SAVESTART) == 0)
1159 panic("msdosfs_rename: lost from startdir");
1161 VOP_UNLOCK(tdvp, 0, p);
1162 (void) relookup(fdvp, &fvp, fcnp);
1165 * From name has disappeared.
1168 panic("rename: lost dir entry");
1171 VOP_UNLOCK(tdvp, 0, p);
1177 from_diroffset = zp->de_fndoffset;
1180 * Ensure that the directory entry still exists and has not
1181 * changed till now. If the source is a file the entry may
1182 * have been unlinked or renamed. In either case there is
1183 * no further work to be done. If the source is a directory
1184 * then it cannot have been rmdir'ed or renamed; this is
1185 * prohibited by the DE_RENAME flag.
1189 panic("rename: lost dir entry");
1191 VOP_UNLOCK(fvp, 0, p);
1193 VOP_UNLOCK(fdvp, 0, p);
1200 * First write a new entry in the destination
1201 * directory and mark the entry in the source directory
1202 * as deleted. Then move the denode to the correct hash
1203 * chain for its new location in the filesystem. And, if
1204 * we moved a directory, then update its .. entry to point
1205 * to the new parent directory.
1207 bcopy(ip->de_Name, oldname, 11);
1208 bcopy(toname, ip->de_Name, 11); /* update denode */
1209 dp->de_fndoffset = to_diroffset;
1210 dp->de_fndcnt = to_count;
1211 error = createde(ip, dp, (struct denode **)0, tcnp);
1213 bcopy(oldname, ip->de_Name, 11);
1215 VOP_UNLOCK(fdvp, 0, p);
1216 VOP_UNLOCK(fvp, 0, p);
1220 zp->de_fndoffset = from_diroffset;
1221 error = removede(zp, ip);
1223 /* XXX should really panic here, fs is corrupt */
1225 VOP_UNLOCK(fdvp, 0, p);
1226 VOP_UNLOCK(fvp, 0, p);
1229 if (!doingdirectory) {
1230 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1231 &ip->de_dirclust, 0);
1233 /* XXX should really panic here, fs is corrupt */
1235 VOP_UNLOCK(fdvp, 0, p);
1236 VOP_UNLOCK(fvp, 0, p);
1239 if (ip->de_dirclust == MSDOSFSROOT)
1240 ip->de_diroffset = to_diroffset;
1242 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1246 VOP_UNLOCK(fdvp, 0, p);
1250 * If we moved a directory to a new parent directory, then we must
1251 * fixup the ".." entry in the moved directory.
1253 if (doingdirectory && newparent) {
1254 cn = ip->de_StartCluster;
1255 if (cn == MSDOSFSROOT) {
1256 /* this should never happen */
1257 panic("msdosfs_rename(): updating .. in root directory?");
1259 bn = cntobn(pmp, cn);
1260 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1263 /* XXX should really panic here, fs is corrupt */
1265 VOP_UNLOCK(fvp, 0, p);
1268 dotdotp = (struct direntry *)bp->b_data + 1;
1269 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1271 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1274 /* XXX should really panic here, fs is corrupt */
1275 VOP_UNLOCK(fvp, 0, p);
1280 VOP_UNLOCK(fvp, 0, p);
1286 ip->de_flag &= ~DE_RENAME;
1294 struct direntry dot;
1295 struct direntry dotdot;
1296 } dosdirtemplate = {
1297 { ". ", " ", /* the . entry */
1298 ATTR_DIRECTORY, /* file attribute */
1300 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1301 { 0, 0 }, /* access date */
1302 { 0, 0 }, /* high bits of start cluster */
1303 { 210, 4 }, { 210, 4 }, /* modify time & date */
1304 { 0, 0 }, /* startcluster */
1305 { 0, 0, 0, 0 } /* filesize */
1307 { ".. ", " ", /* the .. entry */
1308 ATTR_DIRECTORY, /* file attribute */
1310 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1311 { 0, 0 }, /* access date */
1312 { 0, 0 }, /* high bits of start cluster */
1313 { 210, 4 }, { 210, 4 }, /* modify time & date */
1314 { 0, 0 }, /* startcluster */
1315 { 0, 0, 0, 0 } /* filesize */
1321 struct vop_mkdir_args /* {
1322 struct vnode *a_dvp;
1323 struvt vnode **a_vpp;
1324 struvt componentname *a_cnp;
1325 struct vattr *a_vap;
1328 struct componentname *cnp = ap->a_cnp;
1330 struct denode *pdep = VTODE(ap->a_dvp);
1331 struct direntry *denp;
1332 struct msdosfsmount *pmp = pdep->de_pmp;
1334 u_long newcluster, pcl;
1337 struct denode ndirent;
1341 * If this is the root directory and there is no space left we
1342 * can't do anything. This is because the root directory can not
1345 if (pdep->de_StartCluster == MSDOSFSROOT
1346 && pdep->de_fndoffset >= pdep->de_FileSize) {
1352 * Allocate a cluster to hold the about to be created directory.
1354 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1358 bzero(&ndirent, sizeof(ndirent));
1359 ndirent.de_pmp = pmp;
1360 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1362 DETIMES(&ndirent, &ts, &ts, &ts);
1365 * Now fill the cluster with the "." and ".." entries. And write
1366 * the cluster to disk. This way it is there for the parent
1367 * directory to be pointing at if there were a crash.
1369 bn = cntobn(pmp, newcluster);
1370 /* always succeeds */
1371 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0);
1372 bzero(bp->b_data, pmp->pm_bpcluster);
1373 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1374 denp = (struct direntry *)bp->b_data;
1375 putushort(denp[0].deStartCluster, newcluster);
1376 putushort(denp[0].deCDate, ndirent.de_CDate);
1377 putushort(denp[0].deCTime, ndirent.de_CTime);
1378 denp[0].deCHundredth = ndirent.de_CHun;
1379 putushort(denp[0].deADate, ndirent.de_ADate);
1380 putushort(denp[0].deMDate, ndirent.de_MDate);
1381 putushort(denp[0].deMTime, ndirent.de_MTime);
1382 pcl = pdep->de_StartCluster;
1383 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1385 putushort(denp[1].deStartCluster, pcl);
1386 putushort(denp[1].deCDate, ndirent.de_CDate);
1387 putushort(denp[1].deCTime, ndirent.de_CTime);
1388 denp[1].deCHundredth = ndirent.de_CHun;
1389 putushort(denp[1].deADate, ndirent.de_ADate);
1390 putushort(denp[1].deMDate, ndirent.de_MDate);
1391 putushort(denp[1].deMTime, ndirent.de_MTime);
1393 putushort(denp[0].deHighClust, newcluster >> 16);
1394 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1402 * Now build up a directory entry pointing to the newly allocated
1403 * cluster. This will be written to an empty slot in the parent
1407 if ((cnp->cn_flags & HASBUF) == 0)
1408 panic("msdosfs_mkdir: no name");
1410 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1414 ndirent.de_Attributes = ATTR_DIRECTORY;
1415 ndirent.de_LowerCase = 0;
1416 ndirent.de_StartCluster = newcluster;
1417 ndirent.de_FileSize = 0;
1418 ndirent.de_dev = pdep->de_dev;
1419 ndirent.de_devvp = pdep->de_devvp;
1420 error = createde(&ndirent, pdep, &dep, cnp);
1423 if ((cnp->cn_flags & SAVESTART) == 0)
1424 zfree(namei_zone, cnp->cn_pnbuf);
1425 *ap->a_vpp = DETOV(dep);
1429 clusterfree(pmp, newcluster, NULL);
1431 zfree(namei_zone, cnp->cn_pnbuf);
1437 struct vop_rmdir_args /* {
1438 struct vnode *a_dvp;
1440 struct componentname *a_cnp;
1443 register struct vnode *vp = ap->a_vp;
1444 register struct vnode *dvp = ap->a_dvp;
1445 register struct componentname *cnp = ap->a_cnp;
1446 register struct denode *ip, *dp;
1447 struct proc *p = cnp->cn_proc;
1454 * Verify the directory is empty (and valid).
1455 * (Rmdir ".." won't be valid since
1456 * ".." will contain a reference to
1457 * the current directory and thus be
1461 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1466 * Delete the entry from the directory. For dos filesystems this
1467 * gets rid of the directory entry on disk, the in memory copy
1468 * still exists but the de_refcnt is <= 0. This prevents it from
1469 * being found by deget(). When the vput() on dep is done we give
1470 * up access and eventually msdosfs_reclaim() will be called which
1471 * will remove it from the denode cache.
1473 error = removede(dp, ip);
1477 * This is where we decrement the link count in the parent
1478 * directory. Since dos filesystems don't do this we just purge
1482 VOP_UNLOCK(dvp, 0, p);
1484 * Truncate the directory that is being deleted.
1486 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, p);
1489 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
1495 * DOS filesystems don't know what symlinks are.
1499 struct vop_symlink_args /* {
1500 struct vnode *a_dvp;
1501 struct vnode **a_vpp;
1502 struct componentname *a_cnp;
1503 struct vattr *a_vap;
1507 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
1508 /* VOP_ABORTOP(ap->a_dvp, ap->a_cnp); ??? */
1509 return (EOPNOTSUPP);
1514 struct vop_readdir_args /* {
1517 struct ucred *a_cred;
1534 struct denode *dep = VTODE(ap->a_vp);
1535 struct msdosfsmount *pmp = dep->de_pmp;
1536 struct direntry *dentp;
1537 struct dirent dirbuf;
1538 struct uio *uio = ap->a_uio;
1539 u_long *cookies = NULL;
1544 #ifdef MSDOSFS_DEBUG
1545 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1546 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1550 * msdosfs_readdir() won't operate properly on regular files since
1551 * it does i/o only with the the filesystem vnode, and hence can
1552 * retrieve the wrong block from the buffer cache for a plain file.
1553 * So, fail attempts to readdir() on a plain file.
1555 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1559 * To be safe, initialize dirbuf
1561 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1564 * If the user buffer is smaller than the size of one dos directory
1565 * entry or the file offset is not a multiple of the size of a
1566 * directory entry, then we fail the read.
1568 off = offset = uio->uio_offset;
1569 if (uio->uio_resid < sizeof(struct direntry) ||
1570 (offset & (sizeof(struct direntry) - 1)))
1573 if (ap->a_ncookies) {
1574 ncookies = uio->uio_resid / 16;
1575 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1577 *ap->a_cookies = cookies;
1578 *ap->a_ncookies = ncookies;
1581 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1584 * If they are reading from the root directory then, we simulate
1585 * the . and .. entries since these don't exist in the root
1586 * directory. We also set the offset bias to make up for having to
1587 * simulate these entries. By this I mean that at file offset 64 we
1588 * read the first entry in the root directory that lives on disk.
1590 if (dep->de_StartCluster == MSDOSFSROOT
1591 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1593 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1596 bias = 2 * sizeof(struct direntry);
1597 if (offset < bias) {
1598 for (n = (int)offset / sizeof(struct direntry);
1601 dirbuf.d_fileno = cntobn(pmp,
1605 dirbuf.d_fileno = 1;
1606 dirbuf.d_type = DT_DIR;
1609 dirbuf.d_namlen = 1;
1610 strcpy(dirbuf.d_name, ".");
1613 dirbuf.d_namlen = 2;
1614 strcpy(dirbuf.d_name, "..");
1617 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1618 if (uio->uio_resid < dirbuf.d_reclen)
1620 error = uiomove((caddr_t) &dirbuf,
1621 dirbuf.d_reclen, uio);
1624 offset += sizeof(struct direntry);
1627 *cookies++ = offset;
1628 if (--ncookies <= 0)
1636 while (uio->uio_resid > 0) {
1637 lbn = de_cluster(pmp, offset - bias);
1638 on = (offset - bias) & pmp->pm_crbomask;
1639 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1640 diff = dep->de_FileSize - (offset - bias);
1644 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1647 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1652 n = min(n, blsize - bp->b_resid);
1655 * Convert from dos directory entries to fs-independent
1656 * directory entries.
1658 for (dentp = (struct direntry *)(bp->b_data + on);
1659 (char *)dentp < bp->b_data + on + n;
1660 dentp++, offset += sizeof(struct direntry)) {
1662 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1663 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1666 * If this is an unused entry, we can stop.
1668 if (dentp->deName[0] == SLOT_EMPTY) {
1673 * Skip deleted entries.
1675 if (dentp->deName[0] == SLOT_DELETED) {
1681 * Handle Win95 long directory entries
1683 if (dentp->deAttributes == ATTR_WIN95) {
1684 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1686 chksum = win2unixfn((struct winentry *)dentp,
1688 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1694 * Skip volume labels
1696 if (dentp->deAttributes & ATTR_VOLUME) {
1701 * This computation of d_fileno must match
1702 * the computation of va_fileid in
1705 if (dentp->deAttributes & ATTR_DIRECTORY) {
1706 fileno = getushort(dentp->deStartCluster);
1708 fileno |= getushort(dentp->deHighClust) << 16;
1709 /* if this is the root directory */
1710 if (fileno == MSDOSFSROOT)
1712 fileno = cntobn(pmp,
1718 fileno = cntobn(pmp, fileno) * dirsperblk;
1719 dirbuf.d_fileno = fileno;
1720 dirbuf.d_type = DT_DIR;
1722 dirbuf.d_fileno = offset / sizeof(struct direntry);
1723 dirbuf.d_type = DT_REG;
1725 if (chksum != winChksum(dentp->deName))
1726 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1727 (u_char *)dirbuf.d_name,
1728 dentp->deLowerCase |
1729 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1730 (LCASE_BASE | LCASE_EXT) : 0),
1731 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1733 pmp->pm_flags & MSDOSFSMNT_ULTABLE,
1736 dirbuf.d_name[dirbuf.d_namlen] = 0;
1738 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1739 if (uio->uio_resid < dirbuf.d_reclen) {
1743 error = uiomove((caddr_t) &dirbuf,
1744 dirbuf.d_reclen, uio);
1750 *cookies++ = offset + sizeof(struct direntry);
1751 if (--ncookies <= 0) {
1756 off = offset + sizeof(struct direntry);
1761 /* Subtract unused cookies */
1763 *ap->a_ncookies -= ncookies;
1765 uio->uio_offset = off;
1768 * Set the eofflag (NFS uses it)
1770 if (ap->a_eofflag) {
1771 if (dep->de_FileSize - (offset - bias) <= 0)
1781 struct vop_abortop_args /* {
1782 struct vnode *a_dvp;
1783 struct componentname *a_cnp;
1786 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
1787 zfree(namei_zone, ap->a_cnp->cn_pnbuf);
1792 * vp - address of vnode file the file
1793 * bn - which cluster we are interested in mapping to a filesystem block number.
1794 * vpp - returns the vnode for the block special file holding the filesystem
1795 * containing the file of interest
1796 * bnp - address of where to return the filesystem relative block number
1800 struct vop_bmap_args /* {
1803 struct vnode **a_vpp;
1809 struct denode *dep = VTODE(ap->a_vp);
1811 if (ap->a_vpp != NULL)
1812 *ap->a_vpp = dep->de_devvp;
1813 if (ap->a_bnp == NULL)
1817 * Sequential clusters should be counted here.
1824 return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
1828 msdosfs_strategy(ap)
1829 struct vop_strategy_args /* {
1834 struct buf *bp = ap->a_bp;
1835 struct denode *dep = VTODE(bp->b_vp);
1839 if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
1840 panic("msdosfs_strategy: spec");
1842 * If we don't already know the filesystem relative block number
1843 * then get it using pcbmap(). If pcbmap() returns the block
1844 * number as -1 then we've got a hole in the file. DOS filesystems
1845 * don't allow files with holes, so we shouldn't ever see this.
1847 if (bp->b_blkno == bp->b_lblkno) {
1848 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0, 0);
1850 bp->b_error = error;
1851 bp->b_flags |= B_ERROR;
1855 if ((long)bp->b_blkno == -1)
1858 if (bp->b_blkno == -1) {
1863 * Read/write the block from/to the disk that contains the desired
1867 bp->b_dev = vp->v_rdev;
1868 VOP_STRATEGY(vp, bp);
1874 struct vop_print_args /* {
1878 struct denode *dep = VTODE(ap->a_vp);
1881 "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ",
1882 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1883 printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev));
1884 lockmgr_printinfo(&dep->de_lock);
1890 msdosfs_pathconf(ap)
1891 struct vop_pathconf_args /* {
1897 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1899 switch (ap->a_name) {
1904 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1907 *ap->a_retval = PATH_MAX;
1909 case _PC_CHOWN_RESTRICTED:
1924 * XXX By default, wimp out... note that a_offset is ignored (and always
1928 msdosfs_getpages(ap)
1929 struct vop_getpages_args *ap;
1931 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
1938 * XXX By default, wimp out... note that a_offset is ignored (and always
1942 msdosfs_putpages(ap)
1943 struct vop_putpages_args *ap;
1945 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
1946 ap->a_sync, ap->a_rtvals);
1949 /* Global vfs data structures for msdosfs */
1950 vop_t **msdosfs_vnodeop_p;
1951 static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1952 { &vop_default_desc, (vop_t *) vop_defaultop },
1953 { &vop_abortop_desc, (vop_t *) msdosfs_abortop },
1954 { &vop_access_desc, (vop_t *) msdosfs_access },
1955 { &vop_bmap_desc, (vop_t *) msdosfs_bmap },
1956 { &vop_cachedlookup_desc, (vop_t *) msdosfs_lookup },
1957 { &vop_close_desc, (vop_t *) msdosfs_close },
1958 { &vop_create_desc, (vop_t *) msdosfs_create },
1959 { &vop_fsync_desc, (vop_t *) msdosfs_fsync },
1960 { &vop_getattr_desc, (vop_t *) msdosfs_getattr },
1961 { &vop_inactive_desc, (vop_t *) msdosfs_inactive },
1962 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
1963 { &vop_link_desc, (vop_t *) msdosfs_link },
1964 { &vop_lock_desc, (vop_t *) vop_stdlock },
1965 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
1966 { &vop_mkdir_desc, (vop_t *) msdosfs_mkdir },
1967 { &vop_mknod_desc, (vop_t *) msdosfs_mknod },
1968 { &vop_pathconf_desc, (vop_t *) msdosfs_pathconf },
1969 { &vop_print_desc, (vop_t *) msdosfs_print },
1970 { &vop_read_desc, (vop_t *) msdosfs_read },
1971 { &vop_readdir_desc, (vop_t *) msdosfs_readdir },
1972 { &vop_reclaim_desc, (vop_t *) msdosfs_reclaim },
1973 { &vop_remove_desc, (vop_t *) msdosfs_remove },
1974 { &vop_rename_desc, (vop_t *) msdosfs_rename },
1975 { &vop_rmdir_desc, (vop_t *) msdosfs_rmdir },
1976 { &vop_setattr_desc, (vop_t *) msdosfs_setattr },
1977 { &vop_strategy_desc, (vop_t *) msdosfs_strategy },
1978 { &vop_symlink_desc, (vop_t *) msdosfs_symlink },
1979 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
1980 { &vop_write_desc, (vop_t *) msdosfs_write },
1981 { &vop_getpages_desc, (vop_t *) msdosfs_getpages },
1982 { &vop_putpages_desc, (vop_t *) msdosfs_putpages },
1985 static struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1986 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1988 VNODEOP_SET(msdosfs_vnodeop_opv_desc);