diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-03-26 19:21:20 +0000 |
---|---|---|
committer | <> | 2014-05-08 15:03:54 +0000 |
commit | fb123f93f9f5ce42c8e5785d2f8e0edaf951740e (patch) | |
tree | c2103d76aec5f1f10892cd1d3a38e24f665ae5db /src/VBox/Runtime/common/vfs/vfsstdfile.cpp | |
parent | 58ed4748338f9466599adfc8a9171280ed99e23f (diff) | |
download | VirtualBox-master.tar.gz |
Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2.HEADVirtualBox-4.3.10master
Diffstat (limited to 'src/VBox/Runtime/common/vfs/vfsstdfile.cpp')
-rw-r--r-- | src/VBox/Runtime/common/vfs/vfsstdfile.cpp | 71 |
1 files changed, 57 insertions, 14 deletions
diff --git a/src/VBox/Runtime/common/vfs/vfsstdfile.cpp b/src/VBox/Runtime/common/vfs/vfsstdfile.cpp index 8b01af67..5f023e74 100644 --- a/src/VBox/Runtime/common/vfs/vfsstdfile.cpp +++ b/src/VBox/Runtime/common/vfs/vfsstdfile.cpp @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2010 Oracle Corporation + * Copyright (C) 2010-2011 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -418,6 +418,31 @@ DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtVfsStdFileOps = }; +/** + * Internal worker for RTVfsFileFromRTFile and RTVfsFileOpenNormal. + * + * @returns IRPT status code. + * @param hFile The IPRT file handle. + * @param fOpen The RTFILE_O_XXX flags. + * @param fLeaveOpen Whether to leave it open or close it. + * @param phVfsFile Where to return the handle. + */ +static int rtVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile) +{ + PRTVFSSTDFILE pThis; + RTVFSFILE hVfsFile; + int rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK, + &hVfsFile, (void **)&pThis); + if (RT_FAILURE(rc)) + return rc; + + pThis->hFile = hFile; + pThis->fLeaveOpen = fLeaveOpen; + *phVfsFile = hVfsFile; + return VINF_SUCCESS; +} + + RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSFILE phVfsFile) { /* @@ -429,28 +454,36 @@ RTDECL(int) RTVfsFileFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, P return rc; /* - * Set up some fake fOpen flags. + * Set up some fake fOpen flags if necessary and create a VFS file handle. */ if (!fOpen) fOpen = RTFILE_O_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN_CREATE; + return rtVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, phVfsFile); +} + + +RTDECL(int) RTVfsFileOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSFILE phVfsFile) +{ /* - * Create the handle. + * Open the file the normal way and pass it to RTVfsFileFromRTFile. */ - PRTVFSSTDFILE pThis; - RTVFSFILE hVfsFile; - rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(RTVFSSTDFILE), fOpen, NIL_RTVFS, NIL_RTVFSLOCK, &hVfsFile, (void **)&pThis); - if (RT_FAILURE(rc)) - return rc; - - pThis->hFile = hFile; - pThis->fLeaveOpen = fLeaveOpen; - *phVfsFile = hVfsFile; - return VINF_SUCCESS; + RTFILE hFile; + int rc = RTFileOpen(&hFile, pszFilename, fOpen); + if (RT_SUCCESS(rc)) + { + /* + * Create a VFS file handle. + */ + rc = rtVfsFileFromRTFile(hFile, fOpen, false /*fLeaveOpen*/, phVfsFile); + if (RT_FAILURE(rc)) + RTFileClose(hFile); + } + return rc; } -RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos) +RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLeaveOpen, PRTVFSIOSTREAM phVfsIos) { RTVFSFILE hVfsFile; int rc = RTVfsFileFromRTFile(hFile, fOpen, fLeaveOpen, &hVfsFile); @@ -459,3 +492,13 @@ RTDECL(int) RTVfsIoStrmFromRTFile(RTFILE hFile, uint64_t fOpen, bool fLe return rc; } + +RTDECL(int) RTVfsIoStrmOpenNormal(const char *pszFilename, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos) +{ + RTVFSFILE hVfsFile; + int rc = RTVfsFileOpenNormal(pszFilename, fOpen, &hVfsFile); + if (RT_SUCCESS(rc)) + *phVfsIos = RTVfsFileToIoStream(hVfsFile); + return rc; +} + |