VirtualBox

Changeset 69840 in vbox for trunk/src/VBox/Storage/testcase


Ignore:
Timestamp:
Nov 27, 2017 3:19:30 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119281
Message:

IPRT: VFS volume mouning cleanup, replacing RTFilesystemVfsFromFile with RTVfsMountVol.

  • RTVfsMountVol will do basic file system recognizion and call the right file system volume open API.
  • Moved ext2 definitions to iprt/formats/ext2.h, dropping unnecessary pragma pack(1) and adjusted names.
  • Added RTFsExt2VolOpen.
  • Removed iprt/filesystem.h.
  • Removed include/internal/filesystem.h.
  • Nothing has been tested yet! :-)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/testcase/vbox-img.cpp

    r69616 r69840  
    3636#include <iprt/assert.h>
    3737#include <iprt/dvm.h>
    38 #include <iprt/filesystem.h>
    3938#include <iprt/vfs.h>
    4039
     
    13601359static int handleCompact(HandlerArg *a)
    13611360{
    1362     int rc = VINF_SUCCESS;
    13631361    PVDISK pDisk = NULL;
    1364     const char *pszFilename = NULL;
    1365     bool fFilesystemAware = false;
    13661362    VDINTERFACEQUERYRANGEUSE VDIfQueryRangeUse;
    13671363    PVDINTERFACE pIfsCompact = NULL;
     
    13721368    static const RTGETOPTDEF s_aOptions[] =
    13731369    {
    1374         { "--filename",        'f', RTGETOPT_REQ_STRING },
    1375         { "--filesystemaware", 'a', RTGETOPT_REQ_NOTHING }
     1370        { "--filename",          'f', RTGETOPT_REQ_STRING },
     1371        { "--filesystemaware",   'a', RTGETOPT_REQ_NOTHING },
     1372        { "--file-system-aware", 'a', RTGETOPT_REQ_NOTHING },
    13761373    };
     1374
     1375    const char *pszFilename      = NULL;
     1376    bool        fFilesystemAware = false;
     1377    bool        fVerbose         = true;
     1378
    13771379    int ch;
    13781380    RTGETOPTUNION ValueUnion;
     
    14051407    char *pszFormat = NULL;
    14061408    VDTYPE enmType = VDTYPE_INVALID;
    1407     rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);
     1409    int rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);
    14081410    if (RT_FAILURE(rc))
    14091411        return errorSyntax("Format autodetect failed: %Rrc\n", rc);
     
    14191421        return errorRuntime("Error while opening the image: %Rrf (%Rrc)\n", rc, rc);
    14201422
     1423    /*
     1424     * If --file-system-aware, we first ask the disk volume manager (DVM) to
     1425     * find the volumes on the disk.
     1426     */
    14211427    if (   RT_SUCCESS(rc)
    14221428        && fFilesystemAware)
     
    14341440                    && RTDvmMapGetValidVolumes(hDvm) > 0)
    14351441                {
    1436                     /* Get all volumes and set the block query status callback. */
     1442                    /*
     1443                     * Enumerate the volumes: Try finding a file system interpreter and
     1444                     * set the block query status callback to work with the FS.
     1445                     */
     1446                    uint32_t    iVol = 0;
    14371447                    RTDVMVOLUME hVol;
    14381448                    rc = RTDvmMapQueryFirstVolume(hDvm, &hVol);
     
    14411451                    while (RT_SUCCESS(rc))
    14421452                    {
     1453                        if (fVerbose)
     1454                        {
     1455                            char *pszVolName;
     1456                            rc = RTDvmVolumeQueryName(hVol, &pszVolName);
     1457                            if (RT_FAILURE(rc))
     1458                                pszVolName = NULL;
     1459                            RTMsgInfo("Vol%u: %Rhcb %u %s%s%s\n", iVol, RTDvmVolumeGetSize(hVol),
     1460                                      RTDvmVolumeTypeGetDescr(RTDvmVolumeGetType(hVol)),
     1461                                      pszVolName ? " " : "", pszVolName ? pszVolName : "");
     1462                            RTStrFree(pszVolName);
     1463                        }
     1464
    14431465                        RTVFSFILE hVfsFile;
    14441466                        rc = RTDvmVolumeCreateVfsFile(hVol, RTFILE_O_READWRITE, &hVfsFile);
    14451467                        if (RT_FAILURE(rc))
     1468                        {
     1469                            errorRuntime("RTDvmVolumeCreateVfsFile failed: %Rrc\n");
    14461470                            break;
     1471                        }
    14471472
    14481473                        /* Try to detect the filesystem in this volume. */
     1474                        RTERRINFOSTATIC ErrInfo;
    14491475                        RTVFS hVfs;
    1450                         rc = RTFilesystemVfsFromFile(hVfsFile, &hVfs);
    1451                         if (rc == VERR_NOT_SUPPORTED)
    1452                         {
    1453                             /* Release the file handle and continue.*/
    1454                             RTVfsFileRelease(hVfsFile);
    1455                         }
    1456                         else if (RT_FAILURE(rc))
    1457                             break;
    1458                         else
     1476                        rc = RTVfsMountVol(hVfsFile, RTVFSMNT_F_READ_ONLY | RTVFSMNT_F_FOR_RANGE_IN_USE, &hVfs,
     1477                                           RTErrInfoInitStatic(&ErrInfo));
     1478                        RTVfsFileRelease(hVfsFile);
     1479                        if (RT_SUCCESS(rc))
    14591480                        {
    14601481                            PVBOXIMGVFS pVBoxImgVfs = (PVBOXIMGVFS)RTMemAllocZ(sizeof(VBOXIMGVFS));
    14611482                            if (!pVBoxImgVfs)
     1483                            {
     1484                                RTVfsRelease(hVfs);
    14621485                                rc = VERR_NO_MEMORY;
    1463                             else
    1464                             {
    1465                                 pVBoxImgVfs->hVfs = hVfs;
    1466                                 pVBoxImgVfs->pNext = pVBoxImgVfsHead;
    1467                                 pVBoxImgVfsHead = pVBoxImgVfs;
    1468                                 RTDvmVolumeSetQueryBlockStatusCallback(hVol, vboximgQueryBlockStatus, hVfs);
     1486                                break;
    14691487                            }
     1488                            pVBoxImgVfs->hVfs = hVfs;
     1489                            pVBoxImgVfs->pNext = pVBoxImgVfsHead;
     1490                            pVBoxImgVfsHead = pVBoxImgVfs;
     1491                            RTDvmVolumeSetQueryBlockStatusCallback(hVol, vboximgQueryBlockStatus, hVfs);
    14701492                        }
    1471 
     1493                        else if (rc != VERR_NOT_SUPPORTED)
     1494                        {
     1495                            if (RTErrInfoIsSet(&ErrInfo.Core))
     1496                                errorRuntime("RTVfsMountVol failed: %s\n", ErrInfo.Core.pszMsg);
     1497                            break;
     1498                        }
     1499                        else if (fVerbose && RTErrInfoIsSet(&ErrInfo.Core))
     1500                            RTMsgInfo("Unsupported file system: %s", ErrInfo.Core.pszMsg);
     1501
     1502                        /*
     1503                         * Advance.  (Releasing hVol here is fine since RTDvmVolumeCreateVfsFile
     1504                         * retained a reference and the hVfs a reference of it again.)
     1505                         */
    14721506                        RTDVMVOLUME hVolNext = NIL_RTDVMVOLUME;
    14731507                        if (RT_SUCCESS(rc))
    14741508                            rc = RTDvmMapQueryNextVolume(hDvm, hVol, &hVolNext);
    1475 
    1476                         /*
    1477                          * Release the volume handle, the file handle has a reference
    1478                          * to keep it open.
    1479                          */
    14801509                        RTDvmVolumeRelease(hVol);
    14811510                        hVol = hVolNext;
     1511                        iVol++;
    14821512                    }
    14831513
     
    14961526                else if (rc == VERR_NOT_FOUND)
    14971527                {
     1528                    RTPrintf("No known volume format on disk found\n");
    14981529                    rc = VINF_SUCCESS;
    1499                     RTPrintf("No known volume format on disk found\n");
    15001530                }
    15011531                else
Note: See TracChangeset for help on using the changeset viewer.

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