VirtualBox

Ignore:
Timestamp:
Mar 17, 2019 1:46:38 AM (6 years ago)
Author:
vboxsync
Message:

linux/vboxsf: More informative error message from mount.vboxsf when a shared folder was not found. Kernel module also logs this in dmesg and host release log. Cleaned up the super block read code in the process. bugref:9172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c

    r77534 r77739  
    378378    int c;
    379379    int err;
     380    int saved_errno;
    380381    int nomtab = 0;
    381382    unsigned long flags = MS_NODEV;
     
    497498     */
    498499    err = mount(host_name, mount_point, "vboxsf", flags, &mntinf);
    499     if (err == -1 && errno == EPROTO)
    500     {
    501         /* Sometimes the mount utility messes up the share name.  Try to
    502          * un-mangle it again. */
     500    saved_errno = errno;
     501
     502    /* Some versions of the mount utility (unknown which, if any) will turn the
     503       shared folder name into an absolute path.  So, we check if it starts with
     504       the CWD and removes it.  We must do this after failing, because there is
     505       not actual restrictions on the shared folder name wrt to slashes and such. */
     506    if (err == -1 && errno == ENXIO && host_name[0] == '/')
     507    {
    503508        char szCWD[4096];
    504         size_t cchCWD;
    505         if (!getcwd(szCWD, sizeof(szCWD)))
    506             panic_err("%s: failed to get the current working directory", argv[0]);
    507         cchCWD = strlen(szCWD);
    508         if (!strncmp(host_name, szCWD, cchCWD))
    509         {
    510             while (host_name[cchCWD] == '/')
    511                 ++cchCWD;
    512             /* We checked before that we have enough space */
    513             strcpy(mntinf.name, host_name + cchCWD);
    514         }
    515         err = mount(host_name, mount_point, "vboxsf", flags, &mntinf);
     509        if (getcwd(szCWD, sizeof(szCWD)) != NULL)
     510        {
     511            size_t cchCWD = strlen(szCWD);
     512            if (!strncmp(host_name, szCWD, cchCWD))
     513            {
     514                while (host_name[cchCWD] == '/')
     515                    ++cchCWD;
     516                if (host_name[cchCWD])
     517                {
     518                    /* We checked before that we have enough space. */
     519                    strcpy(mntinf.name, host_name + cchCWD);
     520                    err = mount(host_name, mount_point, "vboxsf", flags, &mntinf);
     521                    saved_errno = errno;
     522                }
     523            }
     524        }
     525        else
     526            fprintf(stderr, "%s: failed to get the current working directory: %s", argv[0], strerror(errno));
     527        errno = saved_errno;
    516528    }
    517529    if (err)
    518         panic_err("%s: mounting failed with the error", argv[0]);
     530    {
     531        if (saved_errno == ENXIO)
     532            panic("%s: shared folder '%s' was not found (check VM settings / spelling)\n", argv[0], host_name);
     533        else
     534            panic_err("%s: mounting failed with the error", argv[0]);
     535    }
    519536
    520537    if (!nomtab)
Note: See TracChangeset for help on using the changeset viewer.

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