2012년 4월 4일 수요일

solaris: 시스템 마운트 정보 가져오기

1 #include <stdio.h>
2 #include <sys/mnttab.h>
3 #include <sys/types.h>
4 #include <sys/statvfs.h>
5 int main()
6 {
7       FILE *fp = NULL;
8       struct mnttab mountEntry;
9       struct statvfs m;
10     int ret = 0;
11


12     fp = fopen("/etc/mnttab", "r");
13     if( fp )
14     {
15         while(getmntent(fp, &mountEntry) == 0 )
16        {
17             if( statvfs(mountEntry.mnt_mountp, &m))
18                  continue;
19             if( m.f_blocks > 0 )
20            {
21                 printf("name: %s ", mountEntry.mnt_mountp);
22                 printf(" (free size: %d KB)\n", (int)(m.f_bavail * (m.f_bsize / 1024.0)));
23
24            }
25         }
26      }
27      fclose(fp);
28 }

댓글 없음:

댓글 쓰기