Ignore:
Timestamp:
Jan 28, 2011, 5:50:41 PM (15 years ago)
Author:
dmik
Message:

kernel32: Implemented GetVolumePathName() API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/disk.cpp

    r10560 r21567  
    9090       TVFSTOHPFS = 1
    9191       */
    92         if(lpSectorsPerCluster!=NULL) 
     92        if(lpSectorsPerCluster!=NULL)
    9393        {
    94             if(*lpSectorsPerCluster==1024 && PROFILE_GetOdinIniBool("DRIVESPACE","CLUSTERTO32",0)) 
     94            if(*lpSectorsPerCluster==1024 && PROFILE_GetOdinIniBool("DRIVESPACE","CLUSTERTO32",0))
    9595            {/* TVFS returns 1024 sectors per cluster */
    9696                dprintf(("KERNEL32:  GetDiskFreeSpaceA, TVFS-Drive detected. Faking clustersize to 32.\n"));
     
    231231    else {
    232232        //Volume functions only available in Windows 2000 and up
    233         if(VERSION_IS_WIN2000_OR_HIGHER() && !strncmp(lpszDrive, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1)) 
     233        if(VERSION_IS_WIN2000_OR_HIGHER() && !strncmp(lpszDrive, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1))
    234234        {
    235235            char *pszVolume;
     
    240240            pszVolume = (char *)alloca(length);
    241241
    242             if(OSLibLVMStripVolumeName(lpszDrive, pszVolume, length)) 
     242            if(OSLibLVMStripVolumeName(lpszDrive, pszVolume, length))
    243243            {
    244244                rc = OSLibLVMGetDriveType(pszVolume);
     
    311311    else {
    312312        //Volume functions only available in Windows 2000 and up
    313         if(LOBYTE(GetVersion()) >= 5 && !strncmp(lpRootPathName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1)) 
     313        if(LOBYTE(GetVersion()) >= 5 && !strncmp(lpRootPathName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1))
    314314        {
    315315            int   length;
     
    319319            pszVolume = (char *)alloca(length);
    320320
    321             if(OSLibLVMStripVolumeName(lpRootPathName, pszVolume, length)) 
     321            if(OSLibLVMStripVolumeName(lpRootPathName, pszVolume, length))
    322322            {
    323323                pszVolume[length-2] = 0;
     
    343343        }
    344344    }
    345     if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags) 
     345    if(lpFileSystemNameBuffer || lpMaximumComponentLength || lpFileSystemFlags)
    346346    {
    347347        if(!lpFileSystemNameBuffer || (nFileSystemNameSize == 0)) {
     
    357357        if(rc == ERROR_SUCCESS) strcpy(szOrgFileSystemName, lpFileSystemNameBuffer);
    358358
    359         if(lpFileSystemNameBuffer) 
     359        if(lpFileSystemNameBuffer)
    360360        {
    361361            dprintf2(("File system name: %s", lpFileSystemNameBuffer));
    362             if(!strcmp(lpFileSystemNameBuffer, "JFS")) 
     362            if(!strcmp(lpFileSystemNameBuffer, "JFS"))
    363363            {
    364364                strncpy(lpFileSystemNameBuffer, "NTFS", nFileSystemNameSize);
     
    372372                //do nothing
    373373            }
    374             else 
     374            else
    375375            {//pretend everything else is FAT16 (HPFS and FAT have the same file size limit)
    376376                // @@VP:20040323 - nFileSystemNameSize may be 0!!!
     
    379379            if(fForce2GBFileSize) {
    380380                if(strcmp(lpFileSystemNameBuffer, "CDFS") &&
    381                    strcmp(lpFileSystemNameBuffer, "UDF")) 
     381                   strcmp(lpFileSystemNameBuffer, "UDF"))
    382382                {//everything is FAT -> 2 GB file size limit
    383383                    strncpy(lpFileSystemNameBuffer, "FAT16", nFileSystemNameSize);
     
    565565//******************************************************************************
    566566//******************************************************************************
    567 BOOL WIN32API FindNextVolumeA(HANDLE hFindVolume, LPTSTR lpszVolumeName, 
     567BOOL WIN32API FindNextVolumeA(HANDLE hFindVolume, LPTSTR lpszVolumeName,
    568568                              DWORD cchBufferLength)
    569569{
     
    583583        return FALSE;
    584584    }
    585     if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, &pVolInfo->lastvol, 
     585    if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, &pVolInfo->lastvol,
    586586                               szVolume, sizeof(szVolume)) == FALSE) {
    587587        SetLastError(ERROR_NO_MORE_FILES);
     
    603603//******************************************************************************
    604604//******************************************************************************
    605 BOOL WIN32API FindNextVolumeW(HANDLE hFindVolume, LPWSTR lpszVolumeName, 
     605BOOL WIN32API FindNextVolumeW(HANDLE hFindVolume, LPWSTR lpszVolumeName,
    606606                              DWORD cchBufferLength)
    607607{
     
    646646//******************************************************************************
    647647//******************************************************************************
    648 HANDLE WIN32API FindFirstVolumeMountPointA(LPTSTR lpszRootPathName, 
     648HANDLE WIN32API FindFirstVolumeMountPointA(LPTSTR lpszRootPathName,
    649649                                           LPTSTR lpszVolumeMountPoint,
    650650                                           DWORD cchBufferLength)
     
    654654        return INVALID_HANDLE_VALUE;
    655655    }
    656    
     656
    657657    SetLastError(ERROR_NO_MORE_FILES);
    658658    return INVALID_HANDLE_VALUE;
     
    660660//******************************************************************************
    661661//******************************************************************************
    662 HANDLE WIN32API FindFirstVolumeMountPointW(LPWSTR lpszRootPathName, 
     662HANDLE WIN32API FindFirstVolumeMountPointW(LPWSTR lpszRootPathName,
    663663                                           LPWSTR lpszVolumeMountPoint,
    664664                                           DWORD cchBufferLength)
     
    761761    }
    762762
    763     if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, pszvol, 
    764                                                 cchBufferLength) == TRUE) 
     763    if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, pszvol,
     764                                                cchBufferLength) == TRUE)
    765765    {
    766766        int length = strlen(pszvol);
     
    771771        sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", pszvol);
    772772
    773         dprintf(("GetVolumeNameForVolumeMountPointA %s returned %s", lpszVolumeMountPoint, lpszVolumeName));
     773        dprintf(("KERNEL32: GetVolumeNameForVolumeMountPointA %s returned %s", lpszVolumeMountPoint, lpszVolumeName));
    774774        SetLastError(ERROR_SUCCESS);
    775775        return TRUE;
    776776    }
    777     dprintf(("GetVolumeNameForVolumeMountPointA: %s not found!!", lpszVolumeMountPoint));
     777    dprintf(("KERNEL32: GetVolumeNameForVolumeMountPointA: %s not found!!", lpszVolumeMountPoint));
    778778    SetLastError(ERROR_FILE_NOT_FOUND);
    779779    return FALSE;
     
    810810//******************************************************************************
    811811//******************************************************************************
     812BOOL WIN32API GetVolumePathNameA(LPCSTR lpszFileName,
     813                                 LPSTR lpszVolumePathName,
     814                                 DWORD cchBufferLength)
     815{
     816    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     817        SetLastError(ERROR_NOT_SUPPORTED);
     818        return FALSE;
     819    }
     820
     821    if(!*lpszFileName) {
     822        // According to MSDN:
     823        SetLastError(ERROR_SUCCESS);
     824        return FALSE;
     825    }
     826
     827    // We only support drive letters as volume names
     828    if(cchBufferLength < 3) {
     829        SetLastError(ERROR_INSUFFICIENT_BUFFER);
     830        return FALSE;
     831    }
     832
     833    CHAR fullName[MAX_PATH];
     834    DWORD rc = GetFullPathNameA(lpszFileName, sizeof(fullName), fullName, NULL);
     835    if (rc == 0 || rc > sizeof(fullName))
     836        return FALSE;
     837
     838    if(fullName[0] == '\\' && fullName[1] == '\\') {
     839        // UNC path, search for the 2nd single slash: we should return "\\foo\bar\"
     840        LPSTR slash1 = strchr(&fullName[2], '\\');
     841        if(!slash1 || slash1 - fullName == 2) {
     842            SetLastError(ERROR_INVALID_NAME);
     843            return FALSE;
     844        }
     845        LPSTR slash2 = strchr(slash1 + 1, '\\');
     846        if(!slash2 || slash2 - slash1 == 1) {
     847            SetLastError(ERROR_INVALID_NAME);
     848            return FALSE;
     849        }
     850        DWORD len = slash2 - fullName + 1; // with trailing slash
     851        if(cchBufferLength < len + 1) {
     852            SetLastError(ERROR_INSUFFICIENT_BUFFER);
     853            return FALSE;
     854        }
     855        memcpy(lpszVolumePathName, fullName, len);
     856        lpszVolumePathName[len] = '\0';
     857    } else {
     858        lpszVolumePathName[0] = fullName[0];
     859        lpszVolumePathName[1] = ':';
     860        if(cchBufferLength == 3) {
     861            lpszVolumePathName[2] = '\0';
     862        } else {
     863            lpszVolumePathName[2] = '\\';
     864            lpszVolumePathName[3] = '\0';
     865        }
     866    }
     867
     868    dprintf(("KERNEL32: GetVolumePathNameA %s returned %s", lpszFileName, lpszVolumePathName));
     869    SetLastError(ERROR_SUCCESS);
     870    return TRUE;
     871}
     872//******************************************************************************
     873//******************************************************************************
     874BOOL WIN32API GetVolumePathNameW(LPCWSTR lpszFileName,
     875                                 LPWSTR lpszVolumePathName,
     876                                 DWORD cchBufferLength)
     877{
     878    LPSTR  lpszFileNameA = NULL;
     879    LPSTR  lpszVolumePathNameA = NULL;
     880    BOOL   ret;
     881    int    len;
     882
     883    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     884        SetLastError(ERROR_NOT_SUPPORTED);
     885        return FALSE;
     886    }
     887    len = WideCharToMultiByte( CP_ACP, 0, lpszFileName, -1, NULL, 0, 0, NULL);
     888    lpszFileNameA = (char *)alloca(len+1);
     889    WideCharToMultiByte(CP_ACP, 0, lpszFileName, -1, lpszFileNameA, len, 0, NULL);
     890
     891    if(cchBufferLength && lpszVolumePathName) {
     892        lpszVolumePathNameA = (char *)alloca(cchBufferLength);
     893    }
     894    ret = GetVolumePathNameA(lpszFileNameA, lpszVolumePathNameA, cchBufferLength);
     895    if(ret) {
     896        int len = MultiByteToWideChar( CP_ACP, 0, lpszVolumePathNameA, -1, NULL, 0);
     897        MultiByteToWideChar(CP_ACP, 0, lpszVolumePathNameA, -1, lpszVolumePathName, len);
     898    }
     899    return ret;
     900}
     901//******************************************************************************
     902//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.