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/resourcevar.h> /* defines plimit structure in proc struct */
54 #include <sys/kernel.h>
59 #include <sys/namei.h>
60 #include <sys/mount.h>
61 #include <sys/unistd.h>
62 #include <sys/vnode.h>
63 #include <sys/malloc.h>
64 #include <sys/dirent.h>
65 #include <sys/signalvar.h>
68 #include <vm/vm_extern.h>
69 #include <vm/vm_zone.h>
70 #include <vm/vnode_pager.h>
74 #include <machine/inttypes.h>
79 #include "msdosfsmount.h"
82 #define DOS_FILESIZE_MAX 0xffffffff
87 * In the ufs filesystem the inodes, superblocks, and indirect blocks are
88 * read/written using the vnode for the filesystem. Blocks that represent
89 * the contents of a file are read/written using the vnode for the file
90 * (including directories when they are read/written as files). This
91 * presents problems for the dos filesystem because data that should be in
92 * an inode (if dos had them) resides in the directory itself. Since we
93 * must update directory entries without the benefit of having the vnode
94 * for the directory we must use the vnode for the filesystem. This means
95 * that when a directory is actually read/written (via read, write, or
96 * readdir, or seek) we must use the vnode for the filesystem instead of
97 * the vnode for the directory as would happen in ufs. This is to insure we
98 * retreive the correct block from the buffer cache since the hash value is
99 * based upon the vnode address and the desired block number.
103 * Create a regular file. On entry the directory to contain the file being
104 * created is locked. We must release before we return.
106 * msdosfs_create(struct vnode *a_dvp, struct vnode **a_vpp,
107 * struct componentname *a_cnp, struct vattr *a_vap)
110 msdosfs_create(struct vop_old_create_args *ap)
112 struct componentname *cnp = ap->a_cnp;
113 struct denode ndirent;
115 struct denode *pdep = VTODE(ap->a_dvp);
120 kprintf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
124 * If this is the root directory and there is no space left we
125 * can't do anything. This is because the root directory can not
128 if (pdep->de_StartCluster == MSDOSFSROOT
129 && pdep->de_fndoffset >= pdep->de_FileSize) {
135 * Create a directory entry for the file, then call createde() to
136 * have it installed. NOTE: DOS files are always executable. We
137 * use the absence of the owner write bit to make the file
140 bzero(&ndirent, sizeof(ndirent));
141 error = uniqdosname(pdep, cnp, ndirent.de_Name);
145 ndirent.de_Attributes = (ap->a_vap->va_mode & VWRITE) ?
146 ATTR_ARCHIVE : ATTR_ARCHIVE | ATTR_READONLY;
147 ndirent.de_LowerCase = 0;
148 ndirent.de_StartCluster = 0;
149 ndirent.de_FileSize = 0;
150 ndirent.de_dev = pdep->de_dev;
151 ndirent.de_devvp = pdep->de_devvp;
152 ndirent.de_pmp = pdep->de_pmp;
153 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
155 DETIMES(&ndirent, &ts, &ts, &ts);
156 error = createde(&ndirent, pdep, &dep, cnp);
159 *ap->a_vpp = DETOV(dep);
166 static int msdosfs_mkdir(struct vop_old_mkdir_args *);
169 * msdosfs_mknod(struct vnode *a_dvp, struct vnode **a_vpp,
170 * struct componentname *a_cnp, struct vattr *a_vap)
173 msdosfs_mknod(struct vop_old_mknod_args *ap)
175 switch (ap->a_vap->va_type) {
177 return (msdosfs_mkdir((struct vop_old_mkdir_args *)ap));
179 return (msdosfs_create((struct vop_old_create_args *)ap));
187 * msdosfs_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
191 msdosfs_open(struct vop_open_args *ap)
193 return(vop_stdopen(ap));
197 * msdosfs_close(struct vnode *a_vp, int a_fflag)
200 msdosfs_close(struct vop_close_args *ap)
202 struct vnode *vp = ap->a_vp;
203 struct denode *dep = VTODE(vp);
206 if (VREFCNT(vp) > 1) {
208 DETIMES(dep, &ts, &ts, &ts);
210 return (vop_stdclose(ap));
214 * msdosfs_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred)
217 msdosfs_access(struct vop_access_args *ap)
219 struct denode *dep = VTODE(ap->a_vp);
220 struct msdosfsmount *pmp = dep->de_pmp;
223 file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) |
224 ((dep->de_Attributes & ATTR_READONLY) ?
225 0 : (S_IWUSR|S_IWGRP|S_IWOTH));
226 file_mode &= pmp->pm_mask;
228 return (vop_helper_access(ap, pmp->pm_uid, pmp->pm_gid, file_mode, 0));
232 * msdosfs_getattr(struct vnode *a_vp, struct vattr *a_vap)
235 msdosfs_getattr(struct vop_getattr_args *ap)
237 struct denode *dep = VTODE(ap->a_vp);
238 struct msdosfsmount *pmp = dep->de_pmp;
239 struct vattr *vap = ap->a_vap;
242 u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
246 DETIMES(dep, &ts, &ts, &ts);
247 vap->va_fsid = dev2udev(dep->de_dev);
249 * The following computation of the fileid must be the same as that
250 * used in msdosfs_readdir() to compute d_fileno. If not, pwd
253 if (dep->de_Attributes & ATTR_DIRECTORY) {
254 fileid = xcntobn(pmp, dep->de_StartCluster) * dirsperblk;
255 if (dep->de_StartCluster == MSDOSFSROOT)
258 fileid = xcntobn(pmp, dep->de_dirclust) * dirsperblk;
259 if (dep->de_dirclust == MSDOSFSROOT)
260 fileid = roottobn(pmp, 0) * dirsperblk;
261 fileid += dep->de_diroffset / sizeof(struct direntry);
263 vap->va_fileid = fileid;
264 if ((dep->de_Attributes & ATTR_READONLY) == 0)
265 mode = S_IRWXU|S_IRWXG|S_IRWXO;
267 mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
268 vap->va_mode = mode & pmp->pm_mask;
269 vap->va_uid = pmp->pm_uid;
270 vap->va_gid = pmp->pm_gid;
272 vap->va_rmajor = VNOVAL;
273 vap->va_rminor = VNOVAL;
274 vap->va_size = dep->de_FileSize;
275 dos2unixtime(dep->de_MDate, dep->de_MTime, 0, &vap->va_mtime);
276 if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
277 dos2unixtime(dep->de_ADate, 0, 0, &vap->va_atime);
278 dos2unixtime(dep->de_CDate, dep->de_CTime, dep->de_CHun,
281 vap->va_atime = vap->va_mtime;
282 vap->va_ctime = vap->va_mtime;
285 if ((dep->de_Attributes & ATTR_ARCHIVE) == 0)
286 vap->va_flags |= SF_ARCHIVED;
288 vap->va_blocksize = pmp->pm_bpcluster;
290 (dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
291 vap->va_type = ap->a_vp->v_type;
292 vap->va_filerev = dep->de_modrev;
297 * msdosfs_setattr(struct vnode *a_vp, struct vattr *a_vap,
298 * struct ucred *a_cred)
301 msdosfs_setattr(struct vop_setattr_args *ap)
303 struct vnode *vp = ap->a_vp;
304 struct denode *dep = VTODE(ap->a_vp);
305 struct msdosfsmount *pmp = dep->de_pmp;
306 struct vattr *vap = ap->a_vap;
307 struct ucred *cred = ap->a_cred;
311 kprintf("msdosfs_setattr(): vp %p, vap %p, cred %p\n",
312 ap->a_vp, vap, cred);
316 * Check for unsettable attributes.
318 if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
319 (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
320 (vap->va_blocksize != VNOVAL) || (vap->va_rmajor != VNOVAL) ||
321 (vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
323 kprintf("msdosfs_setattr(): returning EINVAL\n");
324 kprintf(" va_type %u, va_nlink %"PRIx64", va_fsid %x, va_fileid %"PRIx64"\n",
325 vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
326 kprintf(" va_blocksize %lx, va_rmajor %x, va_bytes %"PRIx64", va_gen %"PRIx64"\n",
327 vap->va_blocksize, vap->va_rmajor, vap->va_bytes,
329 kprintf(" va_uid %x, va_gid %x\n",
330 vap->va_uid, vap->va_gid);
334 if (vap->va_flags != VNOVAL) {
335 if (vp->v_mount->mnt_flag & MNT_RDONLY)
337 if (cred->cr_uid != pmp->pm_uid &&
338 (error = priv_check_cred(cred, PRIV_VFS_SETATTR, 0)))
341 * We are very inconsistent about handling unsupported
342 * attributes. We ignored the access time and the
343 * read and execute bits. We were strict for the other
346 * Here we are strict, stricter than ufs in not allowing
347 * users to attempt to set SF_SETTABLE bits or anyone to
348 * set unsupported bits. However, we ignore attempts to
349 * set ATTR_ARCHIVE for directories `cp -pr' from a more
350 * sensible file system attempts it a lot.
352 if (cred->cr_uid != 0) {
353 if (vap->va_flags & SF_SETTABLE)
356 if (vap->va_flags & ~SF_ARCHIVED)
358 if (vap->va_flags & SF_ARCHIVED)
359 dep->de_Attributes &= ~ATTR_ARCHIVE;
360 else if (!(dep->de_Attributes & ATTR_DIRECTORY))
361 dep->de_Attributes |= ATTR_ARCHIVE;
362 dep->de_flag |= DE_MODIFIED;
365 if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
369 if (vp->v_mount->mnt_flag & MNT_RDONLY)
372 if (uid == (uid_t)VNOVAL)
375 if (gid == (gid_t)VNOVAL)
377 if ((cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
378 (gid != pmp->pm_gid && !groupmember(gid, cred))) &&
379 (error = priv_check_cred(cred, PRIV_VFS_SETATTR, 0)))
381 if (uid != pmp->pm_uid || gid != pmp->pm_gid)
385 if (vap->va_size != VNOVAL) {
387 * Disallow write attempts on read-only file systems;
388 * unless the file is a socket, fifo, or a block or
389 * character device resident on the file system.
391 switch (vp->v_type) {
397 if (vp->v_mount->mnt_flag & MNT_RDONLY)
403 error = detrunc(dep, vap->va_size, 0);
407 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
408 if (vp->v_mount->mnt_flag & MNT_RDONLY)
410 if (cred->cr_uid != pmp->pm_uid &&
411 (error = priv_check_cred(cred, PRIV_VFS_SETATTR, 0)) &&
412 ((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
413 (error = VOP_EACCESS(ap->a_vp, VWRITE, cred))))
415 if (vp->v_type != VDIR) {
416 if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
417 vap->va_atime.tv_sec != VNOVAL) {
418 dep->de_flag &= ~DE_ACCESS;
419 unix2dostime(&vap->va_atime, &dep->de_ADate,
422 if (vap->va_mtime.tv_sec != VNOVAL) {
423 dep->de_flag &= ~DE_UPDATE;
424 unix2dostime(&vap->va_mtime, &dep->de_MDate,
425 &dep->de_MTime, NULL);
427 dep->de_Attributes |= ATTR_ARCHIVE;
428 dep->de_flag |= DE_MODIFIED;
432 * DOS files only have the ability to have their writability
433 * attribute set, so we use the owner write bit to set the readonly
436 if (vap->va_mode != (mode_t)VNOVAL) {
437 if (vp->v_mount->mnt_flag & MNT_RDONLY)
439 if (cred->cr_uid != pmp->pm_uid &&
440 (error = priv_check_cred(cred, PRIV_VFS_SETATTR, 0)))
442 if (vp->v_type != VDIR) {
443 /* We ignore the read and execute bits. */
444 if (vap->va_mode & VWRITE)
445 dep->de_Attributes &= ~ATTR_READONLY;
447 dep->de_Attributes |= ATTR_READONLY;
448 dep->de_Attributes |= ATTR_ARCHIVE;
449 dep->de_flag |= DE_MODIFIED;
452 return (deupdat(dep, 1));
456 * msdosfs_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
457 * struct ucred *a_cred)
460 msdosfs_read(struct vop_read_args *ap)
476 struct vnode *vp = ap->a_vp;
477 struct denode *dep = VTODE(vp);
478 struct msdosfsmount *pmp = dep->de_pmp;
479 struct uio *uio = ap->a_uio;
481 if (uio->uio_offset < 0)
484 if ((uoff_t)uio->uio_offset > DOS_FILESIZE_MAX)
487 * If they didn't ask for any data, then we are done.
489 orig_resid = uio->uio_resid;
493 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
495 isadir = dep->de_Attributes & ATTR_DIRECTORY;
497 if (uio->uio_offset >= dep->de_FileSize)
501 * note: lbn is a cluster number, not a device block number.
503 lbn = de_off2cn(pmp, uio->uio_offset);
504 loffset = de_cn2doff(pmp, lbn);
507 * If we are operating on a directory file then be sure to
508 * do i/o with the vnode for the filesystem instead of the
509 * vnode for the directory.
513 * convert cluster # to block #. lbn is a
514 * device block number after this.
516 error = pcbmap(dep, lbn, &lbn, NULL, &blsize);
517 loffset = de_bntodoff(pmp, lbn);
518 if (error == E2BIG) {
523 error = bread(pmp->pm_devvp, loffset, blsize, &bp);
525 blsize = pmp->pm_bpcluster;
527 raoffset = de_cn2doff(pmp, rablock);
529 raoffset < dep->de_FileSize) {
530 rasize = pmp->pm_bpcluster;
531 error = breadn(vp, loffset, blsize,
532 &raoffset, &rasize, 1, &bp);
534 error = bread(vp, loffset, blsize, &bp);
541 on = uio->uio_offset & pmp->pm_crbomask;
542 diff = pmp->pm_bpcluster - on;
543 n = szmin(uio->uio_resid, diff);
544 diff = dep->de_FileSize - uio->uio_offset;
547 diff = blsize - bp->b_resid;
550 error = uiomovebp(bp, bp->b_data + on, (size_t)n, uio);
552 } while (error == 0 && uio->uio_resid > 0 && n != 0);
554 if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
555 (vp->v_mount->mnt_flag & MNT_NOATIME) == 0)
556 dep->de_flag |= DE_ACCESS;
561 * Write data to a file or directory.
563 * msdosfs_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
564 * struct ucred *a_cred)
567 msdosfs_write(struct vop_write_args *ap)
577 int ioflag = ap->a_ioflag;
578 struct uio *uio = ap->a_uio;
579 struct thread *td = uio->uio_td;
580 struct vnode *vp = ap->a_vp;
581 struct vnode *thisvp;
582 struct denode *dep = VTODE(vp);
583 struct msdosfsmount *pmp = dep->de_pmp;
584 struct proc *p = (td ? td->td_proc : NULL);
585 struct lwp *lp = (td ? td->td_lwp : NULL);
588 kprintf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
589 vp, uio, ioflag, ap->a_cred);
590 kprintf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
591 dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
594 switch (vp->v_type) {
596 if (ioflag & IO_APPEND)
597 uio->uio_offset = dep->de_FileSize;
603 panic("msdosfs_write(): bad file type");
606 if (uio->uio_offset < 0)
609 if (uio->uio_resid == 0)
613 * If they've exceeded their filesize limit, tell them about it.
616 ((uoff_t)uio->uio_offset + uio->uio_resid >
617 p->p_rlimit[RLIMIT_FSIZE].rlim_cur)) {
618 lwpsignal(p, lp, SIGXFSZ);
622 if ((uoff_t)uio->uio_offset > DOS_FILESIZE_MAX)
624 if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
628 * If the offset we are starting the write at is beyond the end of
629 * the file, then they've done a seek. Unix filesystems allow
630 * files with holes in them, DOS doesn't so we must fill the hole
631 * with zeroed blocks.
633 if (uio->uio_offset > dep->de_FileSize) {
634 error = deextend(dep, uio->uio_offset);
640 * Remember some values in case the write fails.
642 resid = uio->uio_resid;
643 osize = dep->de_FileSize;
646 * If we write beyond the end of the file, extend it to its ultimate
647 * size ahead of the time to hopefully get a contiguous area.
649 if (uio->uio_offset + resid > osize) {
650 count = de_clcount(pmp, uio->uio_offset + resid) -
651 de_clcount(pmp, osize);
652 error = extendfile(dep, count, NULL, NULL, 0);
653 if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
655 lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
657 lastcn = de_clcount(pmp, osize) - 1;
660 if (de_off2cn(pmp, uio->uio_offset) > lastcn) {
665 croffset = uio->uio_offset & pmp->pm_crbomask;
666 n = (int)szmin(uio->uio_resid, pmp->pm_bpcluster - croffset);
667 if (uio->uio_offset + n > dep->de_FileSize) {
668 dep->de_FileSize = uio->uio_offset + n;
669 /* The object size needs to be set before buffer is allocated */
670 vnode_pager_setsize(vp, dep->de_FileSize);
674 * If either the whole cluster gets written, or we write
675 * the cluster from its start beyond EOF, then no need to
676 * read data from disk.
678 * If UIO_NOCOPY is set we have to do a read-before-write
679 * to fill in any missing pieces of the buffer since no
680 * actual overwrite will occur.
682 cn = de_off2cn(pmp, uio->uio_offset);
683 if ((uio->uio_offset & pmp->pm_crbomask) == 0
684 && uio->uio_segflg != UIO_NOCOPY
685 && (de_off2cn(pmp, uio->uio_offset + uio->uio_resid)
686 > de_off2cn(pmp, uio->uio_offset)
687 || uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
688 bp = getblk(thisvp, de_cn2doff(pmp, cn),
689 pmp->pm_bpcluster, 0, 0);
692 * Do the bmap now, since pcbmap needs buffers
693 * for the fat table. (see msdosfs_strategy)
695 if (bp->b_bio2.bio_offset == NOOFFSET) {
696 daddr_t lblkno = de_off2cn(pmp, bp->b_loffset);
699 error = pcbmap(dep, lblkno,
700 &dblkno, NULL, NULL);
701 if (error || dblkno == (daddr_t)-1) {
702 bp->b_bio2.bio_offset = NOOFFSET;
704 bp->b_bio2.bio_offset = de_bntodoff(pmp,
708 if (bp->b_bio2.bio_offset == NOOFFSET) {
711 error = EIO; /* XXX */
716 * The block we need to write into exists, so read
719 error = bread(thisvp, de_cn2doff(pmp, cn),
720 pmp->pm_bpcluster, &bp);
728 * Should these vnode_pager_* functions be done on dir
733 * Copy the data from user space into the buf header.
735 error = uiomovebp(bp, bp->b_data + croffset, (size_t)n, uio);
742 * If they want this synchronous then write it and wait for
743 * it. Otherwise, if on a cluster boundary write it
744 * asynchronously so we can move on to the next block
745 * without delay. Otherwise do a delayed write because we
746 * may want to write somemore into the block later.
748 if (ioflag & IO_SYNC)
750 else if (n + croffset == pmp->pm_bpcluster)
754 dep->de_flag |= DE_UPDATE;
755 } while (error == 0 && uio->uio_resid > 0);
758 * If the write failed and they want us to, truncate the file back
759 * to the size it was before the write was attempted.
763 if (ioflag & IO_UNIT) {
764 detrunc(dep, osize, ioflag & IO_SYNC);
765 uio->uio_offset -= resid - uio->uio_resid;
766 uio->uio_resid = resid;
768 detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC);
769 if (uio->uio_resid != resid)
772 } else if (ioflag & IO_SYNC)
773 error = deupdat(dep, 1);
778 * Flush the blocks of a file to disk.
780 * This function is worthless for vnodes that represent directories. Maybe we
781 * could just do a sync if they try an fsync on a directory file.
783 * msdosfs_fsync(struct vnode *a_vp, int a_waitfor)
786 msdosfs_fsync(struct vop_fsync_args *ap)
788 struct vnode *vp = ap->a_vp;
791 * Flush all dirty buffers associated with a vnode.
796 vfsync(vp, ap->a_waitfor, 0, NULL, NULL);
798 if (ap->a_waitfor == MNT_WAIT && !RB_EMPTY(&vp->v_rbdirty_tree)) {
799 vprint("msdosfs_fsync: dirty", vp);
803 return (deupdat(VTODE(vp), ap->a_waitfor == MNT_WAIT));
807 * msdosfs_remove(struct vnode *a_dvp, struct vnode *a_vp,
808 * struct componentname *a_cnp)
811 msdosfs_remove(struct vop_old_remove_args *ap)
813 struct denode *dep = VTODE(ap->a_vp);
814 struct denode *ddep = VTODE(ap->a_dvp);
817 if (ap->a_vp->v_type == VDIR)
820 error = removede(ddep, dep);
822 kprintf("msdosfs_remove(), dep %p, v_refcnt 0x%08x\n",
823 dep, ap->a_vp->v_refcnt);
829 * DOS filesystems don't know what links are. But since we already called
830 * msdosfs_lookup() with create and lockparent, the parent is locked so we
831 * have to free it before we return the error.
833 * msdosfs_link(struct vnode *a_tdvp, struct vnode *a_vp,
834 * struct componentname *a_cnp)
837 msdosfs_link(struct vop_old_link_args *ap)
843 * Renames on files require moving the denode to a new hash queue since the
844 * denode's location is used to compute which hash queue to put the file
845 * in. Unless it is a rename in place. For example "mv a b".
847 * What follows is the basic algorithm:
850 * if (dest file exists) {
853 * if (dest and src in same directory) {
854 * rewrite name in existing directory slot
856 * write new entry in dest directory
857 * update offset and dirclust in denode
858 * move denode to new hash chain
859 * clear old directory entry
863 * if (dest directory exists) {
864 * if (dest is not empty) {
867 * remove dest directory
869 * if (dest and src in same directory) {
870 * rewrite name in existing entry
872 * be sure dest is not a child of src directory
873 * write entry in dest directory
874 * update "." and ".." in moved directory
875 * clear old directory entry for moved directory
880 * source's parent directory is unlocked
881 * source file or directory is unlocked
882 * destination's parent directory is locked
883 * destination file or directory is locked if it exists
886 * all denodes should be released
889 * I'm not sure how the memory containing the pathnames pointed at by the
890 * componentname structures is freed, there may be some memory bleeding
891 * for each rename done.
893 * msdosfs_rename(struct vnode *a_fdvp, struct vnode *a_fvp,
894 * struct componentname *a_fcnp, struct vnode *a_tdvp,
895 * struct vnode *a_tvp, struct componentname *a_tcnp)
898 msdosfs_rename(struct vop_old_rename_args *ap)
900 struct vnode *tdvp = ap->a_tdvp;
901 struct vnode *fvp = ap->a_fvp;
902 struct vnode *fdvp = ap->a_fdvp;
903 struct vnode *tvp = ap->a_tvp;
904 struct componentname *tcnp = ap->a_tcnp;
905 struct componentname *fcnp = ap->a_fcnp;
906 struct denode *ip, *xp, *dp, *zp;
907 u_char toname[11], oldname[11];
908 u_long from_diroffset, to_diroffset;
910 int doingdirectory = 0, newparent = 0;
914 struct msdosfsmount *pmp;
915 struct direntry *dotdotp;
918 pmp = VFSTOMSDOSFS(fdvp->v_mount);
921 * Check for cross-device rename.
923 if ((fvp->v_mount != tdvp->v_mount) ||
924 (tvp && (fvp->v_mount != tvp->v_mount))) {
939 * If source and dest are the same, do nothing.
947 * fvp, fdvp are unlocked, tvp, tdvp are locked. Lock fvp and note
948 * that we have to unlock it to use the abortit target.
950 error = vn_lock(fvp, LK_EXCLUSIVE | LK_FAILRECLAIM);
957 * Be sure we are not renaming ".", "..", or an alias of ".". This
958 * leads to a crippled directory tree. It's pretty tough to do a
959 * "ls" or "pwd" with the "." directory entry missing, and "cd .."
960 * doesn't work if the ".." entry is missing.
962 if (ip->de_Attributes & ATTR_DIRECTORY) {
964 * Avoid ".", "..", and aliases of "." for obvious reasons.
966 if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
968 (fcnp->cn_flags & CNP_ISDOTDOT) ||
969 (tcnp->cn_flags & CNP_ISDOTDOT) ||
970 (ip->de_flag & DE_RENAME)) {
975 ip->de_flag |= DE_RENAME;
980 * fvp locked, fdvp unlocked, tvp, tdvp locked. DE_RENAME only
981 * set if doingdirectory. We will get fvp unlocked in fairly
982 * short order. dp and xp must be setup and fvp must be unlocked
983 * for the out and bad targets to work properly.
986 xp = tvp ? VTODE(tvp) : NULL;
989 * Remember direntry place to use for destination
991 to_diroffset = dp->de_fndoffset;
992 to_count = dp->de_fndcnt;
995 * If ".." must be changed (ie the directory gets a new
996 * parent) then the source directory must not be in the
997 * directory heirarchy above the target, as this would
998 * orphan everything below the source directory. Also
999 * the user must have write permission in the source so
1000 * as to be able to change "..". We must repeat the call
1001 * to namei, as the parent directory is unlocked by the
1002 * call to doscheckpath().
1004 error = VOP_EACCESS(fvp, VWRITE, tcnp->cn_cred);
1006 if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
1010 * ok. fvp, fdvp unlocked, tvp, tdvp locked. tvp may be NULL.
1011 * DE_RENAME only set if doingdirectory.
1013 if (doingdirectory && newparent) {
1014 if (error) /* write access check above */
1021 * checkpath vput's tdvp (VTOI(dp)) on return no matter what,
1022 * get an extra ref so we wind up with just an unlocked, ref'd
1023 * tdvp. The 'out' target skips tvp and tdvp cleanups (tdvp
1024 * isn't locked so we can't use the out target).
1027 error = doscheckpath(ip, dp);
1028 tcnp->cn_flags |= CNP_PDIRUNLOCK;
1034 * relookup no longer messes with the ref count. tdvp must
1035 * be unlocked on entry and on success will be locked on
1038 error = relookup(tdvp, &tvp, tcnp);
1040 if (tcnp->cn_flags & CNP_PDIRUNLOCK)
1048 * tvp and tdvp are now locked again.
1051 xp = tvp ? VTODE(tvp) : NULL;
1055 * tvp and tdvp are now locked again, the 'bad' target can be used
1056 * to clean them up again. Delete an existant target and clean
1057 * up tvp. Set xp to NULL to indicate that tvp has been cleaned up.
1061 * Target must be empty if a directory and have no links
1062 * to it. Also, ensure source and target are compatible
1063 * (both directories, or both not directories).
1065 if (xp->de_Attributes & ATTR_DIRECTORY) {
1066 if (!dosdirempty(xp)) {
1070 if (!doingdirectory) {
1074 } else if (doingdirectory) {
1078 error = removede(dp, xp);
1087 * Convert the filename in tcnp into a dos filename. We copy this
1088 * into the denode and directory entry for the destination
1091 error = uniqdosname(VTODE(tdvp), tcnp, toname);
1096 * Since from wasn't locked at various places above, we have to do
1097 * a relookup here. If the target and source are the same directory
1098 * we have to unlock the target directory in order to safely relookup
1099 * the source, because relookup expects its directory to be unlocked.
1101 * Note that ap->a_fvp is still valid and ref'd. Any cleanup must
1102 * now take that into account.
1104 * The tdvp locking issues make this a real mess.
1106 fcnp->cn_flags &= ~CNP_MODMASK;
1107 fcnp->cn_flags |= CNP_LOCKPARENT;
1110 error = relookup(fdvp, &fvp, fcnp);
1111 if (error || fvp == NULL) {
1113 * From name has disappeared. Note: fdvp might == tdvp.
1115 * DE_RENAME is only set if doingdirectory.
1118 panic("rename: lost dir entry");
1119 if (fcnp->cn_flags & CNP_PDIRUNLOCK)
1132 * No error occured. tdvp, fdvp and fvp are all locked. If
1133 * newparent was 0 be aware that fdvp == tdvp. tvp has been cleaned
1134 * up. ap->a_fvp is still refd.
1138 from_diroffset = zp->de_fndoffset;
1141 * Ensure that the directory entry still exists and has not
1142 * changed till now. If the source is a file the entry may
1143 * have been unlinked or renamed. In either case there is
1144 * no further work to be done. If the source is a directory
1145 * then it cannot have been rmdir'ed or renamed; this is
1146 * prohibited by the DE_RENAME flag.
1148 * DE_RENAME is only set if doingdirectory.
1152 panic("rename: lost dir entry");
1155 u_long new_dirclust;
1156 u_long new_diroffset;
1159 * First write a new entry in the destination
1160 * directory and mark the entry in the source directory
1161 * as deleted. Then move the denode to the correct hash
1162 * chain for its new location in the filesystem. And, if
1163 * we moved a directory, then update its .. entry to point
1164 * to the new parent directory.
1166 bcopy(ip->de_Name, oldname, 11);
1167 bcopy(toname, ip->de_Name, 11); /* update denode */
1168 dp->de_fndoffset = to_diroffset;
1169 dp->de_fndcnt = to_count;
1170 error = createde(ip, dp, NULL, tcnp);
1172 bcopy(oldname, ip->de_Name, 11);
1176 zp->de_fndoffset = from_diroffset;
1177 error = removede(zp, ip);
1179 /* XXX should really panic here, fs is corrupt */
1182 if (!doingdirectory) {
1183 error = pcbmap(dp, de_cluster(pmp, to_diroffset),
1184 NULL, &new_dirclust, NULL);
1186 /* XXX should really panic here, fs is corrupt */
1189 if (new_dirclust == MSDOSFSROOT)
1190 new_diroffset = to_diroffset;
1192 new_diroffset = to_diroffset & pmp->pm_crbomask;
1193 msdosfs_reinsert(ip, new_dirclust, new_diroffset);
1198 * If we moved a directory to a new parent directory, then we must
1199 * fixup the ".." entry in the moved directory.
1201 if (doingdirectory && newparent) {
1202 cn = ip->de_StartCluster;
1203 if (cn == MSDOSFSROOT) {
1204 /* this should never happen */
1205 panic("msdosfs_rename(): updating .. in root directory?");
1207 bn = xcntobn(pmp, cn);
1209 error = bread(pmp->pm_devvp, de_bntodoff(pmp, bn),
1210 pmp->pm_bpcluster, &bp);
1212 /* XXX should really panic here, fs is corrupt */
1216 dotdotp = (struct direntry *)bp->b_data + 1;
1217 putushort(dotdotp->deStartCluster, dp->de_StartCluster);
1219 putushort(dotdotp->deHighClust, dp->de_StartCluster >> 16);
1222 /* XXX should really panic here, fs is corrupt */
1228 * done case fvp, fdvp, tdvp are locked. ap->a_fvp is refd
1232 ip->de_flag &= ~DE_RENAME; /* XXX fvp not locked */
1243 * 'bad' target: xp governs tvp. tvp and tdvp arel ocked, fdvp and fvp
1244 * are not locked. ip points to fvp's inode which may have DE_RENAME
1253 * 'out' target: tvp and tdvp have already been cleaned up.
1256 ip->de_flag &= ~DE_RENAME;
1264 struct direntry dot;
1265 struct direntry dotdot;
1266 } dosdirtemplate = {
1267 { ". ", /* the . entry */
1268 ATTR_DIRECTORY, /* file attribute */
1270 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1271 { 0, 0 }, /* access date */
1272 { 0, 0 }, /* high bits of start cluster */
1273 { 210, 4 }, { 210, 4 }, /* modify time & date */
1274 { 0, 0 }, /* startcluster */
1275 { 0, 0, 0, 0 } /* filesize */
1277 { ".. ", /* the .. entry */
1278 ATTR_DIRECTORY, /* file attribute */
1280 0, { 0, 0 }, { 0, 0 }, /* create time & date */
1281 { 0, 0 }, /* access date */
1282 { 0, 0 }, /* high bits of start cluster */
1283 { 210, 4 }, { 210, 4 }, /* modify time & date */
1284 { 0, 0 }, /* startcluster */
1285 { 0, 0, 0, 0 } /* filesize */
1290 * msdosfs_mkdir(struct vnode *a_dvp, struct vnode **a_vpp,
1291 * struct componentname *a_cnp, struct vattr *a_vap)
1294 msdosfs_mkdir(struct vop_old_mkdir_args *ap)
1296 struct componentname *cnp = ap->a_cnp;
1298 struct denode *pdep = VTODE(ap->a_dvp);
1299 struct direntry *denp;
1300 struct msdosfsmount *pmp = pdep->de_pmp;
1302 u_long newcluster, pcl;
1305 struct denode ndirent;
1309 * If this is the root directory and there is no space left we
1310 * can't do anything. This is because the root directory can not
1313 if (pdep->de_StartCluster == MSDOSFSROOT
1314 && pdep->de_fndoffset >= pdep->de_FileSize) {
1320 * Allocate a cluster to hold the about to be created directory.
1322 error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
1326 bzero(&ndirent, sizeof(ndirent));
1327 ndirent.de_pmp = pmp;
1328 ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
1330 DETIMES(&ndirent, &ts, &ts, &ts);
1333 * Now fill the cluster with the "." and ".." entries. And write
1334 * the cluster to disk. This way it is there for the parent
1335 * directory to be pointing at if there were a crash.
1337 bn = xcntobn(pmp, newcluster);
1338 /* always succeeds */
1339 bp = getblk(pmp->pm_devvp, de_bntodoff(pmp, bn),
1340 pmp->pm_bpcluster, 0, 0);
1341 bzero(bp->b_data, pmp->pm_bpcluster);
1342 bcopy(&dosdirtemplate, bp->b_data, sizeof(dosdirtemplate));
1343 denp = (struct direntry *)bp->b_data;
1344 putushort(denp[0].deStartCluster, newcluster);
1345 putushort(denp[0].deCDate, ndirent.de_CDate);
1346 putushort(denp[0].deCTime, ndirent.de_CTime);
1347 denp[0].deCHundredth = ndirent.de_CHun;
1348 putushort(denp[0].deADate, ndirent.de_ADate);
1349 putushort(denp[0].deMDate, ndirent.de_MDate);
1350 putushort(denp[0].deMTime, ndirent.de_MTime);
1351 pcl = pdep->de_StartCluster;
1352 if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
1354 putushort(denp[1].deStartCluster, pcl);
1355 putushort(denp[1].deCDate, ndirent.de_CDate);
1356 putushort(denp[1].deCTime, ndirent.de_CTime);
1357 denp[1].deCHundredth = ndirent.de_CHun;
1358 putushort(denp[1].deADate, ndirent.de_ADate);
1359 putushort(denp[1].deMDate, ndirent.de_MDate);
1360 putushort(denp[1].deMTime, ndirent.de_MTime);
1362 putushort(denp[0].deHighClust, newcluster >> 16);
1363 putushort(denp[1].deHighClust, pdep->de_StartCluster >> 16);
1371 * Now build up a directory entry pointing to the newly allocated
1372 * cluster. This will be written to an empty slot in the parent
1375 error = uniqdosname(pdep, cnp, ndirent.de_Name);
1379 ndirent.de_Attributes = ATTR_DIRECTORY;
1380 ndirent.de_LowerCase = 0;
1381 ndirent.de_StartCluster = newcluster;
1382 ndirent.de_FileSize = 0;
1383 ndirent.de_dev = pdep->de_dev;
1384 ndirent.de_devvp = pdep->de_devvp;
1385 error = createde(&ndirent, pdep, &dep, cnp);
1388 *ap->a_vpp = DETOV(dep);
1392 clusterfree(pmp, newcluster, NULL);
1398 * msdosfs_rmdir(struct vnode *a_dvp, struct vnode *a_vp,
1399 * struct componentname *a_cnp)
1402 msdosfs_rmdir(struct vop_old_rmdir_args *ap)
1404 struct vnode *vp = ap->a_vp;
1405 struct vnode *dvp = ap->a_dvp;
1406 struct denode *ip, *dp;
1413 * Verify the directory is empty (and valid).
1414 * (Rmdir ".." won't be valid since
1415 * ".." will contain a reference to
1416 * the current directory and thus be
1420 if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
1425 * Delete the entry from the directory. For dos filesystems this
1426 * gets rid of the directory entry on disk, the in memory copy
1427 * still exists but the de_refcnt is <= 0. This prevents it from
1428 * being found by deget(). When the vput() on dep is done we give
1429 * up access and eventually msdosfs_reclaim() will be called which
1430 * will remove it from the denode cache.
1432 error = removede(dp, ip);
1436 * This is where we decrement the link count in the parent
1437 * directory. Since dos filesystems don't do this we just purge
1442 * Truncate the directory that is being deleted.
1444 error = detrunc(ip, (u_long)0, IO_SYNC);
1446 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1452 * DOS filesystems don't know what symlinks are.
1454 * msdosfs_symlink(struct vnode *a_dvp, struct vnode **a_vpp,
1455 * struct componentname *a_cnp, struct vattr *a_vap,
1459 msdosfs_symlink(struct vop_old_symlink_args *ap)
1461 return (EOPNOTSUPP);
1465 * msdosfs_readdir(struct vnode *a_vp, struct uio *a_uio,
1466 * struct ucred *a_cred, int *a_eofflag, int *a_ncookies,
1467 * off_t **a_cookies)
1470 msdosfs_readdir(struct vop_readdir_args *ap)
1484 struct msdosfsmount *pmp;
1485 struct direntry *dentp;
1486 struct uio *uio = ap->a_uio;
1487 off_t *cookies = NULL;
1494 char *d_name_storage = NULL;
1495 char *d_name = NULL;
1497 error = vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY | LK_FAILRECLAIM);
1501 dep = VTODE(ap->a_vp);
1504 #ifdef MSDOSFS_DEBUG
1505 kprintf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
1506 ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
1510 * msdosfs_readdir() won't operate properly on regular files since
1511 * it does i/o only with the the filesystem vnode, and hence can
1512 * retrieve the wrong block from the buffer cache for a plain file.
1513 * So, fail attempts to readdir() on a plain file.
1515 if ((dep->de_Attributes & ATTR_DIRECTORY) == 0) {
1521 * If the user buffer is smaller than the size of one dos directory
1522 * entry or the file offset is not a multiple of the size of a
1523 * directory entry, then we fail the read.
1525 off = offset = uio->uio_offset;
1526 if (uio->uio_resid < sizeof(struct direntry) ||
1527 (offset & (sizeof(struct direntry) - 1))) {
1532 if (ap->a_ncookies) {
1533 ncookies = uio->uio_resid / 16 + 1;
1534 if (ncookies > 1024)
1536 cookies = kmalloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK);
1537 *ap->a_cookies = cookies;
1538 *ap->a_ncookies = ncookies;
1541 dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
1544 * If they are reading from the root directory then, we simulate
1545 * the . and .. entries since these don't exist in the root
1546 * directory. We also set the offset bias to make up for having to
1547 * simulate these entries. By this I mean that at file offset 64 we
1548 * read the first entry in the root directory that lives on disk.
1550 if (dep->de_StartCluster == MSDOSFSROOT
1551 || (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
1552 bias = 2 * sizeof(struct direntry);
1553 if (offset < bias) {
1554 for (n = (int)offset / sizeof(struct direntry); n < 2;
1557 d_ino = xcntobn(pmp, pmp->pm_rootdirblk)
1565 } else if (n == 1) {
1569 if (vop_write_dirent(&error, uio, d_ino, d_type,
1574 offset += sizeof(struct direntry);
1577 *cookies++ = offset;
1578 if (--ncookies <= 0)
1585 d_name_storage = kmalloc(WIN_MAXLEN, M_TEMP, M_WAITOK);
1589 while (uio->uio_resid > 0) {
1590 lbn = de_off2cn(pmp, offset - bias);
1591 on = (offset - bias) & pmp->pm_crbomask;
1592 n = szmin(pmp->pm_bpcluster - on, uio->uio_resid);
1593 diff = dep->de_FileSize - (offset - bias);
1597 error = pcbmap(dep, lbn, &bn, &cn, &blsize);
1600 error = bread(pmp->pm_devvp, de_bntodoff(pmp, bn), blsize, &bp);
1603 kfree(d_name_storage, M_TEMP);
1606 n = min(n, blsize - bp->b_resid);
1609 * Convert from dos directory entries to fs-independent
1610 * directory entries.
1612 for (dentp = (struct direntry *)(bp->b_data + on);
1613 (char *)dentp < bp->b_data + on + n;
1614 dentp++, offset += sizeof(struct direntry)) {
1615 d_name = d_name_storage;
1618 * If this is an unused entry, we can stop.
1620 if (dentp->deName[0] == SLOT_EMPTY) {
1625 * Skip deleted entries.
1627 if (dentp->deName[0] == SLOT_DELETED) {
1633 * Handle Win95 long directory entries
1635 if (dentp->deAttributes == ATTR_WIN95) {
1636 if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
1638 chksum = win2unixfn(&nb,
1639 (struct winentry *)dentp,
1646 * Skip volume labels
1648 if (dentp->deAttributes & ATTR_VOLUME) {
1654 * This computation of d_ino must match
1655 * the computation of va_fileid in
1658 if (dentp->deAttributes & ATTR_DIRECTORY) {
1659 d_ino = getushort(dentp->deStartCluster);
1661 d_ino |= getushort(dentp->deHighClust) << 16;
1662 /* if this is the root directory */
1663 if (d_ino != MSDOSFSROOT)
1664 d_ino = xcntobn(pmp, d_ino) * dirsperblk;
1665 else if (FAT32(pmp))
1666 d_ino = xcntobn(pmp, pmp->pm_rootdirblk)
1672 d_ino = offset / sizeof(struct direntry);
1675 if (chksum != winChksum(dentp->deName)) {
1676 d_namlen = dos2unixfn(dentp->deName,
1678 dentp->deLowerCase |
1679 ((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
1680 (LCASE_BASE | LCASE_EXT) : 0),
1684 mbnambuf_flush(&nb, d_name, &d_namlen);
1687 if (vop_write_dirent(&error, uio, d_ino, d_type,
1688 d_namlen, d_name)) {
1698 *cookies++ = offset + sizeof(struct direntry);
1699 if (--ncookies <= 0) {
1704 off = offset + sizeof(struct direntry);
1709 if (d_name_storage != NULL)
1710 kfree(d_name_storage, M_TEMP);
1712 /* Subtract unused cookies */
1714 *ap->a_ncookies -= ncookies;
1716 uio->uio_offset = off;
1719 * Set the eofflag (NFS uses it)
1721 if (ap->a_eofflag) {
1722 if (dep->de_FileSize - (offset - bias) <= 0)
1728 vn_unlock(ap->a_vp);
1733 * vp - address of vnode file the file
1734 * bn - which cluster we are interested in mapping to a filesystem block number.
1735 * vpp - returns the vnode for the block special file holding the filesystem
1736 * containing the file of interest
1737 * bnp - address of where to return the filesystem relative block number
1739 * msdosfs_bmap(struct vnode *a_vp, off_t a_loffset,
1740 * off_t *a_doffsetp, int *a_runp, int *a_runb)
1743 msdosfs_bmap(struct vop_bmap_args *ap)
1745 struct denode *dep = VTODE(ap->a_vp);
1746 struct msdosfsmount *pmp = dep->de_pmp;
1751 if (ap->a_doffsetp == NULL)
1755 * Sequential clusters should be counted here.
1762 KKASSERT(((int)ap->a_loffset & ((1 << pmp->pm_cnshift) - 1)) == 0);
1763 lbn = de_off2cn(pmp, ap->a_loffset);
1764 error = pcbmap(dep, lbn, &dbn, NULL, NULL);
1765 if (error || dbn == (daddr_t)-1) {
1766 *ap->a_doffsetp = NOOFFSET;
1768 *ap->a_doffsetp = de_bntodoff(pmp, dbn);
1774 * msdosfs_strategy(struct vnode *a_vp, struct bio *a_bio)
1777 msdosfs_strategy(struct vop_strategy_args *ap)
1779 struct bio *bio = ap->a_bio;
1781 struct buf *bp = bio->bio_buf;
1782 struct vnode *vp = ap->a_vp;
1783 struct denode *dep = VTODE(vp);
1784 struct msdosfsmount *pmp = dep->de_pmp;
1788 if (vp->v_type == VBLK || vp->v_type == VCHR)
1789 panic("msdosfs_strategy: spec");
1791 * If we don't already know the filesystem relative block number
1792 * then get it using pcbmap(). If pcbmap() returns the block
1793 * number as -1 then we've got a hole in the file. DOS filesystems
1794 * don't allow files with holes, so we shouldn't ever see this.
1796 nbio = push_bio(bio);
1797 if (nbio->bio_offset == NOOFFSET) {
1798 error = pcbmap(dep, de_off2cn(pmp, bio->bio_offset),
1799 &dblkno, NULL, NULL);
1801 bp->b_error = error;
1802 bp->b_flags |= B_ERROR;
1803 /* I/O was never started on nbio, must biodone(bio) */
1807 if (dblkno == (daddr_t)-1) {
1808 nbio->bio_offset = NOOFFSET;
1811 nbio->bio_offset = de_bntodoff(pmp, dblkno);
1814 if (nbio->bio_offset == NOOFFSET) {
1815 /* I/O was never started on nbio, must biodone(bio) */
1820 * Read/write the block from/to the disk that contains the desired
1823 vn_strategy(dep->de_devvp, nbio);
1828 * msdosfs_print(struct vnode *vp)
1831 msdosfs_print(struct vop_print_args *ap)
1833 struct denode *dep = VTODE(ap->a_vp);
1836 "tag VT_MSDOSFS, startcluster %lu, dircluster %lu, diroffset %lu ",
1837 dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
1838 kprintf(" dev %d, %d", major(dep->de_dev), minor(dep->de_dev));
1839 lockmgr_printinfo(&ap->a_vp->v_lock);
1845 * msdosfs_pathconf(struct vnode *a_vp, int a_name, int *a_retval)
1848 msdosfs_pathconf(struct vop_pathconf_args *ap)
1850 struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
1852 switch (ap->a_name) {
1853 case _PC_CHOWN_RESTRICTED:
1856 case _PC_FILESIZEBITS:
1857 *ap->a_retval = FAT12(pmp) ? 32 : 33;
1864 pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
1870 *ap->a_retval = PATH_MAX;
1878 /* Global vfs data structures for msdosfs */
1879 struct vop_ops msdosfs_vnode_vops = {
1880 .vop_default = vop_defaultop,
1881 .vop_access = msdosfs_access,
1882 .vop_bmap = msdosfs_bmap,
1883 .vop_old_lookup = msdosfs_lookup,
1884 .vop_open = msdosfs_open,
1885 .vop_close = msdosfs_close,
1886 .vop_old_create = msdosfs_create,
1887 .vop_fsync = msdosfs_fsync,
1888 .vop_getattr = msdosfs_getattr,
1889 .vop_inactive = msdosfs_inactive,
1890 .vop_old_link = msdosfs_link,
1891 .vop_old_mkdir = msdosfs_mkdir,
1892 .vop_old_mknod = msdosfs_mknod,
1893 .vop_pathconf = msdosfs_pathconf,
1894 .vop_print = msdosfs_print,
1895 .vop_read = msdosfs_read,
1896 .vop_readdir = msdosfs_readdir,
1897 .vop_reclaim = msdosfs_reclaim,
1898 .vop_old_remove = msdosfs_remove,
1899 .vop_old_rename = msdosfs_rename,
1900 .vop_old_rmdir = msdosfs_rmdir,
1901 .vop_setattr = msdosfs_setattr,
1902 .vop_strategy = msdosfs_strategy,
1903 .vop_old_symlink = msdosfs_symlink,
1904 .vop_write = msdosfs_write,
1905 .vop_getpages = vop_stdgetpages,
1906 .vop_putpages = vop_stdputpages