VirtualBox

Changeset 1175 in kBuild


Ignore:
Timestamp:
Oct 4, 2007 6:33:47 PM (18 years ago)
Author:
bird
Message:

Only use FileNameInformation on NTFS volumes because at least FAT32 will screw up the case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt_fullpath.c

    r1165 r1175  
    225225
    226226static BOOL g_fInitialized = FALSE;
     227static int  g_afNtfsDrives['Z' - 'A' + 1];
    227228static LONG (NTAPI *g_pfnNtQueryInformationFile)(HANDLE FileHandle,
    228229    PMY_IO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation,
     
    238239    LONG                        rcNt;
    239240    HANDLE                      hFile;
     241    int                         cchOut;
     242    char                       *psz;
    240243
    241244    /*
     
    248251            *(FARPROC *)&g_pfnNtQueryInformationFile =
    249252                GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryInformationFile");
     253        if (g_pfnNtQueryInformationFile)
     254        {
     255            unsigned i;
     256            for (i = 0; i < sizeof(g_afNtfsDrives) / sizeof(g_afNtfsDrives[0]); i++ )
     257                g_afNtfsDrives[i] = -1;
     258        }
    250259    }
    251260    if (!g_pfnNtQueryInformationFile)
     261        return -1;
     262
     263    /*
     264     * The FileNameInformation we get is relative to where the volume is mounted,
     265     * so we have to extract the driveletter prefix ourselves.
     266     *
     267     * FIXME: This will probably not work for volumes mounted in NTFS sub-directories.
     268     */
     269    psz = pszFull;
     270    if (pszPath[0] == '\\' || pszPath[0] == '/')
     271    {
     272        /* unc or root of volume */
     273        if (    (pszPath[1] == '\\' || pszPath[1] == '/')
     274            &&  (pszPath[2] != '\\' || pszPath[2] == '/'))
     275        {
     276#if 0 /* don't bother with unc yet. */
     277            /* unc - we get the server + name back */
     278            *psz++ = '\\';
     279#endif
     280            return -1;
     281        }
     282        /* root slash */
     283        *psz++ = _getdrive() + 'A' - 1;
     284        *psz++ = ':';
     285    }
     286    else if (pszPath[1] == ':' && isalpha(pszPath[0]))
     287    {
     288        /* drive letter */
     289        *psz++ = toupper(pszPath[0]);
     290        *psz++ = ':';
     291    }
     292    else
     293    {
     294        /* relative */
     295        *psz++ = _getdrive() + 'A' - 1;
     296        *psz++ = ':';
     297    }
     298
     299    /*
     300     * Fat32 doesn't return filenames with the correct case, so restrict it
     301     * to NTFS volumes for now.
     302     */
     303    if (g_afNtfsDrives[*pszFull - 'A'] == -1)
     304    {
     305        char szFSName[32];
     306
     307        psz[0] = '\\';
     308        psz[1] = '\0';
     309        if (    GetVolumeInformation(pszFull,
     310                                     NULL, 0,   /* volume name */
     311                                     NULL,      /* serial number */
     312                                     NULL,      /* max component */
     313                                     NULL,      /* volume attribs */
     314                                     szFSName,
     315                                     sizeof(szFSName))
     316            &&  !strcmp(szFSName, "NTFS"))
     317            g_afNtfsDrives[*pszFull - 'A'] = 1;
     318        else
     319            g_afNtfsDrives[*pszFull - 'A'] = 0;
     320    }
     321    if (!g_afNtfsDrives[*pszFull - 'A'])
    252322        return -1;
    253323
     
    269339        if (rcNt >= 0)
    270340        {
    271             /*
    272              * The FileNameInformation we get is relative to where the volume is mounted,
    273              * so we have to extract the driveletter prefix ourselves.
    274              *
    275              * FIXME: This will probably not work for volumes mounted in NTFS sub-directories.
    276              */
    277             int cchOut;
    278             int fUnc = 0;
    279             char *psz = pszFull;
    280             if (pszPath[0] == '\\' || pszPath[0] == '/')
    281             {
    282                 /* unc or root of volume */
    283                 if (    (pszPath[1] == '\\' || pszPath[1] == '/')
    284                     &&  (pszPath[2] != '\\' || pszPath[2] == '/'))
    285                 {
    286                     /* unc - we get the server + name back */
    287                     *psz++ = '\\';
    288                     fUnc = 1;
    289                 }
    290                 else
    291                 {
    292                     /* root slash */
    293                     *psz++ = _getdrive() + 'A' - 1;
    294                     *psz++ = ':';
    295                 }
    296             }
    297             else if (pszPath[1] == ':' && isalpha(pszPath[0]))
    298             {
    299                 /* drive letter */
    300                 *psz++ = toupper(pszPath[0]);
    301                 *psz++ = ':';
    302             }
    303             else
    304             {
    305                 /* relative */
    306                 *psz++ = _getdrive() + 'A' - 1;
    307                 *psz++ = ':';
    308             }
    309 
    310341            cchOut = WideCharToMultiByte(CP_ACP, 0,
    311342                                         pFileNameInfo->FileName, pFileNameInfo->FileNameLength / sizeof(WCHAR),
     
    314345            {
    315346                const char *pszEnd;
    316 
     347#if 0
    317348                /* upper case the server and share */
    318349                if (fUnc)
     
    323354                        *psz = toupper(*psz);
    324355                }
    325 
     356#endif
    326357                /* add trailing slash on directories if input has it. */
    327358                pszEnd = strchr(pszPath, '\0');
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