Index: /trunk/doc/manual/en_US/user_VBoxManage.xml
===================================================================
--- /trunk/doc/manual/en_US/user_VBoxManage.xml	(revision 37928)
+++ /trunk/doc/manual/en_US/user_VBoxManage.xml	(revision 37929)
@@ -1567,5 +1567,5 @@
     <screen>VBoxManage storageattach    &lt;uuid|vmname&gt;
                             --storagectl &lt;name&gt;
-                            --port &lt;number&gt;
+                            [--port &lt;number&gt;]
                             [--device &lt;number&gt;]
                             [--type dvddrive|hdd|fdd]
@@ -1582,5 +1582,5 @@
                             [--server &lt;name&gt;|&lt;ip&gt;]
                             [--target &lt;target&gt;]
-                            [--port &lt;port&gt;]
+                            [--tport &lt;port&gt;]
                             [--lun &lt;lun&gt;]
                             [--encodedlun &lt;lun&gt;]
@@ -1618,5 +1618,6 @@
           <glossdef>
             <para>The number of the storage controller's port which is to be
-            modified. Mandatory.</para>
+            modified. Mandatory, unless the storage controller has only a
+            single port.</para>
           </glossdef>
         </glossentry>
@@ -1627,5 +1628,6 @@
           <glossdef>
             <para>The number of the port's device which is to be modified.
-            Optional. Default value is 0.</para>
+            Mandatory, unless the storage controller has only a single device
+            per port.</para>
           </glossdef>
         </glossentry>
Index: /trunk/doc/manual/user_ChangeLogImpl.xml
===================================================================
--- /trunk/doc/manual/user_ChangeLogImpl.xml	(revision 37928)
+++ /trunk/doc/manual/user_ChangeLogImpl.xml	(revision 37929)
@@ -111,4 +111,10 @@
         <para>GUI: decrease time before showing the VM configuration
           dialog</para>
+      </listitem>
+
+      <listitem>
+        <para>VBoxManage: more convenient configuration of storage controller
+          attachments by automatically determining the port or device parameter
+          when a storage controller has only one port or device per port</para>
       </listitem>
 
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 37928)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 37929)
@@ -458,5 +458,5 @@
                      "VBoxManage storageattach    <uuid|vmname>\n"
                      "                            --storagectl <name>\n"
-                     "                            --port <number>\n"
+                     "                            [--port <number>]\n"
                      "                            [--device <number>]\n"
                      "                            [--type dvddrive|hdd|fdd]\n"
@@ -475,5 +475,5 @@
                      "                            [--server <name>|<ip>]\n"
                      "                            [--target <target>]\n"
-                     "                            [--port <port>]\n"
+                     "                            [--tport <port>]\n"
                      "                            [--lun <lun>]\n"
                      "                            [--encodedlun <lun>]\n"
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp	(revision 37928)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp	(revision 37929)
@@ -62,5 +62,5 @@
     { "--server",           'S', RTGETOPT_REQ_STRING },
     { "--target",           'T', RTGETOPT_REQ_STRING },
-    { "--port",             'P', RTGETOPT_REQ_STRING },
+    { "--tport",            'P', RTGETOPT_REQ_STRING },
     { "--lun",              'L', RTGETOPT_REQ_STRING },
     { "--encodedlun",       'E', RTGETOPT_REQ_STRING },
@@ -75,5 +75,5 @@
     HRESULT rc = S_OK;
     ULONG port   = ~0U;
-    ULONG device = 0;                   /* device is optional, default is 0 */
+    ULONG device = ~0U;
     bool fForceUnmount = false;
     bool fSetMediumType = false;
@@ -239,5 +239,5 @@
                 break;
 
-            case 'P':   // --port
+            case 'P':   // --tport
                 bstrPort = ValueUnion.psz;
                 break;
@@ -286,6 +286,4 @@
     if (!pszCtl)
         return errorSyntax(USAGE_STORAGEATTACH, "Storage controller name not specified");
-    if (port == ~0U)
-        return errorSyntax(USAGE_STORAGEATTACH, "Port not specified");
 
     /* get the virtualbox system properties */
@@ -317,4 +315,26 @@
         if (FAILED(rc))
             throw Utf8StrFmt("Could not find a controller named '%s'\n", pszCtl);
+
+        StorageBus_T storageBus = StorageBus_Null;
+        CHECK_ERROR_RET(storageCtl, COMGETTER(Bus)(&storageBus), 1);
+        ULONG maxPorts = 0;
+        CHECK_ERROR_RET(systemProperties, GetMaxPortCountForStorageBus(storageBus, &maxPorts), 1);
+        ULONG maxDevices = 0;
+        CHECK_ERROR_RET(systemProperties, GetMaxDevicesPerPortForStorageBus(storageBus, &maxDevices), 1);
+
+        if (port == ~0U)
+        {
+            if (maxPorts == 1)
+                port = 0;
+            else
+                return errorSyntax(USAGE_STORAGEATTACH, "Port not specified");
+        }
+        if (device == ~0U)
+        {
+            if (maxDevices == 1)
+                device = 0;
+            else
+                return errorSyntax(USAGE_STORAGEATTACH, "Device not specified");
+        }
 
         /* for sata controller check if the port count is big enough
@@ -376,5 +396,4 @@
             else
             {
-                StorageBus_T storageBus = StorageBus_Null;
                 DeviceType_T deviceType = DeviceType_Null;
                 com::SafeArray <DeviceType_T> saDeviceTypes;
@@ -382,5 +401,4 @@
 
                 /* check if the device type is supported by the controller */
-                CHECK_ERROR(storageCtl, COMGETTER(Bus)(&storageBus));
                 CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
                 for (size_t i = 0; i < saDeviceTypes.size(); ++ i)
@@ -461,8 +479,6 @@
             /* check if the device type is supported by the controller */
             {
-                StorageBus_T storageBus = StorageBus_Null;
                 com::SafeArray <DeviceType_T> saDeviceTypes;
 
-                CHECK_ERROR(storageCtl, COMGETTER(Bus)(&storageBus));
                 CHECK_ERROR(systemProperties, GetDeviceTypesForStorageBus(storageBus, ComSafeArrayAsOutParam(saDeviceTypes)));
                 if (SUCCEEDED(rc))
