Changeset 32629 in vbox
- Timestamp:
- Sep 20, 2010 9:24:01 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 66035
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/tar.cpp
r32602 r32629 169 169 170 170 *ppvBuf = 0; 171 void *pvTmp = 0;172 171 do 173 172 { … … 181 180 } 182 181 183 /* Allocate a temporary buffer for reading the tar content in blocks. */184 size_t cbTmp = 0;185 pvTmp = rtTarMemTmpAlloc(&cbTmp);186 if (!pvTmp)187 {188 rc = VERR_NO_MEMORY;189 break;190 }191 192 182 uint64_t cbAllWritten = 0; /* Already copied */ 183 uint64_t cbToRead = 0; /* What to read in the next step */ 193 184 uint64_t cbRead = 0; /* Actually read in the last step */ 194 /* Copy the content from hFile over to the memory. This is done block 195 * wise in 512 byte aligned steps. After this copying is finished hFile 196 * will be on a 512 byte boundary, regardless if the file copied is 512 197 * byte size aligned. */ 185 /* Copy the content from hFile over to the memory. */ 198 186 for (;;) 199 187 { … … 203 191 if (cbAllWritten == cbToCopy) 204 192 break; 205 /* Read one block. This will be 512 aligned in any case.*/206 cb Read = RT_ALIGN(RT_MIN(cbToCopy - cbAllWritten, cbTmp), sizeof(RTTARRECORD));207 rc = RTFileRead(hFile, p vTmp, cbRead, NULL);193 /* Try to read all at once */ 194 cbToRead = cbToCopy - cbAllWritten; 195 rc = RTFileRead(hFile, pcsTmp, cbToRead, &cbRead); 208 196 if (RT_FAILURE(rc)) 209 197 break; 210 /* Check for the last block which has not to be 512 bytes in size. */211 if (cbAllWritten + cbRead > cbToCopy)212 cbRead = cbToCopy - cbAllWritten;213 /* Write the block */214 memcpy(pcsTmp, pvTmp, cbRead);215 198 /* Count how many bytes are written already */ 216 199 cbAllWritten += cbRead; … … 218 201 pcsTmp += cbRead; 219 202 } 203 int64_t offSeek = RT_ALIGN(cbAllWritten, sizeof(RTTARRECORD)) - cbAllWritten; 204 /* We have to make sure the file pointer is 512 byte aligned. */ 205 if ( RT_SUCCESS(rc) 206 && offSeek > 0) 207 { 208 rc = RTFileSeek(hFile, offSeek, RTFILE_SEEK_CURRENT, NULL); 209 if (RT_FAILURE(rc)) 210 break; 211 } 220 212 } 221 213 while(0); 222 223 if (pvTmp)224 RTMemTmpFree(pvTmp);225 214 226 215 if ( RT_FAILURE(rc)
Note:
See TracChangeset
for help on using the changeset viewer.