🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11150

Re: Problems getting DISK_GEOMETRY under WinME

#11150
From: Walt Morrey
Date: Mon, 23 Feb 2004 20:53
96 lines
4342 bytes
I've modified the code as best I can make out using the info on the Microsoft web site (all of the 
Info was NOT on the Windows Platform SDK disk I purchased form Microsoft) to try to get DriveInfo 
data using the Get_ExtFreeSpace (Int 21h Function 7303h).  This compiles and runs, but returns the 
same data for every drive in my system.  I tried setting the Output Buffer in the DeviceIoControl to 
point to DriveInfo, and got different numbers, but all the same for each drive.

What am I doing wrong?  (I just used a Form with one Button1 and Memo1 - Button1->OnClick calls 
GetDrive.

Thanks


#define VWIN32_DIOC_DOS_IOCTL 1
#define VWIN32_DIOC_DOS_DRIVEINFO 6

typedef struct _DEVIOCTL_REGISTERS {
         DWORD reg_EBX;
         DWORD reg_EDX;
         DWORD reg_ECX;
         DWORD reg_EAX;
         DWORD reg_EDI;
         DWORD reg_ESI;
         DWORD reg_Flags;
} DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS;

typedef struct _ExtGetDskFreSpcStruct {
         WORD  Size;
         WORD  Level;
         DWORD SectorsPerCluster;
         DWORD BytesPerSector;
         DWORD AvailableClusters;
         DWORD TotalClusters;
         DWORD AvailablePhysSectors;
         DWORD TotalPhysSectors;
         DWORD AvailableAllocationUnits;
         DWORD TotalAllocationUnits;
         DWORD Rsvd;
} ExtGetDskFreSpcStruct, *PExtGetDskFreSpcStruct;


void __fastcall TForm1::GetDrive(TObject *Sender)
{
    UINT nDrive;
    AnsiString IString;
    ExtGetDskFreSpcStruct DriveInfo;
    char str1[255];

    nDrive = 0;
    Form1->Memo1->Lines->Clear();
    while (nDrive < (DriveStringBufferSize/4))      //  DriveStringBufferSize is 24 for 6 drives
    {
       IString = "Drive "+IntToStr(nDrive)+"  ";
       if( !GetDRIVEINFO(&DriveInfo, nDrive) )
       {
          IString += "error on nDrive";
       }
       else
       {
          sprintf( str1, "0x%08x 0x%08x 0x%08x 0x%08x 0x%08x", DriveInfo.TotalClusters, 
DriveInfo.TotalPhysSectors, DriveInfo.SectorsPerCluster, DriveInfo.BytesPerSector, 
DriveInfo.TotalClusters, DriveInfo.TotalPhysSectors, DriveInfo.TotalAllocationUnits );
          IString += str1;
       }
       Form1->Memo1->Lines->Append(IString);
       nDrive++;
    }
}
//---------------------------------------------------------------------------

BOOL GetDRIVEINFO(PExtGetDskFreSpcStruct poreg, UINT nDrive)
{
     DEVIOCTL_REGISTERS reg;
     HANDLE hDevice;
     BOOL fResult;
     DWORD cb;

     reg.reg_EAX = 0x440D;       /* IOCTL for block devices */
     reg.reg_EBX = nDrive;       /* zero-based drive ID     */
     reg.reg_ECX = 0x0866;       /* Get Media ID command    */
     reg.reg_EDX = (DWORD) poreg; /* receives drive info  */
     hDevice = CreateFile("\\\\.\\vwin32",
         GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
         (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
         FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
     if (hDevice == (HANDLE) INVALID_HANDLE_VALUE)
         return FALSE;
     else
     {
         fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_DRIVEINFO,
              &reg, sizeof(reg), &reg, sizeof(reg), &cb, 0);
     }
     CloseHandle(hDevice);
     if (!fResult)
         return FALSE;
     return TRUE;
}
Technical Details
Message-ID: <403a6854$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4037b73a$1@newsgroups.borland.com> <40382779$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,8ef29fec1dea7408
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-23 13:12:24 PST
Date: Mon, 23 Feb 2004 15:53:21 -0500
From: Walt Morrey <dadinc@bellsouth.net>
User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Problems getting DISK_GEOMETRY under WinME
References: <4037b73a$1@newsgroups.borland.com> <40382779$1@newsgroups.borland.com>
In-Reply-To: <40382779$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 66.157.248.149
Message-ID: <403a6854$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1077569620 66.157.248.149 (23 Feb 2004 12:53:40 -0800)
Lines: 98
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail