Results 1 to 7 of 7
Hello.
I need to write a program that shows disks and their partitions size and types.
So i need to read partition table, right?
But i don't know how to ...
- 05-18-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
Reading partition table.
Hello.
I need to write a program that shows disks and their partitions size and types.
So i need to read partition table, right?
But i don't know how to do this.
Please help me.
Thank you.
- 05-18-2008 #2
Browse the source code for cfdisk, which can be found in this package.
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 06-03-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
Ok so I look into fdisk source code.
And I did manage to get disk or partition size with this code.
Code:#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* size in bytes */ if ((fd = open(argv[1], O_RDONLY)) < 0) { printf("Napaka pri odpiranju!\n"); } err = ioctl(fd, BLKGETSIZE64, &b); if (err || b == 0 || b == sz) printf("Napaka!\n"); else *sectors = b; long long bytes = (*sectors); printf("Velikost v MB: %lld\n",bytes/1000000);
But now I don't know how to get partition type.
I don't understand the code when the program is getting partition type.
Please help me.
- 06-03-2008 #4
I've never used fdisk, but I've used cfdisk (which is the code that I recommended you inspect). cfdisk displays each partition type as a small integer. I think there's a hard-coded correspondence between the number and the partition type.
--
Bill
Old age and treachery will overcome youth and skill.
- 06-03-2008 #5Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The page Partition types: List of partition identifiers for PCs looks useful -- referred from Partition (computing - Wikipedia, the free encyclopedia) ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 06-04-2008 #6Just Joined!
- Join Date
- Feb 2008
- Posts
- 19
Yes I noticed that.cfdisk displays each partition type as a small integer.
But the problem is that i don't know how to get that small integer.
Please help me.
Thank you for your replys.
- 06-04-2008 #7That small integer is most likely stored in either the master boot record for the disk, or somewhere in the first few blocks of the actual partition.But the problem is that i don't know how to get that small integer.
You'll need to read the source code for fdisk (or cfdisk) to find out how it's done. Reading the source code isn't rocket science, but it is time-consuming, which is why I won't do it for you. :)
One approach is to just skim all source files for the program, glancing at the comments and the name of each function until you find what you're looking for.
Another, which is more time-consuming but begins to look more attractive if the first approach doesn't work, is to look for each call to function read(). Then see what function that call is in, and look for where those functions are called, and so on.
Good luck!--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote
