VirtualBox

Changeset 77047 in vbox for trunk/src/VBox/Runtime/common/fs


Ignore:
Timestamp:
Jan 30, 2019 3:38:53 PM (6 years ago)
Author:
vboxsync
Message:

iprt/isomaker: Optimized native handle (file descriptor) usage when adding real directories.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/fs/isomakercmd.cpp

    r76553 r77047  
    17041704 * @param   cDepth              Number of recursions.  Used to deal with loopy
    17051705 *                              directories.
     1706 * @param   fFilesWithSrcPath   Whether to add files using @a pszSrc or to add
     1707 *                              as VFS handles (open first). For saving native
     1708 *                              file descriptors.
    17061709 */
    17071710static int rtFsIsoMakerCmdAddVfsDirRecursive(PRTFSISOMAKERCMDOPTS pOpts, RTVFSDIR hVfsDir, uint32_t idxDirObj,
    1708                                              char *pszSrc, size_t cchSrc, uint32_t fNamespaces, uint8_t cDepth)
     1711                                             char *pszSrc, size_t cchSrc, uint32_t fNamespaces, uint8_t cDepth,
     1712                                             bool fFilesWithSrcPath)
    17091713{
    17101714    /*
     
    17751779                {
    17761780                    /*
    1777                      * Files are added with VFS file sources.
    1778                      * The ASSUMPTION is that we're working with a virtual file system
    1779                      * here and won't be wasting native file descriptors.
     1781                     * Files are either added with VFS handles or paths to the sources,
     1782                     * depending on what's considered more efficient.  We prefer the latter
     1783                     * if hVfsDir maps to native handle and not a virtual one.
    17801784                     */
    1781                     RTVFSFILE hVfsFileSrc;
    1782                     rc = RTVfsDirOpenFile(hVfsDir, pDirEntry->szName,
    1783                                           RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileSrc);
     1785                    if (!fFilesWithSrcPath)
     1786                    {
     1787                        RTVFSFILE hVfsFileSrc;
     1788                        rc = RTVfsDirOpenFile(hVfsDir, pDirEntry->szName,
     1789                                              RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE, &hVfsFileSrc);
     1790                        if (RT_SUCCESS(rc))
     1791                        {
     1792                            rc = RTFsIsoMakerAddUnnamedFileWithVfsFile(pOpts->hIsoMaker, hVfsFileSrc, &idxObj);
     1793                            RTVfsFileRelease(hVfsFileSrc);
     1794                            if (RT_FAILURE(rc))
     1795                                rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive, handle): %Rrc",
     1796                                                            pszSrc, rc);
     1797                        }
     1798                        else
     1799                            rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening file '%s' (VFS recursive): %Rrc", pszSrc, rc);
     1800                    }
     1801                    else
     1802                    {
     1803                        /* Add file with source path: */
     1804                        rc = RTFsIsoMakerAddUnnamedFileWithSrcPath(pOpts->hIsoMaker, pszSrc, &idxObj);
     1805                        if (RT_FAILURE(rc))
     1806                            rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive, path): %Rrc",
     1807                                                        pszSrc, rc);
     1808                    }
    17841809                    if (RT_SUCCESS(rc))
    17851810                    {
    1786                         rc = RTFsIsoMakerAddUnnamedFileWithVfsFile(pOpts->hIsoMaker, hVfsFileSrc, &idxObj);
    1787                         RTVfsFileRelease(hVfsFileSrc);
    1788                         if (RT_SUCCESS(rc))
    1789                         {
    1790                             pOpts->cItemsAdded++;
    1791                             rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
    1792                                                                  pDirEntry->szName);
    1793                             if (RT_FAILURE(rc))
    1794                                 rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting parent & name on file '%s' to '%s': %Rrc",
    1795                                                             pszSrc, pDirEntry->szName, rc);
    1796                         }
    1797                         else
    1798                             rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error adding file '%s' (VFS recursive): %Rrc", pszSrc, rc);
     1811                        pOpts->cItemsAdded++;
     1812                        rc = RTFsIsoMakerObjSetNameAndParent(pOpts->hIsoMaker, idxObj, idxDirObj, fNamespaces,
     1813                                                             pDirEntry->szName);
     1814                        if (RT_FAILURE(rc))
     1815                            rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error setting parent & name on file '%s' to '%s': %Rrc",
     1816                                                        pszSrc, pDirEntry->szName, rc);
    17991817                    }
    1800                     else
    1801                         rc = rtFsIsoMakerCmdErrorRc(pOpts, rc, "Error opening file '%s' (VFS recursive): %Rrc", pszSrc, rc);
    18021818                }
    18031819                else if (RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode))
     
    18191835                                /* Recurse into the sub-directory. */
    18201836                                rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsSubDirSrc, idxObj, pszSrc,
    1821                                                                        cchSrc + 1 + pDirEntry->cbName, fNamespaces, cDepth + 1);
     1837                                                                       cchSrc + 1 + pDirEntry->cbName, fNamespaces, cDepth + 1,
     1838                                                                       fFilesWithSrcPath);
    18221839                            else
    18231840                                rc = rtFsIsoMakerCmdErrorRc(pOpts, rc,
     
    18641881 * @param   pszSrc              The source directory name.
    18651882 * @param   pParsed             The parsed names.
     1883 * @param   fFilesWithSrcPath   Whether to add files using @a pszSrc
     1884 *                              or to add as VFS handles (open first).  For
     1885 *                              saving native file descriptors.
    18661886 * @param   pidxObj             Where to return the configuration index for the
    18671887 *                              added file.  Optional.
    18681888 */
    18691889static int rtFsIsoMakerCmdAddVfsDirCommon(PRTFSISOMAKERCMDOPTS pOpts, RTVFSDIR hVfsDirSrc, char *pszSrc,
    1870                                           PCRTFSISOMKCMDPARSEDNAMES pParsed, PCRTFSOBJINFO pObjInfo)
     1890                                          PCRTFSISOMKCMDPARSEDNAMES pParsed, bool fFilesWithSrcPath, PCRTFSOBJINFO pObjInfo)
    18711891{
    18721892    /*
     
    19041924            fNamespaces |= pParsed->aNames[i].fNameSpecifiers & RTFSISOMAKERCMDNAME_MAJOR_MASK;
    19051925        rc = rtFsIsoMakerCmdAddVfsDirRecursive(pOpts, hVfsDirSrc, idxObj, pszSrc,
    1906                                                pParsed->aNames[pParsed->cNamesWithSrc - 1].cchPath, fNamespaces, 0 /*cDepth*/);
     1926                                               pParsed->aNames[pParsed->cNamesWithSrc - 1].cchPath, fNamespaces, 0 /*cDepth*/,
     1927                                               fFilesWithSrcPath);
    19071928    }
    19081929
     
    19291950    if (RT_SUCCESS(rc))
    19301951    {
    1931         rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed, pObjInfo);
     1952        rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed, false /*fFilesWithSrcPath*/, pObjInfo);
    19321953        RTVfsDirRelease(hVfsDirSrc);
    19331954    }
     
    19581979    if (RT_SUCCESS(rc))
    19591980    {
    1960         rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed, pObjInfo);
     1981        rc = rtFsIsoMakerCmdAddVfsDirCommon(pOpts, hVfsDirSrc, pszSrc, pParsed,
     1982                                            RTVfsDirIsStdDir(hVfsDirSrc) /*fFilesWithSrcPath*/, pObjInfo);
    19611983        RTVfsDirRelease(hVfsDirSrc);
    19621984    }
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