VirtualBox

Ignore:
Timestamp:
Nov 9, 2018 10:25:30 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126515
Message:

Main,VBoxManage,FE/Qt: Extended the createSharedFolder and ISharedFolder methods with a mount poit parameter/attribute for use when auto-mounting. This is especially useful for Windows and OS/2 guests which operates with drive letters. The change has not yet trickled down to the guest interface and VBoxService.

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r75361 r75380  
    4949// funcs
    5050///////////////////////////////////////////////////////////////////////////////
     51
     52/**
     53 * Helper for formatting an indexed name or some such thing.
     54 */
     55static const char *FmtNm(char psz[80], const char *pszFormat, ...)
     56{
     57    va_list va;
     58    va_start(va, pszFormat);
     59    RTStrPrintfV(psz, 80, pszFormat, va);
     60    va_end(va);
     61    return psz;
     62}
    5163
    5264HRESULT showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
     
    368380}
    369381
     382/** Shows a shared folder.   */
     383static HRESULT showSharedFolder(ComPtr<ISharedFolder> &sf, VMINFO_DETAILS details, const char *pszDesc,
     384                                const char *pszMrInfix, size_t idxMr, bool fFirst)
     385{
     386    Bstr name, hostPath, bstrAutoMountPoint;
     387    BOOL writable = FALSE, fAutoMount = FALSE;
     388    CHECK_ERROR2I_RET(sf, COMGETTER(Name)(name.asOutParam()), hrcCheck);
     389    CHECK_ERROR2I_RET(sf, COMGETTER(HostPath)(hostPath.asOutParam()), hrcCheck);
     390    CHECK_ERROR2I_RET(sf, COMGETTER(Writable)(&writable), hrcCheck);
     391    CHECK_ERROR2I_RET(sf, COMGETTER(AutoMount)(&fAutoMount), hrcCheck);
     392    CHECK_ERROR2I_RET(sf, COMGETTER(AutoMountPoint)(bstrAutoMountPoint.asOutParam()), hrcCheck);
     393
     394    if (fFirst && details != VMINFO_MACHINEREADABLE)
     395        RTPrintf("\n\n");
     396    if (details == VMINFO_MACHINEREADABLE)
     397    {
     398        char szNm[80];
     399        outputMachineReadableString(FmtNm(szNm, "SharedFolderName%s%zu", pszMrInfix, idxMr), &name);
     400        outputMachineReadableString(FmtNm(szNm, "SharedFolderPath%s%zu", pszMrInfix, idxMr), &hostPath);
     401    }
     402    else
     403    {
     404        RTPrintf("Name: '%ls', Host path: '%ls' (%s), %s%s%",
     405                 name.raw(), hostPath.raw(), pszDesc, writable ? "writable" : "readonly", fAutoMount ? ", auto-mount" : "");
     406        if (bstrAutoMountPoint.isNotEmpty())
     407            RTPrintf(", mount-point: '%ls'\n", bstrAutoMountPoint.raw());
     408        else
     409            RTPrintf("\n");
     410    }
     411    return S_OK;
     412}
     413
     414
    370415static const char *paravirtProviderToString(ParavirtProvider_T provider, VMINFO_DETAILS details)
    371416{
     
    407452            return "Unknown";
    408453    }
    409 }
    410 
    411 /**
    412  * Helper for formatting an indexed name or some such thing.
    413  */
    414 static const char *FmtNm(char psz[80], const char *pszFormat, ...)
    415 {
    416     va_list va;
    417     va_start(va, pszFormat);
    418     RTStrPrintfV(psz, 80, pszFormat, va);
    419     va_end(va);
    420     return psz;
    421454}
    422455
     
    22182251        {
    22192252            ComPtr<ISharedFolder> sf = sfColl[i];
    2220             Bstr name, hostPath;
    2221             sf->COMGETTER(Name)(name.asOutParam());
    2222             sf->COMGETTER(HostPath)(hostPath.asOutParam());
    2223             RTPrintf("Name: '%ls', Host path: '%ls' (global mapping)\n", name.raw(), hostPath.raw());
     2253            showSharedFolder(sf, details, "global mapping", "GlobalMapping", i + 1, numSharedFolders == 0);
    22242254            ++numSharedFolders;
    22252255        }
     
    22292259    {
    22302260        com::SafeIfaceArray <ISharedFolder> folders;
    2231 
    22322261        CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
    2233 
    22342262        for (size_t i = 0; i < folders.size(); ++i)
    22352263        {
    22362264            ComPtr<ISharedFolder> sf = folders[i];
    2237 
    2238             Bstr name, hostPath;
    2239             BOOL writable;
    2240             sf->COMGETTER(Name)(name.asOutParam());
    2241             sf->COMGETTER(HostPath)(hostPath.asOutParam());
    2242             sf->COMGETTER(Writable)(&writable);
    2243             if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
    2244                 RTPrintf("\n\n");
    2245             if (details == VMINFO_MACHINEREADABLE)
    2246             {
    2247                 outputMachineReadableString(FmtNm(szNm, "SharedFolderNameMachineMapping%zu", i + 1), &name);
    2248                 outputMachineReadableString(FmtNm(szNm, "SharedFolderPathMachineMapping%zu", i + 1), &hostPath);
    2249             }
    2250             else
    2251                 RTPrintf("Name: '%ls', Host path: '%ls' (machine mapping), %s\n",
    2252                          name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
     2265            showSharedFolder(sf, details, "machine mapping", "MachineMapping", i + 1, numSharedFolders == 0);
    22532266            ++numSharedFolders;
    22542267        }
     
    22582271    {
    22592272        com::SafeIfaceArray <ISharedFolder> folders;
    2260 
    22612273        CHECK_ERROR_RET(pConsole, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
    2262 
    22632274        for (size_t i = 0; i < folders.size(); ++i)
    22642275        {
    22652276            ComPtr<ISharedFolder> sf = folders[i];
    2266 
    2267             Bstr name, hostPath;
    2268             sf->COMGETTER(Name)(name.asOutParam());
    2269             sf->COMGETTER(HostPath)(hostPath.asOutParam());
    2270             if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
    2271                 RTPrintf("\n\n");
    2272             if (details == VMINFO_MACHINEREADABLE)
    2273             {
    2274                 outputMachineReadableString(FmtNm(szNm, "SharedFolderNameTransientMapping%zu", i + 1), &name);
    2275                 outputMachineReadableString(FmtNm(szNm, "SharedFolderPathTransientMapping%zu", i + 1), &hostPath);
    2276             }
    2277             else
    2278                 RTPrintf("Name: '%ls', Host path: '%ls' (transient mapping)\n", name.raw(), hostPath.raw());
     2277            showSharedFolder(sf, details, "transient mapping", "TransientMapping", i + 1, numSharedFolders == 0);
    22792278            ++numSharedFolders;
    22802279        }
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r74431 r75380  
    10961096        bool fWritable = true;
    10971097        bool fAutoMount = false;
     1098        char *pszAutoMountPoint = "";
    10981099
    10991100        for (int i = 2; i < a->argc; i++)
     
    11301131                fAutoMount = true;
    11311132            }
     1133            else if (!strcmp(a->argv[i], "--auto-mount-point"))
     1134            {
     1135                if (a->argc <= i + 1 || !*a->argv[i+1])
     1136                    return errorArgument("Missing argument to '%s'", a->argv[i]);
     1137                i++;
     1138                pszAutoMountPoint = a->argv[i];
     1139            }
    11321140            else
    11331141                return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Invalid parameter '%s'", Utf8Str(a->argv[i]).c_str());
     
    11601168                                      "Machine '%s' is not currently running.\n", pszMachineName);
    11611169
    1162             CHECK_ERROR(console, CreateSharedFolder(Bstr(name).raw(),
    1163                                                     Bstr(hostpath).raw(),
    1164                                                     fWritable, fAutoMount));
     1170            CHECK_ERROR(console, CreateSharedFolder(Bstr(name).raw(), Bstr(hostpath).raw(),
     1171                                                    fWritable, fAutoMount, Bstr(pszAutoMountPoint).raw()));
    11651172            a->session->UnlockMachine();
    11661173        }
     
    11741181            a->session->COMGETTER(Machine)(sessionMachine.asOutParam());
    11751182
    1176             CHECK_ERROR(sessionMachine, CreateSharedFolder(Bstr(name).raw(),
    1177                                                            Bstr(hostpath).raw(),
    1178                                                            fWritable, fAutoMount));
     1183            CHECK_ERROR(sessionMachine, CreateSharedFolder(Bstr(name).raw(), Bstr(hostpath).raw(),
     1184                                                           fWritable, fAutoMount, Bstr(pszAutoMountPoint).raw()));
    11791185            if (SUCCEEDED(rc))
    11801186                CHECK_ERROR(sessionMachine, SaveSettings());
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette