Index: trunk/src/VBox/Runtime/common/fs/fatvfs.cpp
===================================================================
--- trunk/src/VBox/Runtime/common/fs/fatvfs.cpp	(revision 69660)
+++ trunk/src/VBox/Runtime/common/fs/fatvfs.cpp	(revision 69663)
@@ -311,4 +311,6 @@
     /** The FAT size. */
     uint32_t                cbFat;
+    /** The Number of clusters in the FAT. */
+    uint32_t                cClusters;
     /** Cluster allocation search hint. */
     uint32_t                idxAllocHint;
@@ -821,34 +823,35 @@
      * Allocate and initialize it all.
      */
-    PRTFSFATCLUSTERMAPCACHE pCache;
-    pThis->pFatCache = pCache = (PRTFSFATCLUSTERMAPCACHE)RTMemAllocZ(RT_OFFSETOF(RTFSFATCLUSTERMAPCACHE, aEntries[cEntries]));
-    if (!pCache)
+    PRTFSFATCLUSTERMAPCACHE pFatCache;
+    pThis->pFatCache = pFatCache = (PRTFSFATCLUSTERMAPCACHE)RTMemAllocZ(RT_OFFSETOF(RTFSFATCLUSTERMAPCACHE, aEntries[cEntries]));
+    if (!pFatCache)
         return RTErrInfoSet(pErrInfo, VERR_NO_MEMORY, "Failed to allocate FAT cache");
-    pCache->cEntries            = cEntries;
-    pCache->fEntryIndexMask     = fEntryIndexMask;
-    pCache->cEntryIndexShift    = cEntryIndexShift;
-    pCache->cbEntry             = cbEntry;
-    pCache->fEntryOffsetMask    = fEntryOffsetMask;
-    pCache->pVol                = pThis;
-    pCache->cbFat               = pThis->cbFat;
+    pFatCache->cEntries            = cEntries;
+    pFatCache->fEntryIndexMask     = fEntryIndexMask;
+    pFatCache->cEntryIndexShift    = cEntryIndexShift;
+    pFatCache->cbEntry             = cbEntry;
+    pFatCache->fEntryOffsetMask    = fEntryOffsetMask;
+    pFatCache->pVol                = pThis;
+    pFatCache->cbFat               = pThis->cbFat;
+    pFatCache->cClusters           = pThis->cClusters;
 
     unsigned i = cEntries;
     while (i-- > 0)
     {
-        pCache->aEntries[i].pbData = (uint8_t *)RTMemAlloc(cbEntry);
-        if (pCache->aEntries[i].pbData == NULL)
+        pFatCache->aEntries[i].pbData = (uint8_t *)RTMemAlloc(cbEntry);
+        if (pFatCache->aEntries[i].pbData == NULL)
         {
             for (i++; i < cEntries; i++)
-                RTMemFree(pCache->aEntries[i].pbData);
-            RTMemFree(pCache);
+                RTMemFree(pFatCache->aEntries[i].pbData);
+            RTMemFree(pFatCache);
             return RTErrInfoSetF(pErrInfo, VERR_NO_MEMORY, "Failed to allocate FAT cache entry (%#x bytes)", cbEntry);
         }
 
-        pCache->aEntries[i].offFat  = UINT32_MAX;
-        pCache->aEntries[i].bmDirty = 0;
+        pFatCache->aEntries[i].offFat  = UINT32_MAX;
+        pFatCache->aEntries[i].bmDirty = 0;
     }
     Log3(("rtFsFatClusterMap_Create:       cbFat=%#RX32 cEntries=%RU32 cEntryIndexShift=%RU32 fEntryIndexMask=%#RX32\n",
-          pCache->cbFat, pCache->cEntries, pCache->cEntryIndexShift, pCache->fEntryIndexMask));
-    Log3(("rtFsFatClusterMap_Create:   cbEntries=%#RX32 fEntryOffsetMask=%#RX32\n", pCache->cbEntry, pCache->fEntryOffsetMask));
+          pFatCache->cbFat, pFatCache->cEntries, pFatCache->cEntryIndexShift, pFatCache->fEntryIndexMask));
+    Log3(("rtFsFatClusterMap_Create:   cbEntries=%#RX32 fEntryOffsetMask=%#RX32\n", pFatCache->cbEntry, pFatCache->fEntryOffsetMask));
 
     /*
@@ -859,29 +862,29 @@
         cbEntry = pThis->cbSector;
 
-    pCache->cDirtyShift = 1;
-    pCache->cbDirtyLine = 1;
-    while (pCache->cbDirtyLine < cbEntry)
-    {
-        pCache->cDirtyShift++;
-        pCache->cbDirtyLine <<= 1;
-    }
-    Assert(pCache->cEntries == 1 || pCache->cbDirtyLine == pThis->cbSector);
-    Log3(("rtFsFatClusterMap_Create: cbDirtyLine=%#RX32 cDirtyShift=%u\n", pCache->cbDirtyLine, pCache->cDirtyShift));
+    pFatCache->cDirtyShift = 1;
+    pFatCache->cbDirtyLine = 1;
+    while (pFatCache->cbDirtyLine < cbEntry)
+    {
+        pFatCache->cDirtyShift++;
+        pFatCache->cbDirtyLine <<= 1;
+    }
+    Assert(pFatCache->cEntries == 1 || pFatCache->cbDirtyLine == pThis->cbSector);
+    Log3(("rtFsFatClusterMap_Create: cbDirtyLine=%#RX32 cDirtyShift=%u\n", pFatCache->cbDirtyLine, pFatCache->cDirtyShift));
 
     /*
      * Fill the cache if single entry or entry size is 512.
      */
