Page 1 of 1

Write direct to HD partition.

Posted: Sun Jun 18, 2006 6:10 pm
by Barney
Hi.

I have recently partitioned my HD to ext3, which is visible in windows, but not accessible. I was wondering, can you write bits directly to the HD from windows? i.e. in another partition, but not formatted so I can effectively create my own filesystem. I know it is possible, can you point me in the right direction?

I dont think I have the skills to yet, but I have my goal, I just need to work out the route I need to take to reach my goal.

Thanks.

Re:Write direct to HD partition.

Posted: Sun Jun 18, 2006 11:09 pm
by guest
I don't recall Windows ever allowing direct device access (at least not to the user). You may be able to create a program to write directly to the disk but the only really viable option is to write a driver (and Microsoft makes you pay for building filesystem drivers because they know it would loosen their monopoly).

Rather than going to the trouble, I suggest you try: http://www.chrysocome.net/explore2fs
It can read files from ext2/ext3 so that you can copy them onto your Windows drives.

Re:Write direct to HD partition.

Posted: Mon Jun 19, 2006 12:50 am
by JoeKayzA
Accessing drives directly (=programming its registers), is AFAIK impossible from usermode, but you can access it in block mode (without going through a filesystem driver). This direct access is restricted however to admin privileges, IIRC. You can open a storage device with a special path somehow like this:

Code: Select all

\\.\c:
How you can read and write the device however is outside my knowledge, you could check the win32 docs for more info. Alternatively you could check out the filesystem driver development kit by microsoft, which allows you to build 'native' filesystem drivers for windows NT based systems. With those, any program can natively access your self-made filesystem.
You may be able to create a program to write directly to the disk but the only really viable option is to write a driver (and Microsoft makes you pay for building filesystem drivers because they know it would loosen their monopoly).
100% agreed. ;) There is an open source ext2 filesystem driver however (ext2fsd), I don't know how they deal with licensing issues.....

cheers Joe

Re:Write direct to HD partition.

Posted: Mon Jun 19, 2006 1:35 am
by mystran
Last I remember you could download the DDK for free. Does it have a price tag now?

Re:Write direct to HD partition.

Posted: Mon Jun 19, 2006 2:46 am
by JoeKayzA
OK, I don't know about a price, but IIRC they have a special license for DDK drivers that conflicts with open source software. I'm not sure, however.

Re:Write direct to HD partition.

Posted: Mon Jun 19, 2006 3:30 am
by viral
Hello..
Reading and Writting sectors in Windows(9x or NT) is possible.. For this you have to use some APIs and manage few things in VC++.

Code: Select all

char * ReadSector(int drive, DWORD startinglogicalsector, int numberofsectors)
{
 // All msdos data structures must be packed on a 1 byte boundary
 #pragma pack (1)???
 struct 
 { 
???DWORD StartingSector ;
???WORD NumberOfSectors ;
???DWORD pBuffer;
 }ControlBlock;
 #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;
 } DIOC_REGISTERS ;
 #pragma pack ()

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

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

 if ( hDevice == INVALID_HANDLE_VALUE )
 {

???// win 2k code 
???HANDLE hDevice; 
???DWORD bytesread;
    
???// Creating a handle to drive a: using CreateFile () function ..
???char _devicename[] = "\\\\.\\A:";
???_devicename[4] += drive;
???hDevice = CreateFile(_devicename, 
        GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 
        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;
 }
 else
 {
??? // 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 ;

??? //  6 == VWIN32_DIOC_DOS_DRIVEINFO
??? fResult = DeviceIoControl ( hDevice, 
?????? 6,
?????? &(reg),
?????? sizeof (reg),
 ?????? &(reg),
?????? sizeof (reg),
?????? &cb, 
?????? 0);
 
??? if (!fResult || (reg.reg_Flags & 0x0001)) return NULL; ??????
 }

 CloseHandle(hDevice); 
 return buffer;
}
This is for reading sectors... for writting you have to go this way only.. just try to GOOGLE this... you'll get lots of thing out there..