Lines Matching defs:pmp

67 static int	chainalloc(struct msdosfsmount *pmp, u_long start,
70 static int chainlength(struct msdosfsmount *pmp, u_long start,
72 static void fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp,
74 static int fatchain(struct msdosfsmount *pmp, u_long start, u_long count,
78 static void updatefats(struct msdosfsmount *pmp, struct buf *bp,
81 usemap_alloc(struct msdosfsmount *pmp, u_long cn);
82 static int usemap_free(struct msdosfsmount *pmp, u_long cn);
83 static int clusteralloc1(struct msdosfsmount *pmp, u_long start,
88 fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, u_long *sizep,
93 fatblocksec = pmp->pm_fatblocksec;
94 if (FAT12(pmp) && fatblocksec % 3 != 0) {
99 bn = ofs / pmp->pm_fatblocksize * pmp->pm_fatblocksec;
100 size = roundup(ulmin(fatblocksec, pmp->pm_FATsecs - bn) * DEV_BSIZE,
101 pmp->pm_BlkPerSec * DEV_BSIZE);
102 bn += pmp->pm_fatblk + pmp->pm_curfat * pmp->pm_FATsecs;
109 *bop = ofs % pmp->pm_fatblocksize;
143 struct msdosfsmount *pmp = dep->de_pmp;
159 if (de_cn2off(pmp, findcn) >= dep->de_FileSize) {
161 *cnp = de_bn2cn(pmp, pmp->pm_rootdirsize);
165 *bnp = pmp->pm_rootdirblk + de_cn2bn(pmp, findcn);
169 *sp = min(pmp->pm_bpcluster,
170 dep->de_FileSize - de_cn2off(pmp, findcn));
183 *sp = pmp->pm_bpcluster;
200 if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
202 byteoffset = FATOFS(pmp, cn);
203 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
207 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
219 if (FAT32(pmp))
223 if (FAT12(pmp) && (prevcn & 1))
225 cn &= pmp->pm_fatmask;
233 if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
234 cn |= ~pmp->pm_fatmask;
237 if (!MSDOSFSEOF(pmp, cn)) {
241 *bnp = cntobn(pmp, cn);
308 * pmp - msdosfsmount structure for filesystem to update
313 updatefats(struct msdosfsmount *pmp, struct buf *bp, u_long fatbn)
319 printf("updatefats(pmp %p, bp %p, fatbn %lu)\n", pmp, bp, fatbn);
322 if (pmp->pm_flags & MSDOSFS_FATMIRROR) {
333 if (fatbn != pmp->pm_fatblk || FAT12(pmp))
335 else if (FAT16(pmp))
339 for (i = 1; i < pmp->pm_FATs; i++) {
340 fatbn += pmp->pm_FATsecs;
342 bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount,
350 if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS)
360 if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS)
386 usemap_alloc(struct msdosfsmount *pmp, u_long cn)
389 MSDOSFS_ASSERT_MP_LOCKED(pmp);
391 KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn,
392 pmp->pm_maxcluster));
393 KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0,
395 KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] &
398 (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS]));
399 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS);
400 KASSERT(pmp->pm_freeclustercount > 0, ("usemap_alloc: too little"));
401 pmp->pm_freeclustercount--;
402 pmp->pm_flags |= MSDOSFS_FSIMOD;
406 usemap_free(struct msdosfsmount *pmp, u_long cn)
409 MSDOSFS_ASSERT_MP_LOCKED(pmp);
411 KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn,
412 pmp->pm_maxcluster));
413 KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0,
415 if ((pmp->pm_inusemap[cn / N_INUSEBITS] &
418 pmp->pm_mountp->mnt_stat.f_mntonname, cn, cn % N_INUSEBITS,
419 (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS]);
420 msdosfs_integrity_error(pmp);
423 pmp->pm_freeclustercount++;
424 pmp->pm_flags |= MSDOSFS_FSIMOD;
425 pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS));
430 clusterfree(struct msdosfsmount *pmp, u_long cluster)
435 error = fatentry(FAT_GET_AND_SET, pmp, cluster, &oldcn, MSDOSFSFREE);
443 MSDOSFS_LOCK_MP(pmp);
444 error = usemap_free(pmp, cluster);
445 MSDOSFS_UNLOCK_MP(pmp);
452 * pmp - address of the msdosfsmount structure for the filesystem
468 fatentry(int function, struct msdosfsmount *pmp, u_long cn, u_long *oldcontents,
477 printf("fatentry(func %d, pmp %p, clust %lu, oldcon %p, newcon %lx)\n",
478 function, pmp, cn, oldcontents, newcontents);
507 if (cn < CLUST_FIRST || cn > pmp->pm_maxcluster)
510 byteoffset = FATOFS(pmp, cn);
511 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
512 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
518 if (FAT32(pmp))
522 if (FAT12(pmp) & (cn & 1))
524 readcn &= pmp->pm_fatmask;
526 if ((readcn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
527 readcn |= ~pmp->pm_fatmask;
531 switch (pmp->pm_fatmask) {
557 updatefats(pmp, bp, bn);
559 pmp->pm_fmod = 1;
569 * pmp - mount point
575 fatchain(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith)
582 printf("fatchain(pmp %p, start %lu, count %lu, fillwith %lx)\n",
583 pmp, start, count, fillwith);
588 if (start < CLUST_FIRST || start + count - 1 > pmp->pm_maxcluster)
592 byteoffset = FATOFS(pmp, start);
593 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
594 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
601 switch (pmp->pm_fatmask) {
622 readcn &= ~pmp->pm_fatmask;
623 readcn |= newc & pmp->pm_fatmask;
631 updatefats(pmp, bp, bn);
633 pmp->pm_fmod = 1;
640 * pmp - mount point
645 chainlength(struct msdosfsmount *pmp, u_long start, u_long count)
651 MSDOSFS_ASSERT_MP_LOCKED(pmp);
653 if (start > pmp->pm_maxcluster)
655 max_idx = pmp->pm_maxcluster / N_INUSEBITS;
658 map = pmp->pm_inusemap[idx];
663 if (start + len > pmp->pm_maxcluster)
664 len = pmp->pm_maxcluster - start + 1;
670 if (start + len > pmp->pm_maxcluster)
671 len = pmp->pm_maxcluster - start + 1;
677 map = pmp->pm_inusemap[idx];
685 if (start + len > pmp->pm_maxcluster)
686 len = pmp->pm_maxcluster - start + 1;
693 * pmp - mount point.
702 chainalloc(struct msdosfsmount *pmp, u_long start, u_long count,
708 MSDOSFS_ASSERT_MP_LOCKED(pmp);
709 KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0,
713 usemap_alloc(pmp, cl++);
714 pmp->pm_nxtfree = start + count;
715 if (pmp->pm_nxtfree > pmp->pm_maxcluster)
716 pmp->pm_nxtfree = CLUST_FIRST;
717 pmp->pm_flags |= MSDOSFS_FSIMOD;
718 error = fatchain(pmp, start, count, fillwith);
721 (void)usemap_free(pmp, cl++);
738 * pmp - mount point.
747 clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count,
752 MSDOSFS_LOCK_MP(pmp);
753 error = clusteralloc1(pmp, start, count, fillwith, retcluster, got);
754 MSDOSFS_UNLOCK_MP(pmp);
759 clusteralloc1(struct msdosfsmount *pmp, u_long start, u_long count,
767 MSDOSFS_ASSERT_MP_LOCKED(pmp);
773 if ((len = chainlength(pmp, start, count)) >= count)
774 return (chainalloc(pmp, start, count, fillwith, retcluster, got));
778 newst = pmp->pm_nxtfree;
781 for (cn = newst; cn <= pmp->pm_maxcluster;) {
783 map = pmp->pm_inusemap[idx];
787 if ((l = chainlength(pmp, cn, count)) >= count)
788 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
800 map = pmp->pm_inusemap[idx];
804 if ((l = chainlength(pmp, cn, count)) >= count)
805 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
820 return (chainalloc(pmp, start, len, fillwith, retcluster, got));
822 return (chainalloc(pmp, foundcn, foundl, fillwith, retcluster, got));
828 * pmp - address of the msdosfs mount structure for the filesystem
834 freeclusterchain(struct msdosfsmount *pmp, u_long cluster)
841 MSDOSFS_LOCK_MP(pmp);
842 while (cluster >= CLUST_FIRST && cluster <= pmp->pm_maxcluster) {
843 byteoffset = FATOFS(pmp, cluster);
844 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
847 updatefats(pmp, bp, lbn);
848 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
850 MSDOSFS_UNLOCK_MP(pmp);
855 error = usemap_free(pmp, cluster);
857 updatefats(pmp, bp, lbn);
858 MSDOSFS_UNLOCK_MP(pmp);
861 switch (pmp->pm_fatmask) {
885 cluster &= pmp->pm_fatmask;
886 if ((cluster | ~pmp->pm_fatmask) >= CLUST_RSRVD)
887 cluster |= pmp->pm_fatmask;
890 updatefats(pmp, bp, bn);
891 MSDOSFS_UNLOCK_MP(pmp);
900 fillinusemap(struct msdosfsmount *pmp)
906 MSDOSFS_ASSERT_MP_LOCKED(pmp);
913 for (cn = 0; cn < (pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS; cn++)
914 pmp->pm_inusemap[cn] = FULL_RUN;
921 pmp->pm_freeclustercount = 0;
922 for (cn = 0; cn <= pmp->pm_maxcluster; cn++) {
923 byteoffset = FATOFS(pmp, cn);
924 bo = byteoffset % pmp->pm_fatblocksize;
929 fatblock(pmp, byteoffset, &bn, &bsize, NULL);
930 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
934 if (FAT32(pmp))
938 if (FAT12(pmp) && (cn & 1))
940 readcn &= pmp->pm_fatmask;
946 if (cn == 0 && readcn != ((pmp->pm_fatmask & 0xffffff00) |
947 pmp->pm_bpb.bpbMedia)) {
955 error = usemap_free(pmp, cn);
965 for (cn = pmp->pm_maxcluster + 1; cn < (pmp->pm_maxcluster +
967 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS);
994 struct msdosfsmount *pmp = dep->de_pmp;
1039 error = clusteralloc(pmp, cn, count, CLUST_EOFE, &cn, &got);
1058 error = fatentry(FAT_SET, pmp,
1062 clusterfree(pmp, cn);
1080 bp = getblk(pmp->pm_devvp,
1081 cntobn(pmp, cn++),
1082 pmp->pm_bpcluster, 0, 0, 0);
1086 pmp->pm_bpcluster, 0, 0, 0);
1127 * pmp The MS-DOS volume to mark
1137 markvoldirty_upgrade(struct msdosfsmount *pmp, bool dirty, bool rw_upgrade)
1147 if (FAT12(pmp))
1154 if ((pmp->pm_flags & MSDOSFSMNT_RONLY) != 0 && !rw_upgrade)
1161 byteoffset = FATOFS(pmp, 1);
1162 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
1163 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
1172 if (FAT32(pmp)) {