VirtualBox

Changeset 47356 in vbox


Ignore:
Timestamp:
Jul 23, 2013 5:45:07 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87502
Message:

IPRT: Added RTVfsIoStrmOpenNormal and RTVfsFileOpenNormal.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r47352 r47356  
    17711771# define RTVfsFileGetSize                               RT_MANGLER(RTVfsFileGetSize)
    17721772# define RTVfsFileOpen                                  RT_MANGLER(RTVfsFileOpen)
     1773# define RTVfsFileOpenNormal                            RT_MANGLER(RTVfsFileOpenNormal)
    17731774# define RTVfsFilePoll                                  RT_MANGLER(RTVfsFilePoll)
    17741775# define RTVfsFileQueryInfo                             RT_MANGLER(RTVfsFileQueryInfo)
     
    17911792# define RTVfsIoStrmFromStdHandle                       RT_MANGLER(RTVfsIoStrmFromStdHandle)
    17921793# define RTVfsIoStrmIsAtEnd                             RT_MANGLER(RTVfsIoStrmIsAtEnd)
     1794# define RTVfsIoStrmOpenNormal                          RT_MANGLER(RTVfsIoStrmOpenNormal)
    17931795# define RTVfsIoStrmPoll                                RT_MANGLER(RTVfsIoStrmPoll)
    17941796# define RTVfsIoStrmQueryInfo                           RT_MANGLER(RTVfsIoStrmQueryInfo)
  • trunk/include/iprt/vfs.h

    r47351 r47356  
    453453
    454454/**
     455 * Convenience function combining RTFileOpen with RTVfsIoStrmFromRTFile.
     456 *
     457 * @returns IPRT status code.
     458 * @param   pszFilename     The path to the file in the normal file system.
     459 * @param   fOpen           The flags to pass to RTFileOpen when opening the
     460 *                          file, i.e. RTFILE_O_XXX.
     461 * @param   phVfsIos        Where to return the VFS I/O stream handle.
     462 */
     463RTDECL(int)         RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos);
     464
     465/**
    455466 * Create a VFS I/O stream handle from one of the standard handles.
    456467 *
     
    706717
    707718/**
     719 * Convenience function combining RTFileOpen with RTVfsFileFromRTFile.
     720 *
     721 * @returns IPRT status code.
     722 * @param   pszFilename     The path to the file in the normal file system.
     723 * @param   fOpen           The flags to pass to RTFileOpen when opening the
     724 *                          file, i.e. RTFILE_O_XXX.
     725 * @param   phVfsFile       Where to return the VFS file handle.
     726 */
     727RTDECL(int)         RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile);
     728
     729/**
    708730 * Convert the VFS file handle to a VFS I/O stream handle.
    709731 *
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r44529 r47356  
    419419
    420420
     421/**
     422 * Internal worker for RTVfsFileFromRTFile and RTVfsFileOpenNormal.
     423 *
     424 * @returns IRPT status code.
     425 * @param   hFile               The IPRT file handle.
     426 * @param   fOpen               The RTFILE_O_XXX flags.
     427 * @param   fLeaveOpen          Whether to leave it open or close it.
     428 * @param   phVfsFile           Where to return the handle.
     429 */
     430static int rtVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile)
     431{
     432    PRTVFSSTDFILE   pThis;
     433    RTVFSFILE       hVfsFile;
     434    int rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK,
     435                          &hVfsFile, (void **)&pThis);
     436    if (RT_FAILURE(rc))
     437        return rc;
     438
     439    pThis->hFile        = hFile;
     440    pThis->fLeaveOpen   = fLeaveOpen;
     441    *phVfsFile = hVfsFile;
     442    return VINF_SUCCESS;
     443}
     444
     445
    421446RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile)
    422447{
     
    430455
    431456    /*
    432      * Set up some fake fOpen flags.
     457     * Set up some fake fOpen flags if necessary and create a VFS file handle.
    433458     */
    434459    if (!fOpen)
    435460        fOpen = RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN_CREATE;
    436461
     462    return rtVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, phVfsFile);
     463}
     464
     465
     466RTDECL(int) RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile)
     467{
    437468    /*
    438      * Create the handle.
     469     * Open the file the normal way and pass it to RTVfsFileFromRTFile.
    439470     */
    440     PRTVFSSTDFILE   pThis;
    441     RTVFSFILE       hVfsFile;
    442     rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK, &hVfsFile, (void **)&pThis);
    443     if (RT_FAILURE(rc))
    444         return rc;
    445 
    446     pThis->hFile        = hFile;
    447     pThis->fLeaveOpen   = fLeaveOpen;
    448     *phVfsFile = hVfsFile;
    449     return VINF_SUCCESS;
    450 }
    451 
    452 
    453 RTDECL(int)         RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
     471    RTFILE hFile;
     472    int rc = RTFileOpen(&hFile, pszFilename, fOpen);
     473    if (RT_SUCCESS(rc))
     474    {
     475        /*
     476         * Create a VFS file handle.
     477         */
     478        rc = rtVfsFileFromRTFile(hFile, fOpen, false /*fLeaveOpen*/, phVfsFile);
     479        if (RT_FAILURE(rc))
     480            RTFileClose(hFile);
     481    }
     482    return rc;
     483}
     484
     485
     486RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos)
    454487{
    455488    RTVFSFILE hVfsFile;
     
    460493}
    461494
     495
     496RTDECL(int) RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos)
     497{
     498    RTVFSFILE hVfsFile;
     499    int rc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile);
     500    if (RT_SUCCESS(rc))
     501        *phVfsIos = RTVfsFileToIoStream(hVfsFile);
     502    return rc;
     503}
     504
     505
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