-    if (pCache->cEntries == 1 || pCache->cbEntry == 512)
-    {
-        memcpy(pCache->aEntries[0].pbData, pbFirst512FatBytes, RT_MIN(512, pCache->cbEntry));
-        if (pCache->cbEntry > 512)
+    if (pFatCache->cEntries == 1 || pFatCache->cbEntry == 512)
+    {
+        memcpy(pFatCache->aEntries[0].pbData, pbFirst512FatBytes, RT_MIN(512, pFatCache->cbEntry));
+        if (pFatCache->cbEntry > 512)
         {
             int rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + 512,
-                                     &pCache->aEntries[0].pbData[512], pCache->cbEntry - 512, NULL);
+                                     &pFatCache->aEntries[0].pbData[512], pFatCache->cbEntry - 512, NULL);
             if (RT_FAILURE(rc))
                 return RTErrInfoSet(pErrInfo, rc, "Error reading FAT into memory");
         }
-        pCache->aEntries[0].offFat  = 0;
-        pCache->aEntries[0].bmDirty = 0;
+        pFatCache->aEntries[0].offFat  = 0;
+        pFatCache->aEntries[0].bmDirty = 0;
     }
 
@@ -900,6 +903,5 @@
 static int rtFsFatClusterMap_FlushWorker(PRTFSFATVOL pThis, uint32_t const iFirstEntry, uint32_t const iLastEntry)
 {
-    PRTFSFATCLUSTERMAPCACHE pCache = pThis->pFatCache;
-
+    PRTFSFATCLUSTERMAPCACHE pFatCache = pThis->pFatCache;
 
     /*
@@ -918,18 +920,18 @@
         for (uint32_t iEntry = iFirstEntry; iEntry <= iLastEntry; iEntry++)
         {
-            uint64_t bmDirty = pCache->aEntries[iEntry].bmDirty;
+            uint64_t bmDirty = pFatCache->aEntries[iEntry].bmDirty;
             if (   bmDirty != 0
-                && pCache->aEntries[iEntry].offFat != UINT32_MAX)
+                && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
             {
                 uint32_t offEntry   = 0;
                 uint64_t iDirtyLine = 1;
-                while (offEntry < pCache->cbEntry)
+                while (offEntry < pFatCache->cbEntry)
                 {
-                    if (pCache->aEntries[iEntry].bmDirty & iDirtyLine)
+                    if (pFatCache->aEntries[iEntry].bmDirty & iDirtyLine)
                     {
                         /*
                          * Found dirty cache line.
                          */
-                        uint64_t offDirtyLine = pThis->aoffFats[iFatCopy] + pCache->aEntries[iEntry].offFat + offEntry;
+                        uint64_t offDirtyLine = pThis->aoffFats[iFatCopy] + pFatCache->aEntries[iEntry].offFat + offEntry;
 
                         /* Can we simply extend the last segment? */
@@ -939,7 +941,7 @@
                             Assert(SgBuf.cSegs > 0);
                             Assert(   (uintptr_t)aSgSegs[SgBuf.cSegs - 1].pvSeg + aSgSegs[SgBuf.cSegs - 1].cbSeg
-                                   == (uintptr_t)&pCache->aEntries[iEntry].pbData[offEntry]);
-                            aSgSegs[SgBuf.cSegs - 1].cbSeg += pCache->cbDirtyLine;
-                            offEdge += pCache->cbDirtyLine;
+                                   == (uintptr_t)&pFatCache->aEntries[iEntry].pbData[offEntry]);
+                            aSgSegs[SgBuf.cSegs - 1].cbSeg += pFatCache->cbDirtyLine;
+                            offEdge += pFatCache->cbDirtyLine;
                         }
                         else
