儲存庫 vbox 的更動 37270
- 時間撮記:
- 2011-5-30 下午09:25:42 (13 年 以前)
- 位置:
- trunk/src/VBox/Runtime
- 檔案:
-
- 新增 1 筆資料
- 修改 4 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/Makefile.kmk
r37254 r37270 279 279 common/dbg/dbgmodnm.cpp \ 280 280 common/dvm/dvm.cpp \ 281 common/dvm/dvmbsdlabel.cpp \ 281 282 common/dvm/dvmgpt.cpp \ 282 283 common/dvm/dvmmbr.cpp \ -
trunk/src/VBox/Runtime/common/dvm/dvm.cpp
r37024 r37270 83 83 extern RTDVMFMTOPS g_rtDvmFmtMbr; 84 84 extern RTDVMFMTOPS g_rtDvmFmtGpt; 85 extern RTDVMFMTOPS g_rtDvmFmtBsdLbl; 85 86 86 87 /** … … 90 91 { 91 92 &g_rtDvmFmtMbr, 92 &g_rtDvmFmtGpt 93 &g_rtDvmFmtGpt, 94 &g_rtDvmFmtBsdLbl 93 95 }; 94 96 … … 233 235 } 234 236 else 235 rc = VERR_NOT_ FOUND;237 rc = VERR_NOT_SUPPORTED; 236 238 } 237 239 -
trunk/src/VBox/Runtime/include/internal/dvm.h
r37024 r37270 227 227 typedef const RTDVMFMTOPS *PCRTDVMFMTOPS; 228 228 229 /** Converts a LBA number to the byte offset. */ 230 #define RTDVM_LBA2BYTE(lba, disk) ((lba) * (disk)->cbSector) 231 /** Converts a Byte offset to the LBA number. */ 232 #define RTDVM_BYTE2LBA(off, disk) ((off) / (disk)->cbSector) 233 229 234 /** 230 235 * Returns the number of sectors in the disk. -
trunk/src/VBox/Runtime/testcase/tstRTDvm.cpp
r36816 r37270 34 34 #include <iprt/dvm.h> 35 35 #include <iprt/file.h> 36 37 RTFILE g_hDisk = NIL_RTFILE; /**< The disk image. */ 38 uint64_t g_cbDisk = 0; /**< Size of the image. */ 36 #include <iprt/string.h> 37 38 /** 39 * Disk structure. 40 */ 41 typedef struct TSTRTDVMDISK 42 { 43 /** Flag whether this disk uses the image file or a volume. */ 44 bool fUseImage; 45 /** Data dependent on the flag. */ 46 union 47 { 48 /** File handle of the image. */ 49 RTFILE hImage; 50 /** Handle of the volume. */ 51 RTDVMVOLUME hVol; 52 }; 53 } TSTRTDVMDISK, *PTSTRTDVMDISK; 39 54 40 55 static int dvmDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) 41 56 { 42 return RTFileReadAt(g_hDisk, off, pvBuf, cbRead, NULL); 57 PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; 58 59 if (pDisk->fUseImage) 60 return RTFileReadAt(pDisk->hImage, off, pvBuf, cbRead, NULL); 61 else 62 return RTDvmVolumeRead(pDisk->hVol, off, pvBuf, cbRead); 43 63 } 44 64 45 65 static int dvmDiskWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite) 46 66 { 47 return RTFileWriteAt(g_hDisk, off, pvBuf, cbWrite, NULL); 67 PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; 68 69 if (pDisk->fUseImage) 70 return RTFileWriteAt(pDisk->hImage, off, pvBuf, cbWrite, NULL); 71 else 72 return RTDvmVolumeWrite(pDisk->hVol, off, pvBuf, cbWrite); 73 } 74 75 static int tstRTDvmVolume(RTTEST hTest, PTSTRTDVMDISK pDisk, uint64_t cb, unsigned cNesting) 76 { 77 char szPrefix[100]; 78 int rc = VINF_SUCCESS; 79 80 memset(szPrefix, 0, sizeof(szPrefix)); 81 82 if (cNesting < sizeof(szPrefix) - 1) 83 { 84 for (unsigned i = 0; i < cNesting; i++) 85 szPrefix[i] = '\t'; 86 } 87 88 RTTestSubF(hTest, "Create DVM"); 89 RTDVM hVolMgr; 90 rc = RTDvmCreate(&hVolMgr, dvmDiskRead, dvmDiskWrite, cb, 512, pDisk); 91 if (RT_FAILURE(rc)) 92 { 93 RTTestIFailed("RTDvmCreate -> %Rrc", rc); 94 return RTTestSummaryAndDestroy(hTest); 95 } 96 97 RTTestSubF(hTest, "Open volume map"); 98 rc = RTDvmMapOpen(hVolMgr); 99 if ( RT_FAILURE(rc) 100 && rc != VERR_NOT_SUPPORTED) 101 { 102 RTTestIFailed("RTDvmOpen -> %Rrc", rc); 103 return RTTestSummaryAndDestroy(hTest); 104 } 105 else if (rc == VERR_NOT_SUPPORTED) 106 return VINF_SUCCESS; 107 108 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Successfully opened map with format: %s.\n", szPrefix, RTDvmMapGetFormat(hVolMgr)); 109 110 /* Dump all volumes. */ 111 RTTestSubF(hTest, "Dump volumes"); 112 uint32_t cVolume = 0; 113 RTDVMVOLUME hVol; 114 115 rc = RTDvmMapQueryFirstVolume(hVolMgr, &hVol); 116 117 while (RT_SUCCESS(rc)) 118 { 119 char *pszVolName = NULL; 120 RTDVMVOLTYPE enmVolType = RTDvmVolumeGetType(hVol); 121 uint64_t fVolFlags = RTDvmVolumeGetFlags(hVol); 122 123 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Volume %u:\n", szPrefix, cVolume); 124 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Volume type %s\n", szPrefix, RTDvmVolumeTypeGetDescr(enmVolType)); 125 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Volume size %llu\n", szPrefix, RTDvmVolumeGetSize(hVol)); 126 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Volume flags %s %s\n\n", szPrefix, 127 fVolFlags & DVMVOLUME_FLAGS_BOOTABLE ? "Bootable" : "", 128 fVolFlags & DVMVOLUME_FLAGS_ACTIVE ? "Active" : ""); 129 130 rc = RTDvmVolumeQueryName(hVol, &pszVolName); 131 if (RT_SUCCESS(rc)) 132 { 133 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Volume name %s.\n", szPrefix, pszVolName); 134 RTStrFree(pszVolName); 135 } 136 else if (rc != VERR_NOT_SUPPORTED) 137 RTTestIFailed("RTDvmVolumeQueryName -> %Rrc", rc); 138 else 139 rc = VINF_SUCCESS; 140 141 /* 142 * Query all volumes which might be inside this. 143 * (think of MBR partitions with a bsdlabel inside) 144 */ 145 TSTRTDVMDISK Disk; 146 Disk.fUseImage = false; 147 Disk.hVol = hVol; 148 rc = tstRTDvmVolume(hTest, &Disk, RTDvmVolumeGetSize(hVol), cNesting + 1); 149 150 RTDVMVOLUME hVolNext; 151 rc = RTDvmMapQueryNextVolume(hVolMgr, hVol, &hVolNext); 152 RTDvmVolumeRelease(hVol); 153 hVol = hVolNext; 154 cVolume++; 155 } 156 157 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Dumped %u volumes\n", szPrefix, cVolume); 158 159 if ( rc == VERR_DVM_MAP_EMPTY 160 || rc == VERR_DVM_MAP_NO_VOLUME) 161 rc = VINF_SUCCESS; 162 163 RTTESTI_CHECK(rc == VINF_SUCCESS); 164 165 RTDvmRelease(hVolMgr); 166 167 return rc; 48 168 } 49 169 … … 69 189 70 190 /* Open image. */ 71 rc = RTFileOpen(&g_hDisk, argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE); 191 RTFILE hFile; 192 uint64_t cb = 0; 193 rc = RTFileOpen(&hFile, argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE); 72 194 if (RT_FAILURE(rc)) 73 195 { … … 76 198 } 77 199 78 rc = RTFileGetSize( g_hDisk, &g_cbDisk);200 rc = RTFileGetSize(hFile, &cb); 79 201 if ( RT_FAILURE(rc) 80 || g_cbDisk% 512 != 0) /* Assume 512 byte sector size. */202 || cb % 512 != 0) /* Assume 512 byte sector size. */ 81 203 { 82 204 RTTestIFailed("RTFileGetSize -> %Rrc", rc); … … 84 206 } 85 207 86 RTTestSubF(hTest, "Create DVM"); 87 RTDVM hVolMgr; 88 rc = RTDvmCreate(&hVolMgr, dvmDiskRead, dvmDiskWrite, g_cbDisk, 512, NULL); 89 if (RT_FAILURE(rc)) 90 { 91 RTTestIFailed("RTDvmCreate -> %Rrc", rc); 92 return RTTestSummaryAndDestroy(hTest); 93 } 94 95 RTTestSubF(hTest, "Open volume map"); 96 rc = RTDvmMapOpen(hVolMgr); 97 if (RT_FAILURE(rc)) 98 { 99 RTTestIFailed("RTDvmOpen -> %Rrc", rc); 100 return RTTestSummaryAndDestroy(hTest); 101 } 102 103 RTTestIPrintf(RTTESTLVL_ALWAYS, " Successfully opened map with format: %s.\n", RTDvmMapGetFormat(hVolMgr)); 104 105 /* Dump all volumes. */ 106 RTTestSubF(hTest, "Dump volumes"); 107 uint32_t cVolume = 0; 108 RTDVMVOLUME hVol; 109 110 rc = RTDvmMapQueryFirstVolume(hVolMgr, &hVol); 111 112 while (RT_SUCCESS(rc)) 113 { 114 RTDVMVOLTYPE enmVolType = RTDvmVolumeGetType(hVol); 115 uint64_t fVolFlags = RTDvmVolumeGetFlags(hVol); 116 117 RTTestIPrintf(RTTESTLVL_ALWAYS, " Volume %u:\n", cVolume); 118 RTTestIPrintf(RTTESTLVL_ALWAYS, " Volume type %s.\n", RTDvmVolumeTypeGetDescr(enmVolType)); 119 RTTestIPrintf(RTTESTLVL_ALWAYS, " Volume size %llu.\n", RTDvmVolumeGetSize(hVol)); 120 RTTestIPrintf(RTTESTLVL_ALWAYS, " Volume flags %s %s.\n\n", 121 fVolFlags & DVMVOLUME_FLAGS_BOOTABLE ? "Bootable" : "", 122 fVolFlags & DVMVOLUME_FLAGS_ACTIVE ? "Active" : ""); 123 124 RTDVMVOLUME hVolNext; 125 rc = RTDvmMapQueryNextVolume(hVolMgr, hVol, &hVolNext); 126 RTDvmVolumeRelease(hVol); 127 hVol = hVolNext; 128 cVolume++; 129 } 130 131 RTTestIPrintf(RTTESTLVL_ALWAYS, " Dumped %u volumes\n", cVolume); 132 133 if ( rc == VERR_DVM_MAP_EMPTY 134 || rc == VERR_DVM_MAP_NO_VOLUME) 135 rc = VINF_SUCCESS; 208 TSTRTDVMDISK Disk; 209 210 Disk.fUseImage = true; 211 Disk.hImage = hFile; 212 rc = tstRTDvmVolume(hTest, &Disk, cb, 0); 136 213 137 214 RTTESTI_CHECK(rc == VINF_SUCCESS); 138 139 RTDvmRelease(hVolMgr);140 215 141 216 /*
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器