Article View: borland.public.cppbuilder.nativeapi
Article #11151Re: Problems getting DISK_GEOMETRY under WinME
From: Remy Lebeau (TeamB)
Date: Mon, 23 Feb 2004 21:44
Date: Mon, 23 Feb 2004 21:44
105 lines
4217 bytes
4217 bytes
"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:
<403a7265@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4037b73a$1@newsgroups.borland.com> <40382779$1@newsgroups.borland.com> <403a6854$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:40:29 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4037b73a$1@newsgroups.borland.com> <40382779$1@newsgroups.borland.com> <403a6854$1@newsgroups.borland.com> Subject: Re: Problems getting DISK_GEOMETRY under WinME Date: Mon, 23 Feb 2004 13:44:28 -0800 Lines: 107 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <403a7265@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1077572197 67.22.138.253 (23 Feb 2004 13:36:37 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail