Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win32 API
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
Edited 21-Jul-12 2:50am
v2
Rate this: bad
good
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.
  Permalink  
Comments
pasztorpisti at 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 at 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 at 24-Jul-12 3:48am
   
LOL I didn't know that 4-5 writes can be recovered, interesting stuff! :D
Rate this: bad
good
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.
  Permalink  
Comments
farzinsantoury at 23-Jul-12 3:55am
   
thanks,
do you have an idea how can I start driver programming? any reference? book?
hbprotoss at 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.
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 CPallini 365
1 Sergey Alexandrovich Kryukov 252
2 OriginalGriff 165
3 George Jonsson 159
4 Richard MacCutchan 110
0 OriginalGriff 6,344
1 Sergey Alexandrovich Kryukov 5,860
2 CPallini 5,135
3 George Jonsson 3,559
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 23 Jul 2012
Copyright © CodeProject, 1999-2014
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