@@ -964,8 +966,8 @@
 
                             /* Append segment. */
-                            aSgSegs[SgBuf.cSegs].cbSeg = pCache->cbDirtyLine;
-                            aSgSegs[SgBuf.cSegs].pvSeg = &pCache->aEntries[iEntry].pbData[offEntry];
+                            aSgSegs[SgBuf.cSegs].cbSeg = pFatCache->cbDirtyLine;
+                            aSgSegs[SgBuf.cSegs].pvSeg = &pFatCache->aEntries[iEntry].pbData[offEntry];
                             SgBuf.cSegs++;
-                            offEdge = offDirtyLine + pCache->cbDirtyLine;
+                            offEdge = offDirtyLine + pFatCache->cbDirtyLine;
                         }
 
@@ -975,5 +977,5 @@
                     }
                     iDirtyLine <<= 1;
-                    offEntry += pCache->cbDirtyLine;
+                    offEntry += pFatCache->cbDirtyLine;
                 }
                 Assert(!bmDirty);
@@ -997,5 +999,5 @@
     if (RT_SUCCESS(rc))
         for (uint32_t iEntry = iFirstEntry; iEntry <= iLastEntry; iEntry++)
-            pCache->aEntries[iEntry].bmDirty = 0;
+            pFatCache->aEntries[iEntry].bmDirty = 0;
 
     return rc;
@@ -1022,10 +1024,10 @@
  *
  * @returns IPRT status code.  On failure, we're currently kind of screwed.
- * @param   pThis       The FAT volume instance.
+ * @param   pFatCache   The FAT cache
  * @param   iEntry      The cache entry to flush.
  */
