VirtualBox

Changeset 67270 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 6, 2017 12:00:36 PM (8 years ago)
Author:
vboxsync
Message:

meeting

File:
1 edited

Legend:

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

    r67259 r67270  
    4848
    4949/*********************************************************************************************************************************
     50*   Defined Constants And Macros                                                                                                 *
     51*********************************************************************************************************************************/
     52/** Asserts valid handle, returns VERR_INVALID_HANDLE if not. */
     53#define RTFSISOMAKER_ASSER_VALID_HANDLE_RET(a_pThis) \
     54    do { AssertPtrReturn(a_pThis, VERR_INVALID_HANDLE); \
     55         AssertPtrReturn((a_pThis)->uMagic == RTFSISOMAKERINT_MAGIC, VERR_INVALID_HANDLE); \
     56    } while (0)
     57
     58/** The sector size. */
     59#define RTFSISOMAKER_SECTOR_SIZE            _2K
     60
     61
     62/*********************************************************************************************************************************
    5063*   Structures and Typedefs                                                                                                      *
    5164*********************************************************************************************************************************/
     
    5871
    5972
     73/** @name RTFSISOMAKER_NAMESPACE_XXX - Namespace selector.
     74 * @{
     75 */
     76#define RTFSISOMAKERNAMESPACE_ISO_9660      RT_BIT_32(0)            /**< The primary ISO-9660 namespace. */
     77#define RTFSISOMAKERNAMESPACE_JOLIET        RT_BIT_32(1)            /**< The joliet namespace. */
     78#define RTFSISOMAKERNAMESPACE_UDF           RT_BIT_32(2)            /**< The UDF namespace. */
     79#define RTFSISOMAKERNAMESPACE_HFS           RT_BIT_32(3)            /**< The HFS namespace */
     80#define RTFSISOMAKERNAMESPACE_ALL           UINT32_C(0x0000000f)    /**< All namespaces. */
     81#define RTFSISOMAKERNAMESPACE_VALID_MASK    UINT32_C(0x0000000f)    /**< Valid namespace bits. */
     82/** @} */
     83
     84
    6085/**
    6186 * Filesystem object type.
     
    6994    RTFSISOMAKEROBJTYPE_END
    7095} RTFSISOMAKEROBJTYPE;
    71 
    7296
    7397/**
     
    93117
    94118/**
    95  * ISO maker object name space node.
     119 * ISO maker object namespace node.
    96120 */
    97121typedef struct RTFSISOMAKERNAME
     
    106130     * freeing. */
    107131    PRTFSISOMAKERNAMEDIR    pDir;
     132
     133    /** The name specified when creating this namespace node.  Helps navigating
     134     * the namespace when we mangle or otherwise change the names.
     135     * Allocated together with of this structure, no spearate free necessary. */
     136    const char             *pszSpecNm;
    108137
    109138    /** Alternative rock ridge name. */
     
    118147    /** The depth in the namespace tree of this name. */
    119148    uint8_t                 uDepth;
    120     uint8_t                 bUnused;
     149    /** Set if pszTransNm is allocated separately. */
     150    bool                    fTransNmAlloced : 1;
     151    /** Set if pszTransNm is allocated separately. */
     152    bool                    fRockRidgeNmAlloced : 1;
     153
    121154/** @todo more rock ridge info here.    */
    122155
     
    135168    /** The linear list entry of the image content. */
    136169    RTLISTNODE              Entry;
     170    /** The object index. */
     171    uint32_t                idxObj;
    137172    /** The type of this object. */
    138173    RTFSISOMAKEROBJTYPE     enmType;
     
    151186
    152187/**
     188 * File source type.
     189 */
     190typedef enum RTFSISOMAKERSRCTYPE
     191{
     192    RTFSISOMAKERSRCTYPE_INVALID = 0,
     193    RTFSISOMAKERSRCTYPE_PATH,
     194    RTFSISOMAKERSRCTYPE_VFS_IO_STREAM,
     195    RTFSISOMAKERSRCTYPE_END,
     196} RTFSISOMAKERSRCTYPE;
     197
     198/**
    153199 * ISO maker file object.
    154200 */
     
    161207    /** Byte offset of the data in the image. */
    162208    uint64_t                offData;
     209
     210    /** The type of source object. */
     211    RTFSISOMAKERSRCTYPE     enmSrcType;
     212    /** The source data. */
     213    union
     214    {
     215        /** Path to the source file. */
     216        const char         *pszSrcPath;
     217        /** Source I/O stream (or file). */
     218        RTVFSIOSTREAM       hVfsIoStr;
     219    } u;
    163220} RTFSISOMAKERFILE;
    164221
     
    200257     * @todo support mkisofs level 4 (ISO-9660:1990, version 2). */
    201258    uint8_t                 uIsoLevel;
     259    /** The ISO rock ridge level: 1 - enabled; 2 - with ER tag.
     260     * Linux behaves a little different when seeing the ER tag. */
     261    uint8_t                 uRockRidgeLevel;
    202262    /** The joliet UCS level (1, 2, or 3), 0 if joliet is not enabled. */
    203263    uint8_t                 uJolietLevel;
    204     /** Set if rock ridge is enabled. */
    205     bool                    fRockRidge;
     264    /** The joliet rock ridge level: 1 - enabled; 2 - with ER tag.
     265     * @note Nobody seems to do rock ridge with joliet, so this is highly
     266     *       expermental and here just because we can. */
     267    uint8_t                 uJolietRockRidgeLevel;
     268    /** Enables UDF.
     269     * @remarks not yet implemented. */
     270    bool                    fUdf;
     271    /** Enables HFS
     272     * @remarks not yet implemented. */
     273    bool                    fHfs;
    206274    /** @} */
    207275
     
    226294
    227295
     296/*********************************************************************************************************************************
     297*   Structures and Typedefs                                                                                                      *
     298*********************************************************************************************************************************/
     299/**
     300 * Help for iterating over namespaces.
     301 */
     302struct const struct
     303{
     304    /** The RTFSISOMAKERNAMESPACE_XXX indicator.  */
     305    uint32_t        fNamespace;
     306    /** Offset into RTFSISOMAKERINT of the root member. */
     307    uintptr_t       offRoot;
     308    /** Offset into RTFSISOMAKERNAMESPACE of the name member. */
     309    uintptr_t       offName;
     310    /** Namespace name for debugging purposes. */
     311    const char     *pszName;
     312} g_aRTFsIosNamespaces[] =
     313{
     314    {   RTFSISOMAKERNAMESPACE_ISO_9660, RT_OFFSETOF(RTFSISOMAKERINT, pPrimaryIsoRoot), RT_OFFSETOF(RTFSISOMAKERNAMESPACE, pPrimaryName), "iso-9660" },
     315    {   RTFSISOMAKERNAMESPACE_JOLIET,   RT_OFFSETOF(RTFSISOMAKERINT, pJolietRoot),     RT_OFFSETOF(RTFSISOMAKERNAMESPACE, pJolietName),  "joliet" },
     316    {   RTFSISOMAKERNAMESPACE_UDF,      RT_OFFSETOF(RTFSISOMAKERINT, pUdfRoot),        RT_OFFSETOF(RTFSISOMAKERNAMESPACE, pUdfName),     "udf" },
     317    {   RTFSISOMAKERNAMESPACE_HFS,      RT_OFFSETOF(RTFSISOMAKERINT, pHfsRoot),        RT_OFFSETOF(RTFSISOMAKERNAMESPACE, pHfsName),     "hfs" },
     318};
     319
    228320
    229321/**
     
    238330    if (pThis)
    239331    {
    240         pThis->uMagic           = RTFSISOMAKERINT_MAGIC;
    241         pThis->cRefs            = 1;
    242         //pThis->fSeenContent     = false;
    243         pThis->uIsoLevel        = 3;
    244         pThis->uJolietLevel     = 3;
    245         pThis->fRockRidge       = true;
     332        pThis->uMagic                   = RTFSISOMAKERINT_MAGIC;
     333        pThis->cRefs                    = 1;
     334        //pThis->fSeenContent             = false;
     335        pThis->uIsoLevel                = 3;
     336        pThis->uRockRidgeLevel          = 1;
     337        pThis->uJolietLevel             = 3;
     338        //pThis->uJolietRockRidgeLevel    = 0;
    246339        RTListInit(&pThis->ObjectHead);
    247         pThis->cbTotal          = _32K; /* system area size */
    248 
     340        pThis->cbTotal                  = _32K /* The system area size. */
     341                                        + RTFSISOMAKER_SECTOR_SIZE /* Primary volume descriptor. */
     342                                        + RTFSISOMAKER_SECTOR_SIZE /* Secondary volume descriptor for joliet. */
     343                                        + RTFSISOMAKER_SECTOR_SIZE /* Terminator descriptor. */;
    249344        *phIsoMaker = pThis;
    250345        return VINF_SUCCESS;
     
    322417 *
    323418 * @returns New reference count on success, UINT32_MAX if invalid handle.
    324  * @param   hIsoMaker           The IOS maker handler.
     419 * @param   hIsoMaker           The ISO maker handle.
    325420 */
    326421RTDECL(uint32_t) RTFsIsoMakerRetain(RTFSISOMAKER hIsoMaker)
     
    340435 *
    341436 * @returns New reference count on success, UINT32_MAX if invalid handle.
    342  * @param   hIsoMaker           The IOS maker handler.  NIL is ignored.
     437 * @param   hIsoMaker           The ISO maker handle.  NIL is ignored.
    343438 */
    344439RTDECL(uint32_t) RTFsIsoMakerRelease(RTFSISOMAKER hIsoMaker)
     
    360455}
    361456
     457
     458/**
     459 * Sets the ISO-9660 level.
     460 *
     461 * @returns IPRT status code
     462 * @param   hIsoMaker           The ISO maker handle.
     463 * @param   uIsoLevel           The level, 1-3.
     464 */
     465RTDECL(int) RTFsIsoMakerSetIso9660Level(RTFSISOMAKER hIsoMaker, uint8_t uIsoLevel)
     466{
     467    PRTFSISOMAKERINT pThis = hIsoMaker;
     468    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     469    AssertReturn(uIsoLevel <= 3, VERR_INVALID_PARAMETER);
     470    AssertReturn(uIsoLevel > 0, VERR_INVALID_PARAMETER); /* currently not possible to disable this */
     471    AssertReturn(!pThis->fSeenContent, VERR_WRONG_ORDER);
     472
     473    pThis->uIsoLevel = uIsoLevel;
     474    return VINF_SUCCESS;
     475}
     476
     477
     478/**
     479 * Sets the joliet level.
     480 *
     481 * @returns IPRT status code
     482 * @param   hIsoMaker           The ISO maker handle.
     483 * @param   uJolietLevel        The joliet UCS-2 level 1-3, or 0 to disable
     484 *                              joliet.
     485 */
     486RTDECL(int) RTFsIsoMakerSetJolietUcs2Level(RTFSISOMAKER hIsoMaker, uint8_t uJolietLevel)
     487{
     488    PRTFSISOMAKERINT pThis = hIsoMaker;
     489    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     490    AssertReturn(uJolietLevel <= 3, VERR_INVALID_PARAMETER);
     491    AssertReturn(!pThis->fSeenContent, VERR_WRONG_ORDER);
     492
     493    if (pThis->uJolietLevel != uJolietLevel)
     494    {
     495        if (uJolietLevel == 0)
     496            pThis->cbTotal -= RTFSISOMAKER_SECTOR_SIZE;
     497        else if (pThis->uJolietLevel == 0)
     498            pThis->cbTotal += RTFSISOMAKER_SECTOR_SIZE;
     499        pThis->uJolietLevel = uJolietLevel;
     500    }
     501    return VINF_SUCCESS;
     502}
     503
     504
     505/**
     506 * Sets the rock ridge support level (on the primary ISO-9660 namespace).
     507 *
     508 * @returns IPRT status code
     509 * @param   hIsoMaker           The ISO maker handle.
     510 * @param   uLevel              0 if disabled, 1 to just enable, 2 to enable and
     511 *                              write the ER tag.
     512 */
     513RTDECL(int) RTFsIsoMakerSetRockRidgeLevel(RTFSISOMAKER hIsoMaker, uint8_t uLevel)
     514{
     515    PRTFSISOMAKERINT pThis = hIsoMaker;
     516    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     517    AssertReturn(!pThis->fSeenContent, VERR_WRONG_ORDER);
     518    AssertReturn(uLevel <= 2, VERR_INVALID_PARAMETER);
     519
     520    pThis->uRockRidgeLevel = uLevel;
     521    return VINF_SUCCESS;
     522}
     523
     524
     525/**
     526 * Sets the rock ridge support level on the joliet namespace (experimental).
     527 *
     528 * @returns IPRT status code
     529 * @param   hIsoMaker           The ISO maker handle.
     530 * @param   uLevel              0 if disabled, 1 to just enable, 2 to enable and
     531 *                              write the ER tag.
     532 */
     533RTDECL(int) RTFsIsoMakerSetJolietRockRidgeLevel(RTFSISOMAKER hIsoMaker, uint8_t uLevel)
     534{
     535    PRTFSISOMAKERINT pThis = hIsoMaker;
     536    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     537    AssertReturn(!pThis->fSeenContent, VERR_WRONG_ORDER);
     538    AssertReturn(uLevel <= 2, VERR_INVALID_PARAMETER);
     539
     540    pThis->uJolietRockRidgeLevel = uLevel;
     541    return VINF_SUCCESS;
     542}
     543
     544
     545/*
     546 *
     547 * Object level config
     548 * Object level config
     549 * Object level config
     550 *
     551 */
     552
     553
     554DECL_NO_INLINE(static, PRTFSISOMAKEROBJ) rtFsIsoMakerIndexToObj(PRTFSISOMAKERINT pThis, uint32_t idxObj)
     555{
     556    PRTFSISOMAKEROBJ pObj;
     557    RTListForEachReverse(&pThis->ObjectHead, pObj, RTFSISOMAKEROBJ, Entry)
     558    {
     559        if (pObj->idxObj == idxObj)
     560            return pObj;
     561    }
     562    return NULL;
     563}
     564
     565
     566DECLINLINE(PRTFSISOMAKEROBJ) rtFsIsoMakerIndexToObj(PRTFSISOMAKERINT pThis, uint32_t idxObj)
     567{
     568    PRTFSISOMAKEROBJ pObj = RTListGetLast(&pThis->ObjectHead, RTFSISOMAKEROBJ, Entry);
     569    if (!pObj || RT_LIKELY(pObj->idxObj == idxObj))
     570        return pObj;
     571    return rtFsIsoMakerIndexToObjSlow(pThis, idxObj)
     572}
     573
     574
     575/**
     576 * Adds an unnamed directory to the image.
     577 *
     578 * The directory must explictly be entered into the desired namespaces.
     579 *
     580 * @returns IPRT status code
     581 * @param   hIsoMaker           The ISO maker handle.
     582 * @param   pidxObj             Where to return the configuration index of the
     583 *                              directory.
     584 */
     585RTDECL(int) RTFsIsoMakerAddUnnamedDir(RTFSISOMAKER hIsoMaker, uint32_t *pidxObj)
     586{
     587    PRTFSISOMAKERINT pThis = hIsoMaker;
     588    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     589    AssertPtr(pidxObj);
     590
     591
     592
     593    return VINF_SUCCESS;
     594}
     595
     596static int rtTFsIsoMakerObjSetPathInOne(RTFSISOMAKER hIsoMaker, uint32_t idxEntry,
     597                                        uint32_t fNamespace, const char *pszPath)
     598{
     599
     600}
     601
     602
     603/**
     604 * Sets the path (name) of an object in the selected namespaces.
     605 *
     606 * The name will be transformed as necessary.
     607 *
     608 * The initial implementation does not allow this function to be called more
     609 * than once on an object.
     610 *
     611 * @returns IPRT status code.
     612 * @param   hIsoMaker           The ISO maker handle.
     613 * @param   idxObj              The configuration index of to name.
     614 * @param   fNamespaces         The namespaces to apply the path to.
     615 * @param   pszPath             The ISO-9660 path.
     616 */
     617RTDECL(int) RTFsIsoMakerObjSetPath(RTFSISOMAKER hIsoMaker, uint32_t idxObj, uint32_t fNamespaces, const char *pszPath)
     618{
     619    /*
     620     * Validate and translate input.
     621     */
     622    PRTFSISOMAKERINT pThis = hIsoMaker;
     623    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     624    AssertReturn(!(fNamespaces & ~RTFSISOMAKERNAMESPACE_VALID_MASK), VERR_INVALID_FLAGS);
     625    AssertPtrReturn(pszPath);
     626    AssertReturn(RTPATH_IS_SLASH(pszPath == '/'), VERR_INVALID_NAME);
     627    PRTFSISOMAKEROBJ pObj = rtFsIsoMakerIndexToObj(pThis, idxObj);
     628    AssertReturn(pObj, VERR_OUT_OF_RANGE);
     629
     630    /*
     631     * Execute requested actions.
     632     */
     633    int rc = VINF_SUCCESS;
     634    for (uint32_t i = 0; i < RT_ELEMENTS(g_aRTFsIosNamespaces); i++)
     635        if (fNamespace & g_aRTFsIosNamespaces[i].fNamespace)
     636        {
     637            int rc2 = rtTFsIsoMakerObjSetPathInOne(pThis, pEntry, g_aRTFsIosNamespaces[i].fNamespace, pszPath,
     638                                                   (PRTFSISOMAKERNAME *)((uintptr_t)pThis + g_aRTFsIosNamespaces[i].offRoot),
     639                                                   (PRTFSISOMAKERNAMESPACE *)((uintptr_t)pEntry + g_aRTFsIosNamespaces[i].offName));
     640            if (RT_SUCCESS(rc2) || RT_FAILURE(rc))
     641                continue;
     642            rc = rc2;
     643        }
     644    return rc;
     645}
     646
     647
     648
     649
     650/**
     651 * Adds a directory to the image.
     652 *
     653 * @returns IPRT status code
     654 * @param   hIsoMaker           The ISO maker handle.
     655 * @param   pszDir              The path (UTF-8) to the directory in the ISO.
     656 *
     657 * @param   pidxEntry           Where to return the configuration index of the
     658 *                              directory.  Optional.
     659 */
     660RTDECL(int) RTFsIsoMakerAddDir(RTFSISOMAKER hIsoMaker, const char *pszDir, uint32_t *pidxEntry)
     661{
     662    PRTFSISOMAKERINT pThis = hIsoMaker;
     663    RTFSISOMAKER_ASSER_VALID_HANDLE_RET(pThis);
     664
     665
     666    AssertReturn(!pThis->fSeenContent, VERR_WRONG_ORDER);
     667    AssertReturn(uLevel <= 2, VERR_INVALID_PARAMETER);
     668
     669    pThis->uJolietRockRidgeLevel = uLevel;
     670    return VINF_SUCCESS;
     671}
     672
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