tokuhirom (owner)

Revisions

gist: 201976 Download_button fork
public
Public Clone URL: git://gist.github.com/201976.git
Embed All Files: show embed
C #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <assert.h>
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <stdlib.h>
#include <stdio.h>
 
int main() {
    int num_of_fs = getfsstat(NULL, 0, MNT_NOWAIT);
    assert(num_of_fs > 0);
 
    struct statfs *buf = malloc(sizeof(struct statfs) * num_of_fs);
    assert(buf);
    if ( getfsstat(buf, sizeof(struct statfs) * num_of_fs, MNT_NOWAIT) < 0) {
        perror("getfsstat");
    }
    printf("number of fs is %d\n", num_of_fs);
 
    // dump it
    {
        int i;
        for (i=0; i<num_of_fs; i++) {
            // f_type
            printf("--\n");
#define DISP_I(x) printf(#x ": %d\n", buf[i].x);
            DISP_I(f_bsize);
            DISP_I(f_iosize);
#undef DISP_I
 
#define DISP_S(x) printf(#x ": %s\n", buf[i].x);
            DISP_S(f_fstypename);
            DISP_S(f_mntonname);
            DISP_S(f_mntfromname);
#undef DISP_S
        }
    }
 
    return 0;
}
 
Text only #