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>
55 #include <sys/clock.h>
56 #include <sys/dirent.h>
58 #include <sys/lockf.h>
59 #include <sys/malloc.h>
60 #include <sys/mount.h>
61 #include <sys/mutex.h>
62 #include <sys/namei.h>
65 #include <sys/resourcevar.h>
66 #include <sys/signalvar.h>
68 #include <sys/unistd.h>
69 #include <sys/vnode.h>
72 #include <vm/vm_extern.h>
74 #include <fs/msdosfs/bpb.h>
75 #include <fs/msdosfs/direntry.h>
76 #include <fs/msdosfs/denode.h>
77 #include <fs/msdosfs/fat.h>
78 #include <fs/msdosfs/msdosfsmount.h>
80 #define DOS_FILESIZE_MAX 0xffffffff
83 * Prototypes for MSDOSFS vnode operations
85 static vop_create_t msdosfs_create;
86 static vop_mknod_t msdosfs_mknod;
87 static vop_open_t msdosfs_open;
88 static vop_close_t msdosfs_close;
89 static vop_access_t msdosfs_access;
90 static vop_getattr_t msdosfs_getattr;
91 static vop_setattr_t msdosfs_setattr;
92 static vop_read_t msdosfs_read;
93 static vop_write_t msdosfs_write;
94 static vop_fsync_t msdosfs_fsync;
95 static vop_remove_t msdosfs_remove;
96 static vop_link_t msdosfs_link;
97 static vop_rename_t msdosfs_rename;
98 static vop_mkdir_t msdosfs_mkdir;
99 static vop_rmdir_t msdosfs_rmdir;
100 static vop_symlink_t msdosfs_symlink;
101 static vop_readdir_t msdosfs_readdir;
102 static vop_bmap_t msdosfs_bmap;
103 static vop_strategy_t msdosfs_strategy;
104 static vop_print_t msdosfs_print;
105 static vop_pathconf_t msdosfs_pathconf;
106 static vop_vptofh_t msdosfs_vptofh;
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_pmp = pdep->de_pmp;
185 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
187 DETIMES(&ndirent, &ts, &ts, &ts);
188 error = createde(&ndirent, pdep, &dep, cnp);
191 *ap->a_vpp = DETOV(dep);
200 struct vop_mknod_args /* {
202 struct vnode **a_vpp;
203 struct componentname *a_cnp;
213 struct vop_open_args /* {
216 struct ucred *a_cred;
221 struct denode *dep = VTODE(ap->a_vp);
222 vnode_create_vobject(ap->a_vp, dep->de_FileSize, ap->a_td);
228 struct vop_close_args /* {
231 struct ucred *a_cred;
235 struct vnode *vp = ap->a_vp;
236 struct denode *dep = VTODE(vp);
240 if (vp->v_usecount > 1) {
242 DETIMES(dep, &ts, &ts, &ts);
250 struct vop_access_args /* {
253 struct ucred *a_cred;
257 struct vnode *vp = ap->a_vp;
258 struct denode *dep = VTODE(ap->a_vp);
259 struct msdosfsmount *pmp = dep->de_pmp;
260 mode_t file_mode, mode = ap->a_mode;
262 file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) |
263 ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH));
264 file_mode &= (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
267 * Disallow writing to directories and regular files if the
268 * filesystem is read-only.
271 switch (vp->v_type) {
274 if (vp->v_mount->mnt_flag & MNT_RDONLY)
282 return (vaccess(vp->v_type, file_mode, pmp->pm_uid, pmp->pm_gid,
283 ap->a_mode, ap->a_cred, NULL));
288 struct vop_getattr_args /* {
291 struct ucred *a_cred;
295 struct denode *dep = VTODE(ap->a_vp);
296 struct msdosfsmount *pmp = dep->de_pmp;
297 struct vattr *vap = ap->a_vap;
300 u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
304 DETIMES(dep, &ts, &ts, &ts);
305 vap->va_fsid = dev2udev(dep->de_dev);
307 * The following computation of the fileid must be the same as that
308 * used in msdosfs_readdir() to compute d_fileno. If not, pwd
311 if (dep->de_Attributes & ATTR_DIRECTORY) {
312 fileid = (uint64_t)cntobn(pmp, dep->de_StartCluster) *
314 if (dep->de_StartCluster == MSDOSFSROOT)
317 fileid = (uint64_t)cntobn(pmp, dep->de_dirclust) *
319 if (dep->de_dirclust == MSDOSFSROOT)
320 fileid = (uint64_t)roottobn(pmp, 0) * dirsperblk;
321 fileid += (uoff_t)dep->de_diroffset / sizeof(struct direntry);
324 if (pmp->pm_flags & MSDOSFS_LARGEFS)
325 vap->va_fileid = msdosfs_fileno_map(pmp->pm_mountp, fileid);
327 vap->va_fileid = (long)fileid;
329 if ((dep->de_Attributes & ATTR_READONLY) == 0)
330 mode = S_IRWXU|S_IRWXG|S_IRWXO;
332 mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
333 vap->va_mode = mode &
334 (ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
335 vap->va_uid = pmp->pm_uid;
336 vap->va_gid = pmp->pm_gid;
338 vap->va_rdev = NODEV;
339 vap->va_size = dep->de_FileSize;
340 fattime2timespec(dep->de_MDate, dep->de_MTime, 0, 0, &vap->va_mtime);
341 vap->va_ctime = vap->va_mtime;
342 if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
343 fattime2timespec(dep->de_ADate, 0, 0, 0, &vap->va_atime);
344 fattime2timespec(dep->de_CDate, dep->de_CTime, dep->de_CHun,
345 0, &vap->va_birthtime);
347 vap->va_atime = vap->va_mtime;
348 vap->va_birthtime.tv_sec = -1;
349 vap->va_birthtime.tv_nsec = 0;
352 if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
353 vap->va_flags |= SF_ARCHIVED;
355 vap->va_blocksize = pmp->pm_bpcluster;
357 (dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
358 vap->va_type = ap->a_vp->v_type;
359 vap->va_filerev = dep->de_modrev;
365 struct vop_setattr_args /* {
368 struct ucred *a_cred;
372 struct vnode *vp = ap->a_vp;
373 struct denode *dep = VTODE(ap->a_vp);
374 struct msdosfsmount *pmp = dep->de_pmp;
375 struct vattr *vap = ap->a_vap;
376 struct ucred *cred = ap->a_cred;
380 printf("msdosfs_setattr(): vp %p, vap %p, cred %p, p %p\n",
381 ap->a_vp, vap, cred, ap->a_td);
385 * Check for unsettable attributes.
387 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
388 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
389 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
390 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
392 printf("msdosfs_setattr(): returning EINVAL\n");
393 printf(" va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
394 vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
395 printf(" va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
396 vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
397 printf(" va_uid %x, va_gid %x\n",
398 vap->va_uid, vap->va_gid);
402 if (vap->va_flags != VNOVAL) {
403 if (vp->v_mount->mnt_flag & MNT_RDONLY)
405 if (cred->cr_uid != pmp->pm_uid) {
406 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
411 * We are very inconsistent about handling unsupported
412 * attributes. We ignored the access time and the
413 * read and execute bits. We were strict for the other
416 * Here we are strict, stricter than ufs in not allowing
417 * users to attempt to set SF_SETTABLE bits or anyone to
418 * set unsupported bits. However, we ignore attempts to
419 * set ATTR_ARCHIVE for directories `cp -pr' from a more
420 * sensible filesystem attempts it a lot.
422 if (vap->va_flags & SF_SETTABLE) {
423 error = priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0);
427 if (vap->va_flags & ~SF_ARCHIVED)
429 if (vap->va_flags & SF_ARCHIVED)
430 dep->de_Attributes &= ~ATTR_ARCHIVE;
431 else if (!(dep->de_Attributes & ATTR_DIRECTORY))
432 dep->de_Attributes |= ATTR_ARCHIVE;
433 dep->de_flag |= DE_MODIFIED;
436 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
440 if (vp->v_mount->mnt_flag & MNT_RDONLY)
443 if (uid == (uid_t)VNOVAL)
446 if (gid == (gid_t)VNOVAL)
448 if (cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
449 (gid != pmp->pm_gid && !groupmember(gid, cred))) {
450 error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0);
454 if (uid != pmp->pm_uid || gid != pmp->pm_gid)
458 if (vap->va_size != VNOVAL) {
459 switch (vp->v_type) {
464 * Truncation is only supported for regular files,
465 * Disallow it if the filesystem is read-only.
467 if (vp->v_mount->mnt_flag & MNT_RDONLY)
472 * According to POSIX, the result is unspecified
473 * for file types other than regular files,
474 * directories and shared memory objects. We
475 * don't support any file types except regular
476 * files and directories in this file system, so
477 * this (default) case is unreachable and can do
478 * anything. Keep falling through to detrunc()
483 error = detrunc(dep, vap->va_size, 0, cred, ap->a_td);
487 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
488 if (vp->v_mount->mnt_flag & MNT_RDONLY)
490 if (vap->va_vaflags & VA_UTIMES_NULL) {
491 error = VOP_ACCESS(vp, VADMIN, cred, ap->a_td);
493 error = VOP_ACCESS(vp, VWRITE, cred,
496 error = VOP_ACCESS(vp, VADMIN, cred, ap->a_td);
497 if (vp->v_type != VDIR) {
498 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
499 vap->va_atime.tv_sec != VNOVAL) {
500 dep->de_flag &= ~DE_ACCESS;
501 timespec2fattime(&vap->va_atime, 0,
502 &dep->de_ADate, NULL, NULL);
504 if (vap->va_mtime.tv_sec != VNOVAL) {
505 dep->de_flag &= ~DE_UPDATE;
506 timespec2fattime(&vap->va_mtime, 0,
507 &dep->de_MDate, &dep->de_MTime, NULL);
509 dep->de_Attributes |= ATTR_ARCHIVE;
510 dep->de_flag |= DE_MODIFIED;
514 * DOS files only have the ability to have their writability
515 * attribute set, so we use the owner write bit to set the readonly
518 if (vap->va_mode != (mode_t)VNOVAL) {
519 if (vp->v_mount->mnt_flag & MNT_RDONLY)
521 if (cred->cr_uid != pmp->pm_uid) {
522 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
526 if (vp->v_type != VDIR) {
527 /* We ignore the read and execute bits. */
528 if (vap->va_mode & VWRITE)
529 dep->de_Attributes &= ~ATTR_READONLY;
531 dep->de_Attributes |= ATTR_READONLY;
532 dep->de_Attributes |= ATTR_ARCHIVE;
533 dep->de_flag |= DE_MODIFIED;
536 return (deupdat(dep, 1));
541 struct vop_read_args /* {
545 struct ucred *a_cred;
560 struct vnode *vp = ap->a_vp;
561 struct denode *dep = VTODE(vp);
562 struct msdosfsmount *pmp = dep->de_pmp;
563 struct uio *uio = ap->a_uio;
566 * If they didn't ask for any data, then we are done.
568 orig_resid = uio->uio_resid;
573 * The caller is supposed to ensure that
574 * uio->uio_offset >= 0 and uio->uio_resid >= 0.
575 * We don't need to check for large offsets as in ffs because
576 * dep->de_FileSize <= DOS_FILESIZE_MAX < OFF_MAX, so large
577 * offsets cannot cause overflow even in theory.
580 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
582 isadir = dep->de_Attributes & ATTR_DIRECTORY;
584 if (uio->uio_offset >= dep->de_FileSize)
586 lbn = de_cluster(pmp, uio->uio_offset);
588 blsize = pmp->pm_bpcluster;
589 on = uio->uio_offset & pmp->pm_crbomask;
591 * If we are operating on a directory file then be sure to
592 * do i/o with the vnode for the filesystem instead of the
593 * vnode for the directory.
596 /* convert cluster # to block # */
597 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
598 if (error == E2BIG) {
603 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
604 } else if (de_cn2off(pmp, rablock) >= dep->de_FileSize) {
605 error = bread(vp, lbn, blsize, NOCRED, &bp);
606 } else if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
607 error = cluster_read(vp, dep->de_FileSize, lbn, blsize,
608 NOCRED, on + uio->uio_resid, seqcount, &bp);
609 } else if (seqcount > 1) {
611 error = breadn(vp, lbn,
612 blsize, &rablock, &rasize, 1, NOCRED, &bp);
614 error = bread(vp, lbn, blsize, NOCRED, &bp);
620 diff = pmp->pm_bpcluster - on;
621 n = diff > uio->uio_resid ? uio->uio_resid : diff;
622 diff = dep->de_FileSize - uio->uio_offset;
625 diff = blsize - bp->b_resid;
628 error = uiomove(bp->b_data + on, (int) n, uio);
630 } while (error == 0 && uio->uio_resid > 0 && n != 0);
631 if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
632 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
633 dep->de_flag |= DE_ACCESS;
638 * Write data to a file or directory.
642 struct vop_write_args /* {
646 struct ucred *a_cred;
658 int ioflag = ap->a_ioflag;
659 struct uio *uio = ap->a_uio;
660 struct thread *td = uio->uio_td;
661 struct vnode *vp = ap->a_vp;
662 struct vnode *thisvp;
663 struct denode *dep = VTODE(vp);
664 struct msdosfsmount *pmp = dep->de_pmp;
665 struct ucred *cred = ap->a_cred;
668 printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
669 vp, uio, ioflag, cred);
670 printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
671 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
674 switch (vp->v_type) {
676 if (ioflag & IO_APPEND)
677 uio->uio_offset = dep->de_FileSize;
683 panic("msdosfs_write(): bad file type");
687 * This is needed (unlike in ffs_write()) because we extend the
688 * file outside of the loop but we don't want to extend the file
689 * for writes of 0 bytes.
691 if (uio->uio_resid == 0)
695 * The caller is supposed to ensure that
696 * uio->uio_offset >= 0 and uio->uio_resid >= 0.
698 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
702 * If they've exceeded their filesize limit, tell them about it.
705 PROC_LOCK(td->td_proc);
706 if ((uoff_t)uio->uio_offset + uio->uio_resid >
707 lim_cur(td->td_proc, RLIMIT_FSIZE)) {
708 psignal(td->td_proc, SIGXFSZ);
709 PROC_UNLOCK(td->td_proc);
712 PROC_UNLOCK(td->td_proc);
716 * If the offset we are starting the write at is beyond the end of
717 * the file, then they've done a seek. Unix filesystems allow
718 * files with holes in them, DOS doesn't so we must fill the hole
719 * with zeroed blocks.
721 if (uio->uio_offset > dep->de_FileSize) {
722 error = deextend(dep, uio->uio_offset, cred);
728 * Remember some values in case the write fails.
730 resid = uio->uio_resid;
731 osize = dep->de_FileSize;
734 * If we write beyond the end of the file, extend it to its ultimate
735 * size ahead of the time to hopefully get a contiguous area.
737 if (uio->uio_offset + resid > osize) {
738 count = de_clcount(pmp, uio->uio_offset + resid) -
739 de_clcount(pmp, osize);
740 error = extendfile(dep, count, NULL, NULL, 0);
741 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
743 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
745 lastcn = de_clcount(pmp, osize) - 1;
747 seqcount = ioflag >> IO_SEQSHIFT;
749 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
754 croffset = uio->uio_offset & pmp->pm_crbomask;
755 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
756 if (uio->uio_offset + n > dep->de_FileSize) {
757 dep->de_FileSize = uio->uio_offset + n;
758 /* The object size needs to be set before buffer is allocated */
759 vnode_pager_setsize(vp, dep->de_FileSize);
762 bn = de_cluster(pmp, uio->uio_offset);
763 if ((uio->uio_offset & pmp->pm_crbomask) == 0
764 && (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
765 > de_cluster(pmp, uio->uio_offset)
766 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
768 * If either the whole cluster gets written,
769 * or we write the cluster from its start beyond EOF,
770 * then no need to read data from disk.
772 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0);
775 * Do the bmap now, since pcbmap needs buffers
776 * for the fat table. (see msdosfs_strategy)
778 if (bp->b_blkno == bp->b_lblkno) {
779 error = pcbmap(dep, bp->b_lblkno, &bn, 0, 0);
785 if (bp->b_blkno == -1) {
788 error = EIO; /* XXX */
793 * The block we need to write into exists, so read it in.
795 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
803 * Should these vnode_pager_* functions be done on dir
808 * Copy the data from user space into the buf header.
810 error = uiomove(bp->b_data + croffset, n, uio);
816 /* Prepare for clustered writes in some else clauses. */
817 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
818 bp->b_flags |= B_CLUSTEROK;
821 * If IO_SYNC, then each buffer is written synchronously.
822 * Otherwise, if we have a severe page deficiency then
823 * write the buffer asynchronously. Otherwise, if on a
824 * cluster boundary then write the buffer asynchronously,
825 * combining it with contiguous clusters if permitted and
826 * possible, since we don't expect more writes into this
827 * buffer soon. Otherwise, do a delayed write because we
828 * expect more writes into this buffer soon.
830 if (ioflag & IO_SYNC)
832 else if (vm_page_count_severe() || buf_dirty_count_severe())
834 else if (n + croffset == pmp->pm_bpcluster) {
835 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
836 cluster_write(vp, bp, dep->de_FileSize,
842 dep->de_flag |= DE_UPDATE;
843 } while (error == 0 && uio->uio_resid > 0);
846 * If the write failed and they want us to, truncate the file back
847 * to the size it was before the write was attempted.
851 if (ioflag & IO_UNIT) {
852 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
853 uio->uio_offset -= resid - uio->uio_resid;
854 uio->uio_resid = resid;
856 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
857 if (uio->uio_resid != resid)
860 } else if (ioflag & IO_SYNC)
861 error = deupdat(dep, 1);
866 * Flush the blocks of a file to disk.
868 * This function is worthless for vnodes that represent directories. Maybe we
869 * could just do a sync if they try an fsync on a directory file.
873 struct vop_fsync_args /* {
875 struct ucred *a_cred;
882 return (deupdat(VTODE(ap->a_vp), ap->a_waitfor == MNT_WAIT));
887 struct vop_remove_args /* {
890 struct componentname *a_cnp;
893 struct denode *dep = VTODE(ap->a_vp);
894 struct denode *ddep = VTODE(ap->a_dvp);
897 if (ap->a_vp->v_type == VDIR)
900 error = removede(ddep, dep);
902 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
908 * DOS filesystems don't know what links are.
912 struct vop_link_args /* {
913 struct vnode *a_tdvp;
915 struct componentname *a_cnp;
922 * Renames on files require moving the denode to a new hash queue since the
923 * denode's location is used to compute which hash queue to put the file
924 * in. Unless it is a rename in place. For example "mv a b".
926 * What follows is the basic algorithm:
929 * if (dest file exists) {
932 * if (dest and src in same directory) {
933 * rewrite name in existing directory slot
935 * write new entry in dest directory
936 * update offset and dirclust in denode
937 * move denode to new hash chain
938 * clear old directory entry
942 * if (dest directory exists) {
943 * if (dest is not empty) {
946 * remove dest directory
948 * if (dest and src in same directory) {
949 * rewrite name in existing entry
951 * be sure dest is not a child of src directory
952 * write entry in dest directory
953 * update "." and ".." in moved directory
954 * clear old directory entry for moved directory
959 * source's parent directory is unlocked
960 * source file or directory is unlocked
961 * destination's parent directory is locked
962 * destination file or directory is locked if it exists
965 * all denodes should be released
969 struct vop_rename_args /* {
970 struct vnode *a_fdvp;
972 struct componentname *a_fcnp;
973 struct vnode *a_tdvp;
975 struct componentname *a_tcnp;
978 struct vnode *tdvp = ap->a_tdvp;
979 struct vnode *fvp = ap->a_fvp;
980 struct vnode *fdvp = ap->a_fdvp;
981 struct vnode *tvp = ap->a_tvp;
982 struct componentname *tcnp = ap->a_tcnp;
983 struct componentname *fcnp = ap->a_fcnp;
984 struct thread *td = fcnp->cn_thread;
985 struct denode *ip, *xp, *dp, *zp;
986 u_char toname[12], oldname[11];
987 u_long from_diroffset, to_diroffset;
989 int doingdirectory = 0, newparent = 0;
993 struct denode *fddep; /* from file's parent directory */
994 struct msdosfsmount *pmp;
995 struct direntry *dotdotp;
998 fddep = VTODE(ap->a_fdvp);
1001 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1004 if ((tcnp->cn_flags & HASBUF) == 0 ||
1005 (fcnp->cn_flags & HASBUF) == 0)
1006 panic("msdosfs_rename: no name");
1009 * Check for cross-device rename.
1011 if (fvp->v_mount != tdvp->v_mount ||
1012 (tvp && fvp->v_mount != tvp->v_mount)) {
1027 * If source and dest are the same, do nothing.
1034 error = vn_lock(fvp, LK_EXCLUSIVE, td);
1041 * Be sure we are not renaming ".", "..", or an alias of ".". This
1042 * leads to a crippled directory tree. It's pretty tough to do a
1043 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
1044 * doesn't work if the ".." entry is missing.
1046 if (ip->de_Attributes & ATTR_DIRECTORY) {
1048 * Avoid ".", "..", and aliases of "." for obvious reasons.
1050 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1052 (fcnp->cn_flags & ISDOTDOT) ||
1053 (tcnp->cn_flags & ISDOTDOT) ||
1054 (ip->de_flag & DE_RENAME)) {
1055 VOP_UNLOCK(fvp, 0, td);
1059 ip->de_flag |= DE_RENAME;
1064 * When the target exists, both the directory
1065 * and target vnodes are returned locked.
1068 xp = tvp ? VTODE(tvp) : NULL;
1070 * Remember direntry place to use for destination
1072 to_diroffset = dp->de_fndoffset;
1073 to_count = dp->de_fndcnt;
1076 * If ".." must be changed (ie the directory gets a new
1077 * parent) then the source directory must not be in the
1078 * directory heirarchy above the target, as this would
1079 * orphan everything below the source directory. Also
1080 * the user must have write permission in the source so
1081 * as to be able to change "..". We must repeat the call
1082 * to namei, as the parent directory is unlocked by the
1083 * call to doscheckpath().
1085 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1086 VOP_UNLOCK(fvp, 0, td);
1087 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1089 if (doingdirectory && newparent) {
1090 if (error) /* write access check above */
1095 * doscheckpath() vput()'s dp,
1096 * so we have to do a relookup afterwards
1098 error = doscheckpath(ip, dp);
1101 if ((tcnp->cn_flags & SAVESTART) == 0)
1102 panic("msdosfs_rename: lost to startdir");
1103 error = relookup(tdvp, &tvp, tcnp);
1107 xp = tvp ? VTODE(tvp) : NULL;
1112 * Target must be empty if a directory and have no links
1113 * to it. Also, ensure source and target are compatible
1114 * (both directories, or both not directories).
1116 if (xp->de_Attributes & ATTR_DIRECTORY) {
1117 if (!dosdirempty(xp)) {
1121 if (!doingdirectory) {
1126 } else if (doingdirectory) {
1130 error = removede(dp, xp);
1138 * Convert the filename in tcnp into a dos filename. We copy this
1139 * into the denode and directory entry for the destination
1142 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1147 * Since from wasn't locked at various places above,
1148 * have to do a relookup here.
1150 fcnp->cn_flags &= ~MODMASK;
1151 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1152 if ((fcnp->cn_flags & SAVESTART) == 0)
1153 panic("msdosfs_rename: lost from startdir");
1155 VOP_UNLOCK(tdvp, 0, td);
1156 if (relookup(fdvp, &fvp, fcnp) == 0)
1160 * From name has disappeared.
1163 panic("rename: lost dir entry");
1165 VOP_UNLOCK(tdvp, 0, td);
1172 from_diroffset = zp->de_fndoffset;
1175 * Ensure that the directory entry still exists and has not
1176 * changed till now. If the source is a file the entry may
1177 * have been unlinked or renamed. In either case there is
1178 * no further work to be done. If the source is a directory
1179 * then it cannot have been rmdir'ed or renamed; this is
1180 * prohibited by the DE_RENAME flag.
1184 panic("rename: lost dir entry");
1185 VOP_UNLOCK(fvp, 0, td);
1187 VOP_UNLOCK(fdvp, 0, td);
1195 * First write a new entry in the destination
1196 * directory and mark the entry in the source directory
1197 * as deleted. Then move the denode to the correct hash
1198 * chain for its new location in the filesystem. And, if
1199 * we moved a directory, then update its .. entry to point
1200 * to the new parent directory.
1202 bcopy(ip->de_Name, oldname, 11);
1203 bcopy(toname, ip->de_Name, 11); /* update denode */
1204 dp->de_fndoffset = to_diroffset;
1205 dp->de_fndcnt = to_count;
1206 error = createde(ip, dp, (struct denode **)0, tcnp);
1208 bcopy(oldname, ip->de_Name, 11);
1210 VOP_UNLOCK(fdvp, 0, td);
1211 VOP_UNLOCK(fvp, 0, td);
1215 zp->de_fndoffset = from_diroffset;
1216 error = removede(zp, ip);
1218 /* XXX should downgrade to ro here, fs is corrupt */
1220 VOP_UNLOCK(fdvp, 0, td);
1221 VOP_UNLOCK(fvp, 0, td);
1224 if (!doingdirectory) {
1225 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1226 &ip->de_dirclust, 0);
1228 /* XXX should downgrade to ro here, fs is corrupt */
1230 VOP_UNLOCK(fdvp, 0, td);
1231 VOP_UNLOCK(fvp, 0, td);
1234 if (ip->de_dirclust == MSDOSFSROOT)
1235 ip->de_diroffset = to_diroffset;
1237 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1241 VOP_UNLOCK(fdvp, 0, td);
1245 * If we moved a directory to a new parent directory, then we must
1246 * fixup the ".." entry in the moved directory.
1248 if (doingdirectory && newparent) {
1249 cn = ip->de_StartCluster;
1250 if (cn == MSDOSFSROOT) {
1251 /* this should never happen */
1252 panic("msdosfs_rename(): updating .. in root directory?");
1254 bn = cntobn(pmp, cn);
1255 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1258 /* XXX should downgrade to ro here, fs is corrupt */
1260 VOP_UNLOCK(fvp, 0, td);
1263 dotdotp = (struct direntry *)bp->b_data + 1;
1264 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1266 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1269 /* XXX should downgrade to ro here, fs is corrupt */
1270 VOP_UNLOCK(fvp, 0, td);
1275 VOP_UNLOCK(fvp, 0, td);
1281 ip->de_flag &= ~DE_RENAME;
1289 struct direntry dot;
1290 struct direntry dotdot;
1291 } dosdirtemplate = {
1292 { ". ", " ", /* the . entry */
1293 ATTR_DIRECTORY, /* file attribute */
1295 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1296 { 0, 0 }, /* access date */
1297 { 0, 0 }, /* high bits of start cluster */
1298 { 210, 4 }, { 210, 4 }, /* modify time & date */
1299 { 0, 0 }, /* startcluster */
1300 { 0, 0, 0, 0 } /* filesize */
1302 { ".. ", " ", /* the .. entry */
1303 ATTR_DIRECTORY, /* file attribute */
1305 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1306 { 0, 0 }, /* access date */
1307 { 0, 0 }, /* high bits of start cluster */
1308 { 210, 4 }, { 210, 4 }, /* modify time & date */
1309 { 0, 0 }, /* startcluster */
1310 { 0, 0, 0, 0 } /* filesize */
1316 struct vop_mkdir_args /* {
1317 struct vnode *a_dvp;
1318 struct vnode **a_vpp;
1319 struvt componentname *a_cnp;
1320 struct vattr *a_vap;
1323 struct componentname *cnp = ap->a_cnp;
1325 struct denode *pdep = VTODE(ap->a_dvp);
1326 struct direntry *denp;
1327 struct msdosfsmount *pmp = pdep->de_pmp;
1329 u_long newcluster, pcl;
1332 struct denode ndirent;
1336 * If this is the root directory and there is no space left we
1337 * can't do anything. This is because the root directory can not
1340 if (pdep->de_StartCluster == MSDOSFSROOT
1341 && pdep->de_fndoffset >= pdep->de_FileSize) {
1347 * Allocate a cluster to hold the about to be created directory.
1349 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1353 bzero(&ndirent, sizeof(ndirent));
1354 ndirent.de_pmp = pmp;
1355 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1357 DETIMES(&ndirent, &ts, &ts, &ts);
1360 * Now fill the cluster with the "." and ".." entries. And write
1361 * the cluster to disk. This way it is there for the parent
1362 * directory to be pointing at if there were a crash.
1364 bn = cntobn(pmp, newcluster);
1365 /* always succeeds */
1366 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0);
1367 bzero(bp->b_data, pmp->pm_bpcluster);
1368 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1369 denp = (struct direntry *)bp->b_data;
1370 putushort(denp[0].deStartCluster, newcluster);
1371 putushort(denp[0].deCDate, ndirent.de_CDate);
1372 putushort(denp[0].deCTime, ndirent.de_CTime);
1373 denp[0].deCHundredth = ndirent.de_CHun;
1374 putushort(denp[0].deADate, ndirent.de_ADate);
1375 putushort(denp[0].deMDate, ndirent.de_MDate);
1376 putushort(denp[0].deMTime, ndirent.de_MTime);
1377 pcl = pdep->de_StartCluster;
1378 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1380 putushort(denp[1].deStartCluster, pcl);
1381 putushort(denp[1].deCDate, ndirent.de_CDate);
1382 putushort(denp[1].deCTime, ndirent.de_CTime);
1383 denp[1].deCHundredth = ndirent.de_CHun;
1384 putushort(denp[1].deADate, ndirent.de_ADate);
1385 putushort(denp[1].deMDate, ndirent.de_MDate);
1386 putushort(denp[1].deMTime, ndirent.de_MTime);
1388 putushort(denp[0].deHighClust, newcluster >> 16);
1389 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1397 * Now build up a directory entry pointing to the newly allocated
1398 * cluster. This will be written to an empty slot in the parent
1402 if ((cnp->cn_flags & HASBUF) == 0)
1403 panic("msdosfs_mkdir: no name");
1405 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1409 ndirent.de_Attributes = ATTR_DIRECTORY;
1410 ndirent.de_LowerCase = 0;
1411 ndirent.de_StartCluster = newcluster;
1412 ndirent.de_FileSize = 0;
1413 ndirent.de_dev = pdep->de_dev;
1414 error = createde(&ndirent, pdep, &dep, cnp);
1417 *ap->a_vpp = DETOV(dep);
1421 clusterfree(pmp, newcluster, NULL);
1428 struct vop_rmdir_args /* {
1429 struct vnode *a_dvp;
1431 struct componentname *a_cnp;
1434 struct vnode *vp = ap->a_vp;
1435 struct vnode *dvp = ap->a_dvp;
1436 struct componentname *cnp = ap->a_cnp;
1437 struct denode *ip, *dp;
1438 struct thread *td = cnp->cn_thread;
1445 * Verify the directory is empty (and valid).
1446 * (Rmdir ".." won't be valid since
1447 * ".." will contain a reference to
1448 * the current directory and thus be
1452 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1457 * Delete the entry from the directory. For dos filesystems this
1458 * gets rid of the directory entry on disk, the in memory copy
1459 * still exists but the de_refcnt is <= 0. This prevents it from
1460 * being found by deget(). When the vput() on dep is done we give
1461 * up access and eventually msdosfs_reclaim() will be called which
1462 * will remove it from the denode cache.
1464 error = removede(dp, ip);
1468 * This is where we decrement the link count in the parent
1469 * directory. Since dos filesystems don't do this we just purge
1473 VOP_UNLOCK(dvp, 0, td);
1475 * Truncate the directory that is being deleted.
1477 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, td);
1480 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
1486 * DOS filesystems don't know what symlinks are.
1490 struct vop_symlink_args /* {
1491 struct vnode *a_dvp;
1492 struct vnode **a_vpp;
1493 struct componentname *a_cnp;
1494 struct vattr *a_vap;
1498 return (EOPNOTSUPP);
1503 struct vop_readdir_args /* {
1506 struct ucred *a_cred;
1524 struct denode *dep = VTODE(ap->a_vp);
1525 struct msdosfsmount *pmp = dep->de_pmp;
1526 struct direntry *dentp;
1527 struct dirent dirbuf;
1528 struct uio *uio = ap->a_uio;
1529 u_long *cookies = NULL;
1534 #ifdef MSDOSFS_DEBUG
1535 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1536 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1540 * msdosfs_readdir() won't operate properly on regular files since
1541 * it does i/o only with the the filesystem vnode, and hence can
1542 * retrieve the wrong block from the buffer cache for a plain file.
1543 * So, fail attempts to readdir() on a plain file.
1545 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1549 * To be safe, initialize dirbuf
1551 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1554 * If the user buffer is smaller than the size of one dos directory
1555 * entry or the file offset is not a multiple of the size of a
1556 * directory entry, then we fail the read.
1558 off = offset = uio->uio_offset;
1559 if (uio->uio_resid < sizeof(struct direntry) ||
1560 (offset & (sizeof(struct direntry) - 1)))
1563 if (ap->a_ncookies) {
1564 ncookies = uio->uio_resid / 16;
1565 MALLOC(cookies, u_long *, ncookies * sizeof(u_long), M_TEMP,
1567 *ap->a_cookies = cookies;
1568 *ap->a_ncookies = ncookies;
1571 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1574 * If they are reading from the root directory then, we simulate
1575 * the . and .. entries since these don't exist in the root
1576 * directory. We also set the offset bias to make up for having to
1577 * simulate these entries. By this I mean that at file offset 64 we
1578 * read the first entry in the root directory that lives on disk.
1580 if (dep->de_StartCluster == MSDOSFSROOT
1581 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1583 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1586 bias = 2 * sizeof(struct direntry);
1587 if (offset < bias) {
1588 for (n = (int)offset / sizeof(struct direntry);
1591 fileno = (uint64_t)cntobn(pmp,
1596 if (pmp->pm_flags & MSDOSFS_LARGEFS) {
1598 msdosfs_fileno_map(pmp->pm_mountp,
1602 dirbuf.d_fileno = (uint32_t)fileno;
1604 dirbuf.d_type = DT_DIR;
1607 dirbuf.d_namlen = 1;
1608 strcpy(dirbuf.d_name, ".");
1611 dirbuf.d_namlen = 2;
1612 strcpy(dirbuf.d_name, "..");
1615 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1616 if (uio->uio_resid < dirbuf.d_reclen)
1618 error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
1621 offset += sizeof(struct direntry);
1624 *cookies++ = offset;
1625 if (--ncookies <= 0)
1634 while (uio->uio_resid > 0) {
1635 lbn = de_cluster(pmp, offset - bias);
1636 on = (offset - bias) & pmp->pm_crbomask;
1637 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1638 diff = dep->de_FileSize - (offset - bias);
1642 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1645 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1650 n = min(n, blsize - bp->b_resid);
1657 * Convert from dos directory entries to fs-independent
1658 * directory entries.
1660 for (dentp = (struct direntry *)(bp->b_data + on);
1661 (char *)dentp < bp->b_data + on + n;
1662 dentp++, offset += sizeof(struct direntry)) {
1664 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1665 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1668 * If this is an unused entry, we can stop.
1670 if (dentp->deName[0] == SLOT_EMPTY) {
1675 * Skip deleted entries.
1677 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(&nb,
1690 (struct winentry *)dentp, chksum, pmp);
1695 * Skip volume labels
1697 if (dentp->deAttributes & ATTR_VOLUME) {
1703 * This computation of d_fileno must match
1704 * the computation of va_fileid in
1707 if (dentp->deAttributes & ATTR_DIRECTORY) {
1708 fileno = getushort(dentp->deStartCluster);
1710 fileno |= getushort(dentp->deHighClust) << 16;
1711 /* if this is the root directory */
1712 if (fileno == MSDOSFSROOT)
1714 fileno = (uint64_t)cntobn(pmp,
1720 fileno = (uint64_t)cntobn(pmp, fileno) *
1722 dirbuf.d_type = DT_DIR;
1724 fileno = (uoff_t)offset /
1725 sizeof(struct direntry);
1726 dirbuf.d_type = DT_REG;
1728 if (pmp->pm_flags & MSDOSFS_LARGEFS) {
1730 msdosfs_fileno_map(pmp->pm_mountp, fileno);
1732 dirbuf.d_fileno = (uint32_t)fileno;
1734 if (chksum != winChksum(dentp)) {
1735 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1736 (u_char *)dirbuf.d_name,
1737 dentp->deLowerCase |
1738 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1739 (LCASE_BASE | LCASE_EXT) : 0),
1743 mbnambuf_flush(&nb, &dirbuf);
1745 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1746 if (uio->uio_resid < dirbuf.d_reclen) {
1750 error = uiomove(&dirbuf, 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 * a_vp - pointer to the file's vnode
1787 * a_bn - logical block number within the file (cluster number for us)
1788 * a_bop - where to return the bufobj of the special file containing the fs
1789 * a_bnp - where to return the "physical" block number corresponding to a_bn
1790 * (relative to the special file; units are blocks of size DEV_BSIZE)
1791 * a_runp - where to return the "run past" a_bn. This is the count of logical
1792 * blocks whose physical blocks (together with a_bn's physical block)
1794 * a_runb - where to return the "run before" a_bn.
1798 struct vop_bmap_args /* {
1801 struct bufobj **a_bop;
1809 struct msdosfsmount *pmp;
1813 int bnpercn, error, maxio, maxrun, run;
1818 if (ap->a_bop != NULL)
1819 *ap->a_bop = &pmp->pm_devvp->v_bufobj;
1820 if (ap->a_bnp == NULL)
1822 if (ap->a_runp != NULL)
1824 if (ap->a_runb != NULL)
1829 error = pcbmap(dep, cn, ap->a_bnp, NULL, NULL);
1830 if (error != 0 || (ap->a_runp == NULL && ap->a_runb == NULL))
1834 maxio = mp->mnt_iosize_max / mp->mnt_stat.f_iosize;
1835 bnpercn = de_cn2bn(pmp, 1);
1836 if (ap->a_runp != NULL) {
1837 maxrun = ulmin(maxio - 1, pmp->pm_maxcluster - cn);
1838 for (run = 1; run <= maxrun; run++) {
1839 if (pcbmap(dep, cn + run, &runbn, NULL, NULL) != 0 ||
1840 runbn != *ap->a_bnp + run * bnpercn)
1843 *ap->a_runp = run - 1;
1845 if (ap->a_runb != NULL) {
1846 maxrun = ulmin(maxio - 1, cn);
1847 for (run = 1; run < maxrun; run++) {
1848 if (pcbmap(dep, cn - run, &runbn, NULL, NULL) != 0 ||
1849 runbn != *ap->a_bnp - run * bnpercn)
1852 *ap->a_runb = run - 1;
1858 msdosfs_strategy(ap)
1859 struct vop_strategy_args /* {
1864 struct buf *bp = ap->a_bp;
1865 struct denode *dep = VTODE(ap->a_vp);
1871 * If we don't already know the filesystem relative block number
1872 * then get it using pcbmap(). If pcbmap() returns the block
1873 * number as -1 then we've got a hole in the file. DOS filesystems
1874 * don't allow files with holes, so we shouldn't ever see this.
1876 if (bp->b_blkno == bp->b_lblkno) {
1877 error = pcbmap(dep, bp->b_lblkno, &blkno, 0, 0);
1878 bp->b_blkno = blkno;
1880 bp->b_error = error;
1881 bp->b_ioflags |= BIO_ERROR;
1885 if ((long)bp->b_blkno == -1)
1888 if (bp->b_blkno == -1) {
1893 * Read/write the block from/to the disk that contains the desired
1896 bp->b_iooffset = dbtob(bp->b_blkno);
1897 bo = dep->de_pmp->pm_bo;
1898 BO_STRATEGY(bo, bp);
1904 struct vop_print_args /* {
1908 struct denode *dep = VTODE(ap->a_vp);
1910 printf("\tstartcluster %lu, dircluster %lu, diroffset %lu, ",
1911 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1912 printf("on dev %s\n", devtoname(dep->de_dev));
1917 msdosfs_pathconf(ap)
1918 struct vop_pathconf_args /* {
1924 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1926 switch (ap->a_name) {
1931 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1934 *ap->a_retval = PATH_MAX;
1936 case _PC_CHOWN_RESTRICTED:
1950 struct vop_vptofh_args /* {
1956 struct defid *defhp;
1958 dep = VTODE(ap->a_vp);
1959 defhp = (struct defid *)ap->a_fhp;
1960 defhp->defid_len = sizeof(struct defid);
1961 defhp->defid_dirclust = dep->de_dirclust;
1962 defhp->defid_dirofs = dep->de_diroffset;
1963 /* defhp->defid_gen = dep->de_gen; */
1967 /* Global vfs data structures for msdosfs */
1968 struct vop_vector msdosfs_vnodeops = {
1969 .vop_default = &default_vnodeops,
1971 .vop_access = msdosfs_access,
1972 .vop_bmap = msdosfs_bmap,
1973 .vop_cachedlookup = msdosfs_lookup,
1974 .vop_open = msdosfs_open,
1975 .vop_close = msdosfs_close,
1976 .vop_create = msdosfs_create,
1977 .vop_fsync = msdosfs_fsync,
1978 .vop_getattr = msdosfs_getattr,
1979 .vop_inactive = msdosfs_inactive,
1980 .vop_link = msdosfs_link,
1981 .vop_lookup = vfs_cache_lookup,
1982 .vop_mkdir = msdosfs_mkdir,
1983 .vop_mknod = msdosfs_mknod,
1984 .vop_pathconf = msdosfs_pathconf,
1985 .vop_print = msdosfs_print,
1986 .vop_read = msdosfs_read,
1987 .vop_readdir = msdosfs_readdir,
1988 .vop_reclaim = msdosfs_reclaim,
1989 .vop_remove = msdosfs_remove,
1990 .vop_rename = msdosfs_rename,
1991 .vop_rmdir = msdosfs_rmdir,
1992 .vop_setattr = msdosfs_setattr,
1993 .vop_strategy = msdosfs_strategy,
1994 .vop_symlink = msdosfs_symlink,
1995 .vop_write = msdosfs_write,
1996 .vop_vptofh = msdosfs_vptofh,