China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-30 19:07
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Discussion] How do BIOS and partitioning software actually confirm the hard disk capacity DigestI View 15,553 Replies 40
Floor 31 Posted 2005-10-31 11:12 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
A small hard disk of 245M can't be operated by SPFDISK when working in LBA mode, but can be operated when working in CHS mode, and there is an additional 0.21M. I don't know the reason.
Floor 32 Posted 2005-11-01 16:30 ·  中国 上海 黄浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Your hard drive of more than 200 MB definitely doesn't support the LBA addressing mode, so it can only use the CHS mode. Which machine are you connecting to and what version of the BIOS is it?
Floor 33 Posted 2005-11-01 16:38 ·  中国 上海 黄浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
CHS and LBA are indeed not the same algorithm, but I think it's not at the BIOS level, but at the ATA interface level. The ATA interface's hard disk addressing registers (taking 28-bit addressing as the basis for discussion, 48-bit is not discussed for the time being) use 16 bits, 4 bits, and 8 bits respectively to represent the number of cylinders, the number of heads, and the number of sectors; so, if addressing in CHS mode, the maximum addressable space is 2^16 * 2^4 * (2^8 - 1) = 267386880 sectors, which is 136,902,082,560 bytes; if the entire 28 bits are used as a linear address expressed as LBA, then it is addressable 2^28 = 268435456 sectors, which is 137,438,953,472 bytes. This is the difference in the maximum addressable space between the two methods.

I have doubts about whether a specific hard disk is as calculated by you. Still taking that 60G hard disk as an example, for the sake of simplicity, we will calculate in sectors (actually it's all the same). If according to the CHS mode, the three parameters are all within the allowable range. But if according to the LBA mode, 0111111111111111110100110100(B) => 134,217,012(D) the number of sectors represented has exceeded the actual usable number of sectors of this hard disk. Conversely, the maximum usable number of sectors of this hard disk is 120,103,200 (D) => 0111001010001010000100100000(B) 28bit, and this value can't be divided into the CHS parameters of this mode no matter how it is divided.

Let's expand and calculate the parameter table of that 60G hard disk:

LBA Sector count: 120,103,200 sectors

Head * Sector * Cylinder = Total Sectors | Remain | Sectors/Cylinder
| |
CHS 16 255 29437 120,102,960 | 240 | 4080
| |
LARGE 240 255 1962 120,074,400 | 28800 | 61200
| |
LBA 255 63 7476 120,101,940 | 1260 | 16065


From the above example, it can be seen that in any mode, the product of the logical CHS parameters to get the total number of sectors is less than the total number of sectors given by LBA (note that this LBA is not the same as the other LBA, which will be explained below), and the remaining number of sectors is less than the number of sectors per cylinder in this mode, that is, it is not enough to form one cylinder. Therefore, I think the difference between the CHS and LBA algorithms is only manifested at the ATA interface level, and the various CHS parameters of each mode displayed at the BIOS level are all converted based on the total number of LBA sectors of the ATA interface, and are allocated in units of cylinders, and the total number of sectors of all these cylinders does not exceed the total number of sectors given by LBA, and the insufficient part is omitted.

Having said so much about LBA and CHS, I think it is necessary to explain, otherwise it is likely to cause confusion

I think there are two concepts of LBA. One is LBA at the ATA level, that is, the maximum number of sectors that can be linearly addressed inside this hard disk. I think this is the maximum available number of sectors of this hard disk; and the other LBA refers to at the BIOS level, that is, the addressing mode reported by the BIOS to the OS.

Similarly, there are two concepts of CHS. One refers to CHS mode, that is, an addressing method of the BIOS; and the other is CHS parameters, which are the parameters of the number of cylinders, heads, and sectors used in all modes.

Up to this point, I think we can tentatively draw a conclusion, which is the first paragraph below the table. I have no theoretical basis and practical experiments to prove the correctness of this conclusion, and I can only "justify" it through some data on paper. The two concepts of LBA and CHS are also conclusions analyzed by myself, and there is no theoretical basis. Now, although there are still many details that are not clear, such as the logical positioning problem of PC Tools 5.0, I think we have made some progress. Thank you very much to all the friends who participated in the discussion and paid attention to this problem, especially fdsiuha. At the same time, I hope that more friends can provide test data and put forward theoretical assumptions, and I also hope that masters with profound skills can not hesitate to give instructions.

[ Last edited by DOSforever on 2005-11-1 at 16:48 ]
Floor 34 Posted 2005-11-01 19:21 ·  中国 湖北 武汉 联通
高级用户
★★★
Credits 587
Posts 302
Joined 2005-07-25 17:31
20-year member
UID 41046
Gender Male
Status Offline

But if according to the LBA mode, 0111111111111111110100110100(B) => 134,217,012(D) The number of sectors represented has exceeded the actual number of usable sectors of this hard disk. Conversely, the maximum number of usable sectors of this hard disk is 120,103,200 (D) => 0111001010001010000100100000(B) 28bit, and no matter how this value is divided, it cannot be composed into the CHS parameters under this mode.


It doesn't mean that. The access of LBA does indeed use the 28-bit register as a unified part for access, but when using this register, it is still divided into 3 parts of C, H, and S to multiply. Among them, for a larger hard disk, H is larger, and the other two parameters are fixed (think about the physical meaning of the 3 parameters carefully); this is the linear increase of the address, not the size of the 28-bit register we see. From 0->n, but all sectors inside the hard disk have a number from small to large. In this way, it is naturally to treat LBA as a hard disk with CHS parameters to maintain compatibility.

So the B->D conversion method you mentioned above is incorrect. So naturally it "can't hold water" later.


PS: In addition, checking the so-called LARGE is nothing more than borrowing 4 bits between the two registers of INT13 to access more space, which has no essential difference from CHS. Also, I forgot to say that the LBA mode does not solve the problem of the 500MB limit.

[ Last edited by fdsiuha on 2005-11-1 at 20:29 ]
欢迎造访DOS的小屋!
http://risky.ik8.com
Floor 35 Posted 2005-11-02 01:16 ·  中国 上海 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
Let's first establish the basis of the discussion, otherwise we'll fall into chaos. First of all, we can be certain of a few things. One is that the maximum addressable sector number of a hard disk is determined and given by the manufacturer. Another is that the sector address to be addressed undergoes two conversions, one by the BIOS and the other by the ATA interface. If these two things can be confirmed, then we'll continue the discussion.

I think the register you mentioned should refer to the ATA register rather than the register used by Int 13h. If that's the case, you said that when the LBA mode uses this register, it's still multiplication of three parts, then in this way it's no different from the CHS mode. How does it reflect the "overall" concept and the essential difference from CHS?

In addition, I think with the increase in hard disk capacity, it's not the increase in the H value but the increase in the C value, and H is instead fixed because the number of bits representing the head is the least and is most likely to reach saturation.

I remember that the LARGE mode was the first to break through the 504M limit, and then the LBA mode appeared. Since this mode is not commonly used now, we won't include it in the discussion. As long as we can figure out CHS and LBA, it's the same.

[ Last edited by DOSforever on 2005-11-2 at 01:17 ]
Floor 36 Posted 2005-11-02 15:44 ·  中国 湖北 武汉 联通
高级用户
★★★
Credits 587
Posts 302
Joined 2005-07-25 17:31
20-year member
UID 41046
Gender Male
Status Offline
As for the concept of "overall," I've mentioned it before; it's the mechanism inside the hard drive. Currently, the internal addressing of hard drives uses CHS, and all sectors are uniformly numbered, with addressing directly based on this number. Then, on the hard drive interface, it's converted into a CHS parameter. Why is this so cumbersome? First, hard drives are too large, and the number of sectors per track differs greatly between the inner and outer circles. Using CHS parameters that directly reflect the 3D structure of the disk is too wide-ranging for software, and it varies between different hard drives. This makes it difficult for software to adapt to most hard drives (for example, 1 head, 10 cylinders has 128 sectors, but since you address up to 64, half the space is lost; and for 1 head, 1 cylinder, there are only 32 sectors, but since the register can address up to 64, addressing often goes out of bounds). After uniformly numbering the sectors, logically, there's only the change in the range of cylinders (that is, the diameter of the disk multiplied by the density, in other words, the change in track density), there's no out-of-bounds or space loss. Second, although direct CHS addressing is abolished, software all uses the fixed CHS format for addressing, especially Microsoft's software. So externally, parameters still need to be passed in CHS mode.

So my point is: the 28-bit register of the hard drive is the interface between software and hardware. That is, after submitting the access method to the hard drive, the internal addressing mechanism of the hard drive will choose the mode of address conversion accordingly. I've already said earlier that although LBA and CHS use different methods for addressing inside the hard drive, all hard drive modes return 28-bit values that are CHS parameters. This conversion process is done by the hard drive, and software doesn't need to and can't interfere with this.

There's actually no essential difference between LBA and CHS. Look at your computer's BIOS; it only has NORMAL, LARGE, LBA, AUTO, not separated into CHS, LBA, LARGE. Because LBA is just one of the CHS methods, except that its 28 bits can all be at the maximum value, all can be 1. The impact is that there are more sectors per cylinder.

And those so-called restrictions we had before were just due to the conversion between software and software. It has nothing to do with CHS and LBA. Only up to 137G is the physical limit, and new hard drives need to use 48-bit registers to solve it.

Then, software—including BIOS—takes over the subsequent work, and the I/O routines address and read/write the disk according to the given C, H, S.

The reason we see different LBA, CHS settings and values in software is just that the hard drive internally addresses differently. BIOS generally doesn't make further conversions (LARGE needs a slight change, so LARGE is actually implemented by software, and thus has poor compatibility).

You also mentioned the issue with PC Rabbit. Not just it, many disk software have had similar problems. The root cause of this problem is the address conversion problem, because it accesses the disk through BIOS (and through DOS, of course, it's even worse). If you switch your current LBA or NORMAL to NORMAL or LBA and then boot, the system won't start and will immediately crash—BIOS can't even locate the boot sector of the operating system, so what can you expect from an old version of PC Rabbit to do through BIOS? I have a bunch of such DOS software, and nine times out of ten, they crash immediately when opened.

--------------------------------------------------
My personal website has a detailed introduction about disks, but it's not finished yet and probably won't be finished by the end of the year. Oh well

[ Last edited by fdsiuha on 2005-11-2 at 16:08 ]
欢迎造访DOS的小屋!
http://risky.ik8.com
Floor 37 Posted 2005-11-03 09:58 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Regarding my small hard disk (245M), please see http://www.cn-dos.net/forum/viewthread.php?tid=17118&fpage. As for the extra 0.21M, it's recognized by SPFDIS, not calculated. A hard disk of over 200MB definitely supports LBA addressing mode, and FDISK can partition in LBA addressing mode. When adding an external hard disk, pqmagic starts normally, no errors are found, and it can also partition. The DOS boot on this hard disk is normal. It's just that SPFDIS is normal when working in CHS mode, but SPFDIS doesn't recognize the partition of the small hard disk when working in other modes. The BIOS version can be seen in 'Post #20'!
Floor 38 Posted 2005-11-04 21:27 ·  中国 湖北 武汉 联通
高级用户
★★★
Credits 587
Posts 302
Joined 2005-07-25 17:31
20-year member
UID 41046
Gender Male
Status Offline
It is suggested to contact the author of this software ^^
欢迎造访DOS的小屋!
http://risky.ik8.com
Floor 39 Posted 2005-11-06 13:39 ·  中国 浙江 电信
中级用户
★★
Credits 300
Posts 137
Joined 2005-11-04 02:00
20-year member
UID 44559
Gender Male
Status Offline
Even when using FDISK for partitioning and checking with SFDISK (a hard disk partitioning and formatting software I often use), there are still a lot of free hard disk spaces, that is, the hard disk has not been 100% partitioned.
Floor 40 Posted 2005-11-07 11:27 ·  中国 上海 长宁区 电信
新手上路
Credits 11
Posts 6
Joined 2005-11-02 10:49
20-year member
UID 44460
Status Offline
Early BIOS/DOS in the early days did not support relatively large Cylinder values under the CHS mode. LBR is an algorithm that virtualizes the Cylinder value into a header, and LARGE is also a virtualization algorithm. Later BIOS and 32-bit systems have supported larger Cylinders, so it should be差不多 the same no matter which method is used.

(注:“差不多”保留英文“差不多”是因为在这种技术讨论场景下直接保留原意更合适,若要完全翻译为“about the same”也可,但根据要求尽量保留原意的非技术化表达,这里暂时保留“差不多”)
Floor 41 Posted 2006-10-06 08:34 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
This discussion about the hard disk is very valuable. It's a pity that my understanding isn't as profound as everyone else's. You know, for the entire computer, the data on this hard disk is the most important.
Forum Jump: