Changeset 41549 in vbox for trunk/src/VBox/Runtime/testcase
- Timestamp:
- Jun 1, 2012 5:29:05 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 78314
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/tstRTFilesystem.cpp
r40029 r41549 30 30 *******************************************************************************/ 31 31 #include <iprt/filesystem.h> 32 32 #include <iprt/vfs.h> 33 33 #include <iprt/err.h> 34 34 #include <iprt/test.h> … … 41 41 *******************************************************************************/ 42 42 43 static int filesystemDiskRead(void *pvUser, uint64_t off, void *pvBuf, size_t cbRead) 44 { 45 RTFILE hFile = (RTFILE)pvUser; 46 47 return RTFileReadAt(hFile, off, pvBuf, cbRead, NULL); 48 } 49 50 static int filesystemDiskWrite(void *pvUser, uint64_t off, const void *pvBuf, size_t cbWrite) 51 { 52 RTFILE hFile = (RTFILE)pvUser; 53 54 return RTFileWriteAt(hFile, off, pvBuf, cbWrite, NULL); 55 } 56 57 static int tstRTFilesystem(RTTEST hTest, RTFILE hFile, uint64_t cb) 43 static int tstRTFilesystem(RTTEST hTest, RTVFSFILE hVfsFile) 58 44 { 59 45 int rc = VINF_SUCCESS; 46 RTVFS hVfs = NIL_RTVFS; 60 47 61 48 RTTestSubF(hTest, "Create filesystem object"); 62 RTFILESYSTEM hFs; 63 rc = RTFilesystem Open(&hFs, filesystemDiskRead, filesystemDiskWrite, cb, 512, hFile, 0 /* fFlags */);49 50 rc = RTFilesystemVfsFromFile(hVfsFile, &hVfs); 64 51 if (RT_FAILURE(rc)) 65 52 { 66 RTTestIFailed("RTFilesystem Open-> %Rrc", rc);53 RTTestIFailed("RTFilesystemVfsFromFile -> %Rrc", rc); 67 54 return rc; 68 55 } 69 70 RTTestIPrintf(RTTESTLVL_ALWAYS, "Successfully opened filesystem with format: %s.\n",71 RTFilesystemGetFormat(hFs));72 RTTestIPrintf(RTTESTLVL_ALWAYS, "Block size is: %llu.\n",73 RTFilesystemGetBlockSize(hFs));74 56 75 57 /* Check all blocks. */ … … 77 59 uint32_t cBlocksUsed = 0; 78 60 uint32_t cBlocksUnused = 0; 61 uint64_t cbFs = 0; 79 62 80 while (off < cb) 63 rc = RTVfsFileGetSize(hVfsFile, &cbFs); 64 if (RT_FAILURE(rc)) 65 { 66 RTTestIFailed("RTVfsFileGetSize -> %Rrc", rc); 67 return rc; 68 } 69 70 while (off < cbFs) 81 71 { 82 72 bool fUsed = false; 83 73 84 rc = RT FilesystemQueryRangeUse(hFs, off, 1024, &fUsed);74 rc = RTVfsIsRangeInUse(hVfs, off, 1024, &fUsed); 85 75 if (RT_FAILURE(rc)) 86 76 { 87 RTTestIFailed("RT FileSysQueryRangeUse -> %Rrc", rc);77 RTTestIFailed("RTVfsIsRangeInUse -> %Rrc", rc); 88 78 break; 89 79 } … … 101 91 cBlocksUsed, cBlocksUnused); 102 92 103 RT FilesystemRelease(hFs);93 RTVfsRelease(hVfs); 104 94 105 95 return rc; … … 128 118 /* Open image. */ 129 119 RTFILE hFile; 130 uint64_t cb = 0;120 RTVFSFILE hVfsFile; 131 121 rc = RTFileOpen(&hFile, argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ); 132 122 if (RT_FAILURE(rc)) … … 136 126 } 137 127 138 rc = RTFileGetSize(hFile, &cb); 139 if ( RT_FAILURE(rc) 140 || cb % 512 != 0) /* Assume 512 byte sector size. */ 128 rc = RTVfsFileFromRTFile(hFile, 0, false, &hVfsFile); 129 if (RT_FAILURE(rc)) 141 130 { 142 RTTestIFailed("RT FileGetSize -> %Rrc", rc);131 RTTestIFailed("RTVfsFileFromRTFile -> %Rrc", rc); 143 132 return RTTestSummaryAndDestroy(hTest); 144 133 } 145 134 146 rc = tstRTFilesystem(hTest, h File, cb);135 rc = tstRTFilesystem(hTest, hVfsFile); 147 136 148 137 RTTESTI_CHECK(rc == VINF_SUCCESS); 138 139 RTVfsFileRelease(hVfsFile); 149 140 150 141 /*
Note:
See TracChangeset
for help on using the changeset viewer.