VirtualBox

Ignore:
Timestamp:
Jul 22, 2010 2:45:41 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63916
Message:

First support for auto-mounted Shared Folders (Windows only yet).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r28800 r31002  
    7878    GUEST_PROP,
    7979#endif
     80#ifdef VBOX_WITH_SHARED_FOLDERS
     81    GUEST_SHAREDFOLDERS,
     82#endif
    8083    USAGE_ALL = UINT32_MAX
    8184};
     
    113116        doUsage("[-timestamp <last timestamp>]");
    114117        doUsage("[-timeout <timeout in ms>");
     118    }
     119#endif
     120#ifdef VBOX_WITH_SHARED_FOLDERS
     121    if ((GUEST_SHAREDFOLDERS == eWhich) || (USAGE_ALL == eWhich))
     122    {
     123        doUsage("list [-automount]", g_pszProgName, "sharedfolder");
    115124    }
    116125#endif
     
    12551264    return 1;
    12561265}
    1257 
     1266#endif
     1267
     1268#ifdef VBOX_WITH_SHARED_FOLDERS
     1269/**
     1270 * Lists the Shared Folders provided by the host.
     1271 */
     1272int listSharedFolders(int argc, char **argv)
     1273{
     1274    bool usageOK = true;
     1275    bool fOnlyShowAutoMount = false;
     1276    if (   argc == 1
     1277        && (   RTStrICmp(argv[0], "-automount") == 0
     1278            || RTStrICmp(argv[0], "/automount") == 0)
     1279       )
     1280    {
     1281        fOnlyShowAutoMount = true;
     1282    }
     1283    else if (argc > 1)
     1284        usageOK = false;
     1285
     1286    if (!usageOK)
     1287    {
     1288        usage(GUEST_SHAREDFOLDERS);
     1289        return 1;
     1290    }
     1291
     1292    uint32_t u32ClientId;
     1293    int rc = VbglR3SharedFolderConnect(&u32ClientId);
     1294    if (!RT_SUCCESS(rc))
     1295        VBoxControlError("Failed to connect to the shared folder service, error %Rrc\n", rc);
     1296    else
     1297    {
     1298        uint32_t cMappings = 64; /* See shflsvc.h for define; should be used later. */
     1299        uint32_t cbMappings = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
     1300        VBGLR3SHAREDFOLDERMAPPING *pMappings = (VBGLR3SHAREDFOLDERMAPPING*)RTMemAlloc(cbMappings);
     1301
     1302        if (pMappings)
     1303        {
     1304            rc = VbglR3SharedFolderGetMappings(u32ClientId, fOnlyShowAutoMount,
     1305                                               pMappings, cbMappings,
     1306                                               &cMappings);
     1307            if (RT_SUCCESS(rc))
     1308            {
     1309                RT_CLAMP(cMappings, 0, 64); /* Maximum mappings, see shflsvc.h */
     1310                RTPrintf("Shared Folder Mappings (%u):\n\n", cMappings);
     1311                for (uint32_t i = 0; i < cMappings; i++)
     1312                {
     1313                    char *ppszName = NULL;
     1314                    uint32_t pcbLen = 0;
     1315                    rc = VbglR3SharedFolderGetName(u32ClientId, pMappings[i].u32Root,
     1316                                                   &ppszName, &pcbLen);
     1317                    if (RT_SUCCESS(rc))
     1318                    {
     1319                        RTPrintf("%02u - %s\n", i + 1, ppszName);
     1320                        RTStrFree(ppszName);
     1321                    }
     1322                    else
     1323                        VBoxControlError("Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
     1324                                         pMappings[i].u32Root, rc);
     1325                }
     1326                if (cMappings == 0)
     1327                    RTPrintf("No Shared Folders available.\n");
     1328            }
     1329            else
     1330                VBoxControlError("Error while getting the shared folder mappings, rc = %Rrc\n", rc);
     1331            RTMemFree(pMappings);
     1332        }
     1333        else
     1334            rc = VERR_NO_MEMORY;
     1335        VbglR3SharedFolderDisconnect(u32ClientId);
     1336    }
     1337    return RT_SUCCESS(rc) ? 0 : 1;
     1338}
     1339
     1340/**
     1341 * Handles Shared Folders control.
     1342 *
     1343 * @returns 0 on success, 1 on failure
     1344 * @note see the command line API description for parameters
     1345 */
     1346static int handleSharedFolder(int argc, char *argv[])
     1347{
     1348    if (0 == argc)
     1349    {
     1350        usage(GUEST_SHAREDFOLDERS);
     1351        return 1;
     1352    }
     1353    if (0 == strcmp(argv[0], "list"))
     1354        return listSharedFolders(argc - 1, argv + 1);
     1355    /* else */
     1356    usage(GUEST_SHAREDFOLDERS);
     1357    return 1;
     1358}
    12581359#endif
    12591360
     
    12791380#ifdef VBOX_WITH_GUEST_PROPS
    12801381    { "guestproperty", handleGuestProperty },
     1382#endif
     1383#ifdef VBOX_WITH_SHARED_FOLDERS
     1384    { "sharedfolder", handleSharedFolder },
    12811385#endif
    12821386    { NULL, NULL }  /* terminator */
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