Changeset 76905 in vbox
- Timestamp:
- Jan 20, 2019 7:49:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTDvm.cpp
r76553 r76905 35 35 #include <iprt/file.h> 36 36 #include <iprt/string.h> 37 #include <iprt/vfs.h> 37 38 38 39 … … 40 41 * Structures and Typedefs * 41 42 *********************************************************************************************************************************/ 42 /**43 * Disk structure.44 */45 typedef struct TSTRTDVMDISK46 {47 /** Flag whether this disk uses the image file or a volume. */48 bool fUseImage;49 /** Data dependent on the flag. */50 union51 {52 /** File handle of the image. */53 RTVFSFILE hImage;54 /** Handle of the volume. */55 RTDVMVOLUME hVol;56 };57 } TSTRTDVMDISK, *PTSTRTDVMDISK;58 43 59 44 60 #if 0 61 static DECLCALLBACK(int) dvmDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) 62 { 63 PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; 64 65 if (pDisk->fUseImage) 66 return RTFileReadAt(pDisk->hImage, off, pvBuf, cbRead, NULL); 67 return RTDvmVolumeRead(pDisk->hVol, off, pvBuf, cbRead); 68 } 69 70 static DECLCALLBACK(int) dvmDiskWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite) 71 { 72 PTSTRTDVMDISK pDisk = (PTSTRTDVMDISK)pvUser; 73 74 if (pDisk->fUseImage) 75 return RTFileWriteAt(pDisk->hImage, off, pvBuf, cbWrite, NULL); 76 return RTDvmVolumeWrite(pDisk->hVol, off, pvBuf, cbWrite); 77 } 78 79 static int tstRTDvmVolume(RTTEST hTest, PTSTRTDVMDISK pDisk, uint64_t cb, unsigned cNesting) 45 static int tstRTDvmVolume(RTTEST hTest, RTVFSFILE hVfsDisk, unsigned cNesting) 80 46 { 81 47 char szPrefix[100]; … … 92 58 RTTestSubF(hTest, "Create DVM"); 93 59 RTDVM hVolMgr; 94 rc = RTDvmCreate(&hVolMgr, dvmDiskRead, dvmDiskWrite, cb, 512, 0, pDisk);60 rc = RTDvmCreate(&hVolMgr, hVfsDisk, 512, 0 /*fFlags*/); 95 61 if (RT_FAILURE(rc)) 96 62 { … … 110 76 return VINF_SUCCESS; 111 77 112 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Successfully opened map with format: %s.\n", szPrefix, RTDvmMapGetFormat (hVolMgr));78 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s Successfully opened map with format: %s.\n", szPrefix, RTDvmMapGetFormatName(hVolMgr)); 113 79 114 80 /* Dump all volumes. */ … … 147 113 * (think of MBR partitions with a bsdlabel inside) 148 114 */ 149 TSTRTDVMDISK Disk; 150 Disk.fUseImage = false; 151 Disk.hVol = hVol; 152 rc = tstRTDvmVolume(hTest, &Disk, RTDvmVolumeGetSize(hVol), cNesting + 1); 115 RTVFSFILE hVfsVol; 116 rc = RTDvmVolumeCreateVfsFile(hVol, RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE, &hVfsVol); 117 if (RT_SUCCESS(rc)) 118 { 119 rc = tstRTDvmVolume(hTest, hVfsVol, cNesting + 1); 120 RTVfsFileRelease(hVfsVol); 121 } 122 else 123 RTTestIFailed("RTDvmVolumeCreateVfsFile -> %Rrc", rc); 153 124 154 125 RTDVMVOLUME hVolNext; … … 171 142 return rc; 172 143 } 173 #endif 144 174 145 175 146 int main(int argc, char **argv) … … 193 164 } 194 165 195 #if 1 196 RTTestFailed(hTest, "Needs updating to RTDvm API changes!"); 197 #else 198 /* Open image. */ 199 RTFILE hFile; 200 uint64_t cb = 0; 201 rc = RTFileOpen(&hFile, argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE); 166 RTVFSFILE hVfsDisk; 167 rc = RTVfsFileOpenNormal(argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READWRITE, &hVfsDisk); 202 168 if (RT_FAILURE(rc)) 203 169 { 204 RTTestIFailed("RT FileOpen-> %Rrc", rc);170 RTTestIFailed("RTVfsFileOpenNormal -> %Rrc", rc); 205 171 return RTTestSummaryAndDestroy(hTest); 206 172 } 207 173 208 rc = RTFileGetSize(hFile, &cb); 174 uint64_t cb = 0; 175 rc = RTVfsFileGetSize(hVfsDisk, &cb); 209 176 if ( RT_FAILURE(rc) 210 177 || cb % 512 != 0) /* Assume 512 byte sector size. */ 211 178 { 212 RTTestIFailed("RT FileGetSize -> %Rrc", rc);179 RTTestIFailed("RTVfsFileGetSize -> %Rrc", rc); 213 180 return RTTestSummaryAndDestroy(hTest); 214 181 } 215 182 216 TSTRTDVMDISK Disk; 217 218 Disk.fUseImage = true; 219 Disk.hImage = hFile; 220 rc = tstRTDvmVolume(hTest, &Disk, cb, 0); 183 rc = tstRTDvmVolume(hTest, hVfsDisk, 0); 221 184 222 185 RTTESTI_CHECK(rc == VINF_SUCCESS); … … 225 188 * Summary 226 189 */ 227 #endif228 190 return RTTestSummaryAndDestroy(hTest); 229 191 }
Note:
See TracChangeset
for help on using the changeset viewer.