Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm developing an application for interfacing with pen drive. I got handle and successfully Read & Write into the sectors. I need to Read/Write values in the reserved space of the drive. In the FAT32 Boot Record, there are reserved sectors in the offset 0Eh. Can i read/write in these reserved sector?. If so how can i do it?

Regards
Mohan
Posted
Updated 11-Jan-11 0:54am
v2

You can use this[^] article to learn about accessing sectors on disk directly.

Considering you specifically ask about writing in reserved sectors, I'll assume you're familiar with the FAT32 file system. Either way, making a back-up of the drive would probably be a good idea.
 
Share this answer
 
Comments
Mohanraj Sam 11-Jan-11 7:10am    
Hi Jones,
Thanks for ur reply. Actually I used ReadFile()/WriteFile() for read/write operations. If i need to write values in the reserved sector of FAT32 of offset 0Eh, how shall i mentined this address in the WriteFile() because it gets only the sector number.

Regards
Mohan
[no name] 11-Jan-11 7:24am    
I added a reply in a new answer for you.
Once more a short description
http://support.microsoft.com/kb/100027[^].

Here is a link that you will find usefull:
http://en.wikipedia.org/wiki/FAT32#FAT32[^]

Regards
Espen Harlinn
 
Share this answer
 
The mentioned 0Eh offset is a byte offset within the boot record containing the number of reserved sectors.

The first reserved sector is sector 0, so any offset from 0 to the number of reserved sectors multiplied with the sector size in bytes, will be in a reserved sector.

Using the code from the article I linked to, you'd want to specify the offset in the Windows NT read/write functions like so:

SetFilePointer(hFloppyDisk,offset,0,FILE_BEGIN);


For example, let's assume we have sectors with a size of 512 bytes each and let's say you'd want to access sector 3. You'd want to set the file pointer like so:

SetFilePointer(hFloppyDisk,3*512,0,FILE_BEGIN);
 
Share this answer
 
Comments
Mohanraj Sam 12-Jan-11 0:24am    
Thanks Jones. I unable to read intermediate data in the sector. That is i want to read data starting from the offset OEh in the first sector. I tried with the below code,

startinglogicalsector = 1;
SetFilePointer (hDeviceHandle, (startinglogicalsector*14), NULL, FILE_BEGIN);
ReadFile (hDeviceHandle, buff, 512, &dwBytesRead, NULL);

But I get all the values of first sector starting from 0th offset. How can i read from 0Eh offset of 1st sector.

Also i have another question, 0Eh offset represents "Reserved Sectors". Is it gives total number of reserved sectors count or i can use that offset as reserved space. If it says about the count then how can i know which are the sectors are reserved. Any idea about this.

Regards
Mohan
[no name] 12-Jan-11 4:43am    
The value stored at byte-offset 14 (0Eh) is a 2-byte sized variable holding the number of reserved clusters.
It's a value, for example 3. This means 'the first 3 sectors are reserved sectors'; it doesn't mean 'sector 3 is a reserved sector'.

If you know the sector size, which is stored as a 2-byte value in sector 0 at byte-offset 0Bh, you can calculate the amount of reserved bytes. Suppose the sector size would be 512, then the amount of reserved bytes is 3*512 = 1536. Any offset used with SetFilePointer from 0 to 1536 will put you in reserved space.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900