Lines Matching defs:pmp
142 fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, u_long *sizep, u_long *bop)
146 bn = ofs / pmp->pm_fatblocksize * pmp->pm_fatblocksec;
147 size = uimin(pmp->pm_fatblocksec, pmp->pm_FATsecs - bn)
148 * pmp->pm_BytesPerSec;
149 bn += pmp->pm_fatblk + pmp->pm_curfat * pmp->pm_FATsecs;
152 size, ofs % pmp->pm_fatblocksize));
158 *bop = ofs % pmp->pm_fatblocksize;
160 pm_fatblocksize = pmp->pm_fatblocksize;
197 struct msdosfsmount *pmp = dep->de_pmp;
219 if (de_cn2off(pmp, findcn) >= dep->de_FileSize) {
221 *cnp = de_bn2cn(pmp, pmp->pm_rootdirsize);
223 de_cn2off(pmp, findcn)));
227 *bnp = pmp->pm_rootdirblk + de_cn2bn(pmp, findcn);
231 *sp = uimin(pmp->pm_bpcluster,
232 dep->de_FileSize - de_cn2off(pmp, findcn));
234 pmp->pm_rootdirblk + de_cn2bn(pmp, findcn),
249 *sp = pmp->pm_bpcluster;
258 DPRINTF(("%s(bpcluster=%lu i=%lu cn=%lu\n", __func__, pmp->pm_bpcluster,
275 if (cn >= (CLUST_RSRVD & pmp->pm_fatmask))
281 if (cn < CLUST_FIRST || cn > pmp->pm_maxcluster) {
283 cn, (u_long)CLUST_FIRST, pmp->pm_maxcluster));
289 byteoffset = FATOFS(pmp, cn);
290 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
294 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), bsize,
311 if (FAT32(pmp))
315 if (FAT12(pmp) && (prevcn & 1))
318 cn & pmp->pm_fatmask));
319 cn &= pmp->pm_fatmask;
322 if (!MSDOSFSEOF(cn, pmp->pm_fatmask)) {
326 *bnp = cntobn(pmp, cn);
329 DPRINTF(("%s(bn=%lu, cn=%lu)\n", __func__, cntobn(pmp, cn),
393 * pmp - msdosfsmount structure for filesystem to update
398 updatefats(struct msdosfsmount *pmp, struct buf *bp, u_long fatbn)
403 DPRINTF(("%s(pmp %p, bp %p, fatbn %lu)\n", __func__, pmp, bp, fatbn));
408 if (pmp->pm_fsinfo) {
409 u_long cn = pmp->pm_nxtfree;
411 if (pmp->pm_freeclustercount
412 && (pmp->pm_inusemap[cn / N_INUSEBITS]
418 for (cn = 0; cn < pmp->pm_maxcluster; cn++)
419 if (pmp->pm_inusemap[cn / N_INUSEBITS] != (u_int)-1)
421 pmp->pm_nxtfree = cn
422 + ffs(pmp->pm_inusemap[cn / N_INUSEBITS]
430 if (bread(pmp->pm_devvp, de_bn2kb(pmp, pmp->pm_fsinfo),
431 pmp->pm_BytesPerSec, B_MODIFY, &bpn) != 0) {
435 pmp->pm_fsinfo = 0;
439 putulong(fp->fsinfree, pmp->pm_freeclustercount);
440 putulong(fp->fsinxtfree, pmp->pm_nxtfree);
441 if (pmp->pm_flags & MSDOSFSMNT_WAITONFAT)
448 if (pmp->pm_flags & MSDOSFS_FATMIRROR) {
459 for (i = 1; i < pmp->pm_FATs; i++) {
460 fatbn += pmp->pm_FATsecs;
462 bpn = getblk(pmp->pm_devvp, de_bn2kb(pmp, fatbn),
465 if (pmp->pm_flags & MSDOSFSMNT_WAITONFAT) {
478 if (pmp->pm_flags & MSDOSFSMNT_WAITONFAT) {
510 usemap_alloc(struct msdosfsmount *pmp, u_long cn)
513 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS);
514 pmp->pm_freeclustercount--;
518 usemap_free(struct msdosfsmount *pmp, u_long cn)
521 pmp->pm_freeclustercount++;
522 pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS));
526 msdosfs_clusterfree(struct msdosfsmount *pmp, u_long cluster, u_long *oldcnp)
531 usemap_free(pmp, cluster);
532 error = msdosfs_fatentry(FAT_GET_AND_SET, pmp, cluster, &oldcn,
535 usemap_alloc(pmp, cluster);
552 * pmp - address of the msdosfsmount structure for the filesystem
568 msdosfs_fatentry(int function, struct msdosfsmount *pmp, u_long cn,
576 DPRINTF(("%s(func %d, pmp %p, clust %lu, oldcon %p, newcon " "%lx)\n",
577 __func__, function, pmp, cn, oldcontents, newcontents));
603 if (cn < CLUST_FIRST || cn > pmp->pm_maxcluster)
606 byteoffset = FATOFS(pmp, cn);
607 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
608 if ((error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), bsize,
614 if (FAT32(pmp))
618 if (FAT12(pmp) & (cn & 1))
620 readcn &= pmp->pm_fatmask;
624 switch (pmp->pm_fatmask) {
650 updatefats(pmp, bp, bn);
652 pmp->pm_fmod = 1;
662 * pmp - mount point
668 fatchain(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith)
674 DPRINTF(("%s(pmp %p, start %lu, count %lu, fillwith %lx)\n", __func__,
675 pmp, start, count, fillwith));
679 if (start < CLUST_FIRST || start + count - 1 > pmp->pm_maxcluster)
683 byteoffset = FATOFS(pmp, start);
684 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
685 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), bsize,
693 switch (pmp->pm_fatmask) {
714 readcn &= ~pmp->pm_fatmask;
715 readcn |= newc & pmp->pm_fatmask;
723 updatefats(pmp, bp, bn);
725 pmp->pm_fmod = 1;
732 * pmp - mount point
737 chainlength(struct msdosfsmount *pmp, u_long start, u_long count)
743 max_idx = pmp->pm_maxcluster / N_INUSEBITS;
746 map = pmp->pm_inusemap[idx];
758 if ((map = pmp->pm_inusemap[idx]) != 0) {
770 * pmp - mount point.
779 chainalloc(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith, u_long *retcluster, u_long *got)
785 usemap_alloc(pmp, cl++);
786 if ((error = fatchain(pmp, start, count, fillwith)) != 0)
801 * pmp - mount point.
810 msdosfs_clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count,
821 if ((len = chainlength(pmp, start, count)) >= count)
822 return (chainalloc(pmp, start, count, fillwith, retcluster, got));
838 newst = (start * 1103515245 + 12345) % (pmp->pm_maxcluster + 1);
841 for (cn = newst; cn <= pmp->pm_maxcluster;) {
843 map = pmp->pm_inusemap[idx];
847 if ((l = chainlength(pmp, cn, count)) >= count)
848 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
860 map = pmp->pm_inusemap[idx];
864 if ((l = chainlength(pmp, cn, count)) >= count)
865 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
880 return (chainalloc(pmp, start, len, fillwith, retcluster, got));
882 return (chainalloc(pmp, foundcn, foundl, fillwith, retcluster, got));
889 * pmp - address of the msdosfs mount structure for the filesystem
895 msdosfs_freeclusterchain(struct msdosfsmount *pmp, u_long cluster)
903 while (cluster >= CLUST_FIRST && cluster <= pmp->pm_maxcluster) {
904 byteoffset = FATOFS(pmp, cluster);
905 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
908 updatefats(pmp, bp, lbn);
909 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), bsize,
916 usemap_free(pmp, cluster);
918 switch (pmp->pm_fatmask) {
942 cluster &= pmp->pm_fatmask;
945 updatefats(pmp, bp, bn);
954 msdosfs_fillinusemap(struct msdosfsmount *pmp)
965 for (cn = 0; cn < (pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS; cn++)
966 pmp->pm_inusemap[cn] = (u_int)-1;
973 pmp->pm_freeclustercount = 0;
974 for (cn = CLUST_FIRST; cn <= pmp->pm_maxcluster; cn++) {
975 byteoffset = FATOFS(pmp, cn);
976 bo = byteoffset % pmp->pm_fatblocksize;
981 fatblock(pmp, byteoffset, &bn, &bsize, NULL);
982 error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), bsize,
988 if (FAT32(pmp))
992 if (FAT12(pmp) && (cn & 1))
994 readcn &= pmp->pm_fatmask;
997 usemap_free(pmp, cn);
1026 struct msdosfsmount *pmp = dep->de_pmp;
1070 error = msdosfs_clusteralloc(pmp, cn, count, &cn, &got);
1089 error = msdosfs_fatentry(FAT_SET, pmp,
1093 msdosfs_clusterfree(pmp, cn, NULL);
1108 bp = getblk(pmp->pm_devvp,
1109 de_bn2kb(pmp, cntobn(pmp, cn++)),
1110 pmp->pm_bpcluster, 0, 0);