LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-31-2014, 04:36 AM   #1
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Rep: Reputation: 15
Question dd read disk in reverse and check for blank sectors


Hello friends

I'm trying to realize what follow, thank you for any hint.

Premise, in my example I'm talking about an 1TB hdd. 1TB hdd is made of 1.953.525.168 LBAs or 512 bytes sectors.

The goal: when checking the hard drive content with HEX editor, the bigger is the drive, the more sensible is vertical scroll bar. In few words, if you move the mouse of 1/10 of mm, the LBAs will scroll for so many hundreds of thousands LBAs/sectors. So it is really hard to determinate the exact position where "something happen".

This is the practical example I'm talking about.

Roughly, with hex editor I see that from sector/LBA 1.350.429.000 on, the drive up to the end (1.953.525.167) is blank

While from sector/LBA 1.279.000.000 down to LBA 0 , the sectors are occupied.

I need to seek the exact position where from blank content it turns to occupied content.

So it should be matter of reading sectors (hopefully in a fast manner, maybe blocks of many sectors at once) and compare their content with HEX value 00.
Ideally this should work with the provided offsets so
from 1.350.429.000 in reverse, down to 1.279.000.000

As soon any non x00 is found, that is the sector I'm seeking for.

I suppose this can be scripted with dd and some other command line tool.

Can you kindly hint or provide the solution

Thank you

Cor

Last edited by Corsari; 10-31-2014 at 04:40 AM.
 
Old 10-31-2014, 04:54 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,773

Rep: Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565Reputation: 7565
blank (non-occupied) does not mean that is filled up with hex 00. Those areas may contain "random" bytes.
 
Old 10-31-2014, 05:16 AM   #3
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by Corsari View Post
Premise, in my example I'm talking about an 1TB hdd. 1TB hdd is made of 1.953.525.168 LBAs or 512 bytes sectors.

The goal: when checking the hard drive content with HEX editor, the bigger is the drive, the more sensible is vertical scroll bar. In few words, if you move the mouse of 1/10 of mm, the LBAs will scroll for so many hundreds of thousands LBAs/sectors. So it is really hard to determinate the exact position where "something happen".
what you describe is obvious, but exactly what one would expect. If you look at the drive on a sector-by-sector level, you have to take the entire capacity into account, because you're working "below" the file system and any information it would provide.

Quote:
Originally Posted by Corsari View Post
Roughly, with hex editor I see that from sector/LBA 1.350.429.000 on, the drive up to the end (1.953.525.167) is blank

While from sector/LBA 1.279.000.000 down to LBA 0 , the sectors are occupied.

I need to seek the exact position where from blank content it turns to occupied content.
For what reason, actually? Bear in mind that sectors with non-zero contents aren't necessarily allocated: If you store huge files and them delete them again some day, the actual contents of the sectors once occupied by that file remains unchanged. There'll just be an entry in some file system structure indicating that these sectors are free now and can be reused. Plus, space on the file system isn't necessarily allocated contiguously. There's fragmentation - all file systems that allow deleting and rewriting files are subject to fragmentation. Some more, some less.

However, if you assume that there is a point where all sectors with lower numbers contain non-zero data and all sectors "behind" contain all zeroes, this point can be found easily and very efficiently. The algorithm is called binary search and works like that:
  1. Assume the transition is at 50%. Convert that into a sector number.
  2. Read the sector number you got so far.
  3. If it is blank, the transition is in the lower half; if it's non-blank, it is in the upper half.
  4. Recalculate the sector number so that it indicates the middle of the portion you found out until now.
  5. Go back to step 2, unless the range of sectors is 1.

That way, you only have to read 31 sectors on a 1TB drive to find the transition - precisely, it's the 2-based logarithm of the total number of sectors.

But again: I think your effort here is pointless, and I can't actually see a purpose.

[X] Doc CPU
 
Old 10-31-2014, 04:06 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,129

Rep: Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639Reputation: 3639
I did a practice problem like that in Python. While I did the practice a while ago doesn't mean I can remember it now. Someone with python memory could make a script that could do what you want.
 
Old 11-03-2014, 02:44 AM   #5
Corsari
Member
 
Registered: Oct 2004
Posts: 57

Original Poster
Rep: Reputation: 15
@ DOC-CPU: thank you for your considerations. As stated in my initial post, I'll give/provide a rough offset in both directions: "rough end of written area (forward)" (non-blank), and "rough end of blank area (reverse) (blank). Rough because if it were siple to seek the turning point with just the HEX editor scroll bar... I would not have been here asking for this help :-)))))). An micro-move of the scroll bar, results in so many hundreds thousands sectors' jump and just pressing the page up/down will take minutes to scroll some just hundreds of sectors.
In the reality, provided the two offsets, the seek can be linear. From the offset "rough end of blank area" in reverse, down to "rough end of written area"

@very one of you friends:

thank you for your replies

About the blank area, it is definitely blank, x00 filled. Though, I was asking to compare with x00, eventually, the blank area I want to skip, could/will be filled with the same value, so instead than x00 it will be compared the value that I'll read in the HEX editor

As stated in my original post, bear in mind that I start from an HEX editor view and check, which shows blank (x00) filled sectors (in reverse) from the last LBA down to a certain one, where the the hdd written the last LBA.

The script I'd like to get hints on, will seek for that turning point (reverse) from blank to non blank (or from any xYZ filled value to a non-xYZ one)

Thank you for your effort and thank you for any further hint.

Last edited by Corsari; 11-03-2014 at 02:55 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I read disk sectors from a C program? stf92 Programming 5 07-21-2014 11:32 AM
re-allocated sectors count shows 2 bad sectors, in Ubuntu 10.04 disk utility james2b Linux - Hardware 4 10-12-2010 11:16 PM
FSCK auto disk check on boot and read-only FS coffeecoffee Linux - Newbie 2 10-29-2009 05:05 PM
code to read sectors from disk not working smeezekitty Programming 13 09-25-2009 06:43 PM
How do i check bad sectors in redhat 9 winxandlinx Linux - Hardware 3 05-30-2006 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration