VirtualBox

Changeset 41549 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Jun 1, 2012 5:29:05 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78314
Message:

VFS/Filesystem: Convert the filesystem specific code to the VFS framework and make it work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTFilesystem.cpp

    r40029 r41549  
    3030*******************************************************************************/
    3131#include <iprt/filesystem.h>
    32 
     32#include <iprt/vfs.h>
    3333#include <iprt/err.h>
    3434#include <iprt/test.h>
     
    4141*******************************************************************************/
    4242
    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)
     43static int tstRTFilesystem(RTTEST hTest, RTVFSFILE hVfsFile)
    5844{
    5945    int rc = VINF_SUCCESS;
     46    RTVFS hVfs = NIL_RTVFS;
    6047
    6148    RTTestSubF(hTest, "Create filesystem object");
    62     RTFILESYSTEM hFs;
    63     rc = RTFilesystemOpen(&hFs, filesystemDiskRead, filesystemDiskWrite, cb, 512, hFile, 0 /* fFlags */);
     49
     50    rc = RTFilesystemVfsFromFile(hVfsFile, &hVfs);
    6451    if (RT_FAILURE(rc))
    6552    {
    66         RTTestIFailed("RTFilesystemOpen -> %Rrc", rc);
     53        RTTestIFailed("RTFilesystemVfsFromFile -> %Rrc", rc);
    6754        return rc;
    6855    }
    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));
    7456
    7557    /* Check all blocks. */
     
    7759    uint32_t cBlocksUsed = 0;
    7860    uint32_t cBlocksUnused = 0;
     61    uint64_t cbFs = 0;
    7962
    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)
    8171    {
    8272        bool fUsed = false;
    8373
    84         rc = RTFilesystemQueryRangeUse(hFs, off, 1024, &fUsed);
     74        rc = RTVfsIsRangeInUse(hVfs, off, 1024, &fUsed);
    8575        if (RT_FAILURE(rc))
    8676        {
    87             RTTestIFailed("RTFileSysQueryRangeUse -> %Rrc", rc);
     77            RTTestIFailed("RTVfsIsRangeInUse -> %Rrc", rc);
    8878            break;
    8979        }
     
    10191                      cBlocksUsed, cBlocksUnused);
    10292
    103     RTFilesystemRelease(hFs);
     93    RTVfsRelease(hVfs);
    10494
    10595    return rc;
     
    128118    /* Open image. */
    129119    RTFILE hFile;
    130     uint64_t cb = 0;
     120    RTVFSFILE hVfsFile;
    131121    rc = RTFileOpen(&hFile, argv[1], RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_READ);
    132122    if (RT_FAILURE(rc))
     
    136126    }
    137127
    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))
    141130    {
    142         RTTestIFailed("RTFileGetSize -> %Rrc", rc);
     131        RTTestIFailed("RTVfsFileFromRTFile -> %Rrc", rc);
    143132        return RTTestSummaryAndDestroy(hTest);
    144133    }
    145134
    146     rc = tstRTFilesystem(hTest, hFile, cb);
     135    rc = tstRTFilesystem(hTest, hVfsFile);
    147136
    148137    RTTESTI_CHECK(rc == VINF_SUCCESS);
     138
     139    RTVfsFileRelease(hVfsFile);
    149140
    150141    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette