Click here to Skip to main content
13,558,860 members
Rate this:
Please Sign up or sign in to vote.
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 21-Jul-12 2:45am
Updated 21-Jul-12 2:50am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
xLordProgrammer 23-Jul-12 3:55am
do you have an idea how can I start driver programming? any reference? book?
hbprotoss 23-Jul-12 5:08am
Refer to MS WDK:
Development kits and docs are included.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Another resource is the SysInternals utilities. There are some interesting file system utilities with source code there.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180515.1 | Last Updated 23 Jul 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100