Changeset 69845 in vbox
- Timestamp:
- Nov 27, 2017 3:49:27 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fs/ext2vfs.cpp
r69844 r69845 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Filesystem API (FileSys) - ext2/3 format.3 * IPRT - Ext2/3/4 Virtual Filesystem. 4 4 */ 5 5 … … 92 92 static int rtFsExtLoadBlkGrpDesc(PRTFILESYSTEMEXT pThis, uint32_t iBlkGrp) 93 93 { 94 int rc = VINF_SUCCESS; 95 PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc = pThis->pBlkGrpDesc; 96 uint64_t offRead = (pThis->iSbBlock + 1) * pThis->cbBlock; 97 EXT2BLOCKGROUPDESC BlkDesc; 98 size_t cbBlockBitmap; 99 100 cbBlockBitmap = pThis->cBlocksPerGroup / 8; 94 size_t cbBlockBitmap = pThis->cBlocksPerGroup / 8; 101 95 if (pThis->cBlocksPerGroup % 8) 102 96 cbBlockBitmap++; 103 97 98 PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc = pThis->pBlkGrpDesc; 104 99 if (!pBlkGrpDesc) 105 100 { … … 110 105 } 111 106 112 rc = RTVfsFileReadAt(pThis->hVfsFile, offRead, &BlkDesc, sizeof(BlkDesc), NULL); 107 uint64_t offRead = (pThis->iSbBlock + 1) * pThis->cbBlock; 108 EXT2BLOCKGROUPDESC BlkDesc; 109 int rc = RTVfsFileReadAt(pThis->hVfsFile, offRead, &BlkDesc, sizeof(BlkDesc), NULL); 113 110 if (RT_SUCCESS(rc)) 114 111 { … … 120 117 121 118 pThis->pBlkGrpDesc = pBlkGrpDesc; 122 123 119 return rc; 124 120 } 125 121 122 126 123 static bool rtFsExtIsBlockRangeInUse(PRTFILESYSTEMEXTBLKGRP pBlkGrpDesc, uint32_t offBlockStart, size_t cBlocks) 127 124 { 128 bool fUsed = false;129 130 125 while (cBlocks) 131 126 { … … 134 129 135 130 if (pBlkGrpDesc->abBlockBitmap[idxByte] & RT_BIT(iBit)) 136 { 137 fUsed = true; 138 break; 139 } 131 return true; 140 132 141 133 cBlocks--; … … 143 135 } 144 136 145 return f Used;137 return false; 146 138 } 147 139 … … 187 179 static DECLCALLBACK(int) rtFsExt2_QueryRangeState(void *pvThis, uint64_t off, size_t cb, bool *pfUsed) 188 180 { 189 int rc = VINF_SUCCESS; 190 uint64_t offStart = (uint64_t)off; 191 PRTFILESYSTEMEXT pThis = (PRTFILESYSTEMEXT)pvThis; 181 int rc = VINF_SUCCESS; 182 PRTFILESYSTEMEXT pThis = (PRTFILESYSTEMEXT)pvThis; 192 183 193 184 *pfUsed = false; … … 195 186 while (cb > 0) 196 187 { 197 bool fUsed; 198 uint32_t offBlockStart = (uint32_t)(offStart / pThis->cbBlock); 199 uint32_t iBlockGroup = (offBlockStart - pThis->iSbBlock) / pThis->cBlocksPerGroup; 200 uint32_t offBlockRelStart = offBlockStart - iBlockGroup * pThis->cBlocksPerGroup; 201 size_t cbThis = 0; 202 203 if ( offStart < pThis->pBlkGrpDesc->offStart 204 || offStart > pThis->pBlkGrpDesc->offLast) 188 uint32_t const offBlockStart = (uint32_t)(off / pThis->cbBlock); 189 uint32_t const iBlockGroup = (offBlockStart - pThis->iSbBlock) / pThis->cBlocksPerGroup; 190 uint32_t const offBlockRelStart = offBlockStart - iBlockGroup * pThis->cBlocksPerGroup; 191 192 if ( off < pThis->pBlkGrpDesc->offStart 193 || off > pThis->pBlkGrpDesc->offLast) 205 194 { 206 195 /* Load new block descriptor. */ … … 210 199 } 211 200 212 cbThis = RT_MIN(cb, pThis->pBlkGrpDesc->offLast - offStart + 1); 213 fUsed = rtFsExtIsBlockRangeInUse(pThis->pBlkGrpDesc, offBlockRelStart, 214 cbThis / pThis->cbBlock + 215 (cbThis % pThis->cbBlock ? 1 : 0)); 216 217 if (fUsed) 201 size_t cbThis = RT_MIN(cb, pThis->pBlkGrpDesc->offLast - off + 1); 202 if (rtFsExtIsBlockRangeInUse(pThis->pBlkGrpDesc, 203 offBlockRelStart, 204 cbThis / pThis->cbBlock + (cbThis % pThis->cbBlock ? 1 : 0)) ) 218 205 { 219 206 *pfUsed = true; … … 221 208 } 222 209 223 cb 224 off Start+= cbThis;210 cb -= cbThis; 211 off += cbThis; 225 212 } 226 213
Note:
See TracChangeset
for help on using the changeset viewer.