__init()
Hi,
Is there any way to execute my own __init() instead of default__init() while running an executable.
Quoted 4 lines · raja
Hi,
Is there any way to execute my own__init()instead of default__init()while running an executable.
-
Sure you link your object file with your own instead of using the default....
gcc -c -o myprog.o myprog.c
as -o start.o start.S
ld -o myprog myprog.o start.o /lib/libc.so.6
| | |___ runtime lib
| |__________________ Your startup
|__________________________ Your program
Startup starts with a label _start. You may have to write it in assembly. It calls main() and must never return. Instead it calls exit() with whatever main() returned, to quit.
__init() is some M$ thing. Linux executables start with _start().
Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips). Warning : 98.36% of all statistics are fiction.
.
I apologize for the following. I tried to kill it with the above dot :
****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.
Thank you.
fdisk & LBA
Hi all,i want to retrieve the partition table of a primary extended partition.
My MBR partition table ,says that the LBA Partition Start sector for the extended partition is 10281600.It is the same that i find with my C code and through fdisk usage.
How can i use this value to seek(lseek) to this point through the main block file (/dev/hda or /dev/hdb) and read the partition table of the logical partition?
Thanks in advance.
Re: fdisk & LBA
Quoted 8 lines · Nanakos Chrysostomos
Hi all,i want to retrieve the partition table of a primary extended partition.
My MBR partition table ,says that the LBA Partition Start sector for the extended partition is 10281600.It is the same that i find with my C code and through fdisk usage.
How can i use this value to seek(lseek) to this point through the main block file (/dev/hdaor/dev/hdb) and read the partition table of the logical partition?
Multiply by the sector size (probably 512 bytes).
Len Sorensen
Re: fdisk & LBA
Yes,the sector size is 512 bytes,but this is not the beginning of my fourth partition.Please check the code below,and if you can please test it..
mbr.c
------
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
struct mbr {
unsigned char boot_indicator;
unsigned char s_head;
unsigned char s_sector;
unsigned char s_cylinder;
unsigned char f_desc;
unsigned char e_head;
unsigned char e_sector;
unsigned char e_cylinder;
unsigned int rs_sector;
unsigned int n_sectors;
} __attribute__((packed));int main()
{
int fd;
struct mbr s;
fd= open("/dev/hdb",O_RDONLY);
lseek(fd,0x01ee,SEEK_SET); /* This is the 4rth entry,extended for
me*/
read(fd,&s,sizeof(struct mbr));
printf("Partition Entry 1:\n");
printf("Boot Indicator: %#x\n",s.boot_indicator);
printf("Starting head %u, cylinder %u, sector%u.\n",s.s_head,((s.s_sector & 0xc0)<<2)+s.s_cylinder,s.s_sector&0x3f);
printf("Filesystem descriptor: %#x\n",s.f_desc); printf("Ending head %u, cylinder %u, sector
%u.\n",s.e_head,((s.e_sector & 0xc0)<<2)+
s.e_cylinder,s.e_sector&0x3f);
printf("Starting sector: %u\n",s.rs_sector);
printf("Number of sectors in partition: %u\n",s.n_sectors);
fd= open("/dev/hdb4",O_RDONLY); /* Where is this in hdb,offset??*/
lseek(fd,446L,SEEK_SET);
read(fd,&s,sizeof(struct mbr));
printf("\nPartition Entry 4: Extended partition\n");
printf("Boot Indicator: %#x\n",s.boot_indicator);
printf("Starting head %u, cylinder %u, sector%u.\n",s.s_head,((s.s_sector & 0xc0)<<2)+s.s_cylinder,s.s_sector&0x3f);
printf("Filesystem descriptor: %#x\n",s.f_desc); printf("Ending head %u, cylinder %u, sector
%u.\n",s.e_head,((s.e_sector & 0xc0)<<2)+
s.e_cylinder,s.e_sector&0x3f);
printf("Starting sector: %u\n",s.rs_sector);
printf("Number of sectors in partition: %u\n",s.n_sectors);
return 0;
}Re: fdisk & LBA
Quoted 46 lines · Nanakos Chrysostomos
Yes,the sector size is 512 bytes,but this is not the beginning of my fourth partition.Please check the code below,and if you can please test it..
mbr.c
------
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>struct mbr { unsigned char boot_indicator; unsigned char s_head; unsigned char s_sector; unsigned char s_cylinder; unsigned char f_desc; unsigned char e_head; unsigned char e_sector; unsigned char e_cylinder; unsigned int rs_sector; unsigned int n_sectors; } __attribute__((packed));int
main(){ int fd; struct mbr s; fd= open("/dev/hdb",O_RDONLY); lseek(fd,0x01ee,SEEK_SET); /* This is the 4rth entry,extended for me*/ read(fd,&s,sizeof(struct mbr)); printf("Partition Entry 1:\n"); printf("Boot Indicator: %#x\n",s.boot_indicator); printf("Starting head %u, cylinder %u, sector%u.\n",s.s_head,((s.s_sector & 0xc0)<<2)+s.s_cylinder,s.s_sector&0x3f);
printf("Filesystem descriptor: %#x\n",s.f_desc); printf("Ending head %u, cylinder %u, sector
%u.\n",s.e_head,((s.e_sector & 0xc0)<<2)+
Quoted 5 lines
s.e_cylinder,s.e_sector&0x3f);
printf("Starting sector: %u\n",s.rs_sector);
printf("Number of sectors in partition: %u\n",s.n_sectors);
fd= open("/dev/hdb4",O_RDONLY); /* Where is this in hdb,offset??*/It is wherever the partition entry in sector 0 of hdb says partition 4 starts.
Why didn't you just print all the partition table entries above rather than just #1, especially since in this case it is number 4 you care about.
Print out the start sector number for partition 4 above and you should find the offset for the extended partition table, in the cases where partition 4 is the extended partition.
Seek to that location, read the partition table there. That should contain either just a primary partition, or a primary partition and another extended partition.
In case it had another extended partition, repeat until no more extended partitions found.
Quoted 11 lines
lseek(fd,446L,SEEK_SET); read(fd,&s,sizeof(struct mbr)); printf("\nPartition Entry 4: Extended partition\n"); printf("Boot Indicator: %#x\n",s.boot_indicator); printf("Starting head %u, cylinder %u, sector%u.\n",s.s_head,((s.s_sector & 0xc0)<<2)+s.s_cylinder,s.s_sector&0x3f);
printf("Filesystem descriptor: %#x\n",s.f_desc); printf("Ending head %u, cylinder %u, sector
%u.\n",s.e_head,((s.e_sector & 0xc0)<<2)+
Quoted 6 lines
s.e_cylinder,s.e_sector&0x3f);
printf("Starting sector: %u\n",s.rs_sector);
printf("Number of sectors in partition: %u\n",s.n_sectors);
return 0;
}Say you had this partition table:
start sector number of sectors pri1 1 10 (hda1) pri2 11 20 (hda2) pri3 31 10 (hda3) pri4 41 100 (extended)
then at sector 41 you would find another partition table:
pri1 42 9 (hda5) pri2 51 90 (extended)
Then sector 51 contains a partition table:
pri1 52 19 (hda6) pri2 71 70 (extended)
Then sector 71 has a partition table:
pri1 72 69 (hda7)
And no more extended entries, so you are done.
C/H/S entries are entirely ignored (or should be) on modern drives. Only start sector and total sectors are relevant as far as I understand things.
Len Sorensen