raeding disk block in linux

K

kg

how to read the disk block in linux using c .. and also i want to
display the information like number of sectors in the disk ..number of
free sector .. totaly i want to display the partion informaation
 
V

Vladimir Oka

kg said:
how to read the disk block in linux using c .. and also i want to
display the information like number of sectors in the disk ..number of
free sector .. totaly i want to display the partion informaation

One of the Linux groups can surely help. Standard C does not provide
any such features. You could also have a look at Linux tools that do
the same thing. Getting their source shoudl be a doddle.
 
I

Ico

kg said:
how to read the disk block in linux using c .. and also i want to
display the information like number of sectors in the disk ..number of
free sector .. totaly i want to display the partion informaation

In linux, like most unices, the raw disk is available as a special file
in the /dev filesystem. You can use the standard C file I/O functions to
access these files:

#include <stdio.h>

int main(void)
{
FILE *f;
char block[512];
int r;

f = fopen("/dev/hda", "r");
if(f == NULL) exit(EXIT_FAILURE);

r = fread(block, 1, sizeof(block), f);

/* Do something with the data */

return 0;
}

For more information about those special device files and their
contents, you better ask the proper *.linux.* newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,514
Latest member
AdeleGelle

Latest Threads

Top