中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-10-31 11:46
47,815 topics / 349,930 posts / today 0 new / 48,290 members
DOS开发编程 & 发展交流 (开发室) » The original program to extend int13 to read the MBR (hard disk master boot record), and read the hard disk serial number through the port
Printable Version  8,950 / 27
Floor16 DOSforever Posted 2006-07-02 05:30
金牌会员 Posts 2,239 Credits 4,639
Originally posted by GOTOmsdos at 2006-6-30 20:41:
Also found a small oddity:
In the program for testing my small hard disk read and write,按理说 it should only be able to read and write 1023 (3FF, 1111111111) cylinders (0-1022)
But, it can read and write 1024 cylinders!

Puzzled beyond measure..

I also don't understand your intention. Since the int13h extended call no longer uses CHS parameters, how do you know you can read and write 1024 cylinders? (It should be the 1024th cylinder) Did you still convert it?
Floor17 qb45 Posted 2006-07-02 17:47
高级用户 Posts 194 Credits 677
Originally posted by GOTOmsdos at 2006-6-30 07:45 PM:
It worked!

Also:
I don't know QB, I don't know if QB can get the address at once?

In the code of qb45:
Can the MKI$ variable take out an address value from buffdat$?
Next...


My program is just a demonstration in principle, just wanting to realize the read and write of extended INT13, and has not done optimization or something. If you want to simplify, only change MKI$(d2%) to MKI$(SADD(buffdat$)). Actually, there is no great significance, but it does seem to have two fewer variables on the surface!

I think in programming, making hard disk utilities is very interesting and very valuable.

On a 486 computer, the BIOS is very old and does not support extended INT13, so large hard disks cannot be read and written, but it is very interesting. We can use IO ports on 486 computers to realize reading and writing of hard disks with a capacity of 137G or more.

Hope everyone can study each other!
Floor18 qb45 Posted 2006-07-02 17:50
高级用户 Posts 194 Credits 677
I don't know if everyone is interested in reading and writing to the hard drive via ports
Floor19 zyl910 Posted 2006-07-02 18:16
中级用户 Posts 126 Credits 282
Originally posted by qb45 at 2006-7-2 17:50:
I don't know if everyone is interested in port reading and writing to the hard disk



Extremely interested!

I've been looking for information on this for a long time
Floor20 darkradx Posted 2006-07-03 00:58
高级用户 Posts 420 Credits 972
I/O methods, it seems that CIH has used them
Floor21 GOTOmsdos Posted 2006-07-03 02:01
铂金会员 Posts 1,827 Credits 5,154
Originally posted by DOSforever at 2006-7-2 05:30 AM:

I also don't understand your intention. Since the extended call of int13h no longer uses CHS parameters, how do you know that you can read and write 1024 cylinders? (It should be the 1024th cylinder) Did you also convert it?


Yeah, I've been researching hard disk reading and writing these days, and there are tests with conversion to the limit.
Floor22 asbai Posted 2006-07-04 00:23
高级用户 Posts 252 Credits 653
So this kind of technical specification must be looked at the official standards~~
Floor23 darkradx Posted 2006-07-06 21:02
高级用户 Posts 420 Credits 972
Floor24 qb45 Posted 2006-07-09 10:56
高级用户 Posts 194 Credits 677
Obtaining the Hard Drive Serial Number (Original Program)
This is an example of programming the hard drive using ports
This program must run under DOS and I have run it successfully under QB4.5 version

There are two IDE interfaces on the mainboard, and each interface is divided into master and slave, so 4 IDE devices can be connected. The port numbers of these 4 are different. This program uses ports 1F0 - 1F7, which are the master interface on the first IDE interface of the mainboard, and this is the most commonly used one. The others just have different port numbers, and the programming method and principle are the same.
Floor25 GOTOmsdos Posted 2006-07-13 20:40
铂金会员 Posts 1,827 Credits 5,154
Floor26 ninao99 Posted 2008-10-27 19:13
新手上路 Posts 5 Credits 12 From 山西省太原市小店区
```c
//rdiskc.c
#include <stdio.h>
#include <math.h>
#include <alloc.h>
#include <string.h>
#ifndef NULL
#define NULL 0
#endif



typedef struct DiskAddressPacket{
char PacketSize;
char Reserved;
unsigned int BlockCount;
unsigned long BufferAddr;
int BlockNum[4];
}*DAP,DiskAddrPack;

extern void DREAD(DAP);

int main(int argc,char *argv[]){
int length,i=0,j=0,k=0,line=16;
unsigned char buffer[512];
DAP psi=(DAP)malloc(sizeof(DiskAddrPack));

if(argc==2&&!strcmp(argv[1],"/?")){
printf("\nbdexpen sector(0x,for 4 section) [line]\n\tline the line on show(must be 16 or 32)");
return 0;
}

if(argc!=5&&argc!=6)
return -1;

for(argv++,i=0;i<4;i++){
length=strlen(*argv);
if(length!=4)
return -2;

for(j=0;j<4;j++){
if((*argv)[j]>='0'&&(*argv)[j]<='9')
(*argv)[j]-='0';
else if((*argv)[j]>='a'&&(*argv)[j]<='f')
(*argv)[j]=(*argv)[j]-'a'+10;
else if((*argv)[j]>='A'&&(*argv)[j]<='F')
(*argv)[j]=(*argv)[j]-'A'+10;
else return -3;
}
psi->BlockNum[3-i]=(int)(*argv)[0]*16*16*16+(int)(*argv)[1]*16*16+(int)(*argv)[2]*16+(int)(*argv)[3];
argv++;
}



if(argc==6){
length=strlen(*argv);
for(j=0,k=0,line=0;j<length;){
if((*argv)[k]<48||(*argv)[k]>57)
return -4;
line+=((int)(*argv)[k++]-48)*(int)(pow(10,--length));
}
printf("%d\n",line);
if(line!=16&&line!=32)
line=16;
}


psi->PacketSize=16;
psi->Reserved=0;
psi->BlockCount=1;
psi->BufferAddr=(unsigned long)buffer;


DREAD(psi);

for(j=0;j<512/line;j++){
printf("%3x:",j*line);
for(k=0;k<line;k++){
printf("%4x",buffer[j*line+k]);
if(k==7||k==15&&line==32||k==23)
printf(" -");
}
printf("\t ");
for(k=0;k<line;k++){
if((buffer[j*line+k])<=128&&buffer[j*line+k]!='\n'&&buffer[j*line+k]!='\t')
printf("%c",buffer[j*line+k]);
else printf("\.");
}
printf("\n");
}
free(psi);
return 0;
}
//rdiska.asm
.model small
.data
.code

public _DREAD

_DREAD proc
push bp
mov bp,sp
push ds
push si

mov ah,42h
mov dl,80h
mov si,word ptr [bp+4]
int 13h

pop si
pop ds
pop bp
ret
_DREAD endp
end

After compiling and linking, it can be executed and can be called like a DOS command. However, the usage method is not written. Probably, you input the linear address of the sector you want to read, divided into 4 segments of 4 bits each in 16 - bit hexadecimal, separated by spaces. In addition, there is a switch to switch between displaying 16 lines/32 lines as the 5th parameter.
```
Floor27 netwinxp Posted 2008-10-29 16:04
高级用户 Posts 366 Credits 741
In the program I tested for reading and writing small hard drives, theoretically, it should only be able to read and write 1023 (3FF, 1111111111) cylinders (0-1022). However, it can read and write 1024 cylinders!

For those supporting INT13 extensions, as long as the final DAP address is the same, they are accessing the same place. CHS has little practical meaning to it. For those not supporting, it will be different. But the problem is that for USB flash drives, many BIOSes report supporting INT13E, but in fact, it's a false appearance (this is also the reason for the poor compatibility of USB flash drive booting). The culprit of this problem is the BIOS. Actually, hard drives conforming to the ATA standard truly use LBA addresses to access (it's not that the number of sectors in different cylinders of antique hard drives is truly different, and CHS is根本 meaningless).
On a 486 computer, the BIOS is very old and doesn't support extended INT13, so it can't read and write large hard drives. But interestingly, we can use I/O ports on a 486 computer to implement reading and writing of hard drives with a capacity of over 137G.

Impossible. The hard drive controller chip of a 486 at most provides LBA28 addresses. The LBA address required for LBA48 is 48 bits, so it can never access a hard drive with a capacity >137G.

[ Last edited by netwinxp on 2008-11-5 at 17:46 ]
Floor28 0zwb Posted 2008-11-20 17:53
新手上路 Posts 6 Credits 11
Is there the simplest tool to modify the hard disk number?
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023