Changeset 67491 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jun 20, 2017 10:10:22 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/fs/isomaker.cpp
r67454 r67491 357 357 RTFSISOMAKERSRCTYPE_PATH, 358 358 RTFSISOMAKERSRCTYPE_VFS_FILE, 359 RTFSISOMAKERSRCTYPE_COMMON, 359 360 RTFSISOMAKERSRCTYPE_TRANS_TBL, 360 361 RTFSISOMAKERSRCTYPE_END … … 384 385 /** Source VFS file. */ 385 386 RTVFSFILE hVfsFile; 387 /** Source is a part of a common VFS file. */ 388 struct 389 { 390 /** The offset into the file */ 391 uint64_t offData; 392 /** The index of the common file. */ 393 uint32_t idxSrc; 394 } Common; 386 395 /** The directory the translation table belongs to. */ 387 396 PRTFSISOMAKERNAME pTransTblDir; … … 464 473 /** The default file mode mask. */ 465 474 RTFMODE fDefaultDirMode; 475 476 /** Number of common source files. */ 477 uint32_t cCommonSources; 478 /** Array of common source file handles. */ 479 PRTVFSFILE paCommonSources; 466 480 467 481 /** @name Boot related stuff … … 766 780 pThis->fDefaultDirMode = 0555 | RTFS_TYPE_DIRECTORY | RTFS_DOS_DIRECTORY | RTFS_DOS_READONLY; 767 781 782 //pThis->cCommonSources = 0; 783 //pThis->paCommonSources = NULL; 784 768 785 //pThis->pBootCatFile = NULL; 769 786 … … 839 856 RTVfsFileRelease(pFile->u.hVfsFile); 840 857 pFile->u.hVfsFile = NIL_RTVFSFILE; 858 break; 859 860 case RTFSISOMAKERSRCTYPE_COMMON: 841 861 break; 842 862 … … 1016 1036 rtFsIsoMakerObjDestroy(pCur); 1017 1037 } 1038 1039 if (pThis->paCommonSources) 1040 { 1041 RTMemFree(pThis->paCommonSources); 1042 pThis->paCommonSources = NULL; 1043 } 1044 1045 pThis->uMagic = ~RTFSISOMAKERINT_MAGIC; 1046 RTMemFree(pThis); 1018 1047 } 1019 1048 … … 2508 2537 PRTFSISOMAKERFILE pFile = (PRTFSISOMAKERFILE)pObj; 2509 2538 AssertReturn( pFile->enmSrcType == RTFSISOMAKERSRCTYPE_PATH 2510 || pFile->enmSrcType == RTFSISOMAKERSRCTYPE_VFS_FILE, 2539 || pFile->enmSrcType == RTFSISOMAKERSRCTYPE_VFS_FILE 2540 || pFile->enmSrcType == RTFSISOMAKERSRCTYPE_COMMON, 2511 2541 VERR_WRONG_TYPE); 2512 2542 … … 2725 2755 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_INVALID; 2726 2756 pFile->u.pszSrcPath = NULL; 2757 pFile->pBootInfoTable = NULL; 2727 2758 RTListInit(&pFile->FinalizedEntry); 2728 2759 … … 2773 2804 if (RT_SUCCESS(rc)) 2774 2805 { 2775 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_PATH; 2776 pFile->u.pszSrcPath = (char *)memcpy(pFile + 1, pszSrcFile, cbSrcFile); 2777 pFile->pBootInfoTable = NULL; 2806 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_PATH; 2807 pFile->u.pszSrcPath = (char *)memcpy(pFile + 1, pszSrcFile, cbSrcFile); 2778 2808 2779 2809 *pidxObj = pFile->Core.idxObj; … … 2823 2853 if (RT_SUCCESS(rc)) 2824 2854 { 2825 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_VFS_FILE; 2826 pFile->u.hVfsFile = hVfsFileSrc; 2827 pFile->pBootInfoTable = NULL; 2855 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_VFS_FILE; 2856 pFile->u.hVfsFile = hVfsFileSrc; 2828 2857 2829 2858 *pidxObj = pFile->Core.idxObj; … … 2832 2861 RTVfsFileRelease(hVfsFileSrc); 2833 2862 return rc; 2863 } 2864 2865 2866 /** 2867 * Adds an unnamed file to the image that's backed by a portion of a common 2868 * source file. 2869 * 2870 * The file must explictly be entered into the desired namespaces. 2871 * 2872 * @returns IPRT status code 2873 * @param hIsoMaker The ISO maker handle. 2874 * @param idxCommonSrc The common source file index. 2875 * @param offData The offset of the data in the source file. 2876 * @param cbData The file size. 2877 * @param pObjInfo Pointer to file info. Optional. 2878 * @param pidxObj Where to return the configuration index of the 2879 * directory. 2880 * @sa RTFsIsoMakerAddUnnamedFileWithSrcPath, RTFsIsoMakerObjSetPath 2881 */ 2882 RTDECL(int) RTFsIsoMakerAddUnnamedFileWithCommonSrc(RTFSISOMAKER hIsoMaker, uint32_t idxCommonSrc, 2883 uint64_t offData, uint64_t cbData, PCRTFSOBJINFO pObjInfo, uint32_t *pidxObj) 2884 { 2885 /* 2886 * Validate and fake input. 2887 */ 2888 PRTFSISOMAKERINT pThis = hIsoMaker; 2889 RTFSISOMAKER_ASSERT_VALID_HANDLE_RET(pThis); 2890 AssertPtrReturn(pidxObj, VERR_INVALID_POINTER); 2891 *pidxObj = UINT32_MAX; 2892 AssertReturn(!pThis->fFinalized, VERR_WRONG_ORDER); 2893 AssertReturn(idxCommonSrc < pThis->cCommonSources, VERR_INVALID_PARAMETER); 2894 AssertReturn(offData < (uint64_t)RTFOFF_MAX, VERR_OUT_OF_RANGE); 2895 AssertReturn(cbData < (uint64_t)RTFOFF_MAX, VERR_OUT_OF_RANGE); 2896 AssertReturn(offData + cbData < (uint64_t)RTFOFF_MAX, VERR_OUT_OF_RANGE); 2897 RTFSOBJINFO ObjInfo; 2898 if (!pObjInfo) 2899 { 2900 ObjInfo.cbObject = cbData; 2901 ObjInfo.cbAllocated = cbData; 2902 ObjInfo.BirthTime = pThis->ImageCreationTime; 2903 ObjInfo.ChangeTime = pThis->ImageCreationTime; 2904 ObjInfo.ModificationTime = pThis->ImageCreationTime; 2905 ObjInfo.AccessTime = pThis->ImageCreationTime; 2906 ObjInfo.Attr.fMode = pThis->fDefaultFileMode; 2907 ObjInfo.Attr.enmAdditional = RTFSOBJATTRADD_UNIX; 2908 ObjInfo.Attr.u.Unix.uid = NIL_RTUID; 2909 ObjInfo.Attr.u.Unix.gid = NIL_RTGID; 2910 ObjInfo.Attr.u.Unix.cHardlinks = 1; 2911 ObjInfo.Attr.u.Unix.INodeIdDevice = 0; 2912 ObjInfo.Attr.u.Unix.INodeId = 0; 2913 ObjInfo.Attr.u.Unix.fFlags = 0; 2914 ObjInfo.Attr.u.Unix.GenerationId = 0; 2915 ObjInfo.Attr.u.Unix.Device = 0; 2916 } 2917 else 2918 { 2919 AssertPtrReturn(pObjInfo, VERR_INVALID_POINTER); 2920 AssertReturn(pObjInfo->Attr.enmAdditional == RTFSOBJATTRADD_UNIX, VERR_WRONG_TYPE); 2921 AssertReturn((uint64_t)pObjInfo->cbObject == cbData, VERR_INVALID_PARAMETER); 2922 } 2923 2924 /* 2925 * Create a file object for it. 2926 */ 2927 PRTFSISOMAKERFILE pFile; 2928 int rc = rtFsIsoMakerAddUnnamedFileWorker(pThis, pObjInfo, 0, &pFile); 2929 if (RT_SUCCESS(rc)) 2930 { 2931 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_COMMON; 2932 pFile->u.Common.idxSrc = idxCommonSrc; 2933 pFile->u.Common.offData = offData; 2934 2935 *pidxObj = pFile->Core.idxObj; 2936 } 2937 return rc; 2938 } 2939 2940 2941 /** 2942 * Adds a common source file. 2943 * 2944 * Using RTFsIsoMakerAddUnnamedFileWithCommonSrc a sections common source file 2945 * can be referenced to make up other files. The typical use case is when 2946 * importing data from an existing ISO. 2947 * 2948 * @returns IPRT status code 2949 * @param hIsoMaker The ISO maker handle. 2950 * @param hVfsFile VFS handle of the common source. (A reference 2951 * is added, none consumed.) 2952 * @param pidxCommonSrc Where to return the assigned common source 2953 * index. This is used to reference the file. 2954 * @sa RTFsIsoMakerAddUnnamedFileWithCommonSrc 2955 */ 2956 RTDECL(int) RTFsIsoMakerAddCommonSourceFile(RTFSISOMAKER hIsoMaker, RTVFSFILE hVfsFile, uint32_t *pidxCommonSrc) 2957 { 2958 /* 2959 * Validate input. 2960 */ 2961 PRTFSISOMAKERINT pThis = hIsoMaker; 2962 RTFSISOMAKER_ASSERT_VALID_HANDLE_RET(pThis); 2963 AssertPtrReturn(pidxCommonSrc, VERR_INVALID_POINTER); 2964 *pidxCommonSrc = UINT32_MAX; 2965 AssertReturn(!pThis->fFinalized, VERR_WRONG_ORDER); 2966 2967 /* 2968 * Resize the common source array if necessary. 2969 */ 2970 if ((pThis->cCommonSources & 15) == 0) 2971 { 2972 void *pvNew = RTMemRealloc(pThis->paCommonSources, (pThis->cCommonSources + 16) * sizeof(pThis->paCommonSources[0])); 2973 AssertReturn(pvNew, VERR_NO_MEMORY); 2974 pThis->paCommonSources = (PRTVFSFILE)pvNew; 2975 } 2976 2977 /* 2978 * Retain a reference to the source file, thereby validating the handle. 2979 * Then add it to the array. 2980 */ 2981 uint32_t cRefs = RTVfsFileRetain(hVfsFile); 2982 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 2983 2984 uint32_t idx = pThis->cCommonSources++; 2985 pThis->paCommonSources[idx] = hVfsFile; 2986 2987 *pidxCommonSrc = idx; 2988 return VINF_SUCCESS; 2834 2989 } 2835 2990 … … 2945 3100 pFile->enmSrcType = RTFSISOMAKERSRCTYPE_VFS_FILE; 2946 3101 pFile->u.hVfsFile = hVfsFile; 2947 pFile->pBootInfoTable = NULL;2948 3102 pFile->Core.cNotOrphan = 1; 2949 3103 … … 3673 3827 int rc; 3674 3828 RTVFSFILE hVfsFile; 3829 uint64_t offBase; 3675 3830 switch (pCurFile->enmSrcType) 3676 3831 { … … 3679 3834 &hVfsFile, NULL, NULL); 3680 3835 AssertMsgRCReturn(rc, ("%s -> %Rrc\n", pCurFile->u.pszSrcPath, rc), rc); 3836 offBase = 0; 3681 3837 break; 3682 3838 case RTFSISOMAKERSRCTYPE_VFS_FILE: 3683 3839 hVfsFile = pCurFile->u.hVfsFile; 3840 offBase = 0; 3841 rc = VINF_SUCCESS; 3842 break; 3843 case RTFSISOMAKERSRCTYPE_COMMON: 3844 hVfsFile = pThis->paCommonSources[pCurFile->u.Common.idxSrc]; 3845 offBase = pCurFile->u.Common.offData; 3684 3846 rc = VINF_SUCCESS; 3685 3847 break; … … 3701 3863 if (cbRead & 3) 3702 3864 RT_ZERO(uBuf); 3703 rc = RTVfsFileReadAt(hVfsFile, off , &uBuf, cbRead, NULL);3865 rc = RTVfsFileReadAt(hVfsFile, offBase + off, &uBuf, cbRead, NULL); 3704 3866 if (RT_FAILURE(rc)) 3705 3867 break; … … 4401 4563 break; 4402 4564 4565 case RTFSISOMAKERSRCTYPE_COMMON: 4566 rc = RTVfsFileReadAt(pIsoMaker->paCommonSources[pFile->u.Common.idxSrc], 4567 pFile->u.Common.offData + offInFile, pbBuf, cbToRead, NULL); 4568 AssertRC(rc); 4569 break; 4570 4403 4571 case RTFSISOMAKERSRCTYPE_TRANS_TBL: 4404 4572 if (pThis->hVfsSrcFile == NIL_RTVFSFILE)
Note:
See TracChangeset
for help on using the changeset viewer.