GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Sep-2006, 21:36
helpmeforlinux helpmeforlinux is offline
New Member
 
Join Date: Sep 2006
Posts: 7
helpmeforlinux is on a distinguished road

How many partition on hard disk?


Hi , i want to know how many partition on hard disk in linux using c program ?
Does any body have idea about this , please give me any idea abt this.
  #2  
Old 07-Sep-2006, 22:52
davis
 
Posts: n/a

Re: How many partition on hard disk?


Quote:
Originally Posted by helpmeforlinux
Hi , i want to know how many partition on hard disk in linux using c program ?
Does any body have idea about this , please give me any idea abt this.

You can try something like:

Code:
$ cat /proc/partitions major minor #blocks name 3 0 60051600 hda 3 1 60050938 hda1 3 64 60051600 hdb 3 65 104391 hdb1 3 66 59946547 hdb2 253 0 57835520 dm-0 253 1 2031616 dm-1

You can easily just read (using fopen) the /proc/partitions file and parse out the partitions very simply.

Here is an example:

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main()
{
    int rc = 0;
    FILE* p_infile = 0;
    char buffer[BUFSIZ] = {0};

    p_infile = fopen( "/proc/partitions", "r" );
    if( !p_infile )
    {
        rc = errno;
        printf( "error reading /proc/partitions for input!  error: %d\n", rc );
    }
    else
    {
        fread( buffer, 1, sizeof( buffer ), p_infile );
        printf( "Partitions:\n%s\n", buffer );
        /*
            Instead of printing, you'd probably want to parse them.
        */
    }

    if( p_infile )
    {
        fclose( p_infile );
        p_infile = 0;
    }
    return rc;
}

Output:

Code:
Partitions: major minor #blocks name 3 0 60051600 hda 3 1 60050938 hda1 3 64 60051600 hdb 3 65 104391 hdb1 3 66 59946547 hdb2 253 0 57835520 dm-0 253 1 2031616 dm-1


:davis:
  #3  
Old 11-Sep-2006, 07:07
helpmeforlinux helpmeforlinux is offline
New Member
 
Join Date: Sep 2006
Posts: 7
helpmeforlinux is on a distinguished road

Thanks for ur kind reply!


Respected Davis,
Thanks for ur reply , but actually i want this information without /proc file system.
The one thing i have done is i have used the object of structure statfs.
But now how to get all the partition information that i don't have idea.
If u have any suggestion then please tell me, but it should be without /proc file system.
Waiting for ur reply.

Quote:
Originally Posted by davis
You can try something like:

Code:
$ cat /proc/partitions major minor #blocks name 3 0 60051600 hda 3 1 60050938 hda1 3 64 60051600 hdb 3 65 104391 hdb1 3 66 59946547 hdb2 253 0 57835520 dm-0 253 1 2031616 dm-1

You can easily just read (using fopen) the /proc/partitions file and parse out the partitions very simply.

Here is an example:

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

int main()
{
    int rc = 0;
    FILE* p_infile = 0;
    char buffer[BUFSIZ] = {0};

    p_infile = fopen( "/proc/partitions", "r" );
    if( !p_infile )
    {
        rc = errno;
        printf( "error reading /proc/partitions for input!  error: %d\n", rc );
    }
    else
    {
        fread( buffer, 1, sizeof( buffer ), p_infile );
        printf( "Partitions:\n%s\n", buffer );
        /*
            Instead of printing, you'd probably want to parse them.
        */
    }

    if( p_infile )
    {
        fclose( p_infile );
        p_infile = 0;
    }
    return rc;
}

Output:

Code:
Partitions: major minor #blocks name 3 0 60051600 hda 3 1 60050938 hda1 3 64 60051600 hdb 3 65 104391 hdb1 3 66 59946547 hdb2 253 0 57835520 dm-0 253 1 2031616 dm-1


:davis:
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find size of hard disk ajeshjohn C Programming Language 4 23-Jun-2006 02:15
Selling Server darkneal128 Managed / Dedicated Servers 4 28-Mar-2006 17:01
Hard disk serial number ameynirgude C Programming Language 1 20-Nov-2005 05:55
How to Remove Host Protected Area (HPA) of (ATA) Hard disk in windows with API calls? nagamohan_p MS Visual C++ / MFC Forum 0 27-Sep-2005 23:27
Hard disk problem!! jack21 Computer Hardware Forum 2 17-May-2004 10:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:35.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.