Click here to Skip to main content
Sign Up to vote bad
good
See more: C++Win32API
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:45
Edited 21 Jul '12 - 2:50


3 solutions

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 - 23 Jul '12 - 18:36
+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:36
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:48
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.
  Permalink  
Comments
farzinsantoury - 23 Jul '12 - 3:55
thanks, do you have an idea how can I start driver programming? any reference? book?
hbprotoss - 23 Jul '12 - 5:08
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Aarti Meswania 210
4 Maciej Los 200
0 Sergey Alexandrovich Kryukov 8,893
1 OriginalGriff 7,134
2 CPallini 3,678
3 Rohan Leuva 3,036
4 Maciej Los 2,428


Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 23 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid