View topic - QNX API to get hard disk sector information

QNX API to get hard disk sector information

anything that doesn't fit to other groups.

QNX API to get hard disk sector information

Postby hello » Wed May 09, 2012 5:35 am

Hi,
I need the information about hard disk sector number,

Suppose the hard disk configuration is

Config: 255 Heads, 63 Sectors/track, 10011 Cylinders, 512 Block Size

Total Number of sectors = 255 * 63 * 10011 = 160826715 sectors

When I executed fdisk command, I received information in terms of number of blocks

_____OS_____ Start End ______Number_____ Size Boot
name type Cylinder Cylinder Cylinders Blocks

1. FAT32 ( 12) 0 500 501 8048502 3929 MB
2. QNZ ( 79) 3824 10010 6187 99394155 48532 MB *
3. FAT32 ( 11) 501 3823 3323 53383995 26066 MB
4. ______ (___) _______ _______ _______ _________ _____

Total Number of blocks = 8048502 + 99394155 + 53383995 = 160826652 blocks

There is a difference of 63 between Total Number of sectors and Total Number of block.

Could you please clarify the reason of this difference.

Also is there any API in QNX to get the number of heads, sectors/track and cylinders so as to calculate the number of sectors from my C++ application?

Thanks,
Hello
hello
Senior Member
 
Posts: 101
Joined: Tue May 08, 2012 1:09 pm

Re: QNX API to get hard disk sector information

Postby denkelly » Wed May 09, 2012 12:56 pm

>>>There is a difference of 63 between Total Number of sectors and Total Number of block.
The first 63 sectors are reserved for partition table, etc.
denkelly
Senior Member
 
Posts: 163
Joined: Sat Aug 02, 2008 3:27 pm

Re: QNX API to get hard disk sector information

Postby maschoen » Wed May 09, 2012 2:30 pm

hello wrote:Hi,
Also is there any API in QNX to get the number of heads, sectors/track and cylinders so as to calculate the number of sectors from my C++ application?


The values of sector/track/cylinder are an ancient remnant from when the controller had to know these values. All modern drives are LBA (Logical Block Addressing) simply numbered 0....N.
The H/T/C numbers that EIDE drives display are artificial and usually have no relation to the actual internal H/T/C numbers. In the case of a solid state drive or CF card, they are of course completely artificial as there are no heads, tracks or cylinders. In some cases the BIOS still needs to know these numbers.

I mention this because I haven't seen any access to these numbers in QNX 6. There might be an API the will provide them, but as I've tried to say they are unnecessary.

On the other hand, you can open your device:

fd = open("/dev/hd0", O_RDONLY);

and then use stat(fd, ...). If you poke around in the stat structure you will find the number you seek.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: QNX API to get hard disk sector information

Postby hello » Thu May 10, 2012 5:21 am

I need to write/read data in blocks to a particular sector of hard disk.

readblock() and writeblock() API requires start block number and number of blocks to write/read as arguments.

From system configuration 255 Heads, 63 Sectors/track, 10011 Cylinders,

Total number of sectors = 255 * 10011 * 63 = 160826715

Executing fdisk on /dev/hd0 , Total blocks = 160826652(Added all partition blocks together)
Executing fstat on /dev/hd0, Total blocks = 160836480

What is the reason of the above difference?
Also there is a confusion regarding sector number and block number. Are they same or different ?

Thanks,
hello
hello
Senior Member
 
Posts: 101
Joined: Tue May 08, 2012 1:09 pm

Re: QNX API to get hard disk sector information

Postby denkelly » Thu May 10, 2012 11:14 am

As machoen pointed out, multiplying cylinders*heads*sectors (CHS) is not accurate for modern drives. The drive typcically contains MORE sectors than this computation.

>>>Executing fstat on /dev/hd0, Total blocks = 160836480
This number is obtained by "asking" the drive interface for the number of LBAs (sectors) it supports. Part of the ATAPI spec.

>>>160826652(Added all partition blocks together)
This is the result of C*H*S-63... (10011*255*63 - 63) The remaining sectors (9828) are "round-off" and can't be put in the partition table - hence they are essentially unusable.

>>> sector number and block number. Are they same or different ?
In traditional unix, "block" was 1K while "sector" was 512b. However in QNX, a block is 512b - so block is the same as sector.

The concept of "block" being an integral number of sectors is analogous to "cluster" in the MS world.
denkelly
Senior Member
 
Posts: 163
Joined: Sat Aug 02, 2008 3:27 pm

Re: QNX API to get hard disk sector information

Postby hello » Thu May 10, 2012 11:50 am

Thank you denkelly and maschoen.
hello
Senior Member
 
Posts: 101
Joined: Tue May 08, 2012 1:09 pm


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest