Article View: borland.public.cppbuilder.nativeapi
Article #11175Re: Problems getting DISK_GEOMETRY under WinME
From: Walt Morrey
Date: Wed, 25 Feb 2004 14:52
Date: Wed, 25 Feb 2004 14:52
204 lines
7665 bytes
7665 bytes
Hi Remy;
With a couple of (DWORD)'s, that compiled and ran -- it again gave me the same stuff for 26 drives.
I modified it to show just the drives I have, and it still gave all the same info.
Here's the latest program:
bool GetDRIVEINFO(PExtGetDskFreSpcStruct poreg, char Drive)
{
DEVIOCTL_REGISTERS reg;
HANDLE hDevice;
BOOL fResult;
DWORD cb;
char drivestr[] = "?:\\";
drivestr[0] = Drive;
reg.reg_Flags = 0x8000; // assume error (carry flag set)
reg.reg_EAX = 0x7303; // Get_ExtFreeSpace
reg.reg_ECX = sizeof(*poreg);
reg.reg_EDX = (DWORD)drivestr;
reg.reg_EDI = (DWORD)poreg;
hDevice = CreateFile("\\\\.\\vwin32", GENERIC_READ, FILE_SHARE_READ
| FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if( hDevice == INVALID_HANDLE_VALUE )
return false;
fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_DRIVEINFO,
®, sizeof(reg), ®, sizeof(reg), &cb, 0);
CloseHandle(hDevice);
if( (!fResult) || (reg.reg_Flags & 0x8000) )
return false;
return true;
}
void __fastcall TForm1::GetDrive(TObject *Sender)
{
AnsiString IString;
ExtGetDskFreSpcStruct DriveInfo;
char str[256],*pc;
UINT nDrive;
SetFileApisToOEM();
DriveStringBufferSize = GetLogicalDriveStrings( 256, DriveStringBuffer );
Memo1->Lines->Clear();
pc = DriveStringBuffer;
for (nDrive =0; nDrive < (DriveStringBufferSize/4); nDrive++) // DriveStringBufferSize is
24 for 6 drives
// for(char c = 'A'; c <= 'Z'; ++c)
{
if( GetDRIVEINFO(&DriveInfo, *pc) )
{
sprintf( str, "Drive %c: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x",
*pc,
DriveInfo.TotalClusters,
DriveInfo.TotalPhysSectors,
DriveInfo.SectorsPerCluster,
DriveInfo.BytesPerSector,
DriveInfo.TotalClusters,
DriveInfo.TotalPhysSectors,
DriveInfo.TotalAllocationUnits );
Memo1->Lines->Append( str );
}
else
Memo1->Lines->Append( "Error on Drive " + AnsiString(*pc) );
pc+=4;
}
}
and here's the result:
Drive a: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive c: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive d: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive e: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive f: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive g: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
Drive h: 0x40037db2 0x0000077e 0x0063f4d6 0x01781a38 0x40037db2
A: is a Floppy w/ no media
C: is my hard drive
D: is a SmartMedia drive w/ no media
E: is a CDROM
F: is an external 80G hard drive on a USB2.0 port
G: is a 512M CompactFlash Card on a USB2.0 port
H: is a SmartMedia drive on a USB2.0 port with no media
What is wrong here?
Thanks for the help so far!!!
Remy Lebeau (TeamB) wrote:
> "Walt Morrey" <dadinc@bellsouth.net> wrote in message
> news:403a6854$1@newsgroups.borland.com...
>
>
>>What am I doing wrong?
>
>
> You are not filling in the DEVIOCTL_REGISTERS structure correctly. You are
> trying to execute Int 21h Function 440Dh Minor Code 66h via
> VWIN32_DIOC_DOS_DRIVEINFO instead of VWIN32_DIOC_DOS_IOCTL. You are not
> trying to execute Int 21h Function 7303h Get_ExtFreeSpace at all.
>
> Try the following instead (untested):
>
> #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;
>
> // this structure must be byte-aligned
> #pragma pack(push, 1)
> 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;
> #pragma pack(pop)
>
> bool GetDRIVEINFO(PExtGetDskFreSpcStruct poreg, char Drive)
> {
> DEVIOCTL_REGISTERS reg;
> HANDLE hDevice;
> BOOL fResult;
> DWORD cb;
>
> char drivestr[] = "?:\\";
> drivestr[0] = Drive;
>
> reg.reg_Flags = 0x8000; // assume error (carry flag set)
>
> reg.reg_EAX = 0x7303; // Get_ExtFreeSpace
> reg.reg_ECX = sizeof(*poreg);
> reg.reg_EDX = drivestr;
> reg.reg_EDI = poreg;
>
> hDevice = CreateFile("\\\\.\\vwin32", GENERIC_READ, FILE_SHARE_READ
> | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
> if( hDevice == INVALID_HANDLE_VALUE )
> return false;
>
> fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_DRIVEINFO, ®,
> sizeof(reg), ®, sizeof(reg), &cb, 0);
> CloseHandle(hDevice);
>
> if( (!fResult) || (reg.reg_Flags & 0x8000) )
> return false;
>
> return true;
> }
>
> void __fastcall TForm1::GetDrive(TObject *Sender)
> {
> AnsiString IString;
> ExtGetDskFreSpcStruct DriveInfo;
> char str[256];
>
> Memo1->Lines->Clear();
> for(char c = 'A'; c <= 'Z'; ++c)
> {
> if( GetDRIVEINFO(&DriveInfo, c) )
> {
> sprintf( str, "Drive %c: 0x%08x 0x%08x 0x%08x 0x%08x
> 0x%08x",
> c,
> DriveInfo.TotalClusters,
> DriveInfo.TotalPhysSectors,
> DriveInfo.SectorsPerCluster,
> DriveInfo.BytesPerSector,
> DriveInfo.TotalClusters,
> DriveInfo.TotalPhysSectors,
> DriveInfo.TotalAllocationUnits );
>
> Memo1->Lines->Append( str );
> }
> else
> Memo1->Lines->Append( "Error on Drive " + AnsiString(c) );
> }
> }
>
> Gambit
>
>
Technical Details
Message-ID:
<403cb6ce@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4037b73a$1@newsgroups.borland.com> <40382779$1@newsgroups.borland.com> <403a6854$1@newsgroups.borland.com> <403a7265@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-25 07:05:12 PST Date: Wed, 25 Feb 2004 09:52:45 -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> <403a6854$1@newsgroups.borland.com> <403a7265@newsgroups.borland.com> In-Reply-To: <403a7265@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.214.65.219 Message-ID: <403cb6ce@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1077720782 68.214.65.219 (25 Feb 2004 06:53:02 -0800) Lines: 205 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!proxad.net!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail