Lines Matching defs:pmp

70 #define	SYNCHRONOUS_WRITES(pmp)	1
72 static int chainalloc(struct msdosfsmount *pmp, u_long start,
75 static int chainlength(struct msdosfsmount *pmp, u_long start,
77 static void fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp,
79 static int fatchain(struct msdosfsmount *pmp, u_long start, u_long count,
83 static void updatefats(struct msdosfsmount *pmp, struct m_buf *bp,
86 usemap_alloc(struct msdosfsmount *pmp, u_long cn);
88 usemap_free(struct msdosfsmount *pmp, u_long cn);
89 static int clusteralloc1(struct msdosfsmount *pmp, u_long start,
94 fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, u_long *sizep,
99 bn = ofs / pmp->pm_fatblocksize * pmp->pm_fatblocksec;
100 size = MIN(pmp->pm_fatblocksec, pmp->pm_FATsecs - bn)
102 bn += pmp->pm_fatblk + pmp->pm_curfat * pmp->pm_FATsecs;
109 *bop = ofs % pmp->pm_fatblocksize;
143 struct msdosfsmount *pmp = dep->de_pmp;
157 if (de_cn2off(pmp, findcn) >= dep->de_FileSize) {
159 *cnp = de_bn2cn(pmp, pmp->pm_rootdirsize);
163 *bnp = pmp->pm_rootdirblk + de_cn2bn(pmp, findcn);
167 *sp = MIN(pmp->pm_bpcluster,
168 dep->de_FileSize - de_cn2off(pmp, findcn));
181 *sp = pmp->pm_bpcluster;
198 if ((cn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
200 byteoffset = FATOFS(pmp, cn);
201 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
205 error = bread((void *)pmp->pm_devvp, bn, bsize,
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);
304 * pmp - msdosfsmount structure for filesystem to update
309 updatefats(struct msdosfsmount *pmp, struct m_buf *bp, u_long fatbn)
315 printf("updatefats(pmp %p, bp %p, fatbn %lu)\n", pmp, bp, fatbn);
318 if (pmp->pm_flags & MSDOSFS_FATMIRROR) {
329 if (fatbn != pmp->pm_fatblk || FAT12(pmp))
331 else if (FAT16(pmp))
335 for (i = 1; i < pmp->pm_FATs; i++) {
336 fatbn += pmp->pm_FATsecs;
338 bpn = getblk((void *)pmp->pm_devvp, fatbn,
346 if (SYNCHRONOUS_WRITES(pmp))
356 if (SYNCHRONOUS_WRITES(pmp))
382 usemap_alloc(struct msdosfsmount *pmp, u_long cn)
385 assert(cn <= pmp->pm_maxcluster);
386 assert((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0);
387 assert((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS)))
389 assert(pmp->pm_freeclustercount > 0);
391 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS);
392 pmp->pm_freeclustercount--;
393 pmp->pm_flags |= MSDOSFS_FSIMOD;
397 usemap_free(struct msdosfsmount *pmp, u_long cn)
400 assert(cn <= pmp->pm_maxcluster);
401 assert((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0);
402 assert((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS)))
405 pmp->pm_freeclustercount++;
406 pmp->pm_flags |= MSDOSFS_FSIMOD;
407 pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS));
411 clusterfree(struct msdosfsmount *pmp, u_long cluster)
416 error = fatentry(FAT_GET_AND_SET, pmp, cluster, &oldcn, MSDOSFSFREE);
424 usemap_free(pmp, cluster);
431 * pmp - address of the msdosfsmount structure for the filesystem
447 fatentry(int function, struct msdosfsmount *pmp, u_long cn, u_long *oldcontents,
456 printf("fatentry(func %d, pmp %p, clust %lu, oldcon %p, newcon %lx)\n",
457 function, pmp, cn, oldcontents, newcontents);
486 if (cn < CLUST_FIRST || cn > pmp->pm_maxcluster)
489 byteoffset = FATOFS(pmp, cn);
490 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
491 error = bread((void *)pmp->pm_devvp, bn, bsize, NOCRED, &bp);
498 if (FAT32(pmp))
502 if (FAT12(pmp) & (cn & 1))
504 readcn &= pmp->pm_fatmask;
506 if ((readcn | ~pmp->pm_fatmask) >= CLUST_RSRVD)
507 readcn |= ~pmp->pm_fatmask;
511 switch (pmp->pm_fatmask) {
537 updatefats(pmp, bp, bn);
539 pmp->pm_fmod = 1;
549 * pmp - mount point
555 fatchain(struct msdosfsmount *pmp, u_long start, u_long count, u_long fillwith)
562 printf("fatchain(pmp %p, start %lu, count %lu, fillwith %lx)\n",
563 pmp, start, count, fillwith);
568 if (start < CLUST_FIRST || start + count - 1 > pmp->pm_maxcluster)
572 byteoffset = FATOFS(pmp, start);
573 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
574 error = bread((void *)pmp->pm_devvp, bn, bsize, NOCRED, &bp);
582 switch (pmp->pm_fatmask) {
603 readcn &= ~pmp->pm_fatmask;
604 readcn |= newc & pmp->pm_fatmask;
612 updatefats(pmp, bp, bn);
614 pmp->pm_fmod = 1;
621 * pmp - mount point
626 chainlength(struct msdosfsmount *pmp, u_long start, u_long count)
632 if (start > pmp->pm_maxcluster)
634 max_idx = pmp->pm_maxcluster / N_INUSEBITS;
637 map = pmp->pm_inusemap[idx];
642 if (start + len > pmp->pm_maxcluster)
643 len = pmp->pm_maxcluster - start + 1;
649 if (start + len > pmp->pm_maxcluster)
650 len = pmp->pm_maxcluster - start + 1;
656 map = pmp->pm_inusemap[idx];
664 if (start + len > pmp->pm_maxcluster)
665 len = pmp->pm_maxcluster - start + 1;
672 * pmp - mount point.
681 chainalloc(struct msdosfsmount *pmp, u_long start, u_long count,
687 assert((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0);
690 usemap_alloc(pmp, cl++);
691 pmp->pm_nxtfree = start + count;
692 if (pmp->pm_nxtfree > pmp->pm_maxcluster)
693 pmp->pm_nxtfree = CLUST_FIRST;
694 pmp->pm_flags |= MSDOSFS_FSIMOD;
695 error = fatchain(pmp, start, count, fillwith);
698 usemap_free(pmp, cl++);
715 * pmp - mount point.
724 clusteralloc(struct msdosfsmount *pmp, u_long start, u_long count,
729 error = clusteralloc1(pmp, start, count, fillwith, retcluster, got);
734 clusteralloc1(struct msdosfsmount *pmp, u_long start, u_long count,
745 if ((len = chainlength(pmp, start, count)) >= count)
746 return (chainalloc(pmp, start, count, fillwith, retcluster, got));
750 newst = pmp->pm_nxtfree;
753 for (cn = newst; cn <= pmp->pm_maxcluster;) {
755 map = pmp->pm_inusemap[idx];
759 if ((l = chainlength(pmp, cn, count)) >= count)
760 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
772 map = pmp->pm_inusemap[idx];
776 if ((l = chainlength(pmp, cn, count)) >= count)
777 return (chainalloc(pmp, cn, count, fillwith, retcluster, got));
792 return (chainalloc(pmp, start, len, fillwith, retcluster, got));
794 return (chainalloc(pmp, foundcn, foundl, fillwith, retcluster, got));
801 * pmp - address of the msdosfs mount structure for the filesystem
807 freeclusterchain(struct msdosfsmount *pmp, u_long cluster)
814 while (cluster >= CLUST_FIRST && cluster <= pmp->pm_maxcluster) {
815 byteoffset = FATOFS(pmp, cluster);
816 fatblock(pmp, byteoffset, &bn, &bsize, &bo);
819 updatefats(pmp, bp, lbn);
820 error = bread((void *)pmp->pm_devvp, bn, bsize,
828 usemap_free(pmp, cluster);
829 switch (pmp->pm_fatmask) {
853 cluster &= pmp->pm_fatmask;
854 if ((cluster | ~pmp->pm_fatmask) >= CLUST_RSRVD)
855 cluster |= pmp->pm_fatmask;
858 updatefats(pmp, bp, bn);
867 fillinusemap(struct msdosfsmount *pmp)
879 for (cn = 0; cn < (pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS; cn++)
880 pmp->pm_inusemap[cn] = FULL_RUN;
887 pmp->pm_freeclustercount = 0;
888 for (cn = 0; cn <= pmp->pm_maxcluster; cn++) {
889 byteoffset = FATOFS(pmp, cn);
890 bo = byteoffset % pmp->pm_fatblocksize;
895 fatblock(pmp, byteoffset, &bn, &bsize, NULL);
896 error = bread((void *)pmp->pm_devvp, bn, bsize,
901 if (FAT32(pmp))
905 if (FAT12(pmp) && (cn & 1))
907 readcn &= pmp->pm_fatmask;
913 if (cn == 0 && readcn != ((pmp->pm_fatmask & 0xffffff00) |
914 pmp->pm_bpb.bpbMedia)) {
922 usemap_free(pmp, cn);
927 for (cn = pmp->pm_maxcluster + 1; cn < (pmp->pm_maxcluster +
929 pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS);
956 struct msdosfsmount *pmp = dep->de_pmp;
1000 error = clusteralloc(pmp, cn, count, CLUST_EOFE, &cn, &got);
1019 error = fatentry(FAT_SET, pmp,
1023 clusterfree(pmp, cn);
1038 bp = getblk((void *)pmp->pm_devvp,
1039 cntobn(pmp, cn++),
1040 pmp->pm_bpcluster, 0, 0, 0);