Hi everyone,

I'm really, really confused with the whole CHS thing. Here's what I understand so far...

INT13, function 8 can get me the following drive parameters:-
Heads
Cylinders
Sectors-per-Track

I can use the following calculations to get the disk space:-
Sectors-per-Side = Sectors-per-Track * Cylinders
Total Sectors = Sectors-per-Side * Heads
Total Disk Space = Total Sectors * Bytes-per-Sector

Now this is where I'm stuck! How exactly do I get "Bytes-per-Sector"? I'm aware that the 'standard' is 512, but I've heard that it can be different, and in January 2011 it's going to change. Therefore, I'd rather get the value automatically if possible.

To clarify my situation, I'm working on a bootloader for my own OS in NASM, and I'm hoping to try to develop my own format as opposed to FAT or NTFS. Please can someone shed light on my problem, as this is a big-ass speed bump! :'(

Hi everyone,

I'm really, really confused with the whole CHS thing. Here's what I understand so far...

INT13, function 8 can get me the following drive parameters:-
Heads
Cylinders
Sectors-per-Track

I can use the following calculations to get the disk space:-
Sectors-per-Side = Sectors-per-Track * Cylinders
Total Sectors = Sectors-per-Side * Heads
Total Disk Space = Total Sectors * Bytes-per-Sector

Now this is where I'm stuck! How exactly do I get "Bytes-per-Sector"? I'm aware that the 'standard' is 512, but I've heard that it can be different, and in January 2011 it's going to change. Therefore, I'd rather get the value automatically if possible.

To clarify my situation, I'm working on a bootloader for my own OS in NASM, and I'm hoping to try to develop my own format as opposed to FAT or NTFS. Please can someone shed light on my problem, as this is a big-ass speed bump! :'(

Okay, so now I've looked into it a bit further, and have identified function 0x48, which should be able to do the job. Now I have another question; how exactly do I setup and use a buffer in NASM for use with this function; if anybody has some source code, it would be greatly appreciated!

You can use this snippet:

getdriveparms:
        mov ah,048h                     ; get more detailed drive information
        mov dl,[disk]             
        push DS
        lds SI,[segtmp]
        mov word [SI],01eh
        int 13h
        pop DS
        mov ax,[SI+018h] ; this is value of bytes per sector

You can find detailed information on this function here:
http://www.ctyme.com/intr/rb-0715.htm

You have to prepare a pointer in DS: SI to a free memory location.
If it's in your actual DS segment you can delete push ds and pop ds lines.
I put this for information that your DS maybe corrupted after calling this function if you don't remember that you changed DS for this function.

The buffer must be minimum 30 bytes (18h) and function will not use more buffer you give. You have to mark size of buffer in the first word of buffer.

You will find bytes per sector in returned buffer information at offset 018h.
This will return different values for a hard disk (0200h=512 Bytes) and cdrom drive (0800h=2048 Bytes) for example.

CHS is an obsolete method for disk io. It will work for boot purposes but can not fully address big hard disks. You should use function 42h instead of 02h (int 13h) for reading sectors. You can address hard disk in most cases in LBA mode which is much easier than using CHS.

In CHS mode you can address maximum 8 GB on a hard disk drive.

By the way, function 48h is returning a qword (8 bytes value) at offset 10h to total sectors on volume.
Just multiply with bytes per sector.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.