VirtualBox

Changeset 69663 in vbox for trunk


Ignore:
Timestamp:
Nov 12, 2017 4:17:36 PM (7 years ago)
Author:
vboxsync
Message:

fatvfs: cleanups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fs/fatvfs.cpp

    r69660 r69663  
    311311    /** The FAT size. */
    312312    uint32_t                cbFat;
     313    /** The Number of clusters in the FAT. */
     314    uint32_t                cClusters;
    313315    /** Cluster allocation search hint. */
    314316    uint32_t                idxAllocHint;
     
    821823     * Allocate and initialize it all.
    822824     */
    823     PRTFSFATCLUSTERMAPCACHE pCache;
    824     pThis->pFatCache = pCache = (PRTFSFATCLUSTERMAPCACHE)RTMemAllocZ(RT_OFFSETOF(RTFSFATCLUSTERMAPCACHE, aEntries[cEntries]));
    825     if (!pCache)
     825    PRTFSFATCLUSTERMAPCACHE pFatCache;
     826    pThis->pFatCache = pFatCache = (PRTFSFATCLUSTERMAPCACHE)RTMemAllocZ(RT_OFFSETOF(RTFSFATCLUSTERMAPCACHE, aEntries[cEntries]));
     827    if (!pFatCache)
    826828        return RTErrInfoSet(pErrInfo, VERR_NO_MEMORY, "Failed to allocate FAT cache");
    827     pCache->cEntries            = cEntries;
    828     pCache->fEntryIndexMask     = fEntryIndexMask;
    829     pCache->cEntryIndexShift    = cEntryIndexShift;
    830     pCache->cbEntry             = cbEntry;
    831     pCache->fEntryOffsetMask    = fEntryOffsetMask;
    832     pCache->pVol                = pThis;
    833     pCache->cbFat               = pThis->cbFat;
     829    pFatCache->cEntries            = cEntries;
     830    pFatCache->fEntryIndexMask     = fEntryIndexMask;
     831    pFatCache->cEntryIndexShift    = cEntryIndexShift;
     832    pFatCache->cbEntry             = cbEntry;
     833    pFatCache->fEntryOffsetMask    = fEntryOffsetMask;
     834    pFatCache->pVol                = pThis;
     835    pFatCache->cbFat               = pThis->cbFat;
     836    pFatCache->cClusters           = pThis->cClusters;
    834837
    835838    unsigned i = cEntries;
    836839    while (i-- > 0)
    837840    {
    838         pCache->aEntries[i].pbData = (uint8_t *)RTMemAlloc(cbEntry);
    839         if (pCache->aEntries[i].pbData == NULL)
     841        pFatCache->aEntries[i].pbData = (uint8_t *)RTMemAlloc(cbEntry);
     842        if (pFatCache->aEntries[i].pbData == NULL)
    840843        {
    841844            for (i++; i < cEntries; i++)
    842                 RTMemFree(pCache->aEntries[i].pbData);
    843             RTMemFree(pCache);
     845                RTMemFree(pFatCache->aEntries[i].pbData);
     846            RTMemFree(pFatCache);
    844847            return RTErrInfoSetF(pErrInfo, VERR_NO_MEMORY, "Failed to allocate FAT cache entry (%#x bytes)", cbEntry);
    845848        }
    846849
    847         pCache->aEntries[i].offFat  = UINT32_MAX;
    848         pCache->aEntries[i].bmDirty = 0;
     850        pFatCache->aEntries[i].offFat  = UINT32_MAX;
     851        pFatCache->aEntries[i].bmDirty = 0;
    849852    }
    850853    Log3(("rtFsFatClusterMap_Create:       cbFat=%#RX32 cEntries=%RU32 cEntryIndexShift=%RU32 fEntryIndexMask=%#RX32\n",
    851           pCache->cbFat, pCache->cEntries, pCache->cEntryIndexShift, pCache->fEntryIndexMask));
    852     Log3(("rtFsFatClusterMap_Create:   cbEntries=%#RX32 fEntryOffsetMask=%#RX32\n", pCache->cbEntry, pCache->fEntryOffsetMask));
     854          pFatCache->cbFat, pFatCache->cEntries, pFatCache->cEntryIndexShift, pFatCache->fEntryIndexMask));
     855    Log3(("rtFsFatClusterMap_Create:   cbEntries=%#RX32 fEntryOffsetMask=%#RX32\n", pFatCache->cbEntry, pFatCache->fEntryOffsetMask));
    853856
    854857    /*
     
    859862        cbEntry = pThis->cbSector;
    860863
    861     pCache->cDirtyShift = 1;
    862     pCache->cbDirtyLine = 1;
    863     while (pCache->cbDirtyLine < cbEntry)
    864     {
    865         pCache->cDirtyShift++;
    866         pCache->cbDirtyLine <<= 1;
    867     }
    868     Assert(pCache->cEntries == 1 || pCache->cbDirtyLine == pThis->cbSector);
    869     Log3(("rtFsFatClusterMap_Create: cbDirtyLine=%#RX32 cDirtyShift=%u\n", pCache->cbDirtyLine, pCache->cDirtyShift));
     864    pFatCache->cDirtyShift = 1;
     865    pFatCache->cbDirtyLine = 1;
     866    while (pFatCache->cbDirtyLine < cbEntry)
     867    {
     868        pFatCache->cDirtyShift++;
     869        pFatCache->cbDirtyLine <<= 1;
     870    }
     871    Assert(pFatCache->cEntries == 1 || pFatCache->cbDirtyLine == pThis->cbSector);
     872    Log3(("rtFsFatClusterMap_Create: cbDirtyLine=%#RX32 cDirtyShift=%u\n", pFatCache->cbDirtyLine, pFatCache->cDirtyShift));
    870873
    871874    /*
    872875     * Fill the cache if single entry or entry size is 512.
    873876     */
    874     if (pCache->cEntries == 1 || pCache->cbEntry == 512)
    875     {
    876         memcpy(pCache->aEntries[0].pbData, pbFirst512FatBytes, RT_MIN(512, pCache->cbEntry));
    877         if (pCache->cbEntry > 512)
     877    if (pFatCache->cEntries == 1 || pFatCache->cbEntry == 512)
     878    {
     879        memcpy(pFatCache->aEntries[0].pbData, pbFirst512FatBytes, RT_MIN(512, pFatCache->cbEntry));
     880        if (pFatCache->cbEntry > 512)
    878881        {
    879882            int rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + 512,
    880                                      &pCache->aEntries[0].pbData[512], pCache->cbEntry - 512, NULL);
     883                                     &pFatCache->aEntries[0].pbData[512], pFatCache->cbEntry - 512, NULL);
    881884            if (RT_FAILURE(rc))
    882885                return RTErrInfoSet(pErrInfo, rc, "Error reading FAT into memory");
    883886        }
    884         pCache->aEntries[0].offFat  = 0;
    885         pCache->aEntries[0].bmDirty = 0;
     887        pFatCache->aEntries[0].offFat  = 0;
     888        pFatCache->aEntries[0].bmDirty = 0;
    886889    }
    887890
     
    900903static int rtFsFatClusterMap_FlushWorker(PRTFSFATVOL pThis, uint32_t const iFirstEntry, uint32_t const iLastEntry)
    901904{
    902     PRTFSFATCLUSTERMAPCACHE pCache = pThis->pFatCache;
    903 
     905    PRTFSFATCLUSTERMAPCACHE pFatCache = pThis->pFatCache;
    904906
    905907    /*
     
    918920        for (uint32_t iEntry = iFirstEntry; iEntry <= iLastEntry; iEntry++)
    919921        {
    920             uint64_t bmDirty = pCache->aEntries[iEntry].bmDirty;
     922            uint64_t bmDirty = pFatCache->aEntries[iEntry].bmDirty;
    921923            if (   bmDirty != 0
    922                 && pCache->aEntries[iEntry].offFat != UINT32_MAX)
     924                && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
    923925            {
    924926                uint32_t offEntry   = 0;
    925927                uint64_t iDirtyLine = 1;
    926                 while (offEntry < pCache->cbEntry)
     928                while (offEntry < pFatCache->cbEntry)
    927929                {
    928                     if (pCache->aEntries[iEntry].bmDirty & iDirtyLine)
     930                    if (pFatCache->aEntries[iEntry].bmDirty & iDirtyLine)
    929931                    {
    930932                        /*
    931933                         * Found dirty cache line.
    932934                         */
    933                         uint64_t offDirtyLine = pThis->aoffFats[iFatCopy] + pCache->aEntries[iEntry].offFat + offEntry;
     935                        uint64_t offDirtyLine = pThis->aoffFats[iFatCopy] + pFatCache->aEntries[iEntry].offFat + offEntry;
    934936
    935937                        /* Can we simply extend the last segment? */
     
    939941                            Assert(SgBuf.cSegs > 0);
    940942                            Assert(   (uintptr_t)aSgSegs[SgBuf.cSegs - 1].pvSeg + aSgSegs[SgBuf.cSegs - 1].cbSeg
    941                                    == (uintptr_t)&pCache->aEntries[iEntry].pbData[offEntry]);
    942                             aSgSegs[SgBuf.cSegs - 1].cbSeg += pCache->cbDirtyLine;
    943                             offEdge += pCache->cbDirtyLine;
     943                                   == (uintptr_t)&pFatCache->aEntries[iEntry].pbData[offEntry]);
     944                            aSgSegs[SgBuf.cSegs - 1].cbSeg += pFatCache->cbDirtyLine;
     945                            offEdge += pFatCache->cbDirtyLine;
    944946                        }
    945947                        else
     
    964966
    965967                            /* Append segment. */
    966                             aSgSegs[SgBuf.cSegs].cbSeg = pCache->cbDirtyLine;
    967                             aSgSegs[SgBuf.cSegs].pvSeg = &pCache->aEntries[iEntry].pbData[offEntry];
     968                            aSgSegs[SgBuf.cSegs].cbSeg = pFatCache->cbDirtyLine;
     969                            aSgSegs[SgBuf.cSegs].pvSeg = &pFatCache->aEntries[iEntry].pbData[offEntry];
    968970                            SgBuf.cSegs++;
    969                             offEdge = offDirtyLine + pCache->cbDirtyLine;
     971                            offEdge = offDirtyLine + pFatCache->cbDirtyLine;
    970972                        }
    971973
     
    975977                    }
    976978                    iDirtyLine <<= 1;
    977                     offEntry += pCache->cbDirtyLine;
     979                    offEntry += pFatCache->cbDirtyLine;
    978980                }
    979981                Assert(!bmDirty);
     
    997999    if (RT_SUCCESS(rc))
    9981000        for (uint32_t iEntry = iFirstEntry; iEntry <= iLastEntry; iEntry++)
    999             pCache->aEntries[iEntry].bmDirty = 0;
     1001            pFatCache->aEntries[iEntry].bmDirty = 0;
    10001002
    10011003    return rc;
     
    10221024 *
    10231025 * @returns IPRT status code.  On failure, we're currently kind of screwed.
    1024  * @param   pThis       The FAT volume instance.
     1026 * @param   pFatCache   The FAT cache
    10251027 * @param   iEntry      The cache entry to flush.
    10261028 */
    1027 static int rtFsFatClusterMap_FlushEntry(PRTFSFATVOL pThis, uint32_t iEntry)
    1028 {
    1029     return rtFsFatClusterMap_FlushWorker(pThis, iEntry, iEntry);
     1029static int rtFsFatClusterMap_FlushEntry(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t iEntry)
     1030{
     1031    return rtFsFatClusterMap_FlushWorker(pFatCache->pVol, iEntry, iEntry);
    10301032}
    10311033
     
    10351037 *
    10361038 * @returns IPRT status code.  On failure, we're currently kind of screwed.
    1037  * @param   pCache          The FAT cache.
    1038  * @param   pThis           The FAT volume instance.
    1039  * @param   offFat          The FAT byte offset to get the entry off.
    1040  * @param   ppbEntry        Where to return the pointer to the entry.
    1041  */
    1042 static int rtFsFatClusterMap_GetEntry(PRTFSFATCLUSTERMAPCACHE pCache, PRTFSFATVOL pThis, uint32_t offFat, uint8_t **ppbEntry)
     1039 * @param   pFatCache   The FAT cache.
     1040 * @param   offFat      The FAT byte offset to get the entry off.
     1041 * @param   ppbEntry    Where to return the pointer to the entry.
     1042 */
     1043static int rtFsFatClusterMap_GetEntry(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t offFat, uint8_t **ppbEntry)
    10431044{
    10441045    int rc;
    1045     if (offFat < pThis->cbFat)
    1046     {
    1047         uint32_t const iEntry      = (offFat >> pCache->cEntryIndexShift) & pCache->fEntryIndexMask;
    1048         uint32_t const offInEntry  = offFat & pCache->fEntryOffsetMask;
     1046    if (offFat < pFatCache->cbFat)
     1047    {
     1048        uint32_t const iEntry      = (offFat >> pFatCache->cEntryIndexShift) & pFatCache->fEntryIndexMask;
     1049        uint32_t const offInEntry  = offFat & pFatCache->fEntryOffsetMask;
    10491050        uint32_t const offFatEntry = offFat - offInEntry;
    10501051
    1051         *ppbEntry = pCache->aEntries[iEntry].pbData + offInEntry;
     1052        *ppbEntry = pFatCache->aEntries[iEntry].pbData + offInEntry;
    10521053
    10531054        /* If it's already ready, return immediately. */
    1054         if (pCache->aEntries[iEntry].offFat == offFatEntry)
     1055        if (pFatCache->aEntries[iEntry].offFat == offFatEntry)
    10551056        {
    10561057            Log3(("rtFsFatClusterMap_GetEntry: Hit entry %u for offFat=%#RX32\n", iEntry, offFat));
     
    10601061        /* Do we need to flush it? */
    10611062        rc = VINF_SUCCESS;
    1062         if (   pCache->aEntries[iEntry].bmDirty != 0
    1063             && pCache->aEntries[iEntry].offFat != UINT32_MAX)
     1063        if (   pFatCache->aEntries[iEntry].bmDirty != 0
     1064            && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
    10641065        {
    10651066            Log3(("rtFsFatClusterMap_GetEntry: Flushing entry %u for offFat=%#RX32\n", iEntry, offFat));
    1066             rc = rtFsFatClusterMap_FlushEntry(pThis, iEntry);
     1067            rc = rtFsFatClusterMap_FlushEntry(pFatCache, iEntry);
    10671068        }
    10681069        if (RT_SUCCESS(rc))
    10691070        {
    1070             pCache->aEntries[iEntry].bmDirty = 0;
     1071            pFatCache->aEntries[iEntry].bmDirty = 0;
    10711072
    10721073            /* Read in the entry from disk */
    1073             rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + offFatEntry, pCache->aEntries[iEntry].pbData,
    1074                                  pCache->cbEntry, NULL);
     1074            rc = RTVfsFileReadAt(pFatCache->pVol->hVfsBacking, pFatCache->pVol->aoffFats[0] + offFatEntry,
     1075                                 pFatCache->aEntries[iEntry].pbData, pFatCache->cbEntry, NULL);
    10751076            if (RT_SUCCESS(rc))
    10761077            {
    10771078                Log3(("rtFsFatClusterMap_GetEntry: Loaded entry %u for offFat=%#RX32\n", iEntry, offFat));
    1078                 pCache->aEntries[iEntry].offFat = offFatEntry;
     1079                pFatCache->aEntries[iEntry].offFat = offFatEntry;
    10791080                return VINF_SUCCESS;
    10801081            }
    10811082            /** @todo We can try other FAT copies here... */
    10821083            LogRel(("rtFsFatClusterMap_GetEntry: Error loading entry %u for offFat=%#RX32 (%#64RX32 LB %#x): %Rrc\n",
    1083                     iEntry, offFat, pThis->aoffFats[0] + offFatEntry, pCache->cbEntry, rc));
    1084             pCache->aEntries[iEntry].offFat = UINT32_MAX;
     1084                    iEntry, offFat, pFatCache->pVol->aoffFats[0] + offFatEntry, pFatCache->cbEntry, rc));
     1085            pFatCache->aEntries[iEntry].offFat = UINT32_MAX;
    10851086        }
    10861087    }
     
    10961097 *
    10971098 * @returns IPRT status code.  On failure, we're currently kind of screwed.
    1098  * @param   pCache          The FAT cache.
    1099  * @param   pThis           The FAT volume instance.
    1100  * @param   offFat          The FAT byte offset to get the entry off.
    1101  * @param   ppbEntry        Where to return the pointer to the entry.
    1102  * @param   pidxEntry       Where to return the entry index.
    1103  */
    1104 static int rtFsFatClusterMap_GetEntryEx(PRTFSFATCLUSTERMAPCACHE pCache, PRTFSFATVOL pThis, uint32_t offFat,
     1099 * @param   pFatCache   The FAT cache.
     1100 * @param   offFat      The FAT byte offset to get the entry off.
     1101 * @param   ppbEntry    Where to return the pointer to the entry.
     1102 * @param   pidxEntry   Where to return the entry index.
     1103 */
     1104static int rtFsFatClusterMap_GetEntryEx(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t offFat,
    11051105                                        uint8_t **ppbEntry, uint32_t *pidxEntry)
    11061106{
    11071107    int rc;
    1108     if (offFat < pThis->cbFat)
    1109     {
    1110         uint32_t const iEntry      = (offFat >> pCache->cEntryIndexShift) & pCache->fEntryIndexMask;
    1111         uint32_t const offInEntry  = offFat & pCache->fEntryOffsetMask;
     1108    if (offFat < pFatCache->cbFat)
     1109    {
     1110        uint32_t const iEntry      = (offFat >> pFatCache->cEntryIndexShift) & pFatCache->fEntryIndexMask;
     1111        uint32_t const offInEntry  = offFat & pFatCache->fEntryOffsetMask;
    11121112        uint32_t const offFatEntry = offFat - offInEntry;
    11131113
    1114         *ppbEntry  = pCache->aEntries[iEntry].pbData + offInEntry;
     1114        *ppbEntry  = pFatCache->aEntries[iEntry].pbData + offInEntry;
    11151115        *pidxEntry = iEntry;
    11161116
    11171117        /* If it's already ready, return immediately. */
    1118         if (pCache->aEntries[iEntry].offFat == offFatEntry)
     1118        if (pFatCache->aEntries[iEntry].offFat == offFatEntry)
    11191119        {
    11201120            Log3(("rtFsFatClusterMap_GetEntryEx: Hit entry %u for offFat=%#RX32\n", iEntry, offFat));
     
    11241124        /* Do we need to flush it? */
    11251125        rc = VINF_SUCCESS;
    1126         if (   pCache->aEntries[iEntry].bmDirty != 0
    1127             && pCache->aEntries[iEntry].offFat != UINT32_MAX)
     1126        if (   pFatCache->aEntries[iEntry].bmDirty != 0
     1127            && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
    11281128        {
    11291129            Log3(("rtFsFatClusterMap_GetEntryEx: Flushing entry %u for offFat=%#RX32\n", iEntry, offFat));
    1130             rc = rtFsFatClusterMap_FlushEntry(pThis, iEntry);
     1130            rc = rtFsFatClusterMap_FlushEntry(pFatCache, iEntry);
    11311131        }
    11321132        if (RT_SUCCESS(rc))
    11331133        {
    1134             pCache->aEntries[iEntry].bmDirty = 0;
     1134            pFatCache->aEntries[iEntry].bmDirty = 0;
    11351135
    11361136            /* Read in the entry from disk */
    1137             rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + offFatEntry, pCache->aEntries[iEntry].pbData,
    1138                                  pCache->cbEntry, NULL);
     1137            rc = RTVfsFileReadAt(pFatCache->pVol->hVfsBacking, pFatCache->pVol->aoffFats[0] + offFatEntry,
     1138                                 pFatCache->aEntries[iEntry].pbData, pFatCache->cbEntry, NULL);
    11391139            if (RT_SUCCESS(rc))
    11401140            {
    11411141                Log3(("rtFsFatClusterMap_GetEntryEx: Loaded entry %u for offFat=%#RX32\n", iEntry, offFat));
    1142                 pCache->aEntries[iEntry].offFat = offFatEntry;
     1142                pFatCache->aEntries[iEntry].offFat = offFatEntry;
    11431143                return VINF_SUCCESS;
    11441144            }
    11451145            /** @todo We can try other FAT copies here... */
    11461146            LogRel(("rtFsFatClusterMap_GetEntryEx: Error loading entry %u for offFat=%#RX32 (%#64RX32 LB %#x): %Rrc\n",
    1147                     iEntry, offFat, pThis->aoffFats[0] + offFatEntry, pCache->cbEntry, rc));
    1148             pCache->aEntries[iEntry].offFat = UINT32_MAX;
     1147                    iEntry, offFat, pFatCache->pVol->aoffFats[0] + offFatEntry, pFatCache->cbEntry, rc));
     1148            pFatCache->aEntries[iEntry].offFat = UINT32_MAX;
    11491149        }
    11501150    }
     
    11671167static int rtFsFatClusterMap_Destroy(PRTFSFATVOL pThis)
    11681168{
    1169     int                     rc     = VINF_SUCCESS;
    1170     PRTFSFATCLUSTERMAPCACHE pCache = pThis->pFatCache;
    1171     if (pCache)
     1169    int                     rc        = VINF_SUCCESS;
     1170    PRTFSFATCLUSTERMAPCACHE pFatCache = pThis->pFatCache;
     1171    if (pFatCache)
    11721172    {
    11731173        /* flush stuff. */
     
    11751175
    11761176        /* free everything. */
    1177         uint32_t i = pCache->cEntries;
     1177        uint32_t i = pFatCache->cEntries;
    11781178        while (i-- > 0)
    11791179        {
    1180             RTMemFree(pCache->aEntries[i].pbData);
    1181             pCache->aEntries[i].pbData = NULL;
    1182         }
    1183         pCache->cEntries = 0;
    1184         RTMemFree(pCache);
     1180            RTMemFree(pFatCache->aEntries[i].pbData);
     1181            pFatCache->aEntries[i].pbData = NULL;
     1182        }
     1183        pFatCache->cEntries = 0;
     1184        RTMemFree(pFatCache);
    11851185
    11861186        pThis->pFatCache = NULL;
     
    11941194 * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT12.
    11951195 */
    1196 static int rtFsFatClusterMap_Fat12_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
    1197                                                     PRTFSFATCHAIN pChain)
     1196static int rtFsFatClusterMap_Fat12_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
    11981197{
    11991198    /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
    12001199       way we don't need to deal with entries in different sectors and whatnot.  */
    12011200    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1202     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1201    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    12031202    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    12041203
     
    12121211    {
    12131212        /* Validate the cluster, checking for end of file. */
    1214         if (   idxCluster >= pVol->cClusters
     1213        if (   idxCluster >= pFatCache->cClusters
    12151214            || idxCluster <  FAT_FIRST_DATA_CLUSTER)
    12161215        {
     
    12401239 * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT16.
    12411240 */
    1242 static int rtFsFatClusterMap_Fat16_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
    1243                                                     PRTFSFATCHAIN pChain)
     1241static int rtFsFatClusterMap_Fat16_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
    12441242{
    12451243    /* ASSUME that for FAT16 we cache the whole FAT in a single entry.  That
    12461244       way we don't need to deal with entries in different sectors and whatnot.  */
    12471245    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1248     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1246    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    12491247    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    12501248
     
    12581256    {
    12591257        /* Validate the cluster, checking for end of file. */
    1260         if (   idxCluster >= pVol->cClusters
     1258        if (   idxCluster >= pFatCache->cClusters
    12611259            || idxCluster <  FAT_FIRST_DATA_CLUSTER)
    12621260        {
     
    12801278 * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT32.
    12811279 */
    1282 static int rtFsFatClusterMap_Fat32_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
    1283                                                     PRTFSFATCHAIN pChain)
     1280static int rtFsFatClusterMap_Fat32_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
    12841281{
    12851282    /* Special case for empty files. */
     
    12911288    {
    12921289        /* Validate the cluster, checking for end of file. */
    1293         if (   idxCluster >= pVol->cClusters
     1290        if (   idxCluster >= pFatCache->cClusters
    12941291            || idxCluster <  FAT_FIRST_DATA_CLUSTER)
    12951292        {
     
    13061303        /* Get the next cluster. */
    13071304        uint8_t *pbEntry;
    1308         rc = rtFsFatClusterMap_GetEntry(pFatCache, pVol, idxCluster * 4, &pbEntry);
     1305        rc = rtFsFatClusterMap_GetEntry(pFatCache, idxCluster * 4, &pbEntry);
    13091306        if (RT_SUCCESS(rc))
    13101307            idxCluster = RT_MAKE_U32_FROM_U8(pbEntry[0], pbEntry[1], pbEntry[2], pbEntry[3]);
     
    13331330    switch (pThis->enmFatType)
    13341331    {
    1335         case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_Fat12_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
    1336         case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_Fat16_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
    1337         case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_Fat32_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
     1332        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_Fat12_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
     1333        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_Fat16_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
     1334        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_Fat32_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
    13381335        default:
    13391336            AssertFailedReturn(VERR_INTERNAL_ERROR_2);
     
    13711368
    13721369/** Sets a FAT12 cluster value. */
    1373 static int rtFsFatClusterMap_SetCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1374                                           uint32_t idxCluster, uint32_t uValue)
     1370static int rtFsFatClusterMap_SetCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
    13751371{
    13761372    /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
    13771373       way we don't need to deal with entries in different sectors and whatnot.  */
    13781374    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1379     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1375    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    13801376    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    13811377    AssertReturn(uValue < 0x1000, VERR_INTERNAL_ERROR_2);
     
    14041400
    14051401/** Sets a FAT16 cluster value. */
    1406 static int rtFsFatClusterMap_SetCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1407                                           uint32_t idxCluster, uint32_t uValue)
     1402static int rtFsFatClusterMap_SetCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
    14081403{
    14091404    /* ASSUME that for FAT16 we cache the whole FAT in a single entry.  */
    14101405    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1411     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1406    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    14121407    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    14131408    AssertReturn(uValue < 0x10000, VERR_INTERNAL_ERROR_2);
     
    14271422
    14281423/** Sets a FAT32 cluster value. */
    1429 static int rtFsFatClusterMap_SetCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1430                                           uint32_t idxCluster, uint32_t uValue)
     1424static int rtFsFatClusterMap_SetCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
    14311425{
    14321426    AssertReturn(uValue < 0x10000000, VERR_INTERNAL_ERROR_2);
     
    14351429    uint8_t *pbEntry;
    14361430    uint32_t idxEntry;
    1437     int rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, idxCluster * 4, &pbEntry, &idxEntry);
     1431    int rc = rtFsFatClusterMap_GetEntryEx(pFatCache, idxCluster * 4, &pbEntry, &idxEntry);
    14381432    if (RT_SUCCESS(rc))
    14391433    {
     
    14661460    switch (pThis->enmFatType)
    14671461    {
    1468         case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT12_EOC);
    1469         case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT16_EOC);
    1470         case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT32_EOC);
     1462        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, idxCluster, FAT_FIRST_FAT12_EOC);
     1463        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, idxCluster, FAT_FIRST_FAT16_EOC);
     1464        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, idxCluster, FAT_FIRST_FAT32_EOC);
    14711465        default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
    14721466    }
     
    14861480    switch (pThis->enmFatType)
    14871481    {
    1488         case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, pThis, idxCluster, 0);
    1489         case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, pThis, idxCluster, 0);
    1490         case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, pThis, idxCluster, 0);
     1482        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, idxCluster, 0);
     1483        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, idxCluster, 0);
     1484        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, idxCluster, 0);
    14911485        default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
    14921486    }
     
    14971491 * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT12.
    14981492 */
    1499 static int rtFsFatClusterMap_AllocateCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1500                                                uint32_t idxPrevCluster, uint32_t *pidxCluster)
     1493static int rtFsFatClusterMap_AllocateCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
    15011494{
    15021495    /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
    15031496       way we don't need to deal with entries in different sectors and whatnot.  */
    15041497    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1505     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1498    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    15061499    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    15071500
     
    15311524    uint32_t idxCluster = FAT_FIRST_DATA_CLUSTER;
    15321525    uint32_t offFat     = 3;
    1533     while (idxCluster < pVol->cClusters)
     1526    while (idxCluster < pFatCache->cClusters)
    15341527    {
    15351528        if (idxCluster & 1)
     
    15941587 * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT16.
    15951588 */
    1596 static int rtFsFatClusterMap_AllocateCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1597                                                uint32_t idxPrevCluster, uint32_t *pidxCluster)
     1589static int rtFsFatClusterMap_AllocateCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
    15981590{
    15991591    /* ASSUME that for FAT16 we cache the whole FAT in a single entry. */
    16001592    AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
    1601     AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
     1593    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
    16021594    AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
    16031595
     
    16231615    uint32_t idxCluster = RT_MIN(pFatCache->idxAllocHint, FAT_FIRST_DATA_CLUSTER);
    16241616    uint32_t offFat     = idxCluster * 2;
    1625     uint32_t cClusters  = pVol->cClusters;
     1617    uint32_t cClusters  = pFatCache->cClusters;
    16261618    for (uint32_t i = 0; i < 2; i++)
    16271619    {
    1628         while (idxCluster < pVol->cClusters)
     1620        while (idxCluster < cClusters)
    16291621        {
    16301622            if (   pbFat[offFat + 0] != 0x00
     
    16631655
    16641656        /* Wrap around to the start of the map. */
    1665         cClusters  = RT_MIN(pFatCache->idxAllocHint, pVol->cClusters);
     1657        cClusters  = RT_MIN(pFatCache->idxAllocHint, pFatCache->cClusters);
    16661658        idxCluster = FAT_FIRST_DATA_CLUSTER;
    16671659        offFat     = 4;
     
    16751667 * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT32.
    16761668 */
    1677 static int rtFsFatClusterMap_AllocateCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
    1678                                                uint32_t idxPrevCluster, uint32_t *pidxCluster)
     1669static int rtFsFatClusterMap_AllocateCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
    16791670{
    16801671    /*
     
    16851676    if (idxPrevCluster != UINT32_MAX)
    16861677    {
    1687         rc = rtFsFatClusterMap_GetEntry(pFatCache, pVol, idxPrevCluster * 4, &pbEntry);
     1678        rc = rtFsFatClusterMap_GetEntry(pFatCache, idxPrevCluster * 4, &pbEntry);
    16881679        if (RT_SUCCESS(rc))
    16891680        {
     
    17011692    uint32_t idxCluster = RT_MIN(pFatCache->idxAllocHint, FAT_FIRST_DATA_CLUSTER);
    17021693    uint32_t offFat     = idxCluster * 4;
    1703     uint32_t cClusters  = pVol->cClusters;
     1694    uint32_t cClusters  = pFatCache->cClusters;
    17041695    for (uint32_t i = 0; i < 2; i++)
    17051696    {
    1706         while (idxCluster < pVol->cClusters)
     1697        while (idxCluster < cClusters)
    17071698        {
    17081699            /* Note! This could be done in cache entry chunks.  */
    17091700            uint32_t idxEntry;
    1710             rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, offFat, &pbEntry, &idxEntry);
     1701            rc = rtFsFatClusterMap_GetEntryEx(pFatCache, offFat, &pbEntry, &idxEntry);
    17111702            if (RT_SUCCESS(rc))
    17121703            {
     
    17351726                    if (idxPrevCluster != UINT32_MAX)
    17361727                    {
    1737                         rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, idxPrevCluster * 4, &pbEntry, &idxEntry);
     1728                        rc = rtFsFatClusterMap_GetEntryEx(pFatCache, idxPrevCluster * 4, &pbEntry, &idxEntry);
    17381729                        if (RT_SUCCESS(rc))
    17391730                        {
     
    17471738                        {
    17481739                            /* Try free the cluster. */
    1749                             int rc2 = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, offFat, &pbEntry, &idxEntry);
     1740                            int rc2 = rtFsFatClusterMap_GetEntryEx(pFatCache, offFat, &pbEntry, &idxEntry);
    17501741                            if (RT_SUCCESS(rc2))
    17511742                            {
     
    17711762
    17721763        /* Wrap around to the start of the map. */
    1773         cClusters  = RT_MIN(pFatCache->idxAllocHint, pVol->cClusters);
     1764        cClusters  = RT_MIN(pFatCache->idxAllocHint, pFatCache->cClusters);
    17741765        idxCluster = FAT_FIRST_DATA_CLUSTER;
    17751766        offFat     = 4;
     
    17961787    switch (pThis->enmFatType)
    17971788    {
    1798         case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_AllocateCluster12(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
    1799         case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_AllocateCluster16(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
    1800         case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_AllocateCluster32(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
     1789        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_AllocateCluster12(pThis->pFatCache, idxPrevCluster, pidxCluster);
     1790        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_AllocateCluster16(pThis->pFatCache, idxPrevCluster, pidxCluster);
     1791        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_AllocateCluster32(pThis->pFatCache, idxPrevCluster, pidxCluster);
    18011792        default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
    18021793    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette