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_pmp = pdep->de_pmp;
184 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
186 DETIMES(&ndirent, &ts, &ts, &ts);
187 error = createde(&ndirent, pdep, &dep, cnp);
190 *ap->a_vpp = DETOV(dep);
199 struct vop_mknod_args /* {
201 struct vnode **a_vpp;
202 struct componentname *a_cnp;
212 struct vop_open_args /* {
215 struct ucred *a_cred;
220 struct denode *dep = VTODE(ap->a_vp);
221 vnode_create_vobject(ap->a_vp, dep->de_FileSize, ap->a_td);
227 struct vop_close_args /* {
230 struct ucred *a_cred;
234 struct vnode *vp = ap->a_vp;
235 struct denode *dep = VTODE(vp);
239 if (vp->v_usecount > 1) {
241 DETIMES(dep, &ts, &ts, &ts);
249 struct vop_access_args /* {
252 struct ucred *a_cred;
256 struct vnode *vp = ap->a_vp;
257 struct denode *dep = VTODE(ap->a_vp);
258 struct msdosfsmount *pmp = dep->de_pmp;
260 accmode_t accmode = ap->a_accmode;
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.
270 if (accmode & VWRITE) {
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_accmode, ap->a_cred, NULL));
288 struct vop_getattr_args /* {
291 struct ucred *a_cred;
294 struct denode *dep = VTODE(ap->a_vp);
295 struct msdosfsmount *pmp = dep->de_pmp;
296 struct vattr *vap = ap->a_vap;
299 u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
303 DETIMES(dep, &ts, &ts, &ts);
304 vap->va_fsid = dev2udev(pmp->pm_dev);
306 * The following computation of the fileid must be the same as that
307 * used in msdosfs_readdir() to compute d_fileno. If not, pwd
310 if (dep->de_Attributes & ATTR_DIRECTORY) {
311 fileid = (uint64_t)cntobn(pmp, dep->de_StartCluster) *
313 if (dep->de_StartCluster == MSDOSFSROOT)
316 fileid = (uint64_t)cntobn(pmp, dep->de_dirclust) *
318 if (dep->de_dirclust == MSDOSFSROOT)
319 fileid = (uint64_t)roottobn(pmp, 0) * dirsperblk;
320 fileid += (uoff_t)dep->de_diroffset / sizeof(struct direntry);
323 if (pmp->pm_flags & MSDOSFS_LARGEFS)
324 vap->va_fileid = msdosfs_fileno_map(pmp->pm_mountp, fileid);
326 vap->va_fileid = (long)fileid;
328 if ((dep->de_Attributes & ATTR_READONLY) == 0)
329 mode = S_IRWXU|S_IRWXG|S_IRWXO;
331 mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
332 vap->va_mode = mode &
333 (ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
334 vap->va_uid = pmp->pm_uid;
335 vap->va_gid = pmp->pm_gid;
337 vap->va_rdev = NODEV;
338 vap->va_size = dep->de_FileSize;
339 fattime2timespec(dep->de_MDate, dep->de_MTime, 0, 0, &vap->va_mtime);
340 vap->va_ctime = vap->va_mtime;
341 if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
342 fattime2timespec(dep->de_ADate, 0, 0, 0, &vap->va_atime);
343 fattime2timespec(dep->de_CDate, dep->de_CTime, dep->de_CHun,
344 0, &vap->va_birthtime);
346 vap->va_atime = vap->va_mtime;
347 vap->va_birthtime.tv_sec = -1;
348 vap->va_birthtime.tv_nsec = 0;
351 if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
352 vap->va_flags |= SF_ARCHIVED;
354 vap->va_blocksize = pmp->pm_bpcluster;
356 (dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
357 vap->va_type = ap->a_vp->v_type;
358 vap->va_filerev = dep->de_modrev;
364 struct vop_setattr_args /* {
367 struct ucred *a_cred;
370 struct vnode *vp = ap->a_vp;
371 struct denode *dep = VTODE(ap->a_vp);
372 struct msdosfsmount *pmp = dep->de_pmp;
373 struct vattr *vap = ap->a_vap;
374 struct ucred *cred = ap->a_cred;
375 struct thread *td = curthread;
379 printf("msdosfs_setattr(): vp %p, vap %p, cred %p\n",
380 ap->a_vp, vap, cred);
384 * Check for unsettable attributes.
386 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
387 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
388 (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
389 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
391 printf("msdosfs_setattr(): returning EINVAL\n");
392 printf(" va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
393 vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
394 printf(" va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
395 vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
396 printf(" va_uid %x, va_gid %x\n",
397 vap->va_uid, vap->va_gid);
401 if (vap->va_flags != VNOVAL) {
402 if (vp->v_mount->mnt_flag & MNT_RDONLY)
404 if (cred->cr_uid != pmp->pm_uid) {
405 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
410 * We are very inconsistent about handling unsupported
411 * attributes. We ignored the access time and the
412 * read and execute bits. We were strict for the other
415 * Here we are strict, stricter than ufs in not allowing
416 * users to attempt to set SF_SETTABLE bits or anyone to
417 * set unsupported bits. However, we ignore attempts to
418 * set ATTR_ARCHIVE for directories `cp -pr' from a more
419 * sensible filesystem attempts it a lot.
421 if (vap->va_flags & SF_SETTABLE) {
422 error = priv_check_cred(cred, PRIV_VFS_SYSFLAGS, 0);
426 if (vap->va_flags & ~SF_ARCHIVED)
428 if (vap->va_flags & SF_ARCHIVED)
429 dep->de_Attributes &= ~ATTR_ARCHIVE;
430 else if (!(dep->de_Attributes & ATTR_DIRECTORY))
431 dep->de_Attributes |= ATTR_ARCHIVE;
432 dep->de_flag |= DE_MODIFIED;
435 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
439 if (vp->v_mount->mnt_flag & MNT_RDONLY)
442 if (uid == (uid_t)VNOVAL)
445 if (gid == (gid_t)VNOVAL)
447 if (cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
448 (gid != pmp->pm_gid && !groupmember(gid, cred))) {
449 error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0);
453 if (uid != pmp->pm_uid || gid != pmp->pm_gid)
457 if (vap->va_size != VNOVAL) {
458 switch (vp->v_type) {
463 * Truncation is only supported for regular files,
464 * Disallow it if the filesystem is read-only.
466 if (vp->v_mount->mnt_flag & MNT_RDONLY)
471 * According to POSIX, the result is unspecified
472 * for file types other than regular files,
473 * directories and shared memory objects. We
474 * don't support any file types except regular
475 * files and directories in this file system, so
476 * this (default) case is unreachable and can do
477 * anything. Keep falling through to detrunc()
482 error = detrunc(dep, vap->va_size, 0, cred, td);
486 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
487 if (vp->v_mount->mnt_flag & MNT_RDONLY)
489 if (vap->va_vaflags & VA_UTIMES_NULL) {
490 error = VOP_ACCESS(vp, VADMIN, cred, td);
492 error = VOP_ACCESS(vp, VWRITE, cred, td);
494 error = VOP_ACCESS(vp, VADMIN, cred, td);
495 if (vp->v_type != VDIR) {
496 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
497 vap->va_atime.tv_sec != VNOVAL) {
498 dep->de_flag &= ~DE_ACCESS;
499 timespec2fattime(&vap->va_atime, 0,
500 &dep->de_ADate, NULL, NULL);
502 if (vap->va_mtime.tv_sec != VNOVAL) {
503 dep->de_flag &= ~DE_UPDATE;
504 timespec2fattime(&vap->va_mtime, 0,
505 &dep->de_MDate, &dep->de_MTime, NULL);
507 dep->de_Attributes |= ATTR_ARCHIVE;
508 dep->de_flag |= DE_MODIFIED;
512 * DOS files only have the ability to have their writability
513 * attribute set, so we use the owner write bit to set the readonly
516 if (vap->va_mode != (mode_t)VNOVAL) {
517 if (vp->v_mount->mnt_flag & MNT_RDONLY)
519 if (cred->cr_uid != pmp->pm_uid) {
520 error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
524 if (vp->v_type != VDIR) {
525 /* We ignore the read and execute bits. */
526 if (vap->va_mode & VWRITE)
527 dep->de_Attributes &= ~ATTR_READONLY;
529 dep->de_Attributes |= ATTR_READONLY;
530 dep->de_Attributes |= ATTR_ARCHIVE;
531 dep->de_flag |= DE_MODIFIED;
534 return (deupdat(dep, 0));
539 struct vop_read_args /* {
543 struct ucred *a_cred;
558 struct vnode *vp = ap->a_vp;
559 struct denode *dep = VTODE(vp);
560 struct msdosfsmount *pmp = dep->de_pmp;
561 struct uio *uio = ap->a_uio;
564 * If they didn't ask for any data, then we are done.
566 orig_resid = uio->uio_resid;
571 * The caller is supposed to ensure that
572 * uio->uio_offset >= 0 and uio->uio_resid >= 0.
573 * We don't need to check for large offsets as in ffs because
574 * dep->de_FileSize <= DOS_FILESIZE_MAX < OFF_MAX, so large
575 * offsets cannot cause overflow even in theory.
578 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
580 isadir = dep->de_Attributes & ATTR_DIRECTORY;
582 if (uio->uio_offset >= dep->de_FileSize)
584 lbn = de_cluster(pmp, uio->uio_offset);
586 blsize = pmp->pm_bpcluster;
587 on = uio->uio_offset & pmp->pm_crbomask;
589 * If we are operating on a directory file then be sure to
590 * do i/o with the vnode for the filesystem instead of the
591 * vnode for the directory.
594 /* convert cluster # to block # */
595 error = pcbmap(dep, lbn, &lbn, 0, &blsize);
596 if (error == E2BIG) {
601 error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
602 } else if (de_cn2off(pmp, rablock) >= dep->de_FileSize) {
603 error = bread(vp, lbn, blsize, NOCRED, &bp);
604 } else if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
605 error = cluster_read(vp, dep->de_FileSize, lbn, blsize,
606 NOCRED, on + uio->uio_resid, seqcount, &bp);
607 } else if (seqcount > 1) {
609 error = breadn(vp, lbn,
610 blsize, &rablock, &rasize, 1, NOCRED, &bp);
612 error = bread(vp, lbn, blsize, NOCRED, &bp);
618 diff = pmp->pm_bpcluster - on;
619 n = diff > uio->uio_resid ? uio->uio_resid : diff;
620 diff = dep->de_FileSize - uio->uio_offset;
623 diff = blsize - bp->b_resid;
626 error = uiomove(bp->b_data + on, (int) n, uio);
628 } while (error == 0 && uio->uio_resid > 0 && n != 0);
629 if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
630 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
631 dep->de_flag |= DE_ACCESS;
636 * Write data to a file or directory.
640 struct vop_write_args /* {
644 struct ucred *a_cred;
656 int ioflag = ap->a_ioflag;
657 struct uio *uio = ap->a_uio;
658 struct thread *td = uio->uio_td;
659 struct vnode *vp = ap->a_vp;
660 struct vnode *thisvp;
661 struct denode *dep = VTODE(vp);
662 struct msdosfsmount *pmp = dep->de_pmp;
663 struct ucred *cred = ap->a_cred;
666 printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
667 vp, uio, ioflag, cred);
668 printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
669 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
672 switch (vp->v_type) {
674 if (ioflag & IO_APPEND)
675 uio->uio_offset = dep->de_FileSize;
681 panic("msdosfs_write(): bad file type");
685 * This is needed (unlike in ffs_write()) because we extend the
686 * file outside of the loop but we don't want to extend the file
687 * for writes of 0 bytes.
689 if (uio->uio_resid == 0)
693 * The caller is supposed to ensure that
694 * uio->uio_offset >= 0 and uio->uio_resid >= 0.
696 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
700 * If they've exceeded their filesize limit, tell them about it.
703 PROC_LOCK(td->td_proc);
704 if ((uoff_t)uio->uio_offset + uio->uio_resid >
705 lim_cur(td->td_proc, RLIMIT_FSIZE)) {
706 psignal(td->td_proc, SIGXFSZ);
707 PROC_UNLOCK(td->td_proc);
710 PROC_UNLOCK(td->td_proc);
714 * If the offset we are starting the write at is beyond the end of
715 * the file, then they've done a seek. Unix filesystems allow
716 * files with holes in them, DOS doesn't so we must fill the hole
717 * with zeroed blocks.
719 if (uio->uio_offset > dep->de_FileSize) {
720 error = deextend(dep, uio->uio_offset, cred);
726 * Remember some values in case the write fails.
728 resid = uio->uio_resid;
729 osize = dep->de_FileSize;
732 * If we write beyond the end of the file, extend it to its ultimate
733 * size ahead of the time to hopefully get a contiguous area.
735 if (uio->uio_offset + resid > osize) {
736 count = de_clcount(pmp, uio->uio_offset + resid) -
737 de_clcount(pmp, osize);
738 error = extendfile(dep, count, NULL, NULL, 0);
739 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
741 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
743 lastcn = de_clcount(pmp, osize) - 1;
745 seqcount = ioflag >> IO_SEQSHIFT;
747 if (de_cluster(pmp, uio->uio_offset) > lastcn) {
752 croffset = uio->uio_offset & pmp->pm_crbomask;
753 n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
754 if (uio->uio_offset + n > dep->de_FileSize) {
755 dep->de_FileSize = uio->uio_offset + n;
756 /* The object size needs to be set before buffer is allocated */
757 vnode_pager_setsize(vp, dep->de_FileSize);
760 bn = de_cluster(pmp, uio->uio_offset);
761 if ((uio->uio_offset & pmp->pm_crbomask) == 0
762 && (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
763 > de_cluster(pmp, uio->uio_offset)
764 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
766 * If either the whole cluster gets written,
767 * or we write the cluster from its start beyond EOF,
768 * then no need to read data from disk.
770 bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0);
773 * Do the bmap now, since pcbmap needs buffers
774 * for the fat table. (see msdosfs_strategy)
776 if (bp->b_blkno == bp->b_lblkno) {
777 error = pcbmap(dep, bp->b_lblkno, &bn, 0, 0);
783 if (bp->b_blkno == -1) {
786 error = EIO; /* XXX */
791 * The block we need to write into exists, so read it in.
793 error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
801 * Should these vnode_pager_* functions be done on dir
806 * Copy the data from user space into the buf header.
808 error = uiomove(bp->b_data + croffset, n, uio);
814 /* Prepare for clustered writes in some else clauses. */
815 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
816 bp->b_flags |= B_CLUSTEROK;
819 * If IO_SYNC, then each buffer is written synchronously.
820 * Otherwise, if we have a severe page deficiency then
821 * write the buffer asynchronously. Otherwise, if on a
822 * cluster boundary then write the buffer asynchronously,
823 * combining it with contiguous clusters if permitted and
824 * possible, since we don't expect more writes into this
825 * buffer soon. Otherwise, do a delayed write because we
826 * expect more writes into this buffer soon.
828 if (ioflag & IO_SYNC)
830 else if (vm_page_count_severe() || buf_dirty_count_severe())
832 else if (n + croffset == pmp->pm_bpcluster) {
833 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
834 cluster_write(vp, bp, dep->de_FileSize,
840 dep->de_flag |= DE_UPDATE;
841 } while (error == 0 && uio->uio_resid > 0);
844 * If the write failed and they want us to, truncate the file back
845 * to the size it was before the write was attempted.
849 if (ioflag & IO_UNIT) {
850 detrunc(dep, osize, ioflag & IO_SYNC, NOCRED, NULL);
851 uio->uio_offset -= resid - uio->uio_resid;
852 uio->uio_resid = resid;
854 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED, NULL);
855 if (uio->uio_resid != resid)
858 } else if (ioflag & IO_SYNC)
859 error = deupdat(dep, 1);
864 * Flush the blocks of a file to disk.
866 * This function is worthless for vnodes that represent directories. Maybe we
867 * could just do a sync if they try an fsync on a directory file.
871 struct vop_fsync_args /* {
873 struct ucred *a_cred;
880 return (deupdat(VTODE(ap->a_vp), ap->a_waitfor == MNT_WAIT));
885 struct vop_remove_args /* {
888 struct componentname *a_cnp;
891 struct denode *dep = VTODE(ap->a_vp);
892 struct denode *ddep = VTODE(ap->a_dvp);
895 if (ap->a_vp->v_type == VDIR)
898 error = removede(ddep, dep);
900 printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
906 * DOS filesystems don't know what links are.
910 struct vop_link_args /* {
911 struct vnode *a_tdvp;
913 struct componentname *a_cnp;
920 * Renames on files require moving the denode to a new hash queue since the
921 * denode's location is used to compute which hash queue to put the file
922 * in. Unless it is a rename in place. For example "mv a b".
924 * What follows is the basic algorithm:
927 * if (dest file exists) {
930 * if (dest and src in same directory) {
931 * rewrite name in existing directory slot
933 * write new entry in dest directory
934 * update offset and dirclust in denode
935 * move denode to new hash chain
936 * clear old directory entry
940 * if (dest directory exists) {
941 * if (dest is not empty) {
944 * remove dest directory
946 * if (dest and src in same directory) {
947 * rewrite name in existing entry
949 * be sure dest is not a child of src directory
950 * write entry in dest directory
951 * update "." and ".." in moved directory
952 * clear old directory entry for moved directory
957 * source's parent directory is unlocked
958 * source file or directory is unlocked
959 * destination's parent directory is locked
960 * destination file or directory is locked if it exists
963 * all denodes should be released
967 struct vop_rename_args /* {
968 struct vnode *a_fdvp;
970 struct componentname *a_fcnp;
971 struct vnode *a_tdvp;
973 struct componentname *a_tcnp;
976 struct vnode *tdvp = ap->a_tdvp;
977 struct vnode *fvp = ap->a_fvp;
978 struct vnode *fdvp = ap->a_fdvp;
979 struct vnode *tvp = ap->a_tvp;
980 struct componentname *tcnp = ap->a_tcnp;
981 struct componentname *fcnp = ap->a_fcnp;
982 struct denode *ip, *xp, *dp, *zp;
983 u_char toname[12], 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 msdosfsmount *pmp;
992 struct direntry *dotdotp;
995 fddep = VTODE(ap->a_fdvp);
998 pmp = VFSTOMSDOSFS(fdvp->v_mount);
1001 if ((tcnp->cn_flags & HASBUF) == 0 ||
1002 (fcnp->cn_flags & HASBUF) == 0)
1003 panic("msdosfs_rename: no name");
1006 * Check for cross-device rename.
1008 if (fvp->v_mount != tdvp->v_mount ||
1009 (tvp && fvp->v_mount != tvp->v_mount)) {
1024 * If source and dest are the same, do nothing.
1031 error = vn_lock(fvp, LK_EXCLUSIVE);
1038 * Be sure we are not renaming ".", "..", or an alias of ".". This
1039 * leads to a crippled directory tree. It's pretty tough to do a
1040 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
1041 * doesn't work if the ".." entry is missing.
1043 if (ip->de_Attributes & ATTR_DIRECTORY) {
1045 * Avoid ".", "..", and aliases of "." for obvious reasons.
1047 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
1049 (fcnp->cn_flags & ISDOTDOT) ||
1050 (tcnp->cn_flags & ISDOTDOT) ||
1051 (ip->de_flag & DE_RENAME)) {
1056 ip->de_flag |= DE_RENAME;
1061 * When the target exists, both the directory
1062 * and target vnodes are returned locked.
1065 xp = tvp ? VTODE(tvp) : NULL;
1067 * Remember direntry place to use for destination
1069 to_diroffset = dp->de_fndoffset;
1070 to_count = dp->de_fndcnt;
1073 * If ".." must be changed (ie the directory gets a new
1074 * parent) then the source directory must not be in the
1075 * directory heirarchy above the target, as this would
1076 * orphan everything below the source directory. Also
1077 * the user must have write permission in the source so
1078 * as to be able to change "..". We must repeat the call
1079 * to namei, as the parent directory is unlocked by the
1080 * call to doscheckpath().
1082 error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
1084 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1086 if (doingdirectory && newparent) {
1087 if (error) /* write access check above */
1092 * doscheckpath() vput()'s dp,
1093 * so we have to do a relookup afterwards
1095 error = doscheckpath(ip, dp);
1098 if ((tcnp->cn_flags & SAVESTART) == 0)
1099 panic("msdosfs_rename: lost to startdir");
1100 error = relookup(tdvp, &tvp, tcnp);
1104 xp = tvp ? VTODE(tvp) : NULL;
1109 * Target must be empty if a directory and have no links
1110 * to it. Also, ensure source and target are compatible
1111 * (both directories, or both not directories).
1113 if (xp->de_Attributes & ATTR_DIRECTORY) {
1114 if (!dosdirempty(xp)) {
1118 if (!doingdirectory) {
1123 } else if (doingdirectory) {
1127 error = removede(dp, xp);
1135 * Convert the filename in tcnp into a dos filename. We copy this
1136 * into the denode and directory entry for the destination
1139 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1144 * Since from wasn't locked at various places above,
1145 * have to do a relookup here.
1147 fcnp->cn_flags &= ~MODMASK;
1148 fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
1149 if ((fcnp->cn_flags & SAVESTART) == 0)
1150 panic("msdosfs_rename: lost from startdir");
1152 VOP_UNLOCK(tdvp, 0);
1153 if (relookup(fdvp, &fvp, fcnp) == 0)
1157 * From name has disappeared.
1160 panic("rename: lost dir entry");
1162 VOP_UNLOCK(tdvp, 0);
1169 from_diroffset = zp->de_fndoffset;
1172 * Ensure that the directory entry still exists and has not
1173 * changed till now. If the source is a file the entry may
1174 * have been unlinked or renamed. In either case there is
1175 * no further work to be done. If the source is a directory
1176 * then it cannot have been rmdir'ed or renamed; this is
1177 * prohibited by the DE_RENAME flag.
1181 panic("rename: lost dir entry");
1184 VOP_UNLOCK(fdvp, 0);
1192 * First write a new entry in the destination
1193 * directory and mark the entry in the source directory
1194 * as deleted. Then move the denode to the correct hash
1195 * chain for its new location in the filesystem. And, if
1196 * we moved a directory, then update its .. entry to point
1197 * to the new parent directory.
1199 bcopy(ip->de_Name, oldname, 11);
1200 bcopy(toname, ip->de_Name, 11); /* update denode */
1201 dp->de_fndoffset = to_diroffset;
1202 dp->de_fndcnt = to_count;
1203 error = createde(ip, dp, (struct denode **)0, tcnp);
1205 bcopy(oldname, ip->de_Name, 11);
1207 VOP_UNLOCK(fdvp, 0);
1212 zp->de_fndoffset = from_diroffset;
1213 error = removede(zp, ip);
1215 /* XXX should downgrade to ro here, fs is corrupt */
1217 VOP_UNLOCK(fdvp, 0);
1221 if (!doingdirectory) {
1222 error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
1223 &ip->de_dirclust, 0);
1225 /* XXX should downgrade to ro here, fs is corrupt */
1227 VOP_UNLOCK(fdvp, 0);
1231 if (ip->de_dirclust == MSDOSFSROOT)
1232 ip->de_diroffset = to_diroffset;
1234 ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
1238 VOP_UNLOCK(fdvp, 0);
1242 * If we moved a directory to a new parent directory, then we must
1243 * fixup the ".." entry in the moved directory.
1245 if (doingdirectory && newparent) {
1246 cn = ip->de_StartCluster;
1247 if (cn == MSDOSFSROOT) {
1248 /* this should never happen */
1249 panic("msdosfs_rename(): updating .. in root directory?");
1251 bn = cntobn(pmp, cn);
1252 error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
1255 /* XXX should downgrade to ro here, fs is corrupt */
1260 dotdotp = (struct direntry *)bp->b_data + 1;
1261 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1263 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1264 if (fvp->v_mount->mnt_flag & MNT_ASYNC)
1266 else if ((error = bwrite(bp)) != 0) {
1267 /* XXX should downgrade to ro here, fs is corrupt */
1279 ip->de_flag &= ~DE_RENAME;
1287 struct direntry dot;
1288 struct direntry dotdot;
1289 } dosdirtemplate = {
1290 { ". ", /* the . entry */
1291 ATTR_DIRECTORY, /* file attribute */
1293 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1294 { 0, 0 }, /* access date */
1295 { 0, 0 }, /* high bits of start cluster */
1296 { 210, 4 }, { 210, 4 }, /* modify time & date */
1297 { 0, 0 }, /* startcluster */
1298 { 0, 0, 0, 0 } /* filesize */
1300 { ".. ", /* the .. entry */
1301 ATTR_DIRECTORY, /* file attribute */
1303 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1304 { 0, 0 }, /* access date */
1305 { 0, 0 }, /* high bits of start cluster */
1306 { 210, 4 }, { 210, 4 }, /* modify time & date */
1307 { 0, 0 }, /* startcluster */
1308 { 0, 0, 0, 0 } /* filesize */
1314 struct vop_mkdir_args /* {
1315 struct vnode *a_dvp;
1316 struct vnode **a_vpp;
1317 struvt componentname *a_cnp;
1318 struct vattr *a_vap;
1321 struct componentname *cnp = ap->a_cnp;
1323 struct denode *pdep = VTODE(ap->a_dvp);
1324 struct direntry *denp;
1325 struct msdosfsmount *pmp = pdep->de_pmp;
1327 u_long newcluster, pcl;
1330 struct denode ndirent;
1334 * If this is the root directory and there is no space left we
1335 * can't do anything. This is because the root directory can not
1338 if (pdep->de_StartCluster == MSDOSFSROOT
1339 && pdep->de_fndoffset >= pdep->de_FileSize) {
1345 * Allocate a cluster to hold the about to be created directory.
1347 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1351 bzero(&ndirent, sizeof(ndirent));
1352 ndirent.de_pmp = pmp;
1353 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1355 DETIMES(&ndirent, &ts, &ts, &ts);
1358 * Now fill the cluster with the "." and ".." entries. And write
1359 * the cluster to disk. This way it is there for the parent
1360 * directory to be pointing at if there were a crash.
1362 bn = cntobn(pmp, newcluster);
1363 /* always succeeds */
1364 bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0);
1365 bzero(bp->b_data, pmp->pm_bpcluster);
1366 bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
1367 denp = (struct direntry *)bp->b_data;
1368 putushort(denp[0].deStartCluster, newcluster);
1369 putushort(denp[0].deCDate, ndirent.de_CDate);
1370 putushort(denp[0].deCTime, ndirent.de_CTime);
1371 denp[0].deCHundredth = ndirent.de_CHun;
1372 putushort(denp[0].deADate, ndirent.de_ADate);
1373 putushort(denp[0].deMDate, ndirent.de_MDate);
1374 putushort(denp[0].deMTime, ndirent.de_MTime);
1375 pcl = pdep->de_StartCluster;
1376 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1378 putushort(denp[1].deStartCluster, pcl);
1379 putushort(denp[1].deCDate, ndirent.de_CDate);
1380 putushort(denp[1].deCTime, ndirent.de_CTime);
1381 denp[1].deCHundredth = ndirent.de_CHun;
1382 putushort(denp[1].deADate, ndirent.de_ADate);
1383 putushort(denp[1].deMDate, ndirent.de_MDate);
1384 putushort(denp[1].deMTime, ndirent.de_MTime);
1386 putushort(denp[0].deHighClust, newcluster >> 16);
1387 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1390 if (ap->a_dvp->v_mount->mnt_flag & MNT_ASYNC)
1392 else if ((error = bwrite(bp)) != 0)
1396 * Now build up a directory entry pointing to the newly allocated
1397 * cluster. This will be written to an empty slot in the parent
1401 if ((cnp->cn_flags & HASBUF) == 0)
1402 panic("msdosfs_mkdir: no name");
1404 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1408 ndirent.de_Attributes = ATTR_DIRECTORY;
1409 ndirent.de_LowerCase = 0;
1410 ndirent.de_StartCluster = newcluster;
1411 ndirent.de_FileSize = 0;
1412 error = createde(&ndirent, pdep, &dep, cnp);
1415 *ap->a_vpp = DETOV(dep);
1419 clusterfree(pmp, newcluster, NULL);
1426 struct vop_rmdir_args /* {
1427 struct vnode *a_dvp;
1429 struct componentname *a_cnp;
1432 struct vnode *vp = ap->a_vp;
1433 struct vnode *dvp = ap->a_dvp;
1434 struct componentname *cnp = ap->a_cnp;
1435 struct denode *ip, *dp;
1436 struct thread *td = cnp->cn_thread;
1443 * Verify the directory is empty (and valid).
1444 * (Rmdir ".." won't be valid since
1445 * ".." will contain a reference to
1446 * the current directory and thus be
1450 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1455 * Delete the entry from the directory. For dos filesystems this
1456 * gets rid of the directory entry on disk, the in memory copy
1457 * still exists but the de_refcnt is <= 0. This prevents it from
1458 * being found by deget(). When the vput() on dep is done we give
1459 * up access and eventually msdosfs_reclaim() will be called which
1460 * will remove it from the denode cache.
1462 error = removede(dp, ip);
1466 * This is where we decrement the link count in the parent
1467 * directory. Since dos filesystems don't do this we just purge
1472 * Truncate the directory that is being deleted.
1474 error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred, td);
1482 * DOS filesystems don't know what symlinks are.
1486 struct vop_symlink_args /* {
1487 struct vnode *a_dvp;
1488 struct vnode **a_vpp;
1489 struct componentname *a_cnp;
1490 struct vattr *a_vap;
1494 return (EOPNOTSUPP);
1499 struct vop_readdir_args /* {
1502 struct ucred *a_cred;
1520 struct denode *dep = VTODE(ap->a_vp);
1521 struct msdosfsmount *pmp = dep->de_pmp;
1522 struct direntry *dentp;
1523 struct dirent dirbuf;
1524 struct uio *uio = ap->a_uio;
1525 u_long *cookies = NULL;
1530 #ifdef MSDOSFS_DEBUG
1531 printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1532 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1536 * msdosfs_readdir() won't operate properly on regular files since
1537 * it does i/o only with the the filesystem vnode, and hence can
1538 * retrieve the wrong block from the buffer cache for a plain file.
1539 * So, fail attempts to readdir() on a plain file.
1541 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
1545 * To be safe, initialize dirbuf
1547 bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
1550 * If the user buffer is smaller than the size of one dos directory
1551 * entry or the file offset is not a multiple of the size of a
1552 * directory entry, then we fail the read.
1554 off = offset = uio->uio_offset;
1555 if (uio->uio_resid < sizeof(struct direntry) ||
1556 (offset & (sizeof(struct direntry) - 1)))
1559 if (ap->a_ncookies) {
1560 ncookies = uio->uio_resid / 16;
1561 cookies = malloc(ncookies * sizeof(u_long), M_TEMP,
1563 *ap->a_cookies = cookies;
1564 *ap->a_ncookies = ncookies;
1567 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1570 * If they are reading from the root directory then, we simulate
1571 * the . and .. entries since these don't exist in the root
1572 * directory. We also set the offset bias to make up for having to
1573 * simulate these entries. By this I mean that at file offset 64 we
1574 * read the first entry in the root directory that lives on disk.
1576 if (dep->de_StartCluster == MSDOSFSROOT
1577 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1579 printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
1582 bias = 2 * sizeof(struct direntry);
1583 if (offset < bias) {
1584 for (n = (int)offset / sizeof(struct direntry);
1587 fileno = (uint64_t)cntobn(pmp,
1592 if (pmp->pm_flags & MSDOSFS_LARGEFS) {
1594 msdosfs_fileno_map(pmp->pm_mountp,
1598 dirbuf.d_fileno = (uint32_t)fileno;
1600 dirbuf.d_type = DT_DIR;
1603 dirbuf.d_namlen = 1;
1604 strcpy(dirbuf.d_name, ".");
1607 dirbuf.d_namlen = 2;
1608 strcpy(dirbuf.d_name, "..");
1611 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1612 if (uio->uio_resid < dirbuf.d_reclen)
1614 error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
1617 offset += sizeof(struct direntry);
1620 *cookies++ = offset;
1621 if (--ncookies <= 0)
1630 while (uio->uio_resid > 0) {
1631 lbn = de_cluster(pmp, offset - bias);
1632 on = (offset - bias) & pmp->pm_crbomask;
1633 n = min(pmp->pm_bpcluster - on, uio->uio_resid);
1634 diff = dep->de_FileSize - (offset - bias);
1638 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1641 error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
1646 n = min(n, blsize - bp->b_resid);
1653 * Convert from dos directory entries to fs-independent
1654 * directory entries.
1656 for (dentp = (struct direntry *)(bp->b_data + on);
1657 (char *)dentp < bp->b_data + on + n;
1658 dentp++, offset += sizeof(struct direntry)) {
1660 printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
1661 dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
1664 * If this is an unused entry, we can stop.
1666 if (dentp->deName[0] == SLOT_EMPTY) {
1671 * Skip deleted entries.
1673 if (dentp->deName[0] == SLOT_DELETED) {
1680 * Handle Win95 long directory entries
1682 if (dentp->deAttributes == ATTR_WIN95) {
1683 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1685 chksum = win2unixfn(&nb,
1686 (struct winentry *)dentp, chksum, pmp);
1691 * Skip volume labels
1693 if (dentp->deAttributes & ATTR_VOLUME) {
1699 * This computation of d_fileno must match
1700 * the computation of va_fileid in
1703 if (dentp->deAttributes & ATTR_DIRECTORY) {
1704 fileno = getushort(dentp->deStartCluster);
1706 fileno |= getushort(dentp->deHighClust) << 16;
1707 /* if this is the root directory */
1708 if (fileno == MSDOSFSROOT)
1710 fileno = (uint64_t)cntobn(pmp,
1716 fileno = (uint64_t)cntobn(pmp, fileno) *
1718 dirbuf.d_type = DT_DIR;
1720 fileno = (uoff_t)offset /
1721 sizeof(struct direntry);
1722 dirbuf.d_type = DT_REG;
1724 if (pmp->pm_flags & MSDOSFS_LARGEFS) {
1726 msdosfs_fileno_map(pmp->pm_mountp, fileno);
1728 dirbuf.d_fileno = (uint32_t)fileno;
1730 if (chksum != winChksum(dentp->deName)) {
1731 dirbuf.d_namlen = dos2unixfn(dentp->deName,
1732 (u_char *)dirbuf.d_name,
1733 dentp->deLowerCase |
1734 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1735 (LCASE_BASE | LCASE_EXT) : 0),
1739 mbnambuf_flush(&nb, &dirbuf);
1741 dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
1742 if (uio->uio_resid < dirbuf.d_reclen) {
1746 error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
1752 *cookies++ = offset + sizeof(struct direntry);
1753 if (--ncookies <= 0) {
1758 off = offset + sizeof(struct direntry);
1763 /* Subtract unused cookies */
1765 *ap->a_ncookies -= ncookies;
1767 uio->uio_offset = off;
1770 * Set the eofflag (NFS uses it)
1772 if (ap->a_eofflag) {
1773 if (dep->de_FileSize - (offset - bias) <= 0)
1782 * a_vp - pointer to the file's vnode
1783 * a_bn - logical block number within the file (cluster number for us)
1784 * a_bop - where to return the bufobj of the special file containing the fs
1785 * a_bnp - where to return the "physical" block number corresponding to a_bn
1786 * (relative to the special file; units are blocks of size DEV_BSIZE)
1787 * a_runp - where to return the "run past" a_bn. This is the count of logical
1788 * blocks whose physical blocks (together with a_bn's physical block)
1790 * a_runb - where to return the "run before" a_bn.
1794 struct vop_bmap_args /* {
1797 struct bufobj **a_bop;
1805 struct msdosfsmount *pmp;
1809 int bnpercn, error, maxio, maxrun, run;
1814 if (ap->a_bop != NULL)
1815 *ap->a_bop = &pmp->pm_devvp->v_bufobj;
1816 if (ap->a_bnp == NULL)
1818 if (ap->a_runp != NULL)
1820 if (ap->a_runb != NULL)
1825 error = pcbmap(dep, cn, ap->a_bnp, NULL, NULL);
1826 if (error != 0 || (ap->a_runp == NULL && ap->a_runb == NULL))
1830 maxio = mp->mnt_iosize_max / mp->mnt_stat.f_iosize;
1831 bnpercn = de_cn2bn(pmp, 1);
1832 if (ap->a_runp != NULL) {
1833 maxrun = ulmin(maxio - 1, pmp->pm_maxcluster - cn);
1834 for (run = 1; run <= maxrun; run++) {
1835 if (pcbmap(dep, cn + run, &runbn, NULL, NULL) != 0 ||
1836 runbn != *ap->a_bnp + run * bnpercn)
1839 *ap->a_runp = run - 1;
1841 if (ap->a_runb != NULL) {
1842 maxrun = ulmin(maxio - 1, cn);
1843 for (run = 1; run < maxrun; run++) {
1844 if (pcbmap(dep, cn - run, &runbn, NULL, NULL) != 0 ||
1845 runbn != *ap->a_bnp - run * bnpercn)
1848 *ap->a_runb = run - 1;
1854 msdosfs_strategy(ap)
1855 struct vop_strategy_args /* {
1860 struct buf *bp = ap->a_bp;
1861 struct denode *dep = VTODE(ap->a_vp);
1867 * If we don't already know the filesystem relative block number
1868 * then get it using pcbmap(). If pcbmap() returns the block
1869 * number as -1 then we've got a hole in the file. DOS filesystems
1870 * don't allow files with holes, so we shouldn't ever see this.
1872 if (bp->b_blkno == bp->b_lblkno) {
1873 error = pcbmap(dep, bp->b_lblkno, &blkno, 0, 0);
1874 bp->b_blkno = blkno;
1876 bp->b_error = error;
1877 bp->b_ioflags |= BIO_ERROR;
1881 if ((long)bp->b_blkno == -1)
1884 if (bp->b_blkno == -1) {
1889 * Read/write the block from/to the disk that contains the desired
1892 bp->b_iooffset = dbtob(bp->b_blkno);
1893 bo = dep->de_pmp->pm_bo;
1894 BO_STRATEGY(bo, bp);
1900 struct vop_print_args /* {
1904 struct denode *dep = VTODE(ap->a_vp);
1906 printf("\tstartcluster %lu, dircluster %lu, diroffset %lu, ",
1907 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1908 printf("on dev %s\n", devtoname(dep->de_pmp->pm_dev));
1913 msdosfs_pathconf(ap)
1914 struct vop_pathconf_args /* {
1920 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1922 switch (ap->a_name) {
1927 *ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1930 *ap->a_retval = PATH_MAX;
1932 case _PC_CHOWN_RESTRICTED:
1946 struct vop_vptofh_args /* {
1952 struct defid *defhp;
1954 dep = VTODE(ap->a_vp);
1955 defhp = (struct defid *)ap->a_fhp;
1956 defhp->defid_len = sizeof(struct defid);
1957 defhp->defid_dirclust = dep->de_dirclust;
1958 defhp->defid_dirofs = dep->de_diroffset;
1959 /* defhp->defid_gen = dep->de_gen; */
1963 /* Global vfs data structures for msdosfs */
1964 struct vop_vector msdosfs_vnodeops = {
1965 .vop_default = &default_vnodeops,
1967 .vop_access = msdosfs_access,
1968 .vop_bmap = msdosfs_bmap,
1969 .vop_cachedlookup = msdosfs_lookup,
1970 .vop_open = msdosfs_open,
1971 .vop_close = msdosfs_close,
1972 .vop_create = msdosfs_create,
1973 .vop_fsync = msdosfs_fsync,
1974 .vop_getattr = msdosfs_getattr,
1975 .vop_inactive = msdosfs_inactive,
1976 .vop_link = msdosfs_link,
1977 .vop_lookup = vfs_cache_lookup,
1978 .vop_mkdir = msdosfs_mkdir,
1979 .vop_mknod = msdosfs_mknod,
1980 .vop_pathconf = msdosfs_pathconf,
1981 .vop_print = msdosfs_print,
1982 .vop_read = msdosfs_read,
1983 .vop_readdir = msdosfs_readdir,
1984 .vop_reclaim = msdosfs_reclaim,
1985 .vop_remove = msdosfs_remove,
1986 .vop_rename = msdosfs_rename,
1987 .vop_rmdir = msdosfs_rmdir,
1988 .vop_setattr = msdosfs_setattr,
1989 .vop_strategy = msdosfs_strategy,
1990 .vop_symlink = msdosfs_symlink,
1991 .vop_write = msdosfs_write,
1992 .vop_vptofh = msdosfs_vptofh,