Trying to get partion information with devctl?

The program below deosn’t give me the partion information on my disk. I’m
getting all zero’s.
What did I do wrong. This is in QNX 6.1 and the disk are standard IDE drive.
Rejean Senecal

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <pthread.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <devctl.h>
#include <sys/disk.h>
#include <sys/dcmd_blk.h>
#include “test.hpp”

int main(int argc, char *argv)
{

int iFd, iErr;
partition_entry entry;

iFd=open("/dev/hd0",O_RDONLY);
if (iFd == -1) {
perror(“Error opening /dev/hd0”);
exit(0);
}

iErr = devctl(iFd, DCMD_BLK_PARTENTRY, &entry, sizeof(entry), NULL);
if (iErr) {
perror(“Error getting partion entry”);
exit(0);
}

printf("\nboot_ind %d,\n beg_head %d,\n beg_sector %d,\n beg_cylinder %d,\n
os_type %d,\n end_head %d,\n end_sector %d, end_cylinder %d \n
part_offset %ld,\npart_size %ld;\n",
entry.boot_ind,entry.beg_head,entry.beg_sector,entry.beg_cylinder,entry.os_t
ype,entry.end_head,entry.end_sector,entry.end_cylinder,
entry.part_offset,entry.part_size);

return 0;
}

Rejean Senecal <rsenecal@oerlikon.ca-no-spam> wrote:

The program below deosn’t give me the partion information on my disk.
I’m getting all zero’s.

That is correct. Because the raw disk ("/dev/hd0") isn’t a partition, it
fakes out most of those fields as being zero (all except ‘part_size’).
If you applied this devctl to “/dev/hd0t77” (etc) it would contain the
appropriate values. If you’re trying to find all the partitions then you
need to read block 0 of the raw device and process the 4 entries
(struct partition_entry <sys/disk.h>) found at offset 0x1be …

What did I do wrong. This is in QNX 6.1 and the disk are standard IDE

Thanks it works.
If i want to change the boot partition can I write the entry back and change
the field entry.boot_int to 0 or 128.

Where can I find more information on the QNX filesystem structure and the
devctl function for it. Where did you find the information about the 0x1BE
offset.
Rejean Senecal

“John Garvey” <jgarvey@qnx.com> wrote in message
news:ak57b5$48l$1@nntp.qnx.com

Rejean Senecal <> rsenecal@oerlikon.ca-no-spam> > wrote:
The program below deosn’t give me the partion information on my disk.
I’m getting all zero’s.

That is correct. Because the raw disk ("/dev/hd0") isn’t a partition, it
fakes out most of those fields as being zero (all except ‘part_size’).
If you applied this devctl to “/dev/hd0t77” (etc) it would contain the
appropriate values. If you’re trying to find all the partitions then you
need to read block 0 of the raw device and process the 4 entries
(struct partition_entry <sys/disk.h>) found at offset 0x1be …

What did I do wrong. This is in QNX 6.1 and the disk are standard IDE

Rejean Senecal <rsenecal@oerlikon.ca-no-spam> wrote:

If i want to change the boot partition can I write the entry back and change
the field entry.boot_int to 0 or 128.

Yes, you can do this (write 0x80 in the boot_ind field of the bootable
partition and 0x00 in all others); or you can use the “fdisk” utility
in command mode (“fdisk /dev/hd0 boot t79”).

Where can I find more information on the QNX filesystem structure and the
devctl function for it. Where did you find the information about the 0x1BE

A Google search on “partition table” should provide plenty of info …

Rejean Senecal <rsenecal@oerlikon.ca-no-spam> wrote in article <ak5e6e$l4p$1@inn.qnx.com>…

Thanks it works.
If i want to change the boot partition can I write the entry back and change
the field entry.boot_int to 0 or 128.

Where can I find more information on the QNX filesystem structure and the
devctl function for it. Where did you find the information about the 0x1BE
offset.

0x1be offset… it is thing of Master Boot Record (MBR), it is first sector of hard disk. It has
nothing to do with QNX or any other filesystem. There is a lot of information about MBR structure
on internet. Begin from this offset there is partition table…
Cheers,

Eduard.
ed1k at ukr dot net

Ok, I know that the DOS style MBR has 4 entries and that’s all folks. But
if you wanted to use a partition table that allowed more entry like those
used on common Unix platforms how could you inform the QNX resource managers
to mount the alternate partitions? I have been making disk images and
treating them as partitions, but this is not a particularly elegant
solution.

Pete Eddy

“ed1k” <ed1k@spamerstrap.com> wrote in message
news:01c24f6b$1c26e040$106fa8c0@ED1K…

Rejean Senecal <> rsenecal@oerlikon.ca-no-spam> > wrote in article
ak5e6e$l4p$> 1@inn.qnx.com> >…
Thanks it works.
If i want to change the boot partition can I write the entry back and
change
the field entry.boot_int to 0 or 128.

Where can I find more information on the QNX filesystem structure and
the
devctl function for it. Where did you find the information about the
0x1BE
offset.

0x1be offset… it is thing of Master Boot Record (MBR), it is first
sector of hard disk. It has
nothing to do with QNX or any other filesystem. There is a lot of
information about MBR structure
on internet. Begin from this offset there is partition table…
Cheers,

Eduard.
ed1k at ukr dot net

I’m not very sure I understand you right…
Ok. MBR has 4 entries for partitions. Every entry has included Filesystem Code, if this code is
0x05 then the partition defined by the entry is treated as if it is the start of another physical
drive; that is for normal partition MBR’s entry points to bootsector (first sector) of partition,
for FsysCode=0x05 the MBR’s entry points to MBR. This next MBR allows to have 4 additional
partitions and/or can include pointer to next MBR (again FsysCode=0x05), etc. So you can have as
many partitions as you want. The partitions defined by first MBR are called primary partitions, the
partitions defined by next MBR are called extended partitions or logical drives. AFAIK, currently
QNX’s fdisk is unable to creat/handle extended partitions, this is the only problem. QNX resource
managers, like devb-eide, understand primary and extended partitions, so after starting of the
manager you can get something like:
/dev/hd0 - whole first disk;
/dev/hd0t6 - FAT primary partition;
/dev/hd0t5 - next MBR;
/dev/hd0t6.1 - this FATpartition in extended region, this partitions is described in NEXT MBR
pointed by entry in first MBR
/dev/hd0t79 - this is primary QNX partition.
So, you can mount any of these partitions (hd0t*) except hd0t5 because it’s not a partition but
just MBR (extended partition record) described extended partition. Extended partition record
usually has no any boot code, it includes just partitions table at offset 0x1be.
HTH.

Eduard.
ed1k at ukr dot net

Bob Smith <bobsmith@home.com> wrote in article <alaa36$qcf$1@inn.qnx.com>…

Ok, I know that the DOS style MBR has 4 entries and that’s all folks. But
if you wanted to use a partition table that allowed more entry like those
used on common Unix platforms how could you inform the QNX resource managers
to mount the alternate partitions? I have been making disk images and
treating them as partitions, but this is not a particularly elegant
solution.

Pete Eddy

ed1k <ed1k@spamerstrap.com> wrote in article 01c257de$3d0b4460$106fa8c0@ED1K
[…]

manager you can get something like:
/dev/hd0 - whole first disk;
/dev/hd0t6 - FAT primary partition;
/dev/hd0t5 - next MBR;

Sorry, you will not see this MBR’s entry which is pointing to extended partition record under /dev.
But devb-eide correctly handle this record and definetelly you will see extended partitions if
they are on your drive. Even if it is unsupported file system’s partition. For instance, I’m able
to see /dev/hd0t7 - it is NTFS4 partition in extended region on my disk. Of course, I’m unable to
work with this partition under QNX because there is no file system layer (library) for NTFS in QNX.

Eduard.
ed1k at ukr dot net