Changeset 59524 in vbox
- Timestamp:
- Jan 30, 2016 1:28:29 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105314
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r59480 r59524 2207 2207 # define RTVfsDirRetain RT_MANGLER(RTVfsDirRetain) 2208 2208 # define RTVfsFileFlush RT_MANGLER(RTVfsFileFlush) 2209 # define RTVfsFileFromBuffer RT_MANGLER(RTVfsFileFromBuffer) 2209 2210 # define RTVfsFileFromRTFile RT_MANGLER(RTVfsFileFromRTFile) 2210 2211 # define RTVfsFileGetSize RT_MANGLER(RTVfsFileGetSize) … … 2255 2256 # define RTVfsLockReleaseWriteSlow RT_MANGLER(RTVfsLockReleaseWriteSlow) 2256 2257 # define RTVfsLockRetain RT_MANGLER(RTVfsLockRetain) 2258 # define RTVfsMemFileCreate RT_MANGLER(RTVfsMemFileCreate) 2257 2259 # define RTVfsMemorizeIoStreamAsFile RT_MANGLER(RTVfsMemorizeIoStreamAsFile) 2258 2260 # define RTVfsNew RT_MANGLER(RTVfsNew) -
trunk/include/iprt/vfs.h
r57944 r59524 903 903 904 904 /** 905 * Creates a VFS file from a memory buffer. 906 * 907 * @returns VBox status code. 908 * 909 * @param hVfsIos The VFS I/O stream to memorize. This will be read 910 * to the end on success, on failure its position is 911 * undefined. 912 * @param fFlags A combination of RTFILE_O_READ and RTFILE_O_WRITE. 913 * @param pvBuf The buffer. This will be copied and not referenced 914 * after this function returns. 915 * @param cbBuf The buffer size. 916 * @param phVfsFile Where to return the handle to the memory file on 917 * success. 918 */ 919 RTDECL(int) RTVfsFileFromBuffer(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile); 920 921 /** 922 * Creates a memory backed VFS file object for read and write. 923 * 924 * @returns VBox status code. 925 * 926 * @param hVfsIos The VFS I/O stream to memorize. This will be read 927 * to the end on success, on failure its position is 928 * undefined. 929 * @param cbEstimate The estimated file size. 930 * @param phVfsFile Where to return the handle to the memory file on 931 * success. 932 */ 933 RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile); 934 935 /** 905 936 * Pumps data from one I/O stream to another. 906 937 * -
trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp
r57358 r59524 702 702 703 703 /** 704 * Standardfile operations.705 */ 706 DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtVfs StdFileOps =704 * Memory file operations. 705 */ 706 DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtVfsMemFileOps = 707 707 { 708 708 { /* Stream */ … … 742 742 743 743 744 744 /** 745 * Initialize the RTVFSMEMFILE specific members. 746 * 747 * @param pThis The memory file to initialize. 748 * @param cbObject The object size for estimating extent size. 749 * @param fFlags The user specified flags. 750 */ 751 static void rtVfsMemFileInit(PRTVFSMEMFILE pThis, RTFOFF cbObject, uint32_t fFlags) 752 { 753 pThis->offCurPos = 0; 754 pThis->pCurExt = NULL; 755 RTListInit(&pThis->ExtentHead); 756 if (cbObject <= 0) 757 pThis->cbExtent = _4K; 758 else if (cbObject < RTVFSMEM_MAX_EXTENT_SIZE) 759 pThis->cbExtent = fFlags & RTFILE_O_WRITE ? _4K : cbObject; 760 else 761 pThis->cbExtent = RTVFSMEM_MAX_EXTENT_SIZE; 762 } 763 764 765 /** 766 * Rewinds the file to position 0 and clears the WRITE flag if necessary. 767 * 768 * @param pThis The memory file instance. 769 * @param fFlags The user specified flags. 770 */ 771 static void rtVfsMemFileResetAndFixWriteFlag(PRTVFSMEMFILE pThis, uint32_t fFlags) 772 { 773 pThis->pCurExt = RTListGetFirst(&pThis->ExtentHead, RTVFSMEMEXTENT, Entry); 774 pThis->offCurPos = 0; 775 776 if (!(fFlags & RTFILE_O_WRITE)) 777 { 778 /** @todo clear RTFILE_O_WRITE from the resulting. */ 779 } 780 } 781 782 783 RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile) 784 { 785 /* 786 * Create a memory file instance and set the extension size according to the 787 * buffer size. Add the WRITE flag so we can use normal write APIs for 788 * copying the buffer. 789 */ 790 RTVFSFILE hVfsFile; 791 PRTVFSMEMFILE pThis; 792 int rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), RTFILE_O_READ | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK, 793 &hVfsFile, (void **)&pThis); 794 if (RT_SUCCESS(rc)) 795 { 796 pThis->Base.ObjInfo.cbObject = 0; 797 pThis->Base.ObjInfo.Attr.fMode = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | RTFS_UNIX_IRWXU; 798 rtVfsMemFileInit(pThis, cbEstimate, RTFILE_O_READ | RTFILE_O_WRITE); 799 800 *phVfsFile = hVfsFile; 801 return VINF_SUCCESS; 802 } 803 return rc; 804 } 805 806 807 RTDECL(int) RTVfsFileFromBuffer(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile) 808 { 809 /* 810 * Create a memory file instance and set the extension size according to the 811 * buffer size. Add the WRITE flag so we can use normal write APIs for 812 * copying the buffer. 813 */ 814 RTVFSFILE hVfsFile; 815 PRTVFSMEMFILE pThis; 816 int rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK, 817 &hVfsFile, (void **)&pThis); 818 if (RT_SUCCESS(rc)) 819 { 820 pThis->Base.ObjInfo.cbObject = cbBuf; 821 pThis->Base.ObjInfo.Attr.fMode = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | RTFS_UNIX_IRWXU; 822 rtVfsMemFileInit(pThis, cbBuf, fFlags); 823 824 /* 825 * Copy the buffer and reposition the file pointer to the start. 826 */ 827 rc = RTVfsFileWrite(hVfsFile, pvBuf, cbBuf, NULL); 828 if (RT_SUCCESS(rc)) 829 { 830 rtVfsMemFileResetAndFixWriteFlag(pThis, fFlags); 831 *phVfsFile = hVfsFile; 832 return VINF_SUCCESS; 833 } 834 RTVfsFileRelease(hVfsFile); 835 } 836 return rc; 837 } 745 838 746 839 … … 757 850 RTVFSFILE hVfsFile; 758 851 PRTVFSMEMFILE pThis; 759 rc = RTVfsNewFile(&g_rtVfs StdFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK,852 rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK, 760 853 &hVfsFile, (void **)&pThis); 761 854 if (RT_SUCCESS(rc)) 762 855 { 763 856 pThis->Base.ObjInfo = ObjInfo; 764 pThis->offCurPos = 0; 765 pThis->pCurExt = NULL; 766 RTListInit(&pThis->ExtentHead); 767 if (ObjInfo.cbObject <= 0) 768 pThis->cbExtent = _4K; 769 else if (ObjInfo.cbObject < RTVFSMEM_MAX_EXTENT_SIZE) 770 pThis->cbExtent = _4K /* ObjInfo.cbObject */; 771 else 772 pThis->cbExtent = RTVFSMEM_MAX_EXTENT_SIZE; 857 rtVfsMemFileInit(pThis, ObjInfo.cbObject, fFlags); 773 858 774 859 /* … … 780 865 if (RT_SUCCESS(rc)) 781 866 { 782 pThis->pCurExt = RTListGetFirst(&pThis->ExtentHead, RTVFSMEMEXTENT, Entry); 783 pThis->offCurPos = 0; 784 785 if (!(fFlags & RTFILE_O_WRITE)) 786 { 787 /** @todo clear RTFILE_O_WRITE from the resulting. */ 788 } 867 rtVfsMemFileResetAndFixWriteFlag(pThis, fFlags); 789 868 *phVfsFile = hVfsFile; 790 869 return VINF_SUCCESS; … … 795 874 return rc; 796 875 } 876
Note:
See TracChangeset
for help on using the changeset viewer.