1 /* $FreeBSD: src/sys/msdosfs/msdosfs_vnops.c,v 1.95.2.4 2003/06/13 15:05:47 trhodes Exp $ */
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>
77 #define DOS_FILESIZE_MAX 0xffffffff
80 * Prototypes for MSDOSFS vnode operations
82 static int msdosfs_create __P((struct vop_create_args *));
83 static int msdosfs_mknod __P((struct vop_mknod_args *));
84 static int msdosfs_close __P((struct vop_close_args *));
85 static int msdosfs_access __P((struct vop_access_args *));
86 static int msdosfs_getattr __P((struct vop_getattr_args *));
87 static int msdosfs_setattr __P((struct vop_setattr_args *));
88 static int msdosfs_read __P((struct vop_read_args *));
89 static int msdosfs_write __P((struct vop_write_args *));
90 static int msdosfs_fsync __P((struct vop_fsync_args *));
91 static int msdosfs_remove __P((struct vop_remove_args *));
92 static int msdosfs_link __P((struct vop_link_args *));
93 static int msdosfs_rename __P((struct vop_rename_args *));
94 static int msdosfs_mkdir __P((struct vop_mkdir_args *));
95 static int msdosfs_rmdir __P((struct vop_rmdir_args *));
96 static int msdosfs_symlink __P((struct vop_symlink_args *));
97 static int msdosfs_readdir __P((struct vop_readdir_args *));
98 static int msdosfs_bmap __P((struct vop_bmap_args *));
99 static int msdosfs_strategy __P((struct vop_strategy_args *));
100 static int msdosfs_print __P((struct vop_print_args *));
101 static int msdosfs_pathconf __P((struct vop_pathconf_args *ap));
102 static int msdosfs_getpages __P((struct vop_getpages_args *));
103 static int msdosfs_putpages __P((struct vop_putpages_args *));
106 * Some general notes:
108 * In the ufs filesystem the inodes, superblocks, and indirect blocks are
109 * read/written using the vnode for the filesystem. Blocks that represent
110 * the contents of a file are read/written using the vnode for the file
111 * (including directories when they are read/written as files). This
112 * presents problems for the dos filesystem because data that should be in
113 * an inode (if dos had them) resides in the directory itself. Since we
114 * must update directory entries without the benefit of having the vnode
115 * for the directory we must use the vnode for the filesystem. This means
116 * that when a directory is actually read/written (via read, write, or
117 * readdir, or seek) we must use the vnode for the filesystem instead of
118 * the vnode for the directory as would happen in ufs. This is to insure we
119 * retreive the correct block from the buffer cache since the hash value is
120 * based upon the vnode address and the desired block number.
124 * Create a regular file. On entry the directory to contain the file being
125 * created is locked. We must release before we return. We must also free
126 * the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
127 * only if the SAVESTART bit in cn_flags is clear on success.
131 struct vop_create_args /* {
133 struct vnode **a_vpp;
134 struct componentname *a_cnp;
138 struct componentname *cnp = ap->a_cnp;
139 struct denode ndirent;
141 struct denode *pdep = VTODE(ap->a_dvp);
146 printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
150 * If this is the root directory and there is no space left we
151 * can't do anything. This is because the root directory can not
154 if (pdep->de_StartCluster == MSDOSFSROOT
155 && pdep->de_fndoffset >= pdep->de_FileSize) {
161 * Create a directory entry for the file, then call createde() to
162 * have it installed. NOTE: DOS files are always executable. We
163 * use the absence of the owner write bit to make the file
167 if ((cnp->cn_flags & HASBUF) == 0)
168 panic("msdosfs_create: no name");
170 bzero(&ndirent, sizeof(ndirent));
171 error = uniqdosname(pdep, cnp, ndirent.de_Name);
175 ndirent.de_Attributes = (ap->a_vap->va_mode & VWRITE) ?
176 ATTR_ARCHIVE : ATTR_ARCHIVE | ATTR_READONLY;
177 ndirent.de_LowerCase = 0;
178 ndirent.de_StartCluster = 0;
179 ndirent.de_FileSize = 0;
180 ndirent.de_dev = pdep->de_dev;
181 ndirent.de_devvp = pdep->de_devvp;
182 ndirent.de_pmp = pdep->de_pmp;
183 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
185 DETIMES(&ndirent, &ts, &ts, &ts);
186 error = createde(&ndirent, pdep, &dep, cnp);
189 *ap->a_vpp = DETOV(dep);
198 struct vop_mknod_args /* {
200 struct vnode **a_vpp;
201 struct componentname *a_cnp;
206 switch (ap->a_vap->va_type) {
208 return (msdosfs_mkdir((struct vop_mkdir_args *)ap));
212 return (msdosfs_create((struct vop_create_args *)ap));
223 struct vop_close_args /* {
226 struct ucred *a_cred;
230 struct vnode *vp = ap->a_vp;
231 struct denode *dep = VTODE(vp);
234 simple_lock(&vp->v_interlock);
235 if (vp->v_usecount > 1) {
237 DETIMES(dep, &ts, &ts, &ts);
239 simple_unlock(&vp->v_interlock);
245 struct vop_access_args /* {
248 struct ucred *a_cred;
252 struct vnode *vp = ap->a_vp;
253 struct denode *dep = VTODE(ap->a_vp);
254 struct msdosfsmount *pmp = dep->de_pmp;
255 struct ucred *cred = ap->a_cred;
256 mode_t mask, file_mode, mode = ap->a_mode;
260 file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) |
261 ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH));
262 file_mode &= pmp->pm_mask;
265 * Disallow write attempts on read-only file systems;
266 * unless the file is a socket, fifo, or a block or
267 * character device resident on the file system.
270 switch (vp->v_type) {
274 if (vp->v_mount->mnt_flag & MNT_RDONLY)
282 /* User id 0 always gets access. */
283 if (cred->cr_uid == 0)
288 /* Otherwise, check the owner. */
289 if (cred->cr_uid == pmp->pm_uid) {
296 return (file_mode & mask) == mask ? 0 : EACCES;
299 /* Otherwise, check the groups. */
300 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
301 if (pmp->pm_gid == *gp) {
308 return (file_mode & mask) == mask ? 0 : EACCES;
311 /* Otherwise, check everyone else. */
318 return (file_mode & mask) == mask ? 0 : EACCES;
323 struct vop_getattr_args /* {
326 struct ucred *a_cred;
330 struct denode *dep = VTODE(ap->a_vp);
331 struct msdosfsmount *pmp = dep->de_pmp;
332 struct vattr *vap = ap->a_vap;
335 u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
339 DETIMES(dep, &ts, &ts, &ts);
340 vap->va_fsid = dev2udev(dep->de_dev);
342 * The following computation of the fileid must be the same as that
343 * used in msdosfs_readdir() to compute d_fileno. If not, pwd
346 if (dep->de_Attributes & ATTR_DIRECTORY) {
347 fileid = cntobn(pmp, dep->de_StartCluster) * dirsperblk;
348 if (dep->de_StartCluster == MSDOSFSROOT)
351 fileid = cntobn(pmp, dep->de_dirclust) * dirsperblk;
352 if (dep->de_dirclust == MSDOSFSROOT)
353 fileid = roottobn(pmp, 0) * dirsperblk;
354 fileid += dep->de_diroffset / sizeof(struct direntry);
356 vap->va_fileid = fileid;
357 if ((dep->de_Attributes & ATTR_READONLY) == 0)
358 mode = S_IRWXU|S_IRWXG|S_IRWXO;
360 mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
361 vap->va_mode = mode & pmp->pm_mask;
362 vap->va_uid = pmp->pm_uid;
363 vap->va_gid = pmp->pm_gid;
366 vap->va_size = dep->de_FileSize;
367 dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
368 if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
369 dos2unixtime(dep->de_ADate, 0, 0, &vap->va_atime);
370 dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun, &vap->va_ctime);
372 vap->va_atime = vap->va_mtime;
373 vap->va_ctime = vap->va_mtime;
376 if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
377 vap->va_flags |= SF_ARCHIVED;
379 vap->va_blocksize = pmp->pm_bpcluster;
381 (dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
382 vap->va_type = ap->a_vp->v_type;
383 vap->va_filerev = dep->de_modrev;
389 struct vop_setattr_args /* {
392 struct ucred *a_cred;
396 struct vnode *vp = ap->a_vp;
397 struct denode *dep = VTODE(ap->a_vp);
398 struct msdosfsmount *pmp = dep->de_pmp;
399 struct vattr *vap = ap->a_vap;
400 struct ucred *cred = ap->a_cred;
404 printf("msdosfs_setattr(): vp %p, vap %p, cred %p, p %p\n",
405 ap->a_vp, vap, cred, ap->a_p);
409 * Check for unsettable attributes.
411 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
412 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
413 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
414 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
416 printf("msdosfs_setattr(): returning EINVAL\n");
417 printf(" va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
418 vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
419 printf(" va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
420 vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
421 printf(" va_uid %x, va_gid %x\n",
422 vap->va_uid, vap->va_gid);
426 if (vap->va_flags != VNOVAL) {
427 if (vp->v_mount->mnt_flag & MNT_RDONLY)
429 if (cred->cr_uid != pmp->pm_uid &&
430 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
433 * We are very inconsistent about handling unsupported
434 * attributes. We ignored the access time and the
435 * read and execute bits. We were strict for the other
438 * Here we are strict, stricter than ufs in not allowing
439 * users to attempt to set SF_SETTABLE bits or anyone to
440 * set unsupported bits. However, we ignore attempts to
441 * set ATTR_ARCHIVE for directories `cp -pr' from a more
442 * sensible file system attempts it a lot.
444 if (cred->cr_uid != 0) {
445 if (vap->va_flags & SF_SETTABLE)
448 if (vap->va_flags & ~SF_ARCHIVED)
450 if (vap->va_flags & SF_ARCHIVED)
451 dep->de_Attributes &= ~ATTR_ARCHIVE;
452 else if (!(dep->de_Attributes & ATTR_DIRECTORY))
453 dep->de_Attributes |= ATTR_ARCHIVE;
454 dep->de_flag |= DE_MODIFIED;
457 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
461 if (vp->v_mount->mnt_flag & MNT_RDONLY)
464 if (uid == (uid_t)VNOVAL)
467 if (gid == (gid_t)VNOVAL)
469 if ((cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
470 (gid != pmp->pm_gid && !groupmember(gid, cred))) &&
471 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
473 if (uid != pmp->pm_uid || gid != pmp->pm_gid)
477 if (vap->va_size != VNOVAL) {
479 * Disallow write attempts on read-only file systems;
480 * unless the file is a socket, fifo, or a block or
481 * character device resident on the file system.
483 switch (vp->v_type) {
489 if (vp->v_mount->mnt_flag & MNT_RDONLY)
495 error = detrunc(dep, vap->va_size, 0, cred, ap->a_p);
499 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
500 if (vp->v_mount->mnt_flag & MNT_RDONLY)
502 if (cred->cr_uid != pmp->pm_uid &&
503 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)) &&
504 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
505 (error = VOP_ACCESS(ap->a_vp, VWRITE, cred, ap->a_p))))
507 if (vp->v_type != VDIR) {
508 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
509 vap->va_atime.tv_sec != VNOVAL) {
510 dep->de_flag &= ~DE_ACCESS;
511 unix2dostime(&vap->va_atime, &dep->de_ADate,
514 if (vap->va_mtime.tv_sec != VNOVAL) {
515 dep->de_flag &= ~DE_UPDATE;
516 unix2dostime(&vap->va_mtime, &dep->de_MDate,
517 &dep->de_MTime, NULL);
519 dep->de_Attributes |= ATTR_ARCHIVE;
520 dep->de_flag |= DE_MODIFIED;
524 * DOS files only have the ability to have their writability
525 * attribute set, so we use the owner write bit to set the readonly
528 if (vap->va_mode != (mode_t)VNOVAL) {
529 if (vp->v_mount->mnt_flag & MNT_RDONLY)
531 if (cred->cr_uid != pmp->pm_uid &&
532 (error = suser_xxx(cred, ap->a_p, PRISON_ROOT)))
534 if (vp->v_type != VDIR) {
535 /* We ignore the read and execute bits. */
536 if (vap->va_mode & VWRITE)
537 dep->de_Attributes &= ~ATTR_READONLY;
539 dep->de_Attributes |= ATTR_READONLY;
540 dep->de_Attributes |= ATTR_ARCHIVE;
541 dep->de_flag |= DE_MODIFIED;
544 return (deupdat(dep, 1));
549 struct vop_read_args /* {
553 struct ucred *a_cred;
568 struct vnode *vp = ap->a_vp;
569 struct denode *dep = VTODE(vp);
570 struct msdosfsmount *pmp = dep->de_pmp;
571 struct uio *uio = ap->a_uio;
573 if (uio->uio_offset < 0)
576 if ((uoff_t)uio->uio_offset > DOS_FILESIZE_MAX)
579 * If they didn't ask for any data, then we are done.
581 orig_resid = uio->uio_resid;
585 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
587 isadir = dep->de_Attributes & ATTR_DIRECTORY;
589 if (uio->uio_offset >= dep->de_FileSize)
591 lbn = de_cluster(pmp, uio->uio_offset);
593 * If we are operating on a directory file then be sure to
594 * do i/o with the vnode for the filesystem instead of the
595 * vnode for the directory.
598 /* convert cluster # to block # */
599 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
600 if (error == E2BIG) {
605 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
607 blsize = pmp->pm_bpcluster;
610 de_cn2off(pmp, rablock) < dep->de_FileSize) {
611 rasize = pmp->pm_bpcluster;
612 error = breadn(vp, lbn, blsize,
613 &rablock, &rasize, 1, NOCRED, &bp);
615 error = bread(vp, lbn, blsize, NOCRED, &bp);
622 on = uio->uio_offset & pmp->pm_crbomask;
623 diff = pmp->pm_bpcluster - on;
624 n = diff > uio->uio_resid ? uio->uio_resid : diff;
625 diff = dep->de_FileSize - uio->uio_offset;
628 diff = blsize - bp->b_resid;
631 error = uiomove(bp->b_data + on, (int) n, uio);
633 } while (error == 0 && uio->uio_resid > 0 && n != 0);
634 if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
635 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
636 dep->de_flag |= DE_ACCESS;
641 * Write data to a file or directory.
645 struct vop_write_args /* {
649 struct ucred *a_cred;
660 int ioflag = ap->a_ioflag;
661 struct uio *uio = ap->a_uio;
662 struct proc *p = uio->uio_procp;
663 struct vnode *vp = ap->a_vp;
664 struct vnode *thisvp;
665 struct denode *dep = VTODE(vp);
666 struct msdosfsmount *pmp = dep->de_pmp;
667 struct ucred *cred = ap->a_cred;
670 printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
671 vp, uio, ioflag, cred);
672 printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
673 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
676 switch (vp->v_type) {
678 if (ioflag & IO_APPEND)
679 uio->uio_offset = dep->de_FileSize;
685 panic("msdosfs_write(): bad file type");
688 if (uio->uio_offset < 0)
691 if (uio->uio_resid == 0)
695 * If they've exceeded their filesize limit, tell them about it.
698 ((uoff_t)uio->uio_offset + uio->uio_resid >
699 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
704 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
708 * If the offset we are starting the write at is beyond the end of
709 * the file, then they've done a seek. Unix filesystems allow
710 * files with holes in them, DOS doesn't so we must fill the hole
711 * with zeroed blocks.
713 if (uio->uio_offset > dep->de_FileSize) {
714 error = deextend(dep, uio->uio_offset, cred);
720 * Remember some values in case the write fails.
722 resid = uio->uio_resid;
723 osize = dep->de_FileSize;
726 * If we write beyond the end of the file, extend it to its ultimate
727 * size ahead of the time to hopefully get a contiguous area.
729 if (uio->uio_offset + resid > osize) {
730 count = de_clcount(pmp, uio->uio_offset + resid) -
731 de_clcount(pmp, osize);
732 error = extendfile(dep, count, NULL, NULL, 0);
733 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
735 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
737 lastcn = de_clcount(pmp, osize) - 1;
740 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
745 croffset = uio->uio_offset & pmp->pm_crbomask;
746 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
747 if (uio->uio_offset + n > dep->de_FileSize) {
748 dep->de_FileSize = uio->uio_offset + n;
749 /* The object size needs to be set before buffer is allocated */
750 vnode_pager_setsize(vp, dep->de_FileSize);
753 bn = de_cluster(pmp, uio->uio_offset);
754 if ((uio->uio_offset & pmp->pm_crbomask) == 0
755 && (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
756 > de_cluster(pmp, uio->uio_offset)
757 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
759 * If either the whole cluster gets written,
760 * or we write the cluster from its start beyond EOF,
761 * then no need to read data from disk.
763 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0);
766 * Do the bmap now, since pcbmap needs buffers
767 * for the fat table. (see msdosfs_strategy)
769 if (bp->b_blkno == bp->b_lblkno) {
770 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno,
775 if (bp->b_blkno == -1) {
778 error = EIO; /* XXX */
783 * The block we need to write into exists, so read it in.
785 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
793 * Should these vnode_pager_* functions be done on dir
798 * Copy the data from user space into the buf header.
800 error = uiomove(bp->b_data + croffset, n, uio);
807 * If they want this synchronous then write it and wait for
808 * it. Otherwise, if on a cluster boundary write it
809 * asynchronously so we can move on to the next block
810 * without delay. Otherwise do a delayed write because we
811 * may want to write somemore into the block later.
813 if (ioflag & IO_SYNC)
815 else if (n + croffset == pmp->pm_bpcluster)
819 dep->de_flag |= DE_UPDATE;
820 } while (error == 0 && uio->uio_resid > 0);
823 * If the write failed and they want us to, truncate the file back
824 * to the size it was before the write was attempted.
828 if (ioflag & IO_UNIT) {
829 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
830 uio->uio_offset -= resid - uio->uio_resid;
831 uio->uio_resid = resid;
833 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
834 if (uio->uio_resid != resid)
837 } else if (ioflag & IO_SYNC)
838 error = deupdat(dep, 1);
843 * Flush the blocks of a file to disk.
845 * This function is worthless for vnodes that represent directories. Maybe we
846 * could just do a sync if they try an fsync on a directory file.
850 struct vop_fsync_args /* {
852 struct ucred *a_cred;
857 struct vnode *vp = ap->a_vp;
859 struct buf *bp, *nbp;
862 * Flush all dirty buffers associated with a vnode.
866 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
867 nbp = TAILQ_NEXT(bp, b_vnbufs);
868 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT))
870 if ((bp->b_flags & B_DELWRI) == 0)
871 panic("msdosfs_fsync: not dirty");
877 while (vp->v_numoutput) {
878 vp->v_flag |= VBWAIT;
879 (void) tsleep((caddr_t)&vp->v_numoutput, PRIBIO + 1, "msdosfsn", 0);
882 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
883 vprint("msdosfs_fsync: dirty", vp);
888 return (deupdat(VTODE(vp), ap->a_waitfor == MNT_WAIT));
893 struct vop_remove_args /* {
896 struct componentname *a_cnp;
899 struct denode *dep = VTODE(ap->a_vp);
900 struct denode *ddep = VTODE(ap->a_dvp);
903 if (ap->a_vp->v_type == VDIR)
906 error = removede(ddep, dep);
908 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
914 * DOS filesystems don't know what links are. But since we already called
915 * msdosfs_lookup() with create and lockparent, the parent is locked so we
916 * have to free it before we return the error.
920 struct vop_link_args /* {
921 struct vnode *a_tdvp;
923 struct componentname *a_cnp;
930 * Renames on files require moving the denode to a new hash queue since the
931 * denode's location is used to compute which hash queue to put the file
932 * in. Unless it is a rename in place. For example "mv a b".
934 * What follows is the basic algorithm:
937 * if (dest file exists) {
940 * if (dest and src in same directory) {
941 * rewrite name in existing directory slot
943 * write new entry in dest directory
944 * update offset and dirclust in denode
945 * move denode to new hash chain
946 * clear old directory entry
950 * if (dest directory exists) {
951 * if (dest is not empty) {
954 * remove dest directory
956 * if (dest and src in same directory) {
957 * rewrite name in existing entry
959 * be sure dest is not a child of src directory
960 * write entry in dest directory
961 * update "." and ".." in moved directory
962 * clear old directory entry for moved directory
967 * source's parent directory is unlocked
968 * source file or directory is unlocked
969 * destination's parent directory is locked
970 * destination file or directory is locked if it exists
973 * all denodes should be released
976 * I'm not sure how the memory containing the pathnames pointed at by the
977 * componentname structures is freed, there may be some memory bleeding
978 * for each rename done.
982 struct vop_rename_args /* {
983 struct vnode *a_fdvp;
985 struct componentname *a_fcnp;
986 struct vnode *a_tdvp;
988 struct componentname *a_tcnp;
991 struct vnode *tdvp = ap->a_tdvp;
992 struct vnode *fvp = ap->a_fvp;
993 struct vnode *fdvp = ap->a_fdvp;
994 struct vnode *tvp = ap->a_tvp;
995 struct componentname *tcnp = ap->a_tcnp;
996 struct componentname *fcnp = ap->a_fcnp;
997 struct proc *p = fcnp->cn_proc;
998 struct denode *ip, *xp, *dp, *zp;
999 u_char toname[11], oldname[11];
1000 u_long from_diroffset, to_diroffset;
1002 int doingdirectory = 0, newparent = 0;
1006 struct denode *fddep; /* from file's parent directory */
1007 struct msdosfsmount *pmp;
1008 struct direntry *dotdotp;
1011 fddep = VTODE(ap->a_fdvp);
1012 pmp = fddep->de_pmp;
1014 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1017 if ((tcnp->cn_flags & HASBUF) == 0 ||
1018 (fcnp->cn_flags & HASBUF) == 0)
1019 panic("msdosfs_rename: no name");
1022 * Check for cross-device rename.
1024 if ((fvp->v_mount != tdvp->v_mount) ||
1025 (tvp && (fvp->v_mount != tvp->v_mount))) {
1040 * If source and dest are the same, do nothing.
1047 error = vn_lock(fvp, LK_EXCLUSIVE, p);
1054 * Be sure we are not renaming ".", "..", or an alias of ".". This
1055 * leads to a crippled directory tree. It's pretty tough to do a
1056 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
1057 * doesn't work if the ".." entry is missing.
1059 if (ip->de_Attributes & ATTR_DIRECTORY) {
1061 * Avoid ".", "..", and aliases of "." for obvious reasons.
1063 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1065 (fcnp->cn_flags & ISDOTDOT) ||
1066 (tcnp->cn_flags & ISDOTDOT) ||
1067 (ip->de_flag & DE_RENAME)) {
1068 VOP_UNLOCK(fvp, 0, p);
1072 ip->de_flag |= DE_RENAME;
1077 * When the target exists, both the directory
1078 * and target vnodes are returned locked.
1081 xp = tvp ? VTODE(tvp) : NULL;
1083 * Remember direntry place to use for destination
1085 to_diroffset = dp->de_fndoffset;
1086 to_count = dp->de_fndcnt;
1089 * If ".." must be changed (ie the directory gets a new
1090 * parent) then the source directory must not be in the
1091 * directory heirarchy above the target, as this would
1092 * orphan everything below the source directory. Also
1093 * the user must have write permission in the source so
1094 * as to be able to change "..". We must repeat the call
1095 * to namei, as the parent directory is unlocked by the
1096 * call to doscheckpath().
1098 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_proc);
1099 VOP_UNLOCK(fvp, 0, p);
1100 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1102 if (doingdirectory && newparent) {
1103 if (error) /* write access check above */
1108 * doscheckpath() vput()'s dp,
1109 * so we have to do a relookup afterwards
1111 error = doscheckpath(ip, dp);
1114 if ((tcnp->cn_flags & SAVESTART) == 0)
1115 panic("msdosfs_rename: lost to startdir");
1116 error = relookup(tdvp, &tvp, tcnp);
1120 xp = tvp ? VTODE(tvp) : NULL;
1125 * Target must be empty if a directory and have no links
1126 * to it. Also, ensure source and target are compatible
1127 * (both directories, or both not directories).
1129 if (xp->de_Attributes & ATTR_DIRECTORY) {
1130 if (!dosdirempty(xp)) {
1134 if (!doingdirectory) {
1139 } else if (doingdirectory) {
1143 error = removede(dp, xp);
1151 * Convert the filename in tcnp into a dos filename. We copy this
1152 * into the denode and directory entry for the destination
1155 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1160 * Since from wasn't locked at various places above,
1161 * have to do a relookup here.
1163 fcnp->cn_flags &= ~MODMASK;
1164 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1165 if ((fcnp->cn_flags & SAVESTART) == 0)
1166 panic("msdosfs_rename: lost from startdir");
1168 VOP_UNLOCK(tdvp, 0, p);
1169 if (relookup(fdvp, &fvp, fcnp) == 0)
1173 * From name has disappeared.
1176 panic("rename: lost dir entry");
1179 VOP_UNLOCK(tdvp, 0, p);
1185 from_diroffset = zp->de_fndoffset;
1188 * Ensure that the directory entry still exists and has not
1189 * changed till now. If the source is a file the entry may
1190 * have been unlinked or renamed. In either case there is
1191 * no further work to be done. If the source is a directory
1192 * then it cannot have been rmdir'ed or renamed; this is
1193 * prohibited by the DE_RENAME flag.
1197 panic("rename: lost dir entry");
1199 VOP_UNLOCK(fvp, 0, p);
1201 VOP_UNLOCK(fdvp, 0, p);
1208 * First write a new entry in the destination
1209 * directory and mark the entry in the source directory
1210 * as deleted. Then move the denode to the correct hash
1211 * chain for its new location in the filesystem. And, if
1212 * we moved a directory, then update its .. entry to point
1213 * to the new parent directory.
1215 bcopy(ip->de_Name, oldname, 11);
1216 bcopy(toname, ip->de_Name, 11); /* update denode */
1217 dp->de_fndoffset = to_diroffset;
1218 dp->de_fndcnt = to_count;
1219 error = createde(ip, dp, (struct denode **)0, tcnp);
1221 bcopy(oldname, ip->de_Name, 11);
1223 VOP_UNLOCK(fdvp, 0, p);
1224 VOP_UNLOCK(fvp, 0, p);
1228 zp->de_fndoffset = from_diroffset;
1229 error = removede(zp, ip);
1231 /* XXX should really panic here, fs is corrupt */
1233 VOP_UNLOCK(fdvp, 0, p);
1234 VOP_UNLOCK(fvp, 0, p);
1237 if (!doingdirectory) {
1238 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1239 &ip->de_dirclust, 0);
1241 /* XXX should really panic here, fs is corrupt */
1243 VOP_UNLOCK(fdvp, 0, p);
1244 VOP_UNLOCK(fvp, 0, p);
1247 if (ip->de_dirclust == MSDOSFSROOT)
1248 ip->de_diroffset = to_diroffset;
1250 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1254 VOP_UNLOCK(fdvp, 0, p);
1258 * If we moved a directory to a new parent directory, then we must
1259 * fixup the ".." entry in the moved directory.
1261 if (doingdirectory && newparent) {
1262 cn = ip->de_StartCluster;
1263 if (cn == MSDOSFSROOT) {
1264 /* this should never happen */
1265 panic("msdosfs_rename(): updating .. in root directory?");
1267 bn = cntobn(pmp, cn);
1268 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1271 /* XXX should really panic here, fs is corrupt */
1273 VOP_UNLOCK(fvp, 0, p);
1276 dotdotp = (struct direntry *)bp->b_data + 1;
1277 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1279 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1282 /* XXX should really panic here, fs is corrupt */
1283 VOP_UNLOCK(fvp, 0, p);
1288 VOP_UNLOCK(fvp, 0, p);
1294 ip->de_flag &= ~DE_RENAME;
1302 struct direntry dot;
1303 struct direntry dotdot;
1304 } dosdirtemplate = {
1305 { ". ", " ", /* the . entry */
1306 ATTR_DIRECTORY, /* file attribute */
1308 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1309 { 0, 0 }, /* access date */
1310 { 0, 0 }, /* high bits of start cluster */
1311 { 210, 4 }, { 210, 4 }, /* modify time & date */
1312 { 0, 0 }, /* startcluster */
1313 { 0, 0, 0, 0 } /* filesize */
1315 { ".. ", " ", /* the .. entry */
1316 ATTR_DIRECTORY, /* file attribute */
1318 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1319 { 0, 0 }, /* access date */
1320 { 0, 0 }, /* high bits of start cluster */
1321 { 210, 4 }, { 210, 4 }, /* modify time & date */
1322 { 0, 0 }, /* startcluster */
1323 { 0, 0, 0, 0 } /* filesize */
1329 struct vop_mkdir_args /* {
1330 struct vnode *a_dvp;
1331 struvt vnode **a_vpp;
1332 struvt componentname *a_cnp;
1333 struct vattr *a_vap;
1336 struct componentname *cnp = ap->a_cnp;
1338 struct denode *pdep = VTODE(ap->a_dvp);
1339 struct direntry *denp;
1340 struct msdosfsmount *pmp = pdep->de_pmp;
1342 u_long newcluster, pcl;
1345 struct denode ndirent;
1349 * If this is the root directory and there is no space left we
1350 * can't do anything. This is because the root directory can not
1353 if (pdep->de_StartCluster == MSDOSFSROOT
1354 && pdep->de_fndoffset >= pdep->de_FileSize) {
1360 * Allocate a cluster to hold the about to be created directory.
1362 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1366 bzero(&ndirent, sizeof(ndirent));
1367 ndirent.de_pmp = pmp;
1368 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1370 DETIMES(&ndirent, &ts, &ts, &ts);
1373 * Now fill the cluster with the "." and ".." entries. And write
1374 * the cluster to disk. This way it is there for the parent
1375 * directory to be pointing at if there were a crash.
1377 bn = cntobn(pmp, newcluster);
1378 /* always succeeds */
1379 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0);
1380 bzero(bp->b_data, pmp->pm_bpcluster);
1381 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1382 denp = (struct direntry *)bp->b_data;
1383 putushort(denp[0].deStartCluster, newcluster);
1384 putushort(denp[0].deCDate, ndirent.de_CDate);
1385 putushort(denp[0].deCTime, ndirent.de_CTime);
1386 denp[0].deCHundredth = ndirent.de_CHun;
1387 putushort(denp[0].deADate, ndirent.de_ADate);
1388 putushort(denp[0].deMDate, ndirent.de_MDate);
1389 putushort(denp[0].deMTime, ndirent.de_MTime);
1390 pcl = pdep->de_StartCluster;
1391 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1393 putushort(denp[1].deStartCluster, pcl);
1394 putushort(denp[1].deCDate, ndirent.de_CDate);
1395 putushort(denp[1].deCTime, ndirent.de_CTime);
1396 denp[1].deCHundredth = ndirent.de_CHun;
1397 putushort(denp[1].deADate, ndirent.de_ADate);
1398 putushort(denp[1].deMDate, ndirent.de_MDate);
1399 putushort(denp[1].deMTime, ndirent.de_MTime);
1401 putushort(denp[0].deHighClust, newcluster >> 16);
1402 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1410 * Now build up a directory entry pointing to the newly allocated
1411 * cluster. This will be written to an empty slot in the parent
1415 if ((cnp->cn_flags & HASBUF) == 0)
1416 panic("msdosfs_mkdir: no name");
1418 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1422 ndirent.de_Attributes = ATTR_DIRECTORY;
1423 ndirent.de_LowerCase = 0;
1424 ndirent.de_StartCluster = newcluster;
1425 ndirent.de_FileSize = 0;
1426 ndirent.de_dev = pdep->de_dev;
1427 ndirent.de_devvp = pdep->de_devvp;
1428 error = createde(&ndirent, pdep, &dep, cnp);
1431 *ap->a_vpp = DETOV(dep);
1435 clusterfree(pmp, newcluster, NULL);
1442 struct vop_rmdir_args /* {
1443 struct vnode *a_dvp;
1445 struct componentname *a_cnp;
1448 register struct vnode *vp = ap->a_vp;
1449 register struct vnode *dvp = ap->a_dvp;
1450 register struct componentname *cnp = ap->a_cnp;
1451 register struct denode *ip, *dp;
1452 struct proc *p = cnp->cn_proc;
1459 * Verify the directory is empty (and valid).
1460 * (Rmdir ".." won't be valid since
1461 * ".." will contain a reference to
1462 * the current directory and thus be
1466 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1471 * Delete the entry from the directory. For dos filesystems this
1472 * gets rid of the directory entry on disk, the in memory copy
1473 * still exists but the de_refcnt is <= 0. This prevents it from
1474 * being found by deget(). When the vput() on dep is done we give
1475 * up access and eventually msdosfs_reclaim() will be called which
1476 * will remove it from the denode cache.
1478 error = removede(dp, ip);
1482 * This is where we decrement the link count in the parent
1483 * directory. Since dos filesystems don't do this we just purge
1487 VOP_UNLOCK(dvp, 0, p);
1489 * Truncate the directory that is being deleted.
1491 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, p);
1494 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
1500 * DOS filesystems don't know what symlinks are.
1504 struct vop_symlink_args /* {
1505 struct vnode *a_dvp;
1506 struct vnode **a_vpp;
1507 struct componentname *a_cnp;
1508 struct vattr *a_vap;
1512 return (EOPNOTSUPP);
1517 struct vop_readdir_args /* {
1520 struct ucred *a_cred;
1537 struct denode *dep = VTODE(ap->a_vp);
1538 struct msdosfsmount *pmp = dep->de_pmp;
1539 struct direntry *dentp;
1540 struct dirent dirbuf;
1541 struct uio *uio = ap->a_uio;
1542 u_long *cookies = NULL;
1547 #ifdef MSDOSFS_DEBUG
1548 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1549 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1553 * msdosfs_readdir() won't operate properly on regular files since
1554 * it does i/o only with the the filesystem vnode, and hence can
1555 * retrieve the wrong block from the buffer cache for a plain file.
1556 * So, fail attempts to readdir() on a plain file.
1558 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1562 * To be safe, initialize dirbuf
1564 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1567 * If the user buffer is smaller than the size of one dos directory
1568 * entry or the file offset is not a multiple of the size of a
1569 * directory entry, then we fail the read.
1571 off = offset = uio->uio_offset;
1572 if (uio->uio_resid < sizeof(struct direntry) ||
1573 (offset & (sizeof(struct direntry) - 1)))
1576 if (ap->a_ncookies) {
1577 ncookies = uio->uio_resid / 16;
1578 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1580 *ap->a_cookies = cookies;
1581 *ap->a_ncookies = ncookies;
1584 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1587 * If they are reading from the root directory then, we simulate
1588 * the . and .. entries since these don't exist in the root
1589 * directory. We also set the offset bias to make up for having to
1590 * simulate these entries. By this I mean that at file offset 64 we
1591 * read the first entry in the root directory that lives on disk.
1593 if (dep->de_StartCluster == MSDOSFSROOT
1594 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1596 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1599 bias = 2 * sizeof(struct direntry);
1600 if (offset < bias) {
1601 for (n = (int)offset / sizeof(struct direntry);
1604 dirbuf.d_fileno = cntobn(pmp,
1608 dirbuf.d_fileno = 1;
1609 dirbuf.d_type = DT_DIR;
1612 dirbuf.d_namlen = 1;
1613 strcpy(dirbuf.d_name, ".");
1616 dirbuf.d_namlen = 2;
1617 strcpy(dirbuf.d_name, "..");
1620 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1621 if (uio->uio_resid < dirbuf.d_reclen)
1623 error = uiomove((caddr_t) &dirbuf,
1624 dirbuf.d_reclen, uio);
1627 offset += sizeof(struct direntry);
1630 *cookies++ = offset;
1631 if (--ncookies <= 0)
1639 while (uio->uio_resid > 0) {
1640 lbn = de_cluster(pmp, offset - bias);
1641 on = (offset - bias) & pmp->pm_crbomask;
1642 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1643 diff = dep->de_FileSize - (offset - bias);
1647 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1650 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1655 n = min(n, blsize - bp->b_resid);
1658 * Convert from dos directory entries to fs-independent
1659 * directory entries.
1661 for (dentp = (struct direntry *)(bp->b_data + on);
1662 (char *)dentp < bp->b_data + on + n;
1663 dentp++, offset += sizeof(struct direntry)) {
1665 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1666 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1669 * If this is an unused entry, we can stop.
1671 if (dentp->deName[0] == SLOT_EMPTY) {
1676 * Skip deleted entries.
1678 if (dentp->deName[0] == SLOT_DELETED) {
1684 * Handle Win95 long directory entries
1686 if (dentp->deAttributes == ATTR_WIN95) {
1687 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1689 chksum = win2unixfn((struct winentry *)dentp,
1691 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1697 * Skip volume labels
1699 if (dentp->deAttributes & ATTR_VOLUME) {
1704 * This computation of d_fileno must match
1705 * the computation of va_fileid in
1708 if (dentp->deAttributes & ATTR_DIRECTORY) {
1709 fileno = getushort(dentp->deStartCluster);
1711 fileno |= getushort(dentp->deHighClust) << 16;
1712 /* if this is the root directory */
1713 if (fileno == MSDOSFSROOT)
1715 fileno = cntobn(pmp,
1721 fileno = cntobn(pmp, fileno) * dirsperblk;
1722 dirbuf.d_fileno = fileno;
1723 dirbuf.d_type = DT_DIR;
1725 dirbuf.d_fileno = offset / sizeof(struct direntry);
1726 dirbuf.d_type = DT_REG;
1728 if (chksum != winChksum(dentp->deName))
1729 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1730 (u_char *)dirbuf.d_name,
1731 dentp->deLowerCase |
1732 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1733 (LCASE_BASE | LCASE_EXT) : 0),
1734 pmp->pm_flags & MSDOSFSMNT_U2WTABLE,
1736 pmp->pm_flags & MSDOSFSMNT_ULTABLE,
1739 dirbuf.d_name[dirbuf.d_namlen] = 0;
1741 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1742 if (uio->uio_resid < dirbuf.d_reclen) {
1746 error = uiomove((caddr_t) &dirbuf,
1747 dirbuf.d_reclen, uio);
1753 *cookies++ = offset + sizeof(struct direntry);
1754 if (--ncookies <= 0) {
1759 off = offset + sizeof(struct direntry);
1764 /* Subtract unused cookies */
1766 *ap->a_ncookies -= ncookies;
1768 uio->uio_offset = off;
1771 * Set the eofflag (NFS uses it)
1773 if (ap->a_eofflag) {
1774 if (dep->de_FileSize - (offset - bias) <= 0)
1783 * vp - address of vnode file the file
1784 * bn - which cluster we are interested in mapping to a filesystem block number.
1785 * vpp - returns the vnode for the block special file holding the filesystem
1786 * containing the file of interest
1787 * bnp - address of where to return the filesystem relative block number
1791 struct vop_bmap_args /* {
1794 struct vnode **a_vpp;
1800 struct denode *dep = VTODE(ap->a_vp);
1802 if (ap->a_vpp != NULL)
1803 *ap->a_vpp = dep->de_devvp;
1804 if (ap->a_bnp == NULL)
1808 * Sequential clusters should be counted here.
1815 return (pcbmap(dep, ap->a_bn, ap->a_bnp, 0, 0));
1819 msdosfs_strategy(ap)
1820 struct vop_strategy_args /* {
1825 struct buf *bp = ap->a_bp;
1826 struct denode *dep = VTODE(bp->b_vp);
1830 if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
1831 panic("msdosfs_strategy: spec");
1833 * If we don't already know the filesystem relative block number
1834 * then get it using pcbmap(). If pcbmap() returns the block
1835 * number as -1 then we've got a hole in the file. DOS filesystems
1836 * don't allow files with holes, so we shouldn't ever see this.
1838 if (bp->b_blkno == bp->b_lblkno) {
1839 error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0, 0);
1841 bp->b_error = error;
1842 bp->b_flags |= B_ERROR;
1846 if ((long)bp->b_blkno == -1)
1849 if (bp->b_blkno == -1) {
1854 * Read/write the block from/to the disk that contains the desired
1858 bp->b_dev = vp->v_rdev;
1859 VOP_STRATEGY(vp, bp);
1865 struct vop_print_args /* {
1869 struct denode *dep = VTODE(ap->a_vp);
1872 "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ",
1873 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1874 printf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev));
1875 lockmgr_printinfo(&dep->de_lock);
1881 msdosfs_pathconf(ap)
1882 struct vop_pathconf_args /* {
1888 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1890 switch (ap->a_name) {
1895 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1898 *ap->a_retval = PATH_MAX;
1900 case _PC_CHOWN_RESTRICTED:
1915 * XXX By default, wimp out... note that a_offset is ignored (and always
1919 msdosfs_getpages(ap)
1920 struct vop_getpages_args *ap;
1922 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
1929 * XXX By default, wimp out... note that a_offset is ignored (and always
1933 msdosfs_putpages(ap)
1934 struct vop_putpages_args *ap;
1936 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
1937 ap->a_sync, ap->a_rtvals);
1940 /* Global vfs data structures for msdosfs */
1941 vop_t **msdosfs_vnodeop_p;
1942 static struct vnodeopv_entry_desc msdosfs_vnodeop_entries[] = {
1943 { &vop_default_desc, (vop_t *) vop_defaultop },
1944 { &vop_access_desc, (vop_t *) msdosfs_access },
1945 { &vop_bmap_desc, (vop_t *) msdosfs_bmap },
1946 { &vop_cachedlookup_desc, (vop_t *) msdosfs_lookup },
1947 { &vop_close_desc, (vop_t *) msdosfs_close },
1948 { &vop_create_desc, (vop_t *) msdosfs_create },
1949 { &vop_fsync_desc, (vop_t *) msdosfs_fsync },
1950 { &vop_getattr_desc, (vop_t *) msdosfs_getattr },
1951 { &vop_inactive_desc, (vop_t *) msdosfs_inactive },
1952 { &vop_islocked_desc, (vop_t *) vop_stdislocked },
1953 { &vop_link_desc, (vop_t *) msdosfs_link },
1954 { &vop_lock_desc, (vop_t *) vop_stdlock },
1955 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup },
1956 { &vop_mkdir_desc, (vop_t *) msdosfs_mkdir },
1957 { &vop_mknod_desc, (vop_t *) msdosfs_mknod },
1958 { &vop_pathconf_desc, (vop_t *) msdosfs_pathconf },
1959 { &vop_print_desc, (vop_t *) msdosfs_print },
1960 { &vop_read_desc, (vop_t *) msdosfs_read },
1961 { &vop_readdir_desc, (vop_t *) msdosfs_readdir },
1962 { &vop_reclaim_desc, (vop_t *) msdosfs_reclaim },
1963 { &vop_remove_desc, (vop_t *) msdosfs_remove },
1964 { &vop_rename_desc, (vop_t *) msdosfs_rename },
1965 { &vop_rmdir_desc, (vop_t *) msdosfs_rmdir },
1966 { &vop_setattr_desc, (vop_t *) msdosfs_setattr },
1967 { &vop_strategy_desc, (vop_t *) msdosfs_strategy },
1968 { &vop_symlink_desc, (vop_t *) msdosfs_symlink },
1969 { &vop_unlock_desc, (vop_t *) vop_stdunlock },
1970 { &vop_write_desc, (vop_t *) msdosfs_write },
1971 { &vop_getpages_desc, (vop_t *) msdosfs_getpages },
1972 { &vop_putpages_desc, (vop_t *) msdosfs_putpages },
1975 static struct vnodeopv_desc msdosfs_vnodeop_opv_desc =
1976 { &msdosfs_vnodeop_p, msdosfs_vnodeop_entries };
1978 VNODEOP_SET(msdosfs_vnodeop_opv_desc);