VirtualBox

Changeset 6379 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jan 18, 2008 5:25:20 PM (17 years ago)
Author:
vboxsync
Message:

support read-only shared folders

Location:
trunk/src/VBox/Main
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r6375 r6379  
    882882        vrc = SSMR3PutStrZ (pSSM, hostPath);
    883883        AssertRC (vrc);
     884
     885//        XXX
     886//        vrc = SSMR3PutBool (pSSM, folder->writable());
     887//        AssertRC (vrc);
    884888    }
    885889
     
    953957        ComObjPtr <SharedFolder> sharedFolder;
    954958        sharedFolder.createObject();
    955         HRESULT rc = sharedFolder->init (that, name, hostPath);
     959        HRESULT rc = sharedFolder->init (that, name, hostPath, PR_TRUE); /* TODO: fWritable */
    956960        AssertComRCReturn (rc, VERR_INTERNAL_ERROR);
    957961
     
    13151319        for (SharedFolderMap::const_iterator it = mSharedFolders.begin();
    13161320             it != mSharedFolders.end(); ++ it)
    1317             sharedFolders [it->first] = it->second->hostPath();
     1321            sharedFolders [it->first] = SharedFolderData(it->second->hostPath(), it->second->writable());
    13181322    }
    13191323
     
    19911995
    19921996STDMETHODIMP
    1993 Console::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath)
     1997Console::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable)
    19941998{
    19951999    if (!aName || !aHostPath)
     
    20192023
    20202024    sharedFolder.createObject();
    2021     rc = sharedFolder->init (this, aName, aHostPath);
     2025    rc = sharedFolder->init (this, aName, aHostPath, aWritable);
    20222026    CheckComRCReturnRC (rc);
    20232027
     
    20472051
    20482052        /* second, create the given folder */
    2049         rc = createSharedFolder (aName, aHostPath);
     2053        rc = createSharedFolder (aName, SharedFolderData (aHostPath, aWritable));
    20502054        CheckComRCReturnRC (rc);
    20512055    }
     
    41954199            Bstr name;
    41964200            Bstr hostPath;
     4201            BOOL writable;
    41974202
    41984203            rc = folder->COMGETTER(Name) (name.asOutParam());
     
    42004205            rc = folder->COMGETTER(HostPath) (hostPath.asOutParam());
    42014206            CheckComRCBreakRC (rc);
    4202 
    4203             mMachineSharedFolders.insert (std::make_pair (name, hostPath));
     4207            rc = folder->COMGETTER(Writable) (&writable);
     4208
     4209            mMachineSharedFolders.insert (std::make_pair (name, SharedFolderData (hostPath, writable)));
    42044210
    42054211            /* send changes to HGCM if the VM is running */
     
    42084214            {
    42094215                SharedFolderDataMap::iterator it = oldFolders.find (name);
    4210                 if (it == oldFolders.end() || it->second != hostPath)
     4216                if (it == oldFolders.end() || it->second.mHostPath != hostPath)
    42114217                {
    42124218                    /* a new machine folder is added or
     
    42234229                            rc = removeSharedFolder (name);
    42244230                        /* create the new machine folder */
    4225                         rc = createSharedFolder (name, hostPath);
     4231                        rc = createSharedFolder (name, SharedFolderData (hostPath, writable));
    42264232                    }
    42274233                }
     
    43024308 *  @note Doesn't lock anything.
    43034309 */
    4304 HRESULT Console::createSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath)
     4310HRESULT Console::createSharedFolder (INPTR BSTR aName, SharedFolderData aData)
    43054311{
    43064312    ComAssertRet (aName && *aName, E_FAIL);
    4307     ComAssertRet (aHostPath && *aHostPath, E_FAIL);
     4313    ComAssertRet (aData.mHostPath && *aData.mHostPath, E_FAIL);
    43084314
    43094315    /* sanity checks */
     
    43114317    AssertReturn (mVMMDev->isShFlActive(), E_FAIL);
    43124318
    4313     VBOXHGCMSVCPARM  parms[2];
     4319    VBOXHGCMSVCPARM  parms[SHFL_CPARMS_ADD_MAPPING];
    43144320    SHFLSTRING      *pFolderName, *pMapName;
    43154321    size_t           cbString;
     
    43174323    Log (("Adding shared folder '%ls' -> '%ls'\n", aName, aHostPath));
    43184324
    4319     cbString = (RTStrUcs2Len (aHostPath) + 1) * sizeof (RTUCS2);
     4325    cbString = (RTStrUcs2Len (aData.mHostPath) + 1) * sizeof (RTUCS2);
    43204326    if (cbString >= UINT16_MAX)
    43214327        return setError (E_INVALIDARG, tr ("The name is too long"));
    43224328    pFolderName = (SHFLSTRING *) RTMemAllocZ (sizeof (SHFLSTRING) + cbString);
    43234329    Assert (pFolderName);
    4324     memcpy (pFolderName->String.ucs2, aHostPath, cbString);
     4330    memcpy (pFolderName->String.ucs2, aData.mHostPath, cbString);
    43254331
    43264332    pFolderName->u16Size   = (uint16_t)cbString;
     
    43484354    parms[1].u.pointer.size = sizeof (SHFLSTRING) + (uint16_t)cbString;
    43494355
     4356    parms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
     4357    parms[2].u.uint32 = aData.mWritable;
     4358
    43504359    int vrc = mVMMDev->hgcmHostCall ("VBoxSharedFolders",
    43514360                                     SHFL_FN_ADD_MAPPING,
    4352                                      2, &parms[0]);
     4361                                     SHFL_CPARMS_ADD_MAPPING, &parms[0]);
    43534362    RTMemFree (pFolderName);
    43544363    RTMemFree (pMapName);
     
    43584367                         tr ("Could not create a shared folder '%ls' "
    43594368                             "mapped to '%ls' (%Vrc)"),
    4360                          aName, aHostPath, vrc);
     4369                         aName, aData.mHostPath.raw(), vrc);
    43614370
    43624371    return S_OK;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r6367 r6379  
    23722372
    23732373STDMETHODIMP
    2374 Machine::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath)
     2374Machine::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable)
    23752375{
    23762376    if (!aName || !aHostPath)
     
    23922392
    23932393    sharedFolder.createObject();
    2394     rc = sharedFolder->init (machine(), aName, aHostPath);
     2394    rc = sharedFolder->init (machine(), aName, aHostPath, aWritable);
    23952395    CheckComRCReturnRC (rc);
    23962396
     
    43144314                Bstr hostPath = (*it).stringValue ("hostPath");
    43154315
    4316                 rc = CreateSharedFolder (name, hostPath);
     4316                bool writable = (*it).value <bool> ("writable");
     4317
     4318                rc = CreateSharedFolder (name, hostPath, writable);
    43174319                CheckComRCReturnRC (rc);
    43184320            }
     
    56615663            folderNode.setValue <Bstr> ("name", folder->name());
    56625664            folderNode.setValue <Bstr> ("hostPath", folder->hostPath());
     5665            folderNode.setValue <bool> ("writable", folder->writable());
    56635666        }
    56645667    }
  • trunk/src/VBox/Main/SharedFolderImpl.cpp

    r5999 r6379  
    5858 *  @param aName        logical name of the shared folder
    5959 *  @param aHostPath    full path to the shared folder on the host
     60 *  @param aWritable    writable if true, readonly otherwise
    6061 *
    6162 *  @return          COM result indicator
    6263 */
    6364HRESULT SharedFolder::init (Machine *aMachine,
    64                             const BSTR aName, const BSTR aHostPath)
     65                            const BSTR aName, const BSTR aHostPath, bool aWritable)
    6566{
    6667    /* Enclose the state transition NotReady->InInit->Ready */
     
    7071    unconst (mMachine) = aMachine;
    7172
    72     HRESULT rc = protectedInit (aMachine, aName, aHostPath);
     73    HRESULT rc = protectedInit (aMachine, aName, aHostPath, aWritable);
    7374
    7475    /* Confirm a successful initialization when it's the case */
     
    100101
    101102    HRESULT rc = protectedInit (aMachine, aThat->mData.mName,
    102                                 aThat->mData.mHostPath);
     103                                aThat->mData.mHostPath, aThat->mData.mWritable);
    103104
    104105    /* Confirm a successful initialization when it's the case */
     
    115116 *  @param aName        logical name of the shared folder
    116117 *  @param aHostPath    full path to the shared folder on the host
     118 *  @param aWritable    writable if true, readonly otherwise
    117119 *
    118120 *  @return          COM result indicator
    119121 */
    120122HRESULT SharedFolder::init (Console *aConsole,
    121                             const BSTR aName, const BSTR aHostPath)
     123                            const BSTR aName, const BSTR aHostPath, bool aWritable)
    122124{
    123125    /* Enclose the state transition NotReady->InInit->Ready */
     
    127129    unconst (mConsole) = aConsole;
    128130
    129     HRESULT rc = protectedInit (aConsole, aName, aHostPath);
     131    HRESULT rc = protectedInit (aConsole, aName, aHostPath, aWritable);
    130132
    131133    /* Confirm a successful initialization when it's the case */
     
    142144 *  @param aName        logical name of the shared folder
    143145 *  @param aHostPath    full path to the shared folder on the host
     146 *  @param aWritable    writable if true, readonly otherwise
    144147 *
    145148 *  @return          COM result indicator
    146149 */
    147150HRESULT SharedFolder::init (VirtualBox *aVirtualBox,
    148                             const BSTR aName, const BSTR aHostPath)
     151                            const BSTR aName, const BSTR aHostPath, bool aWritable)
    149152{
    150153    /* Enclose the state transition NotReady->InInit->Ready */
     
    154157    unconst (mVirtualBox) = aVirtualBox;
    155158
    156     HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath);
     159    HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath, aWritable);
    157160
    158161    /* Confirm a successful initialization when it's the case */
     
    170173 */
    171174HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    172                                      const BSTR aName, const BSTR aHostPath)
    173 {
    174     LogFlowThisFunc (("aName={%ls}, aHostPath={%ls}\n", aName, aHostPath));
     175                                     const BSTR aName, const BSTR aHostPath, bool aWritable)
     176{
     177    LogFlowThisFunc (("aName={%ls}, aHostPath={%ls}, aWritable={%d}\n",
     178                      aName, aHostPath, aWritable));
    175179
    176180    ComAssertRet (aParent && aName && aHostPath, E_INVALIDARG);
     
    216220    unconst (mData.mName) = aName;
    217221    unconst (mData.mHostPath) = hostPath;
     222    mData.mWritable = aWritable;
    218223
    219224    return S_OK;
     
    307312}
    308313
     314STDMETHODIMP SharedFolder::COMGETTER(Writable) (BOOL *aWritable)
     315{
     316    if (!aWritable)
     317        return E_POINTER;
     318
     319    *aWritable = mData.mWritable;
     320
     321    return S_OK;
     322}
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r6367 r6379  
    15751575
    15761576STDMETHODIMP
    1577 VirtualBox::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath)
     1577VirtualBox::CreateSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable)
    15781578{
    15791579    if (!aName || !aHostPath)
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r6265 r6379  
    15731573        <desc>Full path to the shared folder in the host file system.</desc>
    15741574      </param>
     1575      <param name="writable" type="boolean" dir="in">
     1576        <desc>Whether the share is writable or readonly</desc>
     1577      </param>
    15751578    </method>
    15761579
     
    30463049        <desc>Full path to the shared folder in the host file system.</desc>
    30473050      </param>
     3051      <param name="writable" type="boolean" dir="in">
     3052        <desc>Whether the share is writable or readonly</desc>
     3053      </param>
    30483054    </method>
    30493055
     
    39013907      <param name="hostPath" type="wstring" dir="in">
    39023908        <desc>Full path to the shared folder in the host file system.</desc>
     3909      </param>
     3910      <param name="writable" type="boolean" dir="in">
     3911        <desc>Whether the share is writable or readonly</desc>
    39033912      </param>
    39043913    </method>
     
    90379046      </desc>
    90389047    </attribute>
     9048   
     9049    <attribute name="writable" type="boolean" readonly="yes">
     9050      <desc>
     9051        Whether the folder defined by the host path is writable or
     9052        not.
     9053      </desc>
     9054    </attribute>
    90399055
    90409056  </interface>
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r6156 r6379  
    134134    STDMETHOD(AttachUSBDevice) (INPTR GUIDPARAM aId);
    135135    STDMETHOD(DetachUSBDevice) (INPTR GUIDPARAM aId, IUSBDevice **aDevice);
    136     STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
     136    STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable);
    137137    STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
    138138    STDMETHOD(TakeSnapshot) (INPTR BSTR aName, INPTR BSTR aDescription,
     
    353353    typedef SafeVMPtrBase <true> SafeVMPtrQuiet;
    354354
     355    class SharedFolderData
     356    {
     357    public:
     358        SharedFolderData() {}
     359        SharedFolderData(Bstr aHostPath, BOOL aWritable)
     360           : mHostPath (aHostPath)
     361           , mWritable (aWritable) {}
     362        SharedFolderData(const SharedFolderData& aThat)
     363           : mHostPath (aThat.mHostPath)
     364           , mWritable (aThat.mWritable) {}
     365        Bstr mHostPath;
     366        BOOL mWritable;
     367    };
    355368    typedef std::map <Bstr, ComObjPtr <SharedFolder> > SharedFolderMap;
    356     typedef std::map <Bstr, Bstr> SharedFolderDataMap;
     369    typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap;
    357370
    358371private:
     
    386399                                SharedFolderDataMap::const_iterator &aIt);
    387400
    388     HRESULT createSharedFolder (INPTR BSTR aName, INPTR BSTR aHostPath);
     401    HRESULT createSharedFolder (INPTR BSTR aName, SharedFolderData aData);
    389402    HRESULT removeSharedFolder (INPTR BSTR aName);
    390403
  • trunk/src/VBox/Main/include/MachineImpl.h

    r6076 r6379  
    498498    STDMETHOD(FindSnapshot) (INPTR BSTR aName, ISnapshot **aSnapshot);
    499499    STDMETHOD(SetCurrentSnapshot) (INPTR GUIDPARAM aId);
    500     STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
     500    STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable);
    501501    STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
    502502    STDMETHOD(CanShowConsoleWindow) (BOOL *aCanShow);
  • trunk/src/VBox/Main/include/SharedFolderImpl.h

    r5999 r6379  
    4141        const Bstr mName;
    4242        const Bstr mHostPath;
     43        bool       mWritable;
    4344    };
    4445
     
    6263
    6364    // public initializer/uninitializer for internal purposes only
    64     HRESULT init (Machine *aMachine, const BSTR aName, const BSTR aHostPath);
     65    HRESULT init (Machine *aMachine, const BSTR aName, const BSTR aHostPath, bool aWritable);
    6566    HRESULT initCopy (Machine *aMachine, SharedFolder *aThat);
    66     HRESULT init (Console *aConsole, const BSTR aName, const BSTR aHostPath);
    67     HRESULT init (VirtualBox *aVirtualBox, const BSTR aName, const BSTR aHostPath);
     67    HRESULT init (Console *aConsole, const BSTR aName, const BSTR aHostPath, bool aWritable);
     68    HRESULT init (VirtualBox *aVirtualBox, const BSTR aName, const BSTR aHostPath, bool aWritable);
    6869    void uninit();
    6970
     
    7273    STDMETHOD(COMGETTER(HostPath)) (BSTR *aHostPath);
    7374    STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
     75    STDMETHOD(COMGETTER(Writable)) (BOOL *aWritable);
    7476
    7577    // public methods for internal purposes only
     
    8183    const Bstr &name() const { return mData.mName; }
    8284    const Bstr &hostPath() const { return mData.mHostPath; }
     85    BOOL writable() const { return mData.mWritable; }
    8386
    8487    // for VirtualBoxSupportErrorInfoImpl
     
    8891
    8992    HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
    90                            const BSTR aName, const BSTR aHostPath);
     93                           const BSTR aName, const BSTR aHostPath, bool aWritable);
    9194
    9295private:
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r6076 r6379  
    161161
    162162    STDMETHOD(GetGuestOSType) (INPTR BSTR aId, IGuestOSType **aType);
    163     STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
     163    STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath, BOOL aWritable);
    164164    STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
    165165    STDMETHOD(GetNextExtraDataKey) (INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r6173 r6379  
    630630  <xsd:attribute name="name" type="TNonEmptyString" use="required"/>
    631631  <xsd:attribute name="hostPath" type="TLocalFile" use="required"/>
     632  <xsd:attribute name="writable" type="xsd:boolean" default="true"/>
    632633</xsd:complexType>
    633634
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