Index: trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 48827)
+++ trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 48879)
@@ -4122,5 +4122,5 @@
   <interface
     name="IMachine" extends="$unknown"
-    uuid="7108c7c7-2c0a-47ee-9c69-022fe2a466bf"
+    uuid="480cf695-2d8d-4256-9c7c-cce4184fa048"
     wsmap="managed"
     >
@@ -5564,4 +5564,44 @@
     </method>
 
+    <method name="setHotPluggableForDevice">
+      <desc>
+        Sets a flag in the device information which indicates that the attached
+        device is hot pluggable or not. This may or may not be supported by a
+        particular controller and/or drive, and is silently ignored in the
+        latter case. Changing the setting while the VM is running is forbidden.
+        The device must already exist; see <link to="IMachine::attachDevice"/>
+        for how to attach a new device.
+
+        The @a controllerPort and @a device parameters specify the device slot and
+        have have the same meaning as with <link to="IMachine::attachDevice" />.
+
+        <result name="E_INVALIDARG">
+          SATA device, SATA port, IDE port or IDE slot out of range.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Attempt to modify an unregistered virtual machine.
+        </result>
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Invalid machine state.
+        </result>
+        <result name="VBOX_E_NOT_SUPPORTED">
+          Controller doesn't support hot plugging.
+        </result>
+      </desc>
+
+      <param name="name" type="wstring" dir="in">
+        <desc>Name of the storage controller.</desc>
+      </param>
+      <param name="controllerPort" type="long" dir="in">
+        <desc>Storage controller port.</desc>
+      </param>
+      <param name="device" type="long" dir="in">
+        <desc>Device slot in the given port.</desc>
+      </param>
+      <param name="hotPluggable" type="boolean" dir="in">
+        <desc>New value for the hot-pluggable device flag.</desc>
+      </param>
+    </method>
+
     <method name="setBandwidthGroupForDevice">
       <desc>
@@ -5629,54 +5669,54 @@
 
     <method name="unmountMedium">
-          <desc>
-            Unmounts any currently mounted medium (<link to="IMedium" />,
-            identified by the given UUID @a id) to the given storage controller
-            (<link to="IStorageController" />, identified by @a name),
-            at the indicated port and device. The device must already exist;
-
-            This method is intended only for managing removable media, where the
-            device is fixed but media is changeable at runtime (such as DVDs
-            and floppies). It cannot be used for fixed media such as hard disks.
-
-            The @a controllerPort and @a device parameters specify the device slot
-            and have have the same meaning as with
-            <link to="IMachine::attachDevice" />.
-
-            The specified device slot must have a medium mounted, which will be
-            unmounted. If there is no mounted medium it will do nothing.
-            See <link to="IMedium"/> for more detailed information about
-            attaching/unmounting media.
-
-            <result name="E_INVALIDARG">
-            SATA device, SATA port, IDE port or IDE slot out of range.
-            </result>
-            <result name="VBOX_E_INVALID_OBJECT_STATE">
-            Attempt to unmount medium that is not removable - not DVD or floppy.
-            </result>
-            <result name="VBOX_E_INVALID_VM_STATE">
-            Invalid machine state.
-            </result>
-            <result name="VBOX_E_OBJECT_IN_USE">
-            Medium already attached to this or another virtual machine.
-            </result>
-            <result name="VBOX_E_OBJECT_NOT_FOUND">
-            Medium not attached to specified port, device, controller.
-            </result>
-
-            </desc>
-              <param name="name" type="wstring" dir="in">
-              <desc>Name of the storage controller to unmount the medium from.</desc>
-              </param>
-              <param name="controllerPort" type="long" dir="in">
-              <desc>Port to unmount the medium from.</desc>
-              </param>
-              <param name="device" type="long" dir="in">
-              <desc>Device slot in the given port to unmount the medium from.</desc>
-              </param>
-              <param name="force" type="boolean" dir="in">
-              <desc>Allows to force unmount of a medium which is locked by
-              the device slot in the given port medium is attached to.</desc>
-              </param>
-          </method>
+      <desc>
+        Unmounts any currently mounted medium (<link to="IMedium" />,
+        identified by the given UUID @a id) to the given storage controller
+        (<link to="IStorageController" />, identified by @a name),
+        at the indicated port and device. The device must already exist;
+
+        This method is intended only for managing removable media, where the
+        device is fixed but media is changeable at runtime (such as DVDs
+        and floppies). It cannot be used for fixed media such as hard disks.
+
+        The @a controllerPort and @a device parameters specify the device slot
+        and have have the same meaning as with
+        <link to="IMachine::attachDevice" />.
+
+        The specified device slot must have a medium mounted, which will be
+        unmounted. If there is no mounted medium it will do nothing.
+        See <link to="IMedium"/> for more detailed information about
+        attaching/unmounting media.
+
+        <result name="E_INVALIDARG">
+          SATA device, SATA port, IDE port or IDE slot out of range.
+        </result>
+        <result name="VBOX_E_INVALID_OBJECT_STATE">
+          Attempt to unmount medium that is not removable - not DVD or floppy.
+        </result>
+        <result name="VBOX_E_INVALID_VM_STATE">
+          Invalid machine state.
+        </result>
+        <result name="VBOX_E_OBJECT_IN_USE">
+          Medium already attached to this or another virtual machine.
+        </result>
+        <result name="VBOX_E_OBJECT_NOT_FOUND">
+          Medium not attached to specified port, device, controller.
+        </result>
+      </desc>
+
+      <param name="name" type="wstring" dir="in">
+        <desc>Name of the storage controller to unmount the medium from.</desc>
+      </param>
+      <param name="controllerPort" type="long" dir="in">
+        <desc>Port to unmount the medium from.</desc>
+      </param>
+      <param name="device" type="long" dir="in">
+        <desc>Device slot in the given port to unmount the medium from.</desc>
+      </param>
+      <param name="force" type="boolean" dir="in">
+        <desc>Allows to force unmount of a medium which is locked by
+        the device slot in the given port medium is attached to.</desc>
+      </param>
+    </method>
 
     <method name="mountMedium">
@@ -12854,5 +12894,5 @@
   <interface
     name="IMediumAttachment" extends="$unknown"
-    uuid="5ee464d6-0613-4331-b154-7ce12170ef9f"
+    uuid="4b252567-5d4e-4db8-b3c8-569ec1c9236c"
     wsmap="struct"
     >
@@ -13082,4 +13122,8 @@
     <attribute name="discard" type="boolean" readonly="yes">
       <desc>Whether the associated medium supports discarding unused blocks.</desc>
+    </attribute>
+
+    <attribute name="hotPluggable" type="boolean" readonly="yes">
+      <desc>Whether this attachment is hot pluggable or not.</desc>
     </attribute>
 
Index: trunk/src/VBox/Main/include/MachineImpl.h
===================================================================
--- trunk/src/VBox/Main/include/MachineImpl.h	(revision 48827)
+++ trunk/src/VBox/Main/include/MachineImpl.h	(revision 48879)
@@ -543,4 +543,5 @@
     STDMETHOD(NonRotationalDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aNonRotational);
     STDMETHOD(SetAutoDiscardForDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aDiscard);
+    STDMETHOD(SetHotPluggableForDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aHotPluggable);
     STDMETHOD(SetNoBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
                                             LONG aDevice);
Index: trunk/src/VBox/Main/include/MediumAttachmentImpl.h
===================================================================
--- trunk/src/VBox/Main/include/MediumAttachmentImpl.h	(revision 48827)
+++ trunk/src/VBox/Main/include/MediumAttachmentImpl.h	(revision 48879)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2011 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -52,4 +52,5 @@
                  bool fNonRotational,
                  bool fDiscard,
+                 bool fHotPluggable,
                  const Utf8Str &strBandwidthGroup);
     HRESULT initCopy(Machine *aParent, MediumAttachment *aThat);
@@ -71,4 +72,5 @@
     STDMETHOD(COMGETTER(Discard))(BOOL *aDiscard);
     STDMETHOD(COMGETTER(BandwidthGroup))(IBandwidthGroup **aBwGroup);
+    STDMETHOD(COMGETTER(HotPluggable))(BOOL *aHotPluggable);
 
     // public internal methods
@@ -91,4 +93,5 @@
     bool getDiscard() const;
     const Utf8Str& getBandwidthGroup() const;
+    bool getHotPluggable() const;
 
     bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice);
@@ -117,4 +120,7 @@
     void updateParentMachine(Machine * const pMachine);
 
+    /** Must be called from under this object's write lock. */
+    void updateHotPluggable(bool aHotPluggable);
+
     /** Get a unique and somewhat descriptive name for logging. */
     const char* getLogName(void) const { return mLogName.c_str(); }
Index: trunk/src/VBox/Main/src-server/MachineImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 48827)
+++ trunk/src/VBox/Main/src-server/MachineImpl.cpp	(revision 48879)
@@ -4501,4 +4501,5 @@
                           false /* fNonRotational */,
                           false /* fDiscard */,
+                          false /* fHotPluggable */,
                           Utf8Str::Empty);
     if (FAILED(rc)) return rc;
@@ -4828,4 +4829,56 @@
                         aDevice, aControllerPort, aControllerName);
     pAttach->updateDiscard(!!aDiscard);
+
+    return S_OK;
+}
+
+STDMETHODIMP Machine::SetHotPluggableForDevice(IN_BSTR aControllerName, LONG aControllerPort,
+                                               LONG aDevice, BOOL aHotPluggable)
+{
+    CheckComArgStrNotEmptyOrNull(aControllerName);
+
+    LogFlowThisFunc(("aControllerName=\"%ls\" aControllerPort=%d aDevice=%d aHotPluggable=%d\n",
+                     aControllerName, aControllerPort, aDevice, aHotPluggable));
+
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    HRESULT rc = checkStateDependency(MutableStateDep);
+    if (FAILED(rc)) return rc;
+
+    AssertReturn(mData->mMachineState != MachineState_Saved, E_FAIL);
+
+    if (Global::IsOnlineOrTransient(mData->mMachineState))
+        return setError(VBOX_E_INVALID_VM_STATE,
+                        tr("Invalid machine state: %s"),
+                        Global::stringifyMachineState(mData->mMachineState));
+
+    MediumAttachment *pAttach = findAttachment(mMediaData->mAttachments,
+                                               aControllerName,
+                                               aControllerPort,
+                                               aDevice);
+    if (!pAttach)
+        return setError(VBOX_E_OBJECT_NOT_FOUND,
+                        tr("No storage device attached to device slot %d on port %d of controller '%ls'"),
+                        aDevice, aControllerPort, aControllerName);
+
+    /** @todo remove this blocker and add the missing code to support this
+     * flag properly in all code areas, with proper support checks below. */
+    return setError(VBOX_E_NOT_SUPPORTED,
+                    tr("Controller '%ls' does not support changing the hot-pluggable device flag"),
+                    aControllerName);
+
+    setModified(IsModified_Storage);
+    mMediaData.backup();
+
+    AutoWriteLock attLock(pAttach COMMA_LOCKVAL_SRC_POS);
+
+    if (pAttach->getType() == DeviceType_Floppy)
+        return setError(E_INVALIDARG,
+                        tr("Setting the hot-pluggable device flag rejected as the device attached to device slot %d on port %d of controller '%ls' is a floppy drive"),
+                        aDevice, aControllerPort, aControllerName);
+    pAttach->updateHotPluggable(!!aHotPluggable);
 
     return S_OK;
@@ -9716,4 +9769,6 @@
                                dev.fNonRotational,
                                dev.fDiscard,
+        /// @todo load setting once the hot-pluggable flag works
+                               false /*dev.fHotPluggable*/,
                                pBwGroup.isNull() ? Utf8Str::Empty : pBwGroup->getName());
         if (FAILED(rc)) break;
@@ -10819,4 +10874,6 @@
         dev.lDevice = pAttach->getDevice();
         dev.fPassThrough = pAttach->getPassthrough();
+        /// @todo save setting once the hot-pluggable flag works
+        dev.fHotPluggable = false /* pAttach->getHotPluggable()*/;
         if (pMedium)
         {
@@ -11161,4 +11218,5 @@
                                   pAtt->getNonRotational(),
                                   pAtt->getDiscard(),
+                                  pAtt->getHotPluggable(),
                                   pAtt->getBandwidthGroup());
             if (FAILED(rc)) throw rc;
@@ -12777,5 +12835,5 @@
         {
             Bstr name;
-            
+
             hrc = mNetworkAdapters[slot]->COMGETTER(NATNetwork)(name.asOutParam());
             if (SUCCEEDED(hrc))
Index: trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp	(revision 48827)
+++ trunk/src/VBox/Main/src-server/MediumAttachmentImpl.cpp	(revision 48879)
@@ -5,5 +5,5 @@
 
 /*
- * Copyright (C) 2006-2011 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -43,5 +43,6 @@
           fNonRotational(false),
           fDiscard(false),
-          fImplicit(false)
+          fImplicit(false),
+          fHotPluggable(false)
     { }
 
@@ -63,4 +64,5 @@
     bool                fDiscard;
     bool                fImplicit;
+    bool                fHotPluggable;
 };
 
@@ -123,8 +125,9 @@
                                bool aNonRotational,
                                bool aDiscard,
+                               bool aHotPluggable,
                                const Utf8Str &strBandwidthGroup)
 {
     LogFlowThisFuncEnter();
-    LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d aPassthrough=%d aTempEject=%d aNonRotational=%d strBandwithGroup=%s\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aImplicit, aPassthrough, aTempEject, aNonRotational, strBandwidthGroup.c_str()));
+    LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d aPassthrough=%d aTempEject=%d aNonRotational=%d aDiscard=%d aHotPluggable=%d strBandwithGroup=%s\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aImplicit, aPassthrough, aTempEject, aNonRotational, aDiscard, aHotPluggable, strBandwidthGroup.c_str()));
 
     if (aType == DeviceType_HardDisk)
@@ -152,4 +155,5 @@
     m->bd->fDiscard = aDiscard;
     m->bd->fImplicit = aImplicit;
+    m->bd->fHotPluggable = aHotPluggable;
 
     /* Confirm a successful initialization when it's the case */
@@ -417,4 +421,21 @@
 }
 
+STDMETHODIMP MediumAttachment::COMGETTER(HotPluggable)(BOOL *aHotPluggable)
+{
+    LogFlowThisFuncEnter();
+
+    CheckComArgOutPointerValid(aHotPluggable);
+
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    AutoReadLock lock(this COMMA_LOCKVAL_SRC_POS);
+
+    *aHotPluggable = m->bd->fHotPluggable;
+
+    LogFlowThisFuncLeave();
+    return S_OK;
+}
+
 /**
  *  @note Locks this object for writing.
@@ -511,4 +532,10 @@
     AutoReadLock lock(this COMMA_LOCKVAL_SRC_POS);
     return m->bd->fDiscard;
+}
+
+bool MediumAttachment::getHotPluggable() const
+{
+    AutoReadLock lock(this COMMA_LOCKVAL_SRC_POS);
+    return m->bd->fHotPluggable;
 }
 
Index: trunk/src/VBox/Main/xml/Settings.cpp
===================================================================
--- trunk/src/VBox/Main/xml/Settings.cpp	(revision 48827)
+++ trunk/src/VBox/Main/xml/Settings.cpp	(revision 48879)
@@ -2022,4 +2022,5 @@
                   && (fNonRotational            == a.fNonRotational)
                   && (fDiscard                  == a.fDiscard)
+                  && (fHotPluggable             == a.fHotPluggable)
                   && (lPort                     == a.lPort)
                   && (lDevice                   == a.lDevice)
@@ -3489,4 +3490,5 @@
                     throw ConfigFileError(this, pelmImage, N_("Required AttachedDevice/@device attribute is missing"));
 
+                pelmAttached->getAttributeValue("hotpluggable", att.fHotPluggable);
                 pelmAttached->getAttributeValue("bandwidthGroup", att.strBwGroup);
                 sctl.llAttachedDevices.push_back(att);
@@ -4918,4 +4920,7 @@
             pelmDevice->setAttribute("type", pcszType);
 
+            if (att.fHotPluggable)
+                pelmDevice->setAttribute("hotpluggable", att.fHotPluggable);
+
             pelmDevice->setAttribute("port", att.lPort);
             pelmDevice->setAttribute("device", att.lDevice);
Index: trunk/src/VBox/Main/xml/VirtualBox-settings.xsd
===================================================================
--- trunk/src/VBox/Main/xml/VirtualBox-settings.xsd	(revision 48827)
+++ trunk/src/VBox/Main/xml/VirtualBox-settings.xsd	(revision 48879)
@@ -626,4 +626,5 @@
   <xsd:attribute name="nonrotational" type="xsd:boolean" default="false"/>
   <xsd:attribute name="discard" type="xsd:boolean" default="false"/>
+  <xsd:attribute name="hotpluggable" type="xsd:boolean" default="false"/>
 </xsd:complexType>
 
