Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp	(revision 458)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp	(revision 459)
@@ -432,4 +432,5 @@
                  "                            [-port <port>]\n"
                  "                            [-lun <lun>]\n"
+                 "                            [-encodedlun <lun>]\n"
                  "                            [-username <username>]\n"
                  "                            [-password <password>]\n"
@@ -658,5 +659,5 @@
     CHECK_ERROR (machine, COMGETTER(Accessible) (&accessible));
     CheckComRCReturnRC (rc);
-    
+
     if (!accessible)
     {
@@ -676,5 +677,5 @@
         return S_OK;
     }
-    
+
     Bstr machineName;
     rc = machine->COMGETTER(Name)(machineName.asOutParam());
@@ -2329,5 +2330,30 @@
             }
             i++;
-            lun = atoi(argv[i]);
+            char *pszNext;
+            int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lun);
+            if (VBOX_FAILURE(rc) || *pszNext != '\0' || lun >= 16384)
+                return errorArgument("Invalid LUN number '%s'", argv[i]);
+            if (lun <= 255)
+            {
+                /* Assume bus identifier = 0. */
+                lun = (lun << 48); /* uses peripheral device addressing method */
+            }
+            else
+            {
+                /* Check above already limited the LUN to 14 bits. */
+                lun = (lun << 48) | (1 << 62); /* uses flat space addressing method */
+            }
+        }
+        else if (strcmp(argv[i], "-encodedlun") == 0)
+        {
+            if (argc <= i + 1)
+            {
+                return errorArgument("Missing argument to '%s'", argv[i]);
+            }
+            i++;
+            char *pszNext;
+            int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lun);
+            if (VBOX_FAILURE(rc) || *pszNext != '\0')
+                return errorArgument("Invalid encoded LUN number '%s'", argv[i]);
         }
         else if (strcmp(argv[i], "-username") == 0)
@@ -4708,5 +4734,5 @@
         ComPtr<IHost> host;
         CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
-    
+
         ComPtr<IHostNetworkInterface> hostif;
         ComPtr<IProgress> progress;
@@ -4715,5 +4741,5 @@
                                        hostif.asOutParam(),
                                        progress.asOutParam()));
-    
+
         showProgress(progress);
         HRESULT result;
@@ -4747,5 +4773,5 @@
 
         ComPtr<IHostNetworkInterface> hostif;
-    
+
         /* first guess is that it's a UUID */
         Guid uuid(argv[0]);
@@ -4758,5 +4784,5 @@
             CHECK_ERROR_BREAK(hostif, COMGETTER(Id)(uuid.asOutParam()));
         }
-    
+
         ComPtr<IProgress> progress;
         CHECK_ERROR_BREAK(host,
