Ignore:
Timestamp:
May 9, 2002, 3:55:35 PM (23 years ago)
Author:
sandervl
Message:

volume api updates (LVM)

File:
1 edited

Legend:

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

    r8392 r8397  
    1 /* $Id: disk.cpp,v 1.34 2002-05-08 15:02:58 sandervl Exp $ */
     1/* $Id: disk.cpp,v 1.35 2002-05-09 13:55:33 sandervl Exp $ */
    22
    33/*
     
    1717
    1818#include <os2win.h>
     19#include <stdio.h>
    1920#include <stdlib.h>
    2021#include <string.h>
     22#include <versionos2.h>
    2123#include "unicode.h"
    2224#include "oslibdos.h"
     25#include "osliblvm.h"
    2326#include "exceptutil.h"
    2427#include "profile.h"
     28#include "hmdisk.h"
    2529
    2630#define DBG_LOCALLOG  DBG_disk
     
    2933
    3034ODINDEBUGCHANNEL(KERNEL32-DISK)
     35
    3136
    3237//******************************************************************************
     
    225230    }
    226231    else {
     232        //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))
     234        {
     235            char *pszVolume;
     236            int   length;
     237
     238            //strip volume name prefix (\\\\?\\Volume\\)
     239            length = strlen(lpszDrive);
     240            pszVolume = (char *)alloca(length);
     241
     242            strcpy(pszVolume, &lpszDrive[sizeof(VOLUME_NAME_PREFIX)-1+1]);  //-zero term + starting '{'
     243            length -= sizeof(VOLUME_NAME_PREFIX)-1+1;
     244            if(pszVolume[length-2] == '}') {
     245                pszVolume[length-2] = 0;
     246                rc = OSLibLVMGetDriveType(pszVolume);
     247                dprintf(("KERNEL32:  GetDriveType %s = %d (LVM)", lpszDrive, rc));
     248                return rc;
     249            }
     250        }
    227251        return DRIVE_NO_ROOT_DIR;   //return value checked in NT4, SP6 (GetDriveType(""), GetDriveType("4");
    228252    }
     
    263287   CHAR   szOrgFileSystemName[256] = "";
    264288   ULONG  drive;
    265    BOOL   rc;
     289   BOOL   rc, fVolumeName = FALSE;
     290   char   *pszVolume;
    266291
    267292    dprintf(("GetVolumeInformationA %s", lpRootPathName));
     
    280305    }
    281306    else {
     307        //Volume functions only available in Windows 2000 and up
     308        if(LOBYTE(GetVersion()) >= 5 && !strncmp(lpRootPathName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1))
     309        {
     310            int   length;
     311
     312            //strip volume name prefix (\\\\?\\Volume\\)
     313            length = strlen(lpRootPathName);
     314            pszVolume = (char *)alloca(length);
     315
     316            strcpy(pszVolume, &lpRootPathName[sizeof(VOLUME_NAME_PREFIX)-1]);
     317            length -= sizeof(VOLUME_NAME_PREFIX)-1;
     318            if(pszVolume[length-1] == '}') {
     319                fVolumeName = TRUE;
     320                goto proceed;
     321            }
     322        }
    282323        SetLastError(ERROR_INVALID_PARAMETER);
    283324        return FALSE;
    284325    }
     326proceed:
    285327
    286328    if(lpVolumeSerialNumber || lpVolumeNameBuffer) {
    287         rc = OSLibDosQueryVolumeSerialAndName(drive, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize);
     329        if(fVolumeName) {
     330             rc = OSLibLVMQueryVolumeSerialAndName(pszVolume, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize);
     331        }
     332        else rc = OSLibDosQueryVolumeSerialAndName(drive, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize);
    288333        if(lpVolumeSerialNumber) {
    289334            dprintf2(("Volume serial number: %x", *lpVolumeSerialNumber));
     
    299344            nFileSystemNameSize    = sizeof(tmpstring);
    300345        }
    301         rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize);
     346        if(fVolumeName) {
     347             rc = OSLibLVMQueryVolumeFS(pszVolume, lpFileSystemNameBuffer, nFileSystemNameSize);
     348        }
     349        else rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize);
     350
    302351        //save original file system name
    303352        if(rc == ERROR_SUCCESS) strcpy(szOrgFileSystemName, lpFileSystemNameBuffer);
     
    435484}
    436485//******************************************************************************
     486typedef struct {
     487    HANDLE hLVMVolumeControlData;
     488    DWORD  lastvol;
     489} VOLINFO;
    437490//******************************************************************************
    438491HANDLE WIN32API FindFirstVolumeA(LPTSTR lpszVolumeName, DWORD cchBufferLength)
    439492{
     493    HANDLE   hVolume;
     494    VOLINFO *pVolInfo;
     495    char     szdrive[3];
     496    char     szVolume[256];
     497
     498    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     499        SetLastError(ERROR_NOT_SUPPORTED);
     500        return FALSE;
     501    }
     502
     503    hVolume = GlobalAlloc(0, sizeof(VOLINFO));
     504    if(hVolume == 0) {
     505        dprintf(("ERROR: FindFirstVolumeA: out of memory!!"));
     506        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     507        return 0;
     508    }
     509    pVolInfo = (VOLINFO *)GlobalLock(hVolume);
     510    pVolInfo->hLVMVolumeControlData = OSLibLVMQueryVolumeControlData();
     511    pVolInfo->lastvol               = 0;
     512
     513    if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, pVolInfo->lastvol, szVolume, sizeof(szVolume)) == FALSE) {
     514        SetLastError(ERROR_NO_MORE_FILES);
     515        goto fail;
     516    }
     517    if(strlen(szVolume) + 14 + 1 > cchBufferLength) {
     518        SetLastError(ERROR_INSUFFICIENT_BUFFER);
     519        goto fail;
     520    }
     521    sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", szVolume);
     522    dprintf(("FindFirstVolumeA returned %s", lpszVolumeName));
     523    pVolInfo->lastvol++;
     524    GlobalUnlock(hVolume);
     525    SetLastError(ERROR_SUCCESS);
     526    return hVolume;
     527
     528fail:
     529    GlobalUnlock(hVolume);
     530    GlobalFree(hVolume);
    440531    return 0;
    441532}
     
    444535HANDLE WIN32API FindFirstVolumeW(LPWSTR lpszVolumeName, DWORD cchBufferLength)
    445536{
    446     return 0;
     537    LPSTR  pszvolname = NULL;
     538    HANDLE hVolume;
     539
     540    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     541        SetLastError(ERROR_NOT_SUPPORTED);
     542        return FALSE;
     543    }
     544
     545    if(cchBufferLength) {
     546        pszvolname = (char *)alloca(cchBufferLength);
     547    }
     548    hVolume = FindFirstVolumeA(pszvolname, cchBufferLength);
     549    if(hVolume) {
     550        int len = MultiByteToWideChar( CP_ACP, 0, pszvolname, -1, NULL, 0);
     551        MultiByteToWideChar(CP_ACP, 0, pszvolname, -1, lpszVolumeName, len);
     552    }
     553    return hVolume;
    447554}
    448555//******************************************************************************
     
    451558                              DWORD cchBufferLength)
    452559{
    453     return FALSE;
     560    VOLINFO *pVolInfo;
     561    char     szdrive[3];
     562    DWORD    DeviceType;
     563    char     szVolume[256];
     564
     565    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     566        SetLastError(ERROR_NOT_SUPPORTED);
     567        return FALSE;
     568    }
     569
     570    pVolInfo = (VOLINFO *)GlobalLock(hFindVolume);
     571    if(pVolInfo == NULL) {
     572        SetLastError(ERROR_INVALID_PARAMETER);
     573        return FALSE;
     574    }
     575    if(OSLibLVMQueryVolumeName(pVolInfo->hLVMVolumeControlData, pVolInfo->lastvol,
     576                               szVolume, sizeof(szVolume)) == FALSE) {
     577        SetLastError(ERROR_NO_MORE_FILES);
     578        GlobalUnlock(hFindVolume);
     579        return FALSE;
     580    }
     581    if(strlen(szVolume) + 14 + 1 > cchBufferLength) {
     582        SetLastError(ERROR_INSUFFICIENT_BUFFER);
     583        GlobalUnlock(hFindVolume);
     584        return FALSE;
     585    }
     586    sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", szVolume);
     587    dprintf(("FindNextVolumeA returned %s", lpszVolumeName));
     588    pVolInfo->lastvol++;
     589    GlobalUnlock(hFindVolume);
     590    SetLastError(ERROR_SUCCESS);
     591    return TRUE;
    454592}
    455593//******************************************************************************
     
    458596                              DWORD cchBufferLength)
    459597{
     598    LPSTR  pszvolnameA = NULL;
     599    BOOL   ret;
     600
     601    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     602        SetLastError(ERROR_NOT_SUPPORTED);
     603        return FALSE;
     604    }
     605
     606    if(cchBufferLength) {
     607        pszvolnameA = (char *)alloca(cchBufferLength);
     608    }
     609    ret = FindNextVolumeA(hFindVolume, pszvolnameA, cchBufferLength);
     610    if(ret) {
     611        int len = MultiByteToWideChar( CP_ACP, 0, pszvolnameA, -1, NULL, 0);
     612        MultiByteToWideChar(CP_ACP, 0, pszvolnameA, -1, lpszVolumeName, len);
     613    }
     614    return ret;
     615}
     616//******************************************************************************
     617//******************************************************************************
     618BOOL WIN32API FindVolumeClose(HANDLE hFindVolume)
     619{
     620    VOLINFO *pVolInfo;
     621
     622    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     623        SetLastError(ERROR_NOT_SUPPORTED);
     624        return FALSE;
     625    }
     626
     627    if(hFindVolume) {
     628        pVolInfo = (VOLINFO *)GlobalLock(hFindVolume);
     629        OSLibLVMFreeVolumeControlData(pVolInfo->hLVMVolumeControlData);
     630        GlobalUnlock(hFindVolume);
     631        GlobalFree(hFindVolume);
     632        return TRUE;
     633    }
    460634    return FALSE;
    461 }
    462 //******************************************************************************
    463 //******************************************************************************
    464 BOOL WIN32API FindVolumeClose(HANDLE hFindVolume)
    465 {
    466     return TRUE;
    467635}
    468636//******************************************************************************
     
    472640                                           DWORD cchBufferLength)
    473641{
     642    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     643        SetLastError(ERROR_NOT_SUPPORTED);
     644        return FALSE;
     645    }
     646   
     647    SetLastError(ERROR_NO_MORE_FILES);
    474648    return 0;
    475649}
     
    480654                                           DWORD cchBufferLength)
    481655{
    482     return 0;
     656    LPSTR  pszmountpointnameA = NULL;
     657    LPSTR  pszrootA = NULL;
     658    HANDLE hVolume;
     659
     660    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     661        SetLastError(ERROR_NOT_SUPPORTED);
     662        return FALSE;
     663    }
     664
     665    if(cchBufferLength) {
     666        pszmountpointnameA = (char *)alloca(cchBufferLength);
     667    }
     668    if(lpszRootPathName) {
     669        pszrootA = (char *)alloca(lstrlenW(lpszRootPathName)+1);
     670
     671        int len = WideCharToMultiByte( CP_ACP, 0, lpszRootPathName, -1, NULL, 0, 0, NULL);
     672        WideCharToMultiByte(CP_ACP, 0, lpszRootPathName, -1, pszrootA, len, 0, NULL);
     673    }
     674
     675    hVolume = FindFirstVolumeMountPointA(pszrootA, pszmountpointnameA, cchBufferLength);
     676    if(hVolume) {
     677        int len = MultiByteToWideChar( CP_ACP, 0, pszmountpointnameA, -1, NULL, 0);
     678        MultiByteToWideChar(CP_ACP, 0, pszmountpointnameA, -1, lpszVolumeMountPoint, len);
     679    }
     680    return hVolume;
    483681}
    484682//******************************************************************************
     
    488686                                        DWORD cchBufferLength)
    489687{
     688    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     689        SetLastError(ERROR_NOT_SUPPORTED);
     690        return FALSE;
     691    }
     692    SetLastError(ERROR_NO_MORE_FILES);
    490693    return FALSE;
    491694}
     
    496699                                        DWORD cchBufferLength)
    497700{
     701    LPSTR  pszmoutpointnameA = NULL;
     702    BOOL   ret;
     703
     704    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     705        SetLastError(ERROR_NOT_SUPPORTED);
     706        return FALSE;
     707    }
     708
     709    if(cchBufferLength) {
     710        pszmoutpointnameA = (char *)alloca(cchBufferLength);
     711    }
     712    ret = FindFirstVolumeA(pszmoutpointnameA, cchBufferLength);
     713    if(ret) {
     714        int len = MultiByteToWideChar( CP_ACP, 0, pszmoutpointnameA, -1, NULL, 0);
     715        MultiByteToWideChar(CP_ACP, 0, pszmoutpointnameA, -1, lpszVolumeMountPoint, len);
     716    }
     717    return ret;
     718}
     719//******************************************************************************
     720//******************************************************************************
     721BOOL WIN32API FindVolumeMountPointClose(HANDLE hFindVolumeMountPoint)
     722{
     723    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     724        SetLastError(ERROR_NOT_SUPPORTED);
     725        return FALSE;
     726    }
     727
     728    if(hFindVolumeMountPoint) {
     729        GlobalFree(hFindVolumeMountPoint);
     730        return TRUE;
     731    }
    498732    return FALSE;
    499 }
    500 //******************************************************************************
    501 //******************************************************************************
    502 BOOL WIN32API FindVolumeMountPointClose(HANDLE hFindVolumeMountPoint)
    503 {
    504     return TRUE;
    505733}
    506734//******************************************************************************
     
    510738                                                DWORD cchBufferLength)
    511739{
     740    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     741        SetLastError(ERROR_NOT_SUPPORTED);
     742        return FALSE;
     743    }
     744
     745    dprintf(("GetVolumeNameForVolumeMountPointA: %s", lpszVolumeMountPoint));
     746    if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, lpszVolumeName,
     747                                                cchBufferLength) == TRUE)
     748    {
     749        SetLastError(ERROR_SUCCESS);
     750        return TRUE;
     751    }
     752    SetLastError(ERROR_FILE_NOT_FOUND);
    512753    return FALSE;
    513754}
     
    518759                                                DWORD cchBufferLength)
    519760{
    520     return FALSE;
    521 }
    522 //******************************************************************************
    523 //******************************************************************************
     761    LPSTR  pszmoutpointnameA = NULL;
     762    LPSTR  pszvolumenameA = NULL;
     763    BOOL   ret;
     764    int    len;
     765
     766    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     767        SetLastError(ERROR_NOT_SUPPORTED);
     768        return FALSE;
     769    }
     770    len = WideCharToMultiByte( CP_ACP, 0, lpszVolumeMountPoint, -1, NULL, 0, 0, NULL);
     771    pszmoutpointnameA = (char *)alloca(len+1);
     772    WideCharToMultiByte(CP_ACP, 0, lpszVolumeMountPoint, -1, pszmoutpointnameA, len, 0, NULL);
     773
     774    if(cchBufferLength && lpszVolumeName) {
     775        pszvolumenameA = (char *)alloca(cchBufferLength);
     776    }
     777    ret = GetVolumeNameForVolumeMountPointA(pszmoutpointnameA, pszvolumenameA, cchBufferLength);
     778    if(ret) {
     779        int len = MultiByteToWideChar( CP_ACP, 0, pszvolumenameA, -1, NULL, 0);
     780        MultiByteToWideChar(CP_ACP, 0, pszvolumenameA, -1, lpszVolumeName, len);
     781    }
     782    return ret;
     783}
     784//******************************************************************************
     785//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.