HDD crash and int13 questions ...

Bare metal programming in PureBasic, for experienced users
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

HDD crash and int13 questions ...

Post by marc_256 »

Hi,

I'm developing a big 3D software, and I lost already 2 HDD with a lot of data in a 6 months time.

1 x 500 GB of data (IDE PATA)
Here ---> http://www.purebasic.fr/english/viewtop ... 17&t=50999

After that, I installed a new backup USB HDD

1 x 2 TB of backup data (USB External Case)
Here ---> http://www.purebasic.fr/english/viewtop ... =7&t=53795

Now I lost also this HDD, with the massage "MFT corrupted..."

I bought and tested a lot of backup/recover software with no good results.

SO... I started my own recover software... ??
and need some help of a ASM guru...

I did some asm programming in the past ?? but with 486 pc ... so long time ago ...


Here we go,
I like to read the important sectors (files) from all my HDD when I stop working at evening
and save it on my USB stick as backup.
c: MBR, MFT main, MFT backup, ...
D: MBR, MFT main, MFT backup, ...
E: MBR, MFT main, MFT backup, ...
F: MBR, MFT main, MFT backup, ...

Step 1: I like to read the MBR on the HDD via BIOS interrupt INT13


First one:

INT 13h AH=02h: Read Sectors From Drive

Parameters:
AH 02h
AL Sectors To Read Count
CX Track / Sector
DH Head
DL Drive
ES:BX Buffer Address Pointer

Results:
CF Set On Error, Clear If No Error
AH Return Code
AL Actual Sectors Read Count

Function = $02 ; 'Read Disk Sector' function
NumberSectors = $01

DiskBuffer = $0000

TrackNumber = $0001 ; Cylinder 0, Sector 1
SectorNumber = $01 ; Sector 1

HeadNumber = $00
;HardDisk = $80 ; value for 1st Hard disk
DriveNumber = $80 ; value for 1st Hard disk



32 bit example:
MOV EAX,0 ; Clear EAX register

MOV AH,Function ; set function 02 of INT13
MOV AL,NumberSectors ; set Number of sectors

LES BX,DiskBuffer ; set Disk Buffer Pointer

MOV CX,TrackNumber ; set Track Number
XCHG CH,CL ; swap data low and high
ROR CL,1 ; shift CL one place to right
ROR CL,1 ; shift CL one place to right
AND CL,SectorNumber ; sector 1
OR CL,(SectorNumber and 03Fh) ; max. 63 sectors

MOV DH,HeadNumber ; Plate 0 / Head 0 /
MOV DL,DriveNumber ; HDD 1

INT 013h


Or this one:

xor ax, ax ; clear ax register
mov es, ax ; ES <- 0
mov cx, 1 ; cylinder 0, sector 1
mov dx, 0080h ; DH = 0 (head), drive = 80h (0th hard disk)
mov bx, 5000h ; segment offset of the buffer
mov ax, 0201h ; AH = 02 (disk read), AL = 01 (number of sectors to read)
int 13h


Q1/ Is this a good asm begin ?

Q2/ How can I bring the data to PB editor gadget ?


thanks in advance,
Greetings,
Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: HDD crash and int13 questions ...

Post by wilbert »

INT13 works for DOS, not for Windows.
PureBasic will be of no help in this case.
Windows (x64)
Raspberry Pi OS (Arm64)
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Re: HDD crash and int13 questions ...

Post by Ramihyn_ »

You would also need the boot sector, the ntldr file and some configuration file which is used by ntldr. But then if some system files become corrupt, you also need to save them - windows does not deal well with corrupt system files ;)

The NTFS file system is quite complex, INT13 is outdated and even extended INT13 does not support the latest HD sizes anymore. It would require a lot work to store the MFT, because it is a (special) file inside the NTFS filesystem. Due to all the different BIOS/Interface problems, it would probably be the easiest to write a linux tool and let linux worry about the physical access layer. You could do that with purebasic and use a live-CD linux like Knoppix to run it from an USB stick.

But IMHO it would make much more sense to simply do file based backups of your sources (changes) onto some remote server (web/ftp/cloud etc.), a local NAS (raid-5 for example) or an USB stick/drive. That way you wouldnt need to worry about complex file system structures (or their inconsistencies) and could even recover your sources if your house burned down ;)

Plus you should once in a while do an image backup with a software like Acronis trueimage.
Nituvious
Addict
Addict
Posts: 1000
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: HDD crash and int13 questions ...

Post by Nituvious »

You can use BitBucket for verson control. You can also keep your projects private if you want.
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: HDD crash and int13 questions ...

Post by NoahPhense »

I use Ghost, runs everyday at 10AM to an external HDD. Love it, and I can mount the dailys anytime to retrieve just one file. Or rebuild my entire system with an HDD swap in less than 15 minutes.

** mom always said, "If you fail to plan, you plan to fail..." :D
marc_256
Enthusiast
Enthusiast
Posts: 745
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: HDD crash and int13 questions ...

Post by marc_256 »

hi NoahPhense,

thanks for the answer.
** mom always said, "If you fail to plan, you plan to fail..." :D
yep, I'ts right

Marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: HDD crash and int13 questions ...

Post by infratec »

Hi, I know I'm late, but...

Have you already tried clonezilla ?
It saves your disk to an image, like 'ghost' but free.

Bernd
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: HDD crash and int13 questions ...

Post by NoahPhense »

infratec wrote:Hi, I know I'm late, but...

Have you already tried clonezilla ?
It saves your disk to an image, like 'ghost' but free.

Bernd
I'll have to look that one up for friends and family. I like Ghost cause it runs as a service and creates backups daily, incrementally. While windows is running.

I dual boot with Linux as well and Ghost backs up that partition as well.
Post Reply