Changeset 2564 in vbox
- Timestamp:
- May 9, 2007 4:13:07 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 21031
- Location:
- trunk/src/VBox/Devices/Storage
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp
r2379 r2564 217 217 int rc; 218 218 size_t cbThisRead; 219 PVBOXHDDIMAGEDESC pCurrImage; 219 220 220 221 /* Loop until all read. */ … … 226 227 cbThisRead = cbRead; 227 228 rc = VINF_VDI_BLOCK_FREE; 228 for ( ; pImage != NULL && rc == VINF_VDI_BLOCK_FREE; pImage = pImage->pPrev)229 for (pCurrImage = pImage; pCurrImage != NULL && rc == VINF_VDI_BLOCK_FREE; pCurrImage = pCurrImage->pPrev) 229 230 { 230 rc = pDisk->Backend->pfnRead(p Image->pvBackendData, uOffset, pvBuf, cbThisRead, &cbThisRead);231 rc = pDisk->Backend->pfnRead(pCurrImage->pvBackendData, uOffset, pvBuf, cbThisRead, &cbThisRead); 231 232 } 232 233 … … 428 429 rc = VERR_VDI_INVALID_TYPE; 429 430 431 /** @todo optionally check UUIDs */ 432 430 433 if (VBOX_SUCCESS(rc)) 431 434 { … … 531 534 PFNVMPROGRESS pfnProgress, void *pvUser) 532 535 { 533 return VERR_NOT_IMPLEMENTED; 536 int rc = VINF_SUCCESS; 537 LogFlow(("%s: pszFilename=\"%s\" uOpenFlags=%#x\n", __FUNCTION__, pszFilename, uOpenFlags)); 538 /* sanity check */ 539 Assert(pDisk); 540 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature)); 541 542 /* Check arguments. */ 543 if ( !pszFilename 544 || *pszFilename == '\0' 545 || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED) 546 || !cbSize 547 || (uOpenFlags & ~VD_OPEN_FLAGS_MASK)) 548 { 549 AssertMsgFailed(("Invalid arguments: pszFilename=%#p uOpenFlags=%#x\n", pszFilename, uOpenFlags)); 550 return VERR_INVALID_PARAMETER; 551 } 552 553 /* Check state. */ 554 if (pDisk->cImages != 0) 555 { 556 AssertMsgFailed(("Create base image cannot be done with other images open\n")); 557 return VERR_VDI_INVALID_STATE; 558 } 559 560 /* Set up image descriptor. */ 561 PVBOXHDDIMAGEDESC pImage = (PVBOXHDDIMAGEDESC)RTMemAllocZ(sizeof(VBOXHDDIMAGEDESC)); 562 if (!pImage) 563 return VERR_NO_MEMORY; 564 pImage->pszFilename = RTStrDup(pszFilename); 565 if (!pImage->pszFilename) 566 rc = VERR_NO_MEMORY; 567 568 if (VBOX_SUCCESS(rc)) 569 rc = pDisk->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize, 570 uImageFlags, pszComment, uOpenFlags, 571 pfnProgress, pvUser, 572 pDisk->pfnError, pDisk->pvErrorUser, 573 &pImage->pvBackendData); 574 575 if (VBOX_FAILURE(rc)) 576 { 577 RTStrFree(pImage->pszFilename); 578 RTMemFree(pImage); 579 } 580 581 return rc; 534 582 } 535 583 -
trunk/src/VBox/Devices/Storage/VBoxHDD-newInternal.h
r2380 r2564 45 45 46 46 /** 47 * Create a disk image. 48 * 49 * @returns VBox status code. 50 * @param pszFilename Name of the image file to create. Guaranteed to be available and 51 * unchanged during the lifetime of this image. 52 * @param penmType Image type. Both base and diff image types are valid. 53 * @param cbSize Image size in bytes. 54 * @param uImageFlags Flags specifying special image features. 55 * @param pszComment Pointer to image comment. NULL is ok. 56 * @param uOpenFlags Image file open mode, see VD_OPEN_FLAGS_* constants. 57 * @param pfnProgress Progress callback. Optional. NULL if not to be used. 58 * @param pvUser User argument for the progress callback. 59 * @param pfnError Callback for setting extended error information. 60 * @param pvErrorUser Opaque parameter for pfnError. 61 * @param ppvBackendData Opaque state data for this image. 62 */ 63 DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, VDIMAGETYPE penmType, uint64_t cbSize, unsigned uImageFlags, const char *pszComment, unsigned uOpenFlags, PFNVMPROGRESS pfnProgress, void *pvUser, PFNVDERROR pfnError, void *pvErrorUser, void **ppvBackendData)); 64 65 /** 47 66 * Close a disk image. 48 67 * … … 107 126 * @returns VBox status code. 108 127 * @param pvBackendData Opaque state data for this image. 109 * @param penm ImageTypeImage type of this image.110 */ 111 DECLR3CALLBACKMEMBER(int, pfnGetImageType, (void *pvBackendData, PVDIMAGETYPE penm ImageType));128 * @param penmType Image type of this image. 129 */ 130 DECLR3CALLBACKMEMBER(int, pfnGetImageType, (void *pvBackendData, PVDIMAGETYPE penmType)); 112 131 113 132 /** -
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r2385 r2564 1965 1965 } 1966 1966 1967 static int vmdkCreate(const char *pszFilename, VDIMAGETYPE penmType, 1968 uint64_t cbSize, unsigned uImageFlags, 1969 const char *pszComment, unsigned uOpenFlags, 1970 PFNVMPROGRESS pfnProgress, void *pvUser, 1971 PFNVDERROR pfnError, void *pvErrorUser, 1972 void **ppvBackendData) 1973 { 1974 return VERR_NOT_IMPLEMENTED; 1975 } 1976 1967 1977 static int vmdkClose(void *pBackendData) 1968 1978 { … … 1983 1993 PVMDKIMAGE pImage = (PVMDKIMAGE)pBackendData; 1984 1994 PVMDKEXTENT pExtent; 1985 uint64_t uSector InExtent;1986 uint64_t uSector Offset;1995 uint64_t uSectorExtentRel; 1996 uint64_t uSectorExtentAbs; 1987 1997 int rc; 1988 1998 … … 1997 2007 1998 2008 rc = vmdkFindExtent(pImage, VMDK_BYTE2SECTOR(uOffset), 1999 &pExtent, &uSector InExtent);2009 &pExtent, &uSectorExtentRel); 2000 2010 if (VBOX_FAILURE(rc)) 2001 2011 goto out; … … 2009 2019 2010 2020 /* Clip read range to remain in this extent. */ 2011 cbRead = RT_MIN(cbRead, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSector InExtent));2021 cbRead = RT_MIN(cbRead, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSectorExtentRel)); 2012 2022 2013 2023 /* Handle the read according to the current extent type. */ … … 2018 2028 case VMDKETYPE_ESX_SPARSE: 2019 2029 #endif /* VBOX_WITH_VMDK_ESX */ 2020 rc = vmdkGetSector(pImage->pGTCache, pExtent, uSector InExtent,2021 &uSector Offset);2030 rc = vmdkGetSector(pImage->pGTCache, pExtent, uSectorExtentRel, 2031 &uSectorExtentAbs); 2022 2032 if (VBOX_FAILURE(rc)) 2023 2033 goto out; 2024 2034 /* Clip read range to at most the rest of the grain. */ 2025 cbRead = RT_MIN(cbRead, VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain - (uSectorOffset % pExtent->cSectorsPerGrain))); 2026 if (uSectorOffset == 0) 2035 cbRead = RT_MIN(cbRead, VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain - uSectorExtentRel % pExtent->cSectorsPerGrain)); 2036 Assert(!(cbRead % 512)); 2037 if (uSectorExtentAbs == 0) 2027 2038 rc = VINF_VDI_BLOCK_FREE; 2028 2039 else 2029 2040 rc = RTFileReadAt(pExtent->File, 2030 VMDK_SECTOR2BYTE(uSector Offset),2041 VMDK_SECTOR2BYTE(uSectorExtentAbs), 2031 2042 pvBuf, cbRead, NULL); 2032 2043 break; 2033 2044 case VMDKETYPE_FLAT: 2034 rc = RTFileReadAt(pExtent->File, VMDK_SECTOR2BYTE(uSector InExtent),2045 rc = RTFileReadAt(pExtent->File, VMDK_SECTOR2BYTE(uSectorExtentRel), 2035 2046 pvBuf, cbRead, NULL); 2036 2047 break; … … 2049 2060 PVMDKIMAGE pImage = (PVMDKIMAGE)pBackendData; 2050 2061 PVMDKEXTENT pExtent; 2051 uint64_t uSector InExtent;2052 uint64_t uSector Offset;2062 uint64_t uSectorExtentRel; 2063 uint64_t uSectorExtentAbs; 2053 2064 int rc; 2054 2065 … … 2070 2081 2071 2082 rc = vmdkFindExtent(pImage, VMDK_BYTE2SECTOR(uOffset), 2072 &pExtent, &uSector InExtent);2083 &pExtent, &uSectorExtentRel); 2073 2084 if (VBOX_FAILURE(rc)) 2074 2085 goto out; … … 2080 2091 goto out; 2081 2092 } 2093 2094 /** @todo implement suppressing of zero data writes (a bit tricky in this 2095 * case, as VMDK has no marker for zero blocks). We somehow need to get the 2096 * information whether the information in this area is all zeroes as of the 2097 * parent image. Then (based on the assumption that parent images are 2098 * immutable) the write can be ignored. */ 2082 2099 2083 2100 /* Handle the write according to the current extent type. */ … … 2088 2105 case VMDKETYPE_ESX_SPARSE: 2089 2106 #endif /* VBOX_WITH_VMDK_ESX */ 2090 rc = vmdkGetSector(pImage->pGTCache, pExtent, uSector InExtent,2091 &uSector Offset);2107 rc = vmdkGetSector(pImage->pGTCache, pExtent, uSectorExtentRel, 2108 &uSectorExtentAbs); 2092 2109 if (VBOX_FAILURE(rc)) 2093 2110 goto out; 2094 2111 /* Clip write range to at most the rest of the grain. */ 2095 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain - (uSectorOffset % pExtent->cSectorsPerGrain)));2096 if (uSector Offset== 0)2112 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain - uSectorExtentRel % pExtent->cSectorsPerGrain)); 2113 if (uSectorExtentAbs == 0) 2097 2114 { 2098 2115 if (cbWrite == VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain)) … … 2101 2118 * Allocate GT and find out where to store the grain. */ 2102 2119 rc = vmdkAllocGrain(pImage->pGTCache, pExtent, 2103 uSector InExtent, pvBuf, cbWrite);2120 uSectorExtentRel, pvBuf, cbWrite); 2104 2121 } 2105 2122 else 2106 2123 { 2107 2124 /* Clip write range to remain in this extent. */ 2108 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSector InExtent));2109 *pcbPreRead = VMDK_SECTOR2BYTE(uSector InExtent% pExtent->cSectorsPerGrain);2125 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSectorExtentRel)); 2126 *pcbPreRead = VMDK_SECTOR2BYTE(uSectorExtentRel % pExtent->cSectorsPerGrain); 2110 2127 *pcbPostRead = VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain) - cbWrite - *pcbPreRead; 2111 2128 rc = VINF_VDI_BLOCK_FREE; … … 2114 2131 else 2115 2132 rc = RTFileWriteAt(pExtent->File, 2116 VMDK_SECTOR2BYTE(uSector Offset),2133 VMDK_SECTOR2BYTE(uSectorExtentAbs), 2117 2134 pvBuf, cbWrite, NULL); 2118 2135 break; 2119 2136 case VMDKETYPE_FLAT: 2120 2137 /* Clip write range to remain in this extent. */ 2121 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSector InExtent));2122 rc = RTFileWriteAt(pExtent->File, VMDK_SECTOR2BYTE(uSector InExtent), pvBuf, cbWrite, NULL);2138 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSectorExtentRel)); 2139 rc = RTFileWriteAt(pExtent->File, VMDK_SECTOR2BYTE(uSectorExtentRel), pvBuf, cbWrite, NULL); 2123 2140 break; 2124 2141 case VMDKETYPE_ZERO: 2125 2142 /* Clip write range to remain in this extent. */ 2126 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSector InExtent));2143 cbWrite = RT_MIN(cbWrite, VMDK_SECTOR2BYTE(pExtent->cNominalSectors - uSectorExtentRel)); 2127 2144 break; 2128 2145 } … … 2448 2465 /* pfnOpen */ 2449 2466 vmdkOpen, 2467 /* pfnCreate */ 2468 vmdkCreate, 2450 2469 /* pfnClose */ 2451 2470 vmdkClose,
Note:
See TracChangeset
for help on using the changeset viewer.