1 |
/* |
2 |
* i-scream libstatgrab |
3 |
* http://www.i-scream.org |
4 |
* Copyright (C) 2000-2010 i-scream |
5 |
* Copyright (C) 2010 Jens Rehsack |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or |
8 |
* modify it under the terms of the GNU General Public License |
9 |
* as published by the Free Software Foundation; either version 2 |
10 |
* of the License, or (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
* |
21 |
* $Id$ |
22 |
*/ |
23 |
|
24 |
/* A very basic example of how to get the filesystem statistics from the |
25 |
* system and display them. |
26 |
*/ |
27 |
|
28 |
#include <stdio.h> |
29 |
#include <statgrab.h> |
30 |
#include <stdlib.h> |
31 |
#include <unistd.h> |
32 |
|
33 |
int main(int argc, char **argv){ |
34 |
sg_fs_stats *fs_stats; |
35 |
int fs_size; |
36 |
int x; |
37 |
char *state = NULL; |
38 |
|
39 |
/* Initialise statgrab */ |
40 |
sg_init(); |
41 |
|
42 |
/* Drop setuid/setgid privileges. */ |
43 |
if (sg_drop_privileges() != 0) { |
44 |
perror("Error. Failed to drop privileges"); |
45 |
return 1; |
46 |
} |
47 |
|
48 |
fs_stats = sg_get_fs_stats(&fs_size); |
49 |
|
50 |
if(fs_stats == NULL){ |
51 |
fprintf(stderr, "Failed to get file systems snapshot\n"); |
52 |
exit(1); |
53 |
} |
54 |
|
55 |
printf( "%-16s %-24s %-8s %16s %16s %16s %7s %7s %7s %7s %9s %9s %7s %7s %7s %7s\n", |
56 |
"device", "mountpt", "fstype", "size", "used", "avail", |
57 |
"i-total", "i-used", "i-free", "i-avail", |
58 |
"io size", "block size", |
59 |
"b-total", "b-used", "b-free", "b-avail"); |
60 |
|
61 |
for( ; fs_size > 0 ; --fs_size, ++fs_stats ) { |
62 |
printf( "%-16s %-24s %-8s %16lld %16lld %16lld %7lld %7lld %7lld %7lld %9lld %9lld %7lld %7lld %7lld %7lld\n", |
63 |
fs_stats->device_name, fs_stats->mnt_point, fs_stats->fs_type, |
64 |
fs_stats->size, fs_stats->used, fs_stats->avail, |
65 |
fs_stats->total_inodes, fs_stats->used_inodes, fs_stats->free_inodes, fs_stats->avail_inodes, |
66 |
fs_stats->io_size, fs_stats->block_size, |
67 |
fs_stats->total_blocks, fs_stats->used_blocks, fs_stats->free_blocks, fs_stats->avail_blocks); |
68 |
} |
69 |
|
70 |
return 0; |
71 |
} |