Switch to full style
User discussion and information resource forum for scripting of TeraByte products using script lanugages such as TBScript, VBScript, Batch Files, and more.
Forum rules
Post a reply

OPEN and read disk sector by sector

Mon May 18, 2020 9:36 am

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.

Re: OPEN and read disk sector by sector

Tue May 19, 2020 12:12 am

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
// partition number to read
// number of a sectors to read in one time
// get info of the disk
if h and h.partition[pn] then
for i=0 to (h.partition[pn].size/nbsect)
// starting lba to read
// 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
// unable to open file (unable to read sectors?)
end if
// unable to read disk, or partition nonexistent
end if
end sub

Re: OPEN and read disk sector by sector

Tue May 19, 2020 5:20 pm

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

Post a reply