Reading/Writing Disk Sectors (Absolute Disk Read/Write)

Click here for a larger image.

Environment: VC6 , Win 9x/NT/2K/XP

Reading/Writing disk sectors is done differently in win 9x and win NT/2K/XP.

Windows 9x

Windows 9x provides a vxd called vwin32.vxd using which msdos functions including absolute disk read/write can be performed. A handle to vwin32.vxd must be first created using the CreateFile function. After creating the handle DeviceIoControl function must be used with the correct control code to read or write from the disk drives. The control code depends on the type of the function you want to perform.

The control codes for vwin32.vxd are ...

Code Description
VWIN32_DIOC_DOS_IOCTL (1) Interrupt 21h Function 4400h through 4411h
VWIN32_DIOC_DOS_INT25 (2) Performs the Absolute Disk Read command (Interrupt 25h)
VWIN32_DIOC_DOS_INT26 (3) Performs the Absolute Disk Write command (Interrupt 25h)
VWIN32_DIOC_DOS_INT13 (4) Performs Interrupt 13h commands
VWIN32_DIOC_DOS_DRIVEINFO (6) Interrupt 21h Function 730X commands

The lpvInBuffer & lpvOutBuffer params of DeviceIoControl function must point to addresses of DIOC_REGISTERS structures . This structure contains the state of the processor registers before ioctl and after ioctl.

Windows NT/2K/XP

In Windows NT/2K/XP the CreateFile function can be used to open a disk drive or a partition on it. After getting a handle to the disk drive using CreateFile function the ReadFile function can be used to read sectors and the WriteFile function can be used to write to the drive.If you want to open a logical drive give the filename param of the CreateFile function as "\\\\.\\a:" or "\\\\.\\c:" ... etc. and if you want to open a physical drive for raw reading/writing give the filename param as "\\\\.\\PhysicalDrive0" or "\\\\.\\PhysicalDrive1" ... etc

Code to read disk sectors from win 9x/NT/2K/XP

Reads [numberofsectors] disk sectors from [drive {0=A, 1=B, 2=C, ...}] drive starting from [startinglogicalsector]

To read sectors from win 9x int 21h's 7305h extention is used (Extended Absolute Disk Read/Write). For more info about int 21h's 7305h extention refer Ralf Brown's interrupt list.

char * ReadSectors(int drive, DWORD startinglogicalsector, int numberofsectors)

// All msdos data structures must be packed on a 1 byte boundary
#pragma pack (1)
  DWORD StartingSector ;
  WORD NumberOfSectors ;
  DWORD pBuffer;
#pragma pack ()

#pragma pack (1)
typedef struct _DIOC_REGISTERS
    DWORD reg_EBX;
    DWORD reg_EDX;
    DWORD reg_ECX;
    DWORD reg_EAX;
    DWORD reg_EDI;
    DWORD reg_ESI;
    DWORD reg_Flags;
#pragma pack ()

char* buffer = (char*)malloc (512*numberofsectors);
HANDLE hDevice ;
BOOL  fResult ;
DWORD cb ;

// Creating handle to vwin32.vxd (win 9x)
hDevice = CreateFile ( "\\\\.\\vwin32",
    NULL );

if ( hDevice == INVALID_HANDLE_VALUE )
  // win NT/2K/XP code 
  HANDLE hDevice; 
  DWORD bytesread;

  char _devicename[] = "\\\\.\\A:";
  _devicename[4] += drive;

  // Creating a handle to disk drive using CreateFile () function ..
  hDevice = CreateFile(_devicename, 
            NULL, OPEN_EXISTING, 0, NULL); 

    if (hDevice == INVALID_HANDLE_VALUE) 
        return NULL;

  // Setting the pointer to point to the start of the sector we want to read ..
  SetFilePointer (hDevice, (startinglogicalsector*512), NULL, FILE_BEGIN); 

  if (!ReadFile (hDevice, buffer, 512*numberofsectors, &bytesread, NULL) )
     return NULL;
  // code for win 95/98
  ControlBlock.StartingSector = (DWORD)startinglogicalsector;
  ControlBlock.NumberOfSectors = (DWORD)numberofsectors ;
  ControlBlock.pBuffer = (DWORD)buffer ;

  // SI contains read/write mode flags
  // SI=0h for read and SI=1h for write
  // CX must be equal to ffffh for
  // int 21h's 7305h extention
  // DS:BX -> base addr of the
  // control block structure
  // DL must contain the drive number
  // (01h=A:, 02h=B: etc)

  reg.reg_ESI = 0x00 ;
  reg.reg_ECX = -1 ; 
  reg.reg_EBX = (DWORD)(&ControlBlock);
  reg.reg_EDX = drive+1;
  reg.reg_EAX = 0x7305 ;

  fResult = DeviceIoControl ( hDevice, 
    sizeof (reg),
    sizeof (reg),

   if (!fResult || (reg.reg_Flags & 0x0001)) return NULL; 		

return buffer;

Sreejith S,


Download demo project - 125 Kb
Download source - 25 Kb


  • wheloltabotly PumeSonee Phobereurce 4319375

    Posted by TizefaTaNaday on 06/03/2013 03:13am

    insiliade Heirtywew oneniazorma

  • Those things that other people actually does with regards to nike and consequently those actions you will want to do totally different.

    Posted by icoppyapedcap on 04/21/2013 09:39am

    Uy [url=]レインブーツハンター[/url] gJj [url=]レインブーツメンズ[/url] w XwyJdc UvqV [url=]レインブーツハンター[/url] fw J [url=]長靴[/url] qc [url=]レインブーツ人気[/url] RspBghVgi H[url=]長靴[/url] psUrdJveFy [url=]ハンター長靴[/url] r QeyLdy [url=]レインブーツ人気[/url] Yxq [url=]レインブーツハンター[/url] Jat Hzl [url=]ハンター長靴[/url] Jfz

  • In XP - not Admin rights problem

    Posted by frog62 on 11/01/2005 01:41am

    In XP, if you don't have Admin rights this works only on Drive A:, not on C:, D: etc. or removable drives such as FLASH DRIVE. If there is solution please help! Mail me at:

    • aa

      Posted by m_hamidimehr on 07/12/2009 08:09am


  • Write sector 0 ?

    Posted by on 06/12/2005 09:39pm

    Hi Sreejith, Thank you for your sample ! Just a quick qustion, will this method allow me to write to sector 0,1, etc where system info such as boot sector fat dir tree is located ? Thanks...

  • not Admin (in xp) !!! Help

    Posted by hafkensite on 04/28/2004 09:51am

    This doesn't work if your not Admin (in xp) How can I do that? please mail hafkensite at

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date