Hi,
I am writing a program to format the drive in NTFS FS.
I searched on net and got a code like this…
CREATE_DISK dsk;
CREATE_DISK_MBR dskmbr;
dskmbr.Signature = 1;
dsk.PartitionStyle = PARTITION_STYLE_MBR;
dsk.Mbr = dskmbr;
DRIVE_LAYOUT_INFORMATION_EX pdg;
DRIVE_LAYOUT_INFORMATION_MBR mbrlayout;
mbrlayout.Signature = 1234;
pdg.PartitionStyle = PARTITION_STYLE_MBR;
pdg.Mbr = mbrlayout;
LARGE_INTEGER lint;
LARGE_INTEGER lint2;
lint.QuadPart=cl_list[19].expected_bytes;
lint2.QuadPart = 0;
PARTITION_INFORMATION_EX dskinfo;
PARTITION_INFORMATION_MBR mbrinfo;
mbrinfo.PartitionType = PARTITION_NTFS;
mbrinfo.HiddenSectors = 1;
dskinfo.PartitionStyle = PARTITION_STYLE_MBR;
dskinfo.StartingOffset = lint2;
dskinfo.PartitionLength = lint;
dskinfo.PartitionNumber = 2;
dskinfo.RewritePartition = TRUE;
dskinfo.Mbr = mbrinfo;
bool bResult=FALSE; // generic results flag
HANDLE hDevice; // handle to the drive
to be examined
DWORD junk; // discard results
hDevice = CreateFile(driver,//“\\.\PhysicalDrive1”,
// drive to open
0, // no access
to the drive
FILE_SHARE_READ | // share
mode
FILE_SHARE_WRITE,
NULL, // default
security attributes
OPEN_EXISTING, //
disposition
0, // file
attributes
NULL); // do not
copy file attributes
if (hDevice == INVALID_HANDLE_VALUE) // cannot
open the drive
{
error[dr] =
ERROR_CODE_CANNOT_OPEN_THE_DRIVE;
AbnormalUnplugDevice=true;
sprintf(Buf, “ERROR,
CMTA178_PLUSDlg::Get_geom INVALID_HANDLE_VALUE
(%s”,driver);
if((m_CK_OVERNIGHT.GetCheck()!=TRUE))
AfxMessageBox(Buf);
else
PrintMSG_RESULT(“Geometry Test”,Buf);
}else{
sprintf(Buf,“Trying first IOCTRL \r\n”);
PrintMSG(Buf);
bResult = DeviceIoControl(hDevice,
// device to be queried
IOCTL_DISK_SET_DRIVE_LAYOUT_EX, // operation to
perform
&pdg, sizeof(pdg),
//sizeof(pdg), // output buffer
NULL, 0, // no
output buffer
&junk, // #
bytes returned
NULL);
//DWORD tmp = GetLastError();
if (!bResult){
sprintf(Buf,“RESULT %d\r\n”,
GetLastError());
PrintMSG(Buf);
}
int ret = Check_write_protection(dr);
bResult = DeviceIoControl(hDevice,
// device to be queried
IOCTL_DISK_CREATE_DISK, //
operation to perform
&dsk, sizeof(dsk),
//sizeof(pdg), // output buffer
NULL, 0, // no
output buffer
&junk, // #
bytes returned
NULL);
// &olap); //
synchronous I/O
//tmp = GetLastError();
if (!bResult){
sprintf(Buf,“RESULT %d\r\n”,
GetLastError());
PrintMSG(Buf);
}}
bResult = DeviceIoControl(hDevice,
// device to be queried
IOCTL_DISK_SET_PARTITION_INFO_EX, // operation to
perform
&dskinfo, sizeof(dskinfo),
//sizeof(pdg), // output buffer
NULL, 0, // no
output buffer
&junk, // #
bytes returned
//(LPOVERLAPPED)
NULL);
if (!bResult){
sprintf(Buf,“RESULT %d\r\n”,
GetLastError());
PrintMSG(Buf);
}
}
CloseHandle(hDevice);
can some one tell me about a complete source cod to
format a drive of a disk.
thanks in advance,
Regards,
rakesh
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com