From: bluestar on
I would like to do partition&format functions in my project.
I hope I don't let user do any action when needing to select any
choices.
Using parameters to do both functions successfully.

I don't know MS has to provide any APIs to do these.
(I use SHFormatDrive, but it pops format-dialog, not auto-format)

I think maybe use bat file and use dos command to do.
(like, "format c:/q")

Could anyone teach me how to finish both functions?
(using APIs or DOS commands are ok, just finish both functoins and
user don't any action)

Could you provide a sample code to let me understand?
From: Christian ASTOR on
bluestar wrote:
> I would like to do partition&format functions in my project.
> I hope I don't let user do any action when needing to select any
> choices.
> Using parameters to do both functions successfully.
>
> I don't know MS has to provide any APIs to do these.
> (I use SHFormatDrive, but it pops format-dialog, not auto-format)

DeviceIoControl(),
FormatEx(), FormatEx2() (FMIFS.DLL), IFormatEngine interface (Vista)
From: bluestar on
On 6$B7n(B25$BF|(B, $B2<8a(B3$B;~(B52$BJ,(B, Christian ASTOR <casto...(a)club-internet.fr> wrote:
> bluestar wrote:
> > I would like to do partition&format functions in my project.
> > I hope I don't let user do any action when needing to select any
> > choices.
> > Using parameters to do both functions successfully.
>
> > I don't know MS has to provide any APIs to do these.
> > (I use SHFormatDrive, but it pops format-dialog, not auto-format)
>
> DeviceIoControl(),
> FormatEx(), FormatEx2() (FMIFS.DLL), IFormatEngine interface (Vista)

Dear Sir:

How to do partition function?
From: Christian ASTOR on
On 30 juin, 08:41, bluestar <bluestar8...(a)gmail.com> wrote:

>  How to do partition function ?

With DeviceIoControl() (IOCTL_DISK_SET_DRIVE_LAYOUT_EX...)



From: bluestar on
Dear Sir:

I use the below code to partition physical disk, and it works
successfully.
But I don't how to format after i partitioned new disk.
I don't know the Logical Drives of new disk, so I can't use
other apis to format.
Could you teach me how to do?

Thanks.

//==================================================================//

DISK_GEOMETRY clsPdg;

bool __fastcall TfrmMain::PartitionPhysicalDisk(BYTE dDrive, __int64
DiskLength)
{
HANDLE hDevice;
bool bResult;
AnsiString HardDisk,str,str1;
DWORD junk;
DRIVE_LAYOUT_INFORMATION_EX drv_layout_info_ex;
CREATE_DISK disk;
VOLUME_DISK_EXTENTS DiskExts;

HardDisk.sprintf("\\\\.\\PhysicalDrive%d",dDrive);
hDevice=::CreateFile(HardDisk.c_str(),GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL);

ZeroMemory(&disk,sizeof(CREATE_DISK));
disk.PartitionStyle = PARTITION_STYLE_MBR;
disk.Mbr.Signature = 0xA4B57300;// the signature can be randomly
generated
// Create primary partition MBR
bResult
= ::DeviceIoControl(hDevice,IOCTL_DISK_CREATE_DISK,&disk,sizeof(CREATE_DISK),NULL,
0,&junk,NULL);
if(!bResult){
CloseHandle(hDevice);
}
::DeviceIoControl(hDevice,IOCTL_DISK_UPDATE_PROPERTIES,NULL,0,NULL,
0,&junk,NULL);

if (hDevice!=INVALID_HANDLE_VALUE)
{
drv_layout_info_ex.PartitionEntry[0].PartitionStyle =
PARTITION_STYLE_MBR;
drv_layout_info_ex.PartitionEntry[0].StartingOffset.QuadPart =
0;
drv_layout_info_ex.PartitionEntry[0].PartitionLength.QuadPart
= DiskLength;
drv_layout_info_ex.PartitionEntry[0].PartitionNumber = 1;
drv_layout_info_ex.PartitionEntry[0].RewritePartition = TRUE;
drv_layout_info_ex.PartitionEntry[0].Mbr.PartitionType =
PARTITION_NTFT;// PARTITION_IFS (NTFS partition or logical drive)
drv_layout_info_ex.PartitionEntry[0].Mbr.BootIndicator =
FALSE;
drv_layout_info_ex.PartitionEntry[0].Mbr.RecognizedPartition =
1;

drv_layout_info_ex.PartitionEntry[0].Mbr.HiddenSectors=(32256/512);
drv_layout_info_ex.PartitionStyle = PARTITION_STYLE_MBR;
drv_layout_info_ex.PartitionCount = 1;// specify AT LEAST 4
partitions!!!
drv_layout_info_ex.Mbr.Signature = 0xA4B57300;


bResult=::DeviceIoControl(hDevice,IOCTL_DISK_SET_DRIVE_LAYOUT_EX,
&drv_layout_info_ex,sizeof(DRIVE_LAYOUT_INFORMATION_EX),
NULL,0,
&junk,
(LPOVERLAPPED) NULL);
if( bResult )
::DeviceIoControl(hDevice,IOCTL_DISK_UPDATE_PROPERTIES, NULL,
0,NULL,0,&junk,NULL);
else
bResult = false;

Sleep(1000);
}

if(hDevice)
CloseHandle(hDevice);

return bResult;
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmMain::GetPhysicalDriveInfo(BYTE dDrive)
{
BYTE index;
HANDLE hDevice;
BOOL bResult;
AnsiString Result,Temp;
AnsiString HardDisk;
DWORD junk;
__int64 DiskSize;

HardDisk.sprintf("\\\\.\\PhysicalDrive%d",dDrive);
hDevice=::CreateFile(HardDisk.c_str(),0,FILE_SHARE_READ |
FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL);

if (hDevice!=INVALID_HANDLE_VALUE)
{
bResult=::DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL,0,
&clsPdg,sizeof(DISK_GEOMETRY),
&junk,
(LPOVERLAPPED) NULL);
if (bResult)
{
Temp="Total num of sectors: "+IntToStr(DiskSize)+"\n";
Result+=Temp;
DiskSize = DiskSize * (ULONG) clsPdg.BytesPerSector;
Temp="Total size: "+IntToStr(DiskSize)+"(Bytes) -> "+
IntToStr(DiskSize/1024/1024)+"(MB) -> "+
IntToStr(DiskSize/1024/1024/1024)+" (GB)";
Result+=Temp;
} else Result ="Can't Get Drive Information!!!";
CloseHandle(hDevice);
} //if(hDevice!=...)
else Result = "Can't Get Physical Drive!!!";

return Result;
}
//---------------------------------------------------------------------------