-static int rtFsFatClusterMap_FlushEntry(PRTFSFATVOL pThis, uint32_t iEntry)
-{
-    return rtFsFatClusterMap_FlushWorker(pThis, iEntry, iEntry);
+static int rtFsFatClusterMap_FlushEntry(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t iEntry)
+{
+    return rtFsFatClusterMap_FlushWorker(pFatCache->pVol, iEntry, iEntry);
 }
 
@@ -1035,22 +1037,21 @@
  *
  * @returns IPRT status code.  On failure, we're currently kind of screwed.
- * @param   pCache          The FAT cache.
- * @param   pThis           The FAT volume instance.
- * @param   offFat          The FAT byte offset to get the entry off.
- * @param   ppbEntry        Where to return the pointer to the entry.
- */
-static int rtFsFatClusterMap_GetEntry(PRTFSFATCLUSTERMAPCACHE pCache, PRTFSFATVOL pThis, uint32_t offFat, uint8_t **ppbEntry)
+ * @param   pFatCache   The FAT cache.
+ * @param   offFat      The FAT byte offset to get the entry off.
+ * @param   ppbEntry    Where to return the pointer to the entry.
+ */
+static int rtFsFatClusterMap_GetEntry(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t offFat, uint8_t **ppbEntry)
 {
     int rc;
-    if (offFat < pThis->cbFat)
-    {
-        uint32_t const iEntry      = (offFat >> pCache->cEntryIndexShift) & pCache->fEntryIndexMask;
-        uint32_t const offInEntry  = offFat & pCache->fEntryOffsetMask;
+    if (offFat < pFatCache->cbFat)
+    {
+        uint32_t const iEntry      = (offFat >> pFatCache->cEntryIndexShift) & pFatCache->fEntryIndexMask;
+        uint32_t const offInEntry  = offFat & pFatCache->fEntryOffsetMask;
         uint32_t const offFatEntry = offFat - offInEntry;
 
-        *ppbEntry = pCache->aEntries[iEntry].pbData + offInEntry;
+        *ppbEntry = pFatCache->aEntries[iEntry].pbData + offInEntry;
 
         /* If it's already ready, return immediately. */
-        if (pCache->aEntries[iEntry].offFat == offFatEntry)
+        if (pFatCache->aEntries[iEntry].offFat == offFatEntry)
         {
             Log3(("rtFsFatClusterMap_GetEntry: Hit entry %u for offFat=%#RX32\n", iEntry, offFat));
@@ -1060,27 +1061,27 @@
         /* Do we need to flush it? */
         rc = VINF_SUCCESS;
-        if (   pCache->aEntries[iEntry].bmDirty != 0
-            && pCache->aEntries[iEntry].offFat != UINT32_MAX)
+        if (   pFatCache->aEntries[iEntry].bmDirty != 0
+            && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
         {
             Log3(("rtFsFatClusterMap_GetEntry: Flushing entry %u for offFat=%#RX32\n", iEntry, offFat));
-            rc = rtFsFatClusterMap_FlushEntry(pThis, iEntry);
+            rc = rtFsFatClusterMap_FlushEntry(pFatCache, iEntry);
         }
         if (RT_SUCCESS(rc))
         {
-            pCache->aEntries[iEntry].bmDirty = 0;
+            pFatCache->aEntries[iEntry].bmDirty = 0;
 
             /* Read in the entry from disk */
-            rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + offFatEntry, pCache->aEntries[iEntry].pbData,
-                                 pCache->cbEntry, NULL);
+            rc = RTVfsFileReadAt(pFatCache->pVol->hVfsBacking, pFatCache->pVol->aoffFats[0] + offFatEntry,
+                                 pFatCache->aEntries[iEntry].pbData, pFatCache->cbEntry, NULL);
             if (RT_SUCCESS(rc))
             {
                 Log3(("rtFsFatClusterMap_GetEntry: Loaded entry %u for offFat=%#RX32\n", iEntry, offFat));
-                pCache->aEntries[iEntry].offFat = offFatEntry;
+                pFatCache->aEntries[iEntry].offFat = offFatEntry;
                 return VINF_SUCCESS;
             }
             /** @todo We can try other FAT copies here... */
             LogRel(("rtFsFatClusterMap_GetEntry: Error loading entry %u for offFat=%#RX32 (%#64RX32 LB %#x): %Rrc\n",
-                    iEntry, offFat, pThis->aoffFats[0] + offFatEntry, pCache->cbEntry, rc));
-            pCache->aEntries[iEntry].offFat = UINT32_MAX;
+                    iEntry, offFat, pFatCache->pVol->aoffFats[0] + offFatEntry, pFatCache->cbEntry, rc));
+            pFatCache->aEntries[iEntry].offFat = UINT32_MAX;
         }
     }
@@ -1096,25 +1097,24 @@
  *
  * @returns IPRT status code.  On failure, we're currently kind of screwed.
- * @param   pCache          The FAT cache.
- * @param   pThis           The FAT volume instance.
- * @param   offFat          The FAT byte offset to get the entry off.
- * @param   ppbEntry        Where to return the pointer to the entry.
- * @param   pidxEntry       Where to return the entry index.
- */
-static int rtFsFatClusterMap_GetEntryEx(PRTFSFATCLUSTERMAPCACHE pCache, PRTFSFATVOL pThis, uint32_t offFat,
+ * @param   pFatCache   The FAT cache.
+ * @param   offFat      The FAT byte offset to get the entry off.
+ * @param   ppbEntry    Where to return the pointer to the entry.
+ * @param   pidxEntry   Where to return the entry index.
+ */
+static int rtFsFatClusterMap_GetEntryEx(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t offFat,
                                         uint8_t **ppbEntry, uint32_t *pidxEntry)
 {
     int rc;
-    if (offFat < pThis->cbFat)
-    {
-        uint32_t const iEntry      = (offFat >> pCache->cEntryIndexShift) & pCache->fEntryIndexMask;
-        uint32_t const offInEntry  = offFat & pCache->fEntryOffsetMask;
+    if (offFat < pFatCache->cbFat)
+    {
+        uint32_t const iEntry      = (offFat >> pFatCache->cEntryIndexShift) & pFatCache->fEntryIndexMask;
+        uint32_t const offInEntry  = offFat & pFatCache->fEntryOffsetMask;
         uint32_t const offFatEntry = offFat - offInEntry;
 
-        *ppbEntry  = pCache->aEntries[iEntry].pbData + offInEntry;
+        *ppbEntry  = pFatCache->aEntries[iEntry].pbData + offInEntry;
         *pidxEntry = iEntry;
 
         /* If it's already ready, return immediately. */
-        if (pCache->aEntries[iEntry].offFat == offFatEntry)
+        if (pFatCache->aEntries[iEntry].offFat == offFatEntry)
         {
             Log3(("rtFsFatClusterMap_GetEntryEx: Hit entry %u for offFat=%#RX32\n", iEntry, offFat));
@@ -1124,27 +1124,27 @@
         /* Do we need to flush it? */
         rc = VINF_SUCCESS;
-        if (   pCache->aEntries[iEntry].bmDirty != 0
-            && pCache->aEntries[iEntry].offFat != UINT32_MAX)
+        if (   pFatCache->aEntries[iEntry].bmDirty != 0
+            && pFatCache->aEntries[iEntry].offFat != UINT32_MAX)
         {
             Log3(("rtFsFatClusterMap_GetEntryEx: Flushing entry %u for offFat=%#RX32\n", iEntry, offFat));
-            rc = rtFsFatClusterMap_FlushEntry(pThis, iEntry);
+            rc = rtFsFatClusterMap_FlushEntry(pFatCache, iEntry);
         }
         if (RT_SUCCESS(rc))
         {
-            pCache->aEntries[iEntry].bmDirty = 0;
+            pFatCache->aEntries[iEntry].bmDirty = 0;
 
             /* Read in the entry from disk */
-            rc = RTVfsFileReadAt(pThis->hVfsBacking, pThis->aoffFats[0] + offFatEntry, pCache->aEntries[iEntry].pbData,
-                                 pCache->cbEntry, NULL);
+            rc = RTVfsFileReadAt(pFatCache->pVol->hVfsBacking, pFatCache->pVol->aoffFats[0] + offFatEntry,
+                                 pFatCache->aEntries[iEntry].pbData, pFatCache->cbEntry, NULL);
             if (RT_SUCCESS(rc))
             {
                 Log3(("rtFsFatClusterMap_GetEntryEx: Loaded entry %u for offFat=%#RX32\n", iEntry, offFat));
-                pCache->aEntries[iEntry].offFat = offFatEntry;
+                pFatCache->aEntries[iEntry].offFat = offFatEntry;
                 return VINF_SUCCESS;
             }
             /** @todo We can try other FAT copies here... */
             LogRel(("rtFsFatClusterMap_GetEntryEx: Error loading entry %u for offFat=%#RX32 (%#64RX32 LB %#x): %Rrc\n",
-                    iEntry, offFat, pThis->aoffFats[0] + offFatEntry, pCache->cbEntry, rc));
-            pCache->aEntries[iEntry].offFat = UINT32_MAX;
+                    iEntry, offFat, pFatCache->pVol->aoffFats[0] + offFatEntry, pFatCache->cbEntry, rc));
+            pFatCache->aEntries[iEntry].offFat = UINT32_MAX;
         }
     }
@@ -1167,7 +1167,7 @@
 static int rtFsFatClusterMap_Destroy(PRTFSFATVOL pThis)
 {
-    int                     rc     = VINF_SUCCESS;
-    PRTFSFATCLUSTERMAPCACHE pCache = pThis->pFatCache;
-    if (pCache)
+    int                     rc        = VINF_SUCCESS;
+    PRTFSFATCLUSTERMAPCACHE pFatCache = pThis->pFatCache;
+    if (pFatCache)
     {
         /* flush stuff. */
@@ -1175,12 +1175,12 @@
 
         /* free everything. */
-        uint32_t i = pCache->cEntries;
+        uint32_t i = pFatCache->cEntries;
         while (i-- > 0)
         {
-            RTMemFree(pCache->aEntries[i].pbData);
-            pCache->aEntries[i].pbData = NULL;
-        }
-        pCache->cEntries = 0;
-        RTMemFree(pCache);
+            RTMemFree(pFatCache->aEntries[i].pbData);
+            pFatCache->aEntries[i].pbData = NULL;
+        }
+        pFatCache->cEntries = 0;
+        RTMemFree(pFatCache);
 
         pThis->pFatCache = NULL;
@@ -1194,11 +1194,10 @@
  * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT12.
  */
-static int rtFsFatClusterMap_Fat12_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
-                                                    PRTFSFATCHAIN pChain)
+static int rtFsFatClusterMap_Fat12_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
 {
     /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
        way we don't need to deal with entries in different sectors and whatnot.  */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
 
@@ -1212,5 +1211,5 @@
     {
         /* Validate the cluster, checking for end of file. */
-        if (   idxCluster >= pVol->cClusters
+        if (   idxCluster >= pFatCache->cClusters
             || idxCluster <  FAT_FIRST_DATA_CLUSTER)
         {
@@ -1240,11 +1239,10 @@
  * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT16.
  */
-static int rtFsFatClusterMap_Fat16_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
-                                                    PRTFSFATCHAIN pChain)
+static int rtFsFatClusterMap_Fat16_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
 {
     /* ASSUME that for FAT16 we cache the whole FAT in a single entry.  That
        way we don't need to deal with entries in different sectors and whatnot.  */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
 
@@ -1258,5 +1256,5 @@
     {
         /* Validate the cluster, checking for end of file. */
-        if (   idxCluster >= pVol->cClusters
+        if (   idxCluster >= pFatCache->cClusters
             || idxCluster <  FAT_FIRST_DATA_CLUSTER)
         {
@@ -1280,6 +1278,5 @@
  * Worker for rtFsFatClusterMap_ReadClusterChain handling FAT32.
  */
-static int rtFsFatClusterMap_Fat32_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol, uint32_t idxCluster,
-                                                    PRTFSFATCHAIN pChain)
+static int rtFsFatClusterMap_Fat32_ReadClusterChain(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, PRTFSFATCHAIN pChain)
 {
     /* Special case for empty files. */
@@ -1291,5 +1288,5 @@
     {
         /* Validate the cluster, checking for end of file. */
-        if (   idxCluster >= pVol->cClusters
+        if (   idxCluster >= pFatCache->cClusters
             || idxCluster <  FAT_FIRST_DATA_CLUSTER)
         {
@@ -1306,5 +1303,5 @@
         /* Get the next cluster. */
         uint8_t *pbEntry;
-        rc = rtFsFatClusterMap_GetEntry(pFatCache, pVol, idxCluster * 4, &pbEntry);
+        rc = rtFsFatClusterMap_GetEntry(pFatCache, idxCluster * 4, &pbEntry);
         if (RT_SUCCESS(rc))
             idxCluster = RT_MAKE_U32_FROM_U8(pbEntry[0], pbEntry[1], pbEntry[2], pbEntry[3]);
@@ -1333,7 +1330,7 @@
     switch (pThis->enmFatType)
     {
-        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_Fat12_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
-        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_Fat16_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
-        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_Fat32_ReadClusterChain(pThis->pFatCache, pThis, idxFirstCluster, pChain);
+        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_Fat12_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
+        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_Fat16_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
+        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_Fat32_ReadClusterChain(pThis->pFatCache, idxFirstCluster, pChain);
         default:
             AssertFailedReturn(VERR_INTERNAL_ERROR_2);
@@ -1371,11 +1368,10 @@
 
 /** Sets a FAT12 cluster value. */
-static int rtFsFatClusterMap_SetCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                          uint32_t idxCluster, uint32_t uValue)
+static int rtFsFatClusterMap_SetCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
 {
     /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
        way we don't need to deal with entries in different sectors and whatnot.  */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
     AssertReturn(uValue < 0x1000, VERR_INTERNAL_ERROR_2);
@@ -1404,10 +1400,9 @@
 
 /** Sets a FAT16 cluster value. */
-static int rtFsFatClusterMap_SetCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                          uint32_t idxCluster, uint32_t uValue)
+static int rtFsFatClusterMap_SetCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
 {
     /* ASSUME that for FAT16 we cache the whole FAT in a single entry.  */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
     AssertReturn(uValue < 0x10000, VERR_INTERNAL_ERROR_2);
@@ -1427,6 +1422,5 @@
 
 /** Sets a FAT32 cluster value. */
-static int rtFsFatClusterMap_SetCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                          uint32_t idxCluster, uint32_t uValue)
+static int rtFsFatClusterMap_SetCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxCluster, uint32_t uValue)
 {
     AssertReturn(uValue < 0x10000000, VERR_INTERNAL_ERROR_2);
@@ -1435,5 +1429,5 @@
     uint8_t *pbEntry;
     uint32_t idxEntry;
-    int rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, idxCluster * 4, &pbEntry, &idxEntry);
+    int rc = rtFsFatClusterMap_GetEntryEx(pFatCache, idxCluster * 4, &pbEntry, &idxEntry);
     if (RT_SUCCESS(rc))
     {
@@ -1466,7 +1460,7 @@
     switch (pThis->enmFatType)
     {
-        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT12_EOC);
-        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT16_EOC);
-        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, pThis, idxCluster, FAT_FIRST_FAT32_EOC);
+        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, idxCluster, FAT_FIRST_FAT12_EOC);
+        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, idxCluster, FAT_FIRST_FAT16_EOC);
+        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, idxCluster, FAT_FIRST_FAT32_EOC);
         default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
     }
@@ -1486,7 +1480,7 @@
     switch (pThis->enmFatType)
     {
-        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, pThis, idxCluster, 0);
-        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, pThis, idxCluster, 0);
-        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, pThis, idxCluster, 0);
+        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_SetCluster12(pThis->pFatCache, idxCluster, 0);
+        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_SetCluster16(pThis->pFatCache, idxCluster, 0);
+        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_SetCluster32(pThis->pFatCache, idxCluster, 0);
         default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
     }
@@ -1497,11 +1491,10 @@
  * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT12.
  */
-static int rtFsFatClusterMap_AllocateCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                               uint32_t idxPrevCluster, uint32_t *pidxCluster)
+static int rtFsFatClusterMap_AllocateCluster12(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
 {
     /* ASSUME that for FAT12 we cache the whole FAT in a single entry.  That
        way we don't need to deal with entries in different sectors and whatnot.  */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
 
@@ -1531,5 +1524,5 @@
     uint32_t idxCluster = FAT_FIRST_DATA_CLUSTER;
     uint32_t offFat     = 3;
-    while (idxCluster < pVol->cClusters)
+    while (idxCluster < pFatCache->cClusters)
     {
         if (idxCluster & 1)
@@ -1594,10 +1587,9 @@
  * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT16.
  */
-static int rtFsFatClusterMap_AllocateCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                               uint32_t idxPrevCluster, uint32_t *pidxCluster)
+static int rtFsFatClusterMap_AllocateCluster16(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
 {
     /* ASSUME that for FAT16 we cache the whole FAT in a single entry. */
     AssertReturn(pFatCache->cEntries == 1, VERR_INTERNAL_ERROR_4);
-    AssertReturn(pFatCache->cbEntry == pVol->cbFat, VERR_INTERNAL_ERROR_4);
+    AssertReturn(pFatCache->cbEntry == pFatCache->cbFat, VERR_INTERNAL_ERROR_4);
     AssertReturn(pFatCache->aEntries[0].offFat == 0, VERR_INTERNAL_ERROR_4);
 
@@ -1623,8 +1615,8 @@
     uint32_t idxCluster = RT_MIN(pFatCache->idxAllocHint, FAT_FIRST_DATA_CLUSTER);
     uint32_t offFat     = idxCluster * 2;
-    uint32_t cClusters  = pVol->cClusters;
+    uint32_t cClusters  = pFatCache->cClusters;
     for (uint32_t i = 0; i < 2; i++)
     {
-        while (idxCluster < pVol->cClusters)
+        while (idxCluster < cClusters)
         {
             if (   pbFat[offFat + 0] != 0x00
@@ -1663,5 +1655,5 @@
 
         /* Wrap around to the start of the map. */
-        cClusters  = RT_MIN(pFatCache->idxAllocHint, pVol->cClusters);
+        cClusters  = RT_MIN(pFatCache->idxAllocHint, pFatCache->cClusters);
         idxCluster = FAT_FIRST_DATA_CLUSTER;
         offFat     = 4;
@@ -1675,6 +1667,5 @@
  * Worker for rtFsFatClusterMap_AllocateCluster that handles FAT32.
  */
-static int rtFsFatClusterMap_AllocateCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, PRTFSFATVOL pVol,
-                                               uint32_t idxPrevCluster, uint32_t *pidxCluster)
+static int rtFsFatClusterMap_AllocateCluster32(PRTFSFATCLUSTERMAPCACHE pFatCache, uint32_t idxPrevCluster, uint32_t *pidxCluster)
 {
     /*
@@ -1685,5 +1676,5 @@
     if (idxPrevCluster != UINT32_MAX)
     {
-        rc = rtFsFatClusterMap_GetEntry(pFatCache, pVol, idxPrevCluster * 4, &pbEntry);
+        rc = rtFsFatClusterMap_GetEntry(pFatCache, idxPrevCluster * 4, &pbEntry);
         if (RT_SUCCESS(rc))
         {
@@ -1701,12 +1692,12 @@
     uint32_t idxCluster = RT_MIN(pFatCache->idxAllocHint, FAT_FIRST_DATA_CLUSTER);
     uint32_t offFat     = idxCluster * 4;
-    uint32_t cClusters  = pVol->cClusters;
+    uint32_t cClusters  = pFatCache->cClusters;
     for (uint32_t i = 0; i < 2; i++)
     {
-        while (idxCluster < pVol->cClusters)
+        while (idxCluster < cClusters)
         {
             /* Note! This could be done in cache entry chunks.  */
             uint32_t idxEntry;
-            rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, offFat, &pbEntry, &idxEntry);
+            rc = rtFsFatClusterMap_GetEntryEx(pFatCache, offFat, &pbEntry, &idxEntry);
             if (RT_SUCCESS(rc))
             {
@@ -1735,5 +1726,5 @@
                     if (idxPrevCluster != UINT32_MAX)
                     {
-                        rc = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, idxPrevCluster * 4, &pbEntry, &idxEntry);
+                        rc = rtFsFatClusterMap_GetEntryEx(pFatCache, idxPrevCluster * 4, &pbEntry, &idxEntry);
                         if (RT_SUCCESS(rc))
                         {
@@ -1747,5 +1738,5 @@
                         {
                             /* Try free the cluster. */
-                            int rc2 = rtFsFatClusterMap_GetEntryEx(pFatCache, pVol, offFat, &pbEntry, &idxEntry);
+                            int rc2 = rtFsFatClusterMap_GetEntryEx(pFatCache, offFat, &pbEntry, &idxEntry);
                             if (RT_SUCCESS(rc2))
                             {
@@ -1771,5 +1762,5 @@
 
         /* Wrap around to the start of the map. */
-        cClusters  = RT_MIN(pFatCache->idxAllocHint, pVol->cClusters);
+        cClusters  = RT_MIN(pFatCache->idxAllocHint, pFatCache->cClusters);
         idxCluster = FAT_FIRST_DATA_CLUSTER;
         offFat     = 4;
@@ -1796,7 +1787,7 @@
     switch (pThis->enmFatType)
     {
-        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_AllocateCluster12(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
-        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_AllocateCluster16(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
-        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_AllocateCluster32(pThis->pFatCache, pThis, idxPrevCluster, pidxCluster);
+        case RTFSFATTYPE_FAT12: return rtFsFatClusterMap_AllocateCluster12(pThis->pFatCache, idxPrevCluster, pidxCluster);
+        case RTFSFATTYPE_FAT16: return rtFsFatClusterMap_AllocateCluster16(pThis->pFatCache, idxPrevCluster, pidxCluster);
+        case RTFSFATTYPE_FAT32: return rtFsFatClusterMap_AllocateCluster32(pThis->pFatCache, idxPrevCluster, pidxCluster);
         default: AssertFailedReturn(VERR_INTERNAL_ERROR_3);
     }
