OPEN and read disk sector by sector

User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
Post Reply
tas3086
Posts: 316
Joined: Mon Mar 19, 2012 6:15 pm

OPEN and read disk sector by sector

Post by tas3086 »

Using your TBscripting language, is it possible to read a hard disk and/or a partition sector by sector? Open seems to be file related. Read seems to do things to CR/LF pairs, Seek seems to ignore CR/LF in its positioning. Is there a way to seek to a specific sector, or LBA position?

TBOSDT does have an open that supports Drive and/or partition opening, and a COPY SECTOR command that will copy LBA data to a file. Do I need to (EXT) CALL these TBOSDT command operations to create a sector file, then back to tbscript commands to open read, analyze, and close that temporary sector file? It seems like a lot of hard drive and temporary file openings, closings overhead and would be required. But, it should work. It does not appear that there are any return codes to verify the success of the (EXT) TBOSDT Function calls. this may be a problem.

There must be a better and easier way?


Thanks in advance.
Eric
Posts: 224
Joined: Mon Sep 05, 2011 6:53 pm
Location: France

Re: OPEN and read disk sector by sector

Post by Eric »

The "copy sectors" without the /w switch is available from inside a script (with the ext function). Then you can read the file created in binary mode. This can be included inside a loop. Start reading the sectors from the starting lba of a partition.
For ex, to browse all the sectors from a partition:

sub main()
// disk number to read
hdnum=0
// partition number to read
pn=1
// number of a sectors to read in one time
nbsect=4096
// get info of the disk
h=GetHdInfo(hdnum)
if h and h.partition[pn] then
for i=0 to (h.partition[pn].size/nbsect)
// starting lba to read
lba=h.partition[pn].startlba+(nbsect*i)
// copy sectors to file "sector.dat"
ext("copy sectors " # hdnum # " " # lba # " " # nbsect # " sector.dat")
// open the file
f=open("sector.dat", "in", "binary")
if f>-1 then
s=readl(f, lof(f))
// get it in hexa (or in string with second parameter set to 0)
r=binary(s, 1)
// do what you want
...
close(f)
else
// unable to open file (unable to read sectors?)
ExitLoop
end if
next
else
// unable to read disk, or partition nonexistent
end if
end sub
TeraByte Support
Posts: 3596
Joined: Thu May 05, 2011 10:37 pm

Re: OPEN and read disk sector by sector

Post by TeraByte Support »

Also, on Linux you can access the device as a file.

Post Reply