Emulate 4KB sector disk

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
zq
Posts: 9
Joined: Wed May 10, 2017 7:00 pm
Libera.chat IRC: si

Emulate 4KB sector disk

Post by zq »

I'm doing something about disk reading under real mode and I wanna my program to be more compatible, that is, consider 4KB(or any size other than conventional 512Bytes ).
However trouble came when I deal with qemu, even I've set those properties such like physical and logical block size in command line, but my program detect that by BIOS int 13h,ah 0x42, still it return a value with sector size 512.
I don't know if my command is wrong, can anyone tell m3 the right solution.
OR Does it means in bios sector size is ALWAYS logical 512B?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Emulate 4KB sector disk

Post by Brendan »

Hi,
zq wrote:I'm doing something about disk reading under real mode and I wanna my program to be more compatible, that is, consider 4KB(or any size other than conventional 512Bytes ).
However trouble came when I deal with qemu, even I've set those properties such like physical and logical block size in command line, but my program detect that by BIOS int 13h,ah 0x42, still it return a value with sector size 512.
I don't know if my command is wrong, can anyone tell m3 the right solution.
OR Does it means in bios sector size is ALWAYS logical 512B?
For backward compatibility for hard drives with 4 KiB sectors:
  • most hard drives emulate 512-byte sectors in their default mode, so that the BIOS and/or old software doesn't break
  • for hard disks that don't emulate 512-byte sectors, the BIOS has to support "4 KiB native" and the BIOS emulates 512-byte sectors
To avoid the performance costs (without writing your own device driver that puts the drive into "native mode") you can just read/write "groups of eight 512-byte pretend sectors that are aligned on an 8 pretend sector boundary".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: Emulate 4KB sector disk

Post by Geri »

hard drives on the market will give 512 byte blocks for you. only older special non-standard hardware will give different sector size, but you will not met any of such on the market. so the vaules you got are correct.
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Emulate 4KB sector disk

Post by Kevin »

zq wrote:Does it means in bios sector size is ALWAYS logical 512B?
Yes, that's how the BIOS interfaces are defined. If you want to use a 4k native disk to boot from, you need something else, like UEFI. (As Brendan says, the BIOS could emulate 512b sectors on a 4k disk, but that would be slow, not 100% correct and in practice I haven't seen a BIOS that supports it.)
Developer of tyndur - community OS of Lowlevel (German)
Post Reply