Index: /trunk/src/VBox/Main/MachineImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MachineImpl.cpp	(revision 31238)
+++ /trunk/src/VBox/Main/MachineImpl.cpp	(revision 31239)
@@ -9007,6 +9007,6 @@
     /* enumerate new attachments */
     for (MediaData::AttachmentList::const_iterator it = mMediaData->mAttachments.begin();
-            it != mMediaData->mAttachments.end();
-            ++it)
+         it != mMediaData->mAttachments.end();
+         ++it)
     {
         MediumAttachment *pAttach = *it;
Index: /trunk/src/VBox/Main/MediumImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/MediumImpl.cpp	(revision 31238)
+++ /trunk/src/VBox/Main/MediumImpl.cpp	(revision 31239)
@@ -1431,5 +1431,5 @@
     /* cannot change the type of a differencing medium */
     if (m->pParent)
-        return setError(E_FAIL,
+        return setError(VBOX_E_INVALID_OBJECT_STATE,
                         tr("Cannot change the type of medium '%s' because it is a differencing medium"),
                         m->strLocationFull.raw());
@@ -1437,5 +1437,5 @@
     /* cannot change the type of a medium being in use by more than one VM */
     if (m->backRefs.size() > 1)
-        return setError(E_FAIL,
+        return setError(VBOX_E_INVALID_OBJECT_STATE,
                         tr("Cannot change the type of medium '%s' because it is attached to %d virtual machines"),
                         m->strLocationFull.raw(), m->backRefs.size());
@@ -1456,5 +1456,5 @@
             /* cannot change to writethrough or shareable if there are children */
             if (getChildren().size() != 0)
-                return setError(E_FAIL,
+                return setError(VBOX_E_OBJECT_IN_USE,
                                 tr("Cannot change type for medium '%s' since it has %d child media"),
                                 m->strLocationFull.raw(), getChildren().size());
@@ -1463,8 +1463,7 @@
                 MediumVariant_T variant = getVariant();
                 if (!(variant & MediumVariant_Fixed))
-                    return setError(E_FAIL,
+                    return setError(VBOX_E_INVALID_OBJECT_STATE,
                                     tr("Cannot change type for medium '%s' to 'Shareable' since it is a dynamic medium storage unit"),
                                     m->strLocationFull.raw());
-
             }
             break;
@@ -2195,9 +2194,9 @@
 
     if (m->type == MediumType_Writethrough)
-        return setError(E_FAIL,
+        return setError(VBOX_E_INVALID_OBJECT_STATE,
                         tr("Medium type of '%s' is Writethrough"),
                         m->strLocationFull.raw());
     else if (m->type == MediumType_Shareable)
-        return setError(E_FAIL,
+        return setError(VBOX_E_INVALID_OBJECT_STATE,
                         tr("Medium type of '%s' is Shareable"),
                         m->strLocationFull.raw());
@@ -2681,5 +2680,5 @@
 
     if (m->numCreateDiffTasks > 0)
-        return setError(E_FAIL,
+        return setError(VBOX_E_OBJECT_IN_USE,
                         tr("Cannot attach medium '%s' {%RTuuid}: %u differencing child media are being created"),
                         m->strLocationFull.raw(),
@@ -2724,5 +2723,5 @@
             dumpBackRefs();
 #endif
-            return setError(E_FAIL,
+            return setError(VBOX_E_OBJECT_IN_USE,
                             tr("Cannot attach medium '%s' {%RTuuid} from snapshot '%RTuuid': medium is already in use by this snapshot!"),
                             m->strLocationFull.raw(),
@@ -3107,5 +3106,5 @@
         int vrc = m->pVirtualBox->calculateFullPath(location, location);
         if (RT_FAILURE(vrc))
-            return setError(E_FAIL,
+            return setError(VBOX_E_FILE_ERROR,
                             tr("Invalid medium storage file location '%s' (%Rrc)"),
                             location.raw(),
@@ -4381,5 +4380,5 @@
 
                 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_INVALID_OBJECT_STATE,
                                tr("Media '%s' and '%s' are unrelated"),
                                m->strLocationFull.raw(), tgtLoc.raw());
@@ -4427,5 +4426,5 @@
             if (getChildren().size() > 1)
             {
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_INVALID_OBJECT_STATE,
                                tr("Medium '%s' involved in the merge operation has more than one child medium (%d)"),
                                m->strLocationFull.raw(), getChildren().size());
@@ -4441,9 +4440,9 @@
                     || (   (!aSnapshotId || !aSnapshotId->isEmpty())
                         && *getFirstMachineBackrefSnapshotId() != *aSnapshotId)))
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_OBJECT_IN_USE,
                                tr("Medium '%s' is attached to %d virtual machines"),
                                m->strLocationFull.raw(), m->backRefs.size());
             if (m->type == MediumType_Immutable)
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_INVALID_OBJECT_STATE,
                                tr("Medium '%s' is immutable"),
                                m->strLocationFull.raw());
@@ -4454,5 +4453,5 @@
             if (pTarget->getChildren().size() > 1)
             {
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_OBJECT_IN_USE,
                                tr("Medium '%s' involved in the merge operation has more than one child medium (%d)"),
                                pTarget->m->strLocationFull.raw(),
@@ -4460,5 +4459,5 @@
             }
             if (pTarget->m->type == MediumType_Immutable)
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_INVALID_OBJECT_STATE,
                                tr("Medium '%s' is immutable"),
                                pTarget->m->strLocationFull.raw());
@@ -4473,5 +4472,5 @@
             if (pLast->getChildren().size() > 1)
             {
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_OBJECT_IN_USE,
                                tr("Medium '%s' involved in the merge operation has more than one child medium (%d)"),
                                pLast->m->strLocationFull.raw(),
@@ -4479,5 +4478,5 @@
             }
             if (pLast->m->backRefs.size() != 0)
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_OBJECT_IN_USE,
                                tr("Medium '%s' is attached to %d virtual machines"),
                                pLast->m->strLocationFull.raw(),
@@ -4873,5 +4872,5 @@
 
     if (getChildren().size() != 0)
-        return setError(E_FAIL,
+        return setError(VBOX_E_OBJECT_IN_USE,
                         tr("Cannot close medium '%s' because it has %d child media"),
                         m->strLocationFull.raw(), getChildren().size());
@@ -5382,7 +5381,7 @@
                                task.mVDOperationIfaces);
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
-                            tr("Could not create the medium storage unit '%s'%s"),
-                            location.raw(), vdError(vrc).raw());
+                throw setError(VBOX_E_FILE_ERROR,
+                               tr("Could not create the medium storage unit '%s'%s"),
+                               location.raw(), vdError(vrc).raw());
 
             size = VDGetFileSize(hdd, 0);
@@ -5528,5 +5527,5 @@
                              pMedium->m->vdDiskIfaces);
                 if (RT_FAILURE(vrc))
-                    throw setError(E_FAIL,
+                    throw setError(VBOX_E_FILE_ERROR,
                                    tr("Could not open the medium storage unit '%s'%s"),
                                    pMedium->m->strLocationFull.raw(),
@@ -5550,5 +5549,5 @@
                                task.mVDOperationIfaces);
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_FILE_ERROR,
                                 tr("Could not create the differencing medium storage unit '%s'%s"),
                                 targetLocation.raw(), vdError(vrc).raw());
@@ -5783,5 +5782,5 @@
         catch (int aVRC)
         {
-            throw setError(E_FAIL,
+            throw setError(VBOX_E_FILE_ERROR,
                             tr("Could not merge the medium '%s' to '%s'%s"),
                             m->strLocationFull.raw(),
@@ -6013,8 +6012,8 @@
                              pMedium->m->vdDiskIfaces);
                 if (RT_FAILURE(vrc))
-                    throw setError(E_FAIL,
-                                    tr("Could not open the medium storage unit '%s'%s"),
-                                    pMedium->m->strLocationFull.raw(),
-                                    vdError(vrc).raw());
+                    throw setError(VBOX_E_FILE_ERROR,
+                                   tr("Could not open the medium storage unit '%s'%s"),
+                                   pMedium->m->strLocationFull.raw(),
+                                   vdError(vrc).raw());
             }
 
@@ -6077,5 +6076,5 @@
                                  pMedium->m->vdDiskIfaces);
                     if (RT_FAILURE(vrc))
-                        throw setError(E_FAIL,
+                        throw setError(VBOX_E_FILE_ERROR,
                                        tr("Could not open the medium storage unit '%s'%s"),
                                        pMedium->m->strLocationFull.raw(),
@@ -6097,7 +6096,7 @@
                              task.mVDOperationIfaces);
                 if (RT_FAILURE(vrc))
-                    throw setError(E_FAIL,
-                                    tr("Could not create the clone medium '%s'%s"),
-                                    targetLocation.raw(), vdError(vrc).raw());
+                    throw setError(VBOX_E_FILE_ERROR,
+                                   tr("Could not create the clone medium '%s'%s"),
+                                   targetLocation.raw(), vdError(vrc).raw());
 
                 size = VDGetFileSize(targetHdd, VD_LAST_IMAGE);
@@ -6232,7 +6231,7 @@
 
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
-                                tr("Could not delete the medium storage unit '%s'%s"),
-                                location.raw(), vdError(vrc).raw());
+                throw setError(VBOX_E_FILE_ERROR,
+                               tr("Could not delete the medium storage unit '%s'%s"),
+                               location.raw(), vdError(vrc).raw());
 
         }
@@ -6327,5 +6326,5 @@
                              pMedium->m->vdDiskIfaces);
                 if (RT_FAILURE(vrc))
-                    throw setError(E_FAIL,
+                    throw setError(VBOX_E_FILE_ERROR,
                                    tr("Could not open the medium storage unit '%s'%s"),
                                    pMedium->m->strLocationFull.raw(),
@@ -6340,5 +6339,5 @@
             vrc = VDClose(hdd, true /* fDelete */);
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
+                throw setError(VBOX_E_FILE_ERROR,
                                tr("Could not delete the medium storage unit '%s'%s"),
                                location.raw(), vdError(vrc).raw());
@@ -6351,7 +6350,7 @@
                          m->vdDiskIfaces);
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
-                                tr("Could not open the medium storage unit '%s'%s"),
-                                parentLocation.raw(), vdError(vrc).raw());
+                throw setError(VBOX_E_FILE_ERROR,
+                               tr("Could not open the medium storage unit '%s'%s"),
+                               parentLocation.raw(), vdError(vrc).raw());
 
             vrc = VDCreateDiff(hdd,
@@ -6367,7 +6366,7 @@
                                task.mVDOperationIfaces);
             if (RT_FAILURE(vrc))
-                throw setError(E_FAIL,
-                                tr("Could not create the differencing medium storage unit '%s'%s"),
-                                location.raw(), vdError(vrc).raw());
+                throw setError(VBOX_E_FILE_ERROR,
+                               tr("Could not create the differencing medium storage unit '%s'%s"),
+                               location.raw(), vdError(vrc).raw());
 
             size = VDGetFileSize(hdd, VD_LAST_IMAGE);
@@ -6457,5 +6456,5 @@
                              pMedium->m->vdDiskIfaces);
                 if (RT_FAILURE(vrc))
-                    throw setError(E_FAIL,
+                    throw setError(VBOX_E_FILE_ERROR,
                                    tr("Could not open the medium storage unit '%s'%s"),
                                    pMedium->m->strLocationFull.raw(),
@@ -6482,5 +6481,5 @@
                                    location.raw());
                 else
-                    throw setError(E_FAIL,
+                    throw setError(VBOX_E_FILE_ERROR,
                                    tr("Could not compact medium '%s'%s"),
                                    location.raw(),
