Lines Matching defs:pmp

63 static int	chainalloc(struct msdosfsmount *pmp, u_long start,
66 static int chainlength(struct msdosfsmount *pmp, u_long start,
68 static void fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp,
70 static int fatchain(struct msdosfsmount *pmp, u_long start, u_long count,
74 static void updatefats(struct msdosfsmount *pmp, struct buf *bp,
77 usemap_alloc(struct msdosfsmount *pmp, u_long cn);
79 usemap_free(struct msdosfsmount *pmp, u_long cn);
80 static int clusteralloc1(struct msdosfsmount *pmp, u_long start,
85 fatblock(pmp, ofs, bnp, sizep, bop)
86 struct msdosfsmount *pmp;
94 bn = ofs / pmp->pm_fatblocksize * pmp->pm_fatblocksec;
95 size = min(pmp->pm_fatblocksec, pmp->pm_FATsecs - bn)
97 bn += pmp->pm_fatblk + pmp->pm_curfat * pmp->pm_FATsecs;
104 *bop = ofs % pmp->pm_fatblocksize;
142 struct msdosfsmount *pmp = dep->de_pmp;
158 if (de_cn2off(pmp, findcn) >= dep->de_FileSize) {
160 *cnp = de_bn2cn(pmp, pmp->pm_rootdirsize);
164 *bnp = pmp->pm_rootdirblk + de_cn2bn(pmp, findcn);
168 *sp = min(pmp->pm_bpcluster,
169 dep->de_FileSize - de_cn2off(pmp, findcn));
182 *sp = pmp->pm_bpcluster;
199 if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
201 byteoffset = FATOFS(pmp, cn);
202 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
206 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);
314 * pmp - msdosfsmount structure for filesystem to update
319 updatefats(pmp, bp, fatbn)
320 struct msdosfsmount *pmp;
328 printf("updatefats(pmp %p, bp %p, fatbn %lu)\n", pmp, bp, fatbn);
331 if (pmp->pm_flags & MSDOSFS_FATMIRROR) {
342 if (fatbn != pmp->pm_fatblk || FAT12(pmp))
344 else if (FAT16(pmp))
348 for (i = 1; i < pmp->pm_FATs; i++) {
349 fatbn += pmp->pm_FATsecs;
351 bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount,
359 if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS)
369 if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS)
395 usemap_alloc(pmp, cn)
396 struct msdosfsmount *pmp;
400 MSDOSFS_ASSERT_MP_LOCKED(pmp);
402 KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS)))
404 (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS]));
405 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1 << (cn % N_INUSEBITS);
406 KASSERT(pmp->pm_freeclustercount > 0, ("usemap_alloc: too little"));
407 pmp->pm_freeclustercount--;
408 pmp->pm_flags |= MSDOSFS_FSIMOD;
412 usemap_free(pmp, cn)
413 struct msdosfsmount *pmp;
417 MSDOSFS_ASSERT_MP_LOCKED(pmp);
418 pmp->pm_freeclustercount++;
419 pmp->pm_flags |= MSDOSFS_FSIMOD;
420 KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS)))
422 (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS]));
423 pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1 << (cn % N_INUSEBITS));
427 clusterfree(pmp, cluster, oldcnp)
428 struct msdosfsmount *pmp;
435 error = fatentry(FAT_GET_AND_SET, pmp, cluster, &oldcn, MSDOSFSFREE);
443 MSDOSFS_LOCK_MP(pmp);
444 usemap_free(pmp, cluster);
445 MSDOSFS_UNLOCK_MP(pmp);
455 * pmp - address of the msdosfsmount structure for the filesystem
471 fatentry(function, pmp, cn, oldcontents, newcontents)
473 struct msdosfsmount *pmp;
484 printf("fatentry(func %d, pmp %p, clust %lu, oldcon %p, newcon %lx)\n",
485 function, pmp, cn, oldcontents, newcontents);
514 if (cn < CLUST_FIRST || cn > pmp->pm_maxcluster)
517 byteoffset = FATOFS(pmp, cn);
518 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
519 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
526 if (FAT32(pmp))
530 if (FAT12(pmp) & (cn & 1))
532 readcn &= pmp->pm_fatmask;
534 if ((readcn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
535 readcn |= ~pmp->pm_fatmask;
539 switch (pmp->pm_fatmask) {
565 updatefats(pmp, bp, bn);
567 pmp->pm_fmod = 1;
577 * pmp - mount point
583 fatchain(pmp, start, count, fillwith)
584 struct msdosfsmount *pmp;
594 printf("fatchain(pmp %p, start %lu, count %lu, fillwith %lx)\n",
595 pmp, start, count, fillwith);
600 if (start < CLUST_FIRST || start + count - 1 > pmp->pm_maxcluster)
604 byteoffset = FATOFS(pmp, start);
605 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
606 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
614 switch (pmp->pm_fatmask) {
635 readcn &= ~pmp->pm_fatmask;
636 readcn |= newc & pmp->pm_fatmask;
644 updatefats(pmp, bp, bn);
646 pmp->pm_fmod = 1;
653 * pmp - mount point
658 chainlength(pmp, start, count)
659 struct msdosfsmount *pmp;
667 MSDOSFS_ASSERT_MP_LOCKED(pmp);
669 max_idx = pmp->pm_maxcluster / N_INUSEBITS;
672 map = pmp->pm_inusemap[idx];
684 map = pmp->pm_inusemap[idx];
697 * pmp - mount point.
706 chainalloc(pmp, start, count, fillwith, retcluster, got)
707 struct msdosfsmount *pmp;
717 MSDOSFS_ASSERT_MP_LOCKED(pmp);
720 usemap_alloc(pmp, cl++);
721 pmp->pm_nxtfree = start + count;
722 if (pmp->pm_nxtfree > pmp->pm_maxcluster)
723 pmp->pm_nxtfree = CLUST_FIRST;
724 pmp->pm_flags |= MSDOSFS_FSIMOD;
725 error = fatchain(pmp, start, count, fillwith);
742 * pmp - mount point.
751 clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count,
756 MSDOSFS_LOCK_MP(pmp);
757 error = clusteralloc1(pmp, start, count, fillwith, retcluster, got);
758 MSDOSFS_UNLOCK_MP(pmp);
763 clusteralloc1(struct msdosfsmount *pmp, u_long start, u_long count,
771 MSDOSFS_ASSERT_MP_LOCKED(pmp);
777 if ((len = chainlength(pmp, start, count)) >= count)
778 return (chainalloc(pmp, start, count, fillwith, retcluster, got));
782 newst = pmp->pm_nxtfree;
785 for (cn = newst; cn <= pmp->pm_maxcluster;) {
787 map = pmp->pm_inusemap[idx];
791 if ((l = chainlength(pmp, cn, count)) >= count)
792 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
804 map = pmp->pm_inusemap[idx];
808 if ((l = chainlength(pmp, cn, count)) >= count)
809 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
824 return (chainalloc(pmp, start, len, fillwith, retcluster, got));
826 return (chainalloc(pmp, foundcn, foundl, fillwith, retcluster, got));
833 * pmp - address of the msdosfs mount structure for the filesystem
839 freeclusterchain(pmp, cluster)
840 struct msdosfsmount *pmp;
848 MSDOSFS_LOCK_MP(pmp);
849 while (cluster >= CLUST_FIRST && cluster <= pmp->pm_maxcluster) {
850 byteoffset = FATOFS(pmp, cluster);
851 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
854 updatefats(pmp, bp, lbn);
855 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
858 MSDOSFS_UNLOCK_MP(pmp);
863 usemap_free(pmp, cluster);
864 switch (pmp->pm_fatmask) {
888 cluster &= pmp->pm_fatmask;
889 if ((cluster | ~pmp->pm_fatmask) >= CLUST_RSRVD)
890 cluster |= pmp->pm_fatmask;
893 updatefats(pmp, bp, bn);
894 MSDOSFS_UNLOCK_MP(pmp);
903 fillinusemap(pmp)
904 struct msdosfsmount *pmp;
911 MSDOSFS_ASSERT_MP_LOCKED(pmp);
917 for (cn = 0; cn < (pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS; cn++)
918 pmp->pm_inusemap[cn] = (u_int)-1;
925 pmp->pm_freeclustercount = 0;
926 for (cn = CLUST_FIRST; cn <= pmp->pm_maxcluster; cn++) {
927 byteoffset = FATOFS(pmp, cn);
928 bo = byteoffset % pmp->pm_fatblocksize;
933 fatblock(pmp, byteoffset, &bn, &bsize, NULL);
934 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
940 if (FAT32(pmp))
944 if (FAT12(pmp) && (cn & 1))
946 readcn &= pmp->pm_fatmask;
949 usemap_free(pmp, cn);
982 struct msdosfsmount *pmp = dep->de_pmp;
1027 error = clusteralloc(pmp, cn, count, CLUST_EOFE, &cn, &got);
1046 error = fatentry(FAT_SET, pmp,
1050 clusterfree(pmp, cn, NULL);
1068 bp = getblk(pmp->pm_devvp,
1069 cntobn(pmp, cn++),
1070 pmp->pm_bpcluster, 0, 0, 0);
1074 pmp->pm_bpcluster, 0, 0, 0);
1111 * pmp The MS-DOS volume to mark
1121 markvoldirty(struct msdosfsmount *pmp, int dirty)
1131 if (FAT12(pmp))
1135 if (pmp->pm_flags & MSDOSFSMNT_RONLY)
1142 byteoffset = FATOFS(pmp, 1);
1143 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
1144 error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp);
1155 if (FAT32(pmp)) {