Click here to Skip to main content
15,843,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a project using win32 API and i need to find files occupied sectors on hard disk, and then write on these sectors.
for example:
I have one file (test.txt) and i want to find which sectors this file has been occupied?


does anybody know how can i do this?
Posted
Updated 21-Jul-12 3:50am
v2

I assume you are trying to write a secure delete application?
That is not as easy as you think...

Google is your friend here: Secure delete c++[^] - but be prepared for some work, it is not at all easy. Just think about SSDs - they don't write where they tell you they are, just mark the old blocks as "available for reuse" at a later date.
 
Share this answer
 
Comments
pasztorpisti 23-Jul-12 18:36pm    
+5 good question what happens on ssd drives. on non-ssd drive maybe it would be enough to open the file, get its size, and write zeros whatever you want into it.
OriginalGriff 24-Jul-12 3:36am    
Nowhere near! :laugh:
If you want to actually do a "proper" secure delete there are a huge number of things you have to take into account, including the magnetic properties of the physical media. For example, did you know that it it always possible to recover the first dataset written to a magnetic media? And that it is normally possible to recover the last 4 or five such datasets? Writing a "0" or "1" affects the magnetic hysteresis of the existing disk surface - it doesn't set it to a specific magnetic "value".

It's fascinating stuff, but there are established rules on how to securely scrub data, and it requires a number of passes with specific data patterns!
pasztorpisti 24-Jul-12 3:48am    
LOL I didn't know that 4-5 writes can be recovered, interesting stuff! :D
As far as I know, it is impossible to write to a specific sector on disk through win32 API. You need to write a driver using low-level kernel API.
 
Share this answer
 
Comments
xLordProgrammer 23-Jul-12 3:55am    
thanks,
do you have an idea how can I start driver programming? any reference? book?
hbprotoss 23-Jul-12 5:08am    
Refer to MS WDK: http://msdn.microsoft.com/en-us/library/windows/hardware/gg487428.aspx
Development kits and docs are included.
Another resource is the SysInternals utilities. There are some interesting file system utilities with source code there.
 
Share this answer
 

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