- Timestamp:
- May 16, 2007 11:48:06 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 21207
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r2650 r2661 295 295 /** Image type. */ 296 296 VDIMAGETYPE enmImageType; 297 /** Image flags defined during creation or determined during open. */ 298 unsigned uImageFlags; 297 299 /** Total size of the image. */ 298 300 uint64_t cbSize; … … 478 480 size_t cbGTRounded; 479 481 uint64_t cbOverhead; 480 482 481 483 if (fPreAlloc) 482 484 cbGTRounded = RT_ALIGN_64(pExtent->cGDEntries * pExtent->cGTEntries * sizeof(uint32_t), 512); … … 587 589 } 588 590 589 static int vmdkDescInitStr(PVMDKIMAGE pImage, PVMDKDESCRIPTOR pDescriptor, 591 static int vmdkDescInitStr(PVMDKIMAGE pImage, PVMDKDESCRIPTOR pDescriptor, 590 592 const char *pszLine) 591 593 { … … 1044 1046 if (VBOX_FAILURE(rc)) 1045 1047 goto out; 1046 rc = vmdkDescInitStr(pImage, pDescriptor, "# 1048 rc = vmdkDescInitStr(pImage, pDescriptor, "#DDB"); 1047 1049 if (VBOX_FAILURE(rc)) 1048 1050 goto out; … … 1566 1568 RTFileClose(pExtent->File); 1567 1569 pExtent->File = NIL_RTFILE; 1568 if (fDelete && pExtent->pszFullname) 1570 if ( fDelete 1571 && strcmp(pExtent->pszFullname, pExtent->pszBasename) != 0 1572 && pExtent->pszFullname) 1569 1573 RTFileDelete(pExtent->pszFullname); 1570 1574 } … … 1663 1667 goto out; 1664 1668 } 1669 1670 /** @todo set up pImage->uImageFlags accordingly somewhere during open. */ 1665 1671 1666 1672 /* Handle the file according to its magic number. */ … … 1884 1890 } 1885 1891 1886 static int vmdkCreateImage(PVMDKIMAGE pImage, const char *pszFilename, VDIMAGETYPE enmType, uint64_t cbSize, unsigned uImageFlags, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors)1892 static int vmdkCreateImage(PVMDKIMAGE pImage, const char *pszFilename, VDIMAGETYPE enmType, uint64_t cbSize, unsigned uImageFlags, const char *pszComment, uint32_t cCylinders, uint32_t cHeads, uint32_t cSectors) 1887 1893 { 1888 1894 int rc; … … 1890 1896 PVMDKEXTENT pExtent; 1891 1897 1898 pImage->uImageFlags = uImageFlags; 1892 1899 rc = vmdkCreateDescriptor(pImage, pImage->pDescData, pImage->cbDescAlloc, &pImage->Descriptor); 1893 1900 if (VBOX_FAILURE(rc)) … … 1898 1905 1899 1906 if ( enmType == VD_IMAGE_TYPE_FIXED 1900 || uImageFlags == VD_VMDK_IMAGE_FLAGS_SPLIT_2G) 1907 || (uImageFlags & VD_VMDK_IMAGE_FLAGS_SPLIT_2G) 1908 || (uImageFlags & VD_VMDK_IMAGE_FLAGS_RAWDISK)) 1901 1909 { 1902 1910 /* Fixed images and split images in general have a separate descriptor 1903 1911 * file. This is the more complicated case, as it requires setting up 1904 1912 * potentially more than one extent, including filename generation. */ 1905 rc = VERR_NOT_IMPLEMENTED; 1906 goto out; 1913 1914 if ( enmType == VD_IMAGE_TYPE_FIXED 1915 && (uImageFlags & VD_VMDK_IMAGE_FLAGS_RAWDISK)) 1916 { 1917 PVBOXHDDRAW pRaw = (PVBOXHDDRAW)(void *)pszComment; 1918 if (pRaw->fRawDisk) 1919 { 1920 /* Full raw disk access. This requires setting up a descriptor 1921 * file and open the (flat) raw disk. */ 1922 rc = vmdkCreateExtents(pImage, 1); 1923 if (VBOX_FAILURE(rc)) 1924 { 1925 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new extent list in '%s'"), pszFilename); 1926 goto out; 1927 } 1928 pExtent = &pImage->pExtents[0]; 1929 rc = RTFileOpen(&pImage->File, pszFilename, 1930 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE); 1931 if (VBOX_FAILURE(rc)) 1932 { 1933 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pszFilename); 1934 goto out; 1935 } 1936 1937 /* Set up basename for extent description. Cannot use StrDup. */ 1938 size_t cbBasename = strlen(pRaw->pszRawDisk) + 1; 1939 char *pszBasename = (char *)RTMemTmpAlloc(cbBasename); 1940 if (!pszBasename) 1941 { 1942 rc = VERR_NO_MEMORY; 1943 goto out; 1944 } 1945 memcpy(pszBasename, pRaw->pszRawDisk, cbBasename); 1946 pExtent->pszBasename = pszBasename; 1947 /* For raw disks the full name is identical to the base name. */ 1948 pExtent->pszFullname = RTStrDup(pszBasename); 1949 if (!pExtent->pszFullname) 1950 { 1951 rc = VERR_NO_MEMORY; 1952 goto out; 1953 } 1954 pExtent->enmType = VMDKETYPE_FLAT; 1955 pExtent->cNominalSectors = VMDK_BYTE2SECTOR(cbSize); 1956 pExtent->uSectorOffset = 0; 1957 pExtent->enmAccess = VMDKACCESS_READWRITE; 1958 pExtent->fMetaDirty = true; 1959 1960 pImage->enmImageType = enmType; 1961 rc = vmdkDescSetStr(pImage, &pImage->Descriptor, pImage->Descriptor.uFirstDesc, "createType", "\"fullDevice\""); 1962 if (VBOX_FAILURE(rc)) 1963 { 1964 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not set the image type in '%s'"), pszFilename); 1965 goto out; 1966 } 1967 1968 /* Open flat image, the raw disk. */ 1969 rc = RTFileOpen(&pExtent->File, pExtent->pszFullname, 1970 RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 1971 if (VBOX_FAILURE(rc)) 1972 { 1973 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not open raw disk file '%s'"), pExtent->pszFullname); 1974 goto out; 1975 } 1976 } 1977 else 1978 { 1979 /******* fixme. */ 1980 rc = VERR_NOT_IMPLEMENTED; 1981 goto out; 1982 } 1983 } 1984 else 1985 { 1986 rc = VERR_NOT_IMPLEMENTED; 1987 goto out; 1988 } 1907 1989 } 1908 1990 else … … 1917 1999 pExtent = &pImage->pExtents[0]; 1918 2000 pImage->File = NIL_RTFILE; 1919 rc = RTFileOpen(&pExtent->File, pszFilename, 2001 rc = RTFileOpen(&pExtent->File, pszFilename, 1920 2002 RTFILE_O_READWRITE | RTFILE_O_CREATE | RTFILE_O_DENY_WRITE); 1921 2003 if (VBOX_FAILURE(rc)) … … 2468 2550 2469 2551 rc = vmdkCreateImage(pImage, pszFilename, enmType, cbSize, uImageFlags, 2470 cCylinders, cHeads, cSectors);2552 pszComment, cCylinders, cHeads, cSectors); 2471 2553 if (VBOX_SUCCESS(rc)) 2472 2554 {
Note:
See TracChangeset
for help on using the changeset viewer.