'디스크 용량'에 해당되는 글 1건

실행한 화면
bash# ./mzdf
System information
==================

Uptime           = 0 21:55:33
Loads 1/5/15 min = 352/3264/512
Total ram        = 527372288 bytes
Free ram         = 9428992 bytes
Shared ram       = 0 bytes
Buffer ram       = 25620480 bytes
Total swap       = 1028149248 bytes
Free swap        = 1027719168 bytes
Processes        = 159

File system            Type  Total   Used  Avail    Use% Mounted on
-------------------------------------------------------------------
rootfs               rootfs   109G 79779M 26255M  75.24% /
/dev/root              ext3   109G 79779M 26255M  75.24% /
proc                   proc     0B     0B     0B   0.00% /proc
sysfs                 sysfs     0B     0B     0B   0.00% /sys
udev                  tmpfs   251M   420K   251M   0.16% /dev
devpts               devpts     0B     0B     0B   0.00% /dev/pts
/dev/hdb1              ext3 38478M 26875M  9648M  73.58% /mnt/sub
none                  tmpfs   251M     0B   251M   0.00% /dev/shm
usbfs                 usbfs     0B     0B     0B   0.00% /proc/bus/usb
nfsd                   nfsd     0B     0B     0B   0.00% /proc/fs/nfs
-------------------------------------------------------------------
Unit : B=1024^0, K=1024^1, M=1024^2, G=1024^3, T=1024^4

End of mzdf.
bash# _


소스 (첨부파일)
코드:
/*
  Copyright (C) Information Equipment co.,LTD
  All rights reserved.
  Code by JaeHyuk Cho <mailto:minzkn@infoeq.com>
  CVSTAG="$Header$"
*/

#include <sys/sysinfo.h>/* for sysinfo */
#include <sys/vfs.h>    /* for statfs */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mntent.h>     /* for *mntent */

typedef long long unsigned int t_mzapi_qword;

int (mzunit_prefix)(t_mzapi_qword *s_value)
{
 if(*(s_value) <= ((t_mzapi_qword)99999u))return((int)'B');
 *(s_value) >>= 10;
 if(*(s_value) <= ((t_mzapi_qword)99999u))return((int)'K');
 *(s_value) >>= 10;
 if(*(s_value) <= ((t_mzapi_qword)99999u))return((int)'M');
 *(s_value) >>= 10;
 if(*(s_value) <= ((t_mzapi_qword)99999u))return((int)'G');
 *(s_value) >>= 10;
 return((int)'T');
}

int (main)(void)
{
 static const char c_hline[] = {"-------------------------------------------------------------------"};
 struct sysinfo s_sysinfo;
 FILE *s_mount_table;
 struct mntent *s_mount_entry;
 struct statfs s_status_fs;
 int s_percent, s_unit_prefix[3];
 t_mzapi_qword s_size[3]; /* 0=total, 1=used, 2=free */
 if(sysinfo((struct sysinfo *)(&s_sysinfo)) == 0)
 {
  (void)fprintf(stdout,
   "System information\n==================\n\n"
   "Uptime           = %lu %02lu:%02lu:%02lu\n"
   "Loads 1/5/15 min = %lu/%lu/%lu\n"
   "Total ram        = %lu bytes\n"
   "Free ram         = %lu bytes\n"
   "Shared ram       = %lu bytes\n"
   "Buffer ram       = %lu bytes\n"
   "Total swap       = %lu bytes\n"
   "Free swap        = %lu bytes\n"
   "Processes        = %lu\n"
   "\n",
   (unsigned long)(((s_sysinfo.uptime / 60) / 60) / 24),
   (unsigned long)(((s_sysinfo.uptime / 60) / 60) % 24),
   (unsigned long)((s_sysinfo.uptime / 60)  % 60),
   (unsigned long)(s_sysinfo.uptime % 60),
   (unsigned long)s_sysinfo.loads[0], (unsigned long)s_sysinfo.loads[1], (unsigned long)s_sysinfo.loads[2],
   (unsigned long)s_sysinfo.totalram, (unsigned long)s_sysinfo.freeram, (unsigned long)s_sysinfo.sharedram, (unsigned long)s_sysinfo.bufferram,
   (unsigned long)s_sysinfo.totalswap, (unsigned long)s_sysinfo.freeswap, (unsigned long)s_sysinfo.procs);
 }
 s_mount_table = setmntent("/proc/mounts", "r");
 if(s_mount_table != ((FILE *)0))
 {
  (void)fprintf(stdout, "%-16s   %8s %6s %6s %6s %6s%% %s\n%s\n", "File system", "Type", "Total", "Used", "Avail", "Use", "Mounted on", (char *)(&c_hline[0]));
  do
  {
   s_mount_entry = getmntent(s_mount_table);
   if(s_mount_entry == ((struct mntent *)0))break;
   if((s_mount_entry->mnt_dir == ((char *)0)) || (s_mount_entry->mnt_fsname == ((char *)0)))continue;
   if(statfs((char *)s_mount_entry->mnt_dir, (struct statfs *)(&s_status_fs)) != 0)continue;
   if(s_status_fs.f_blocks < 0l)continue;
   s_size[0] = ((t_mzapi_qword)s_status_fs.f_blocks) * ((t_mzapi_qword)s_status_fs.f_bsize);
   s_size[1] = ((t_mzapi_qword)(s_status_fs.f_blocks - s_status_fs.f_bfree)) * ((t_mzapi_qword)s_status_fs.f_bsize);
   s_size[2] = ((t_mzapi_qword)s_status_fs.f_bavail) * ((t_mzapi_qword)s_status_fs.f_bsize);
   if(s_size[0] == ((t_mzapi_qword)0))s_percent = 0;
   else s_percent = (int)((((double)(s_size[1] * ((t_mzapi_qword)10000))) / ((double)(s_size[1] + s_size[2]))) + ((double)0.5));
   s_unit_prefix[0] = mzunit_prefix((t_mzapi_qword *)(&s_size[0]));
   s_unit_prefix[1] = mzunit_prefix((t_mzapi_qword *)(&s_size[1]));
   s_unit_prefix[2] = mzunit_prefix((t_mzapi_qword *)(&s_size[2]));
   (void)fprintf(stdout,
    "%-16s %10s %5lu%c %5lu%c %5lu%c %3d.%02d%% %s\n",
    s_mount_entry->mnt_fsname, s_mount_entry->mnt_type,
    (unsigned long)s_size[0], s_unit_prefix[0],
    (unsigned long)s_size[1], s_unit_prefix[1],
    (unsigned long)s_size[2], s_unit_prefix[2],
    s_percent / 100, s_percent % 100, s_mount_entry->mnt_dir);
  }while(1);
  (void)fprintf(stdout, "%s\nUnit : B=1024^0, K=1024^1, M=1024^2, G=1024^3, T=1024^4\n\n", (char *)(&c_hline[0]));
  (void)endmntent(s_mount_table);
 }
 (void)fprintf(stdout, "End of mzdf.\n");
 (void)fflush(stdout);
 return(0);
}

/* vim: set expandtab: */
/* End of source */
크리에이티브 커먼즈 라이센스
Creative Commons License
Posted by minzkn

트랙백 주소 :: http://blog.minzkn.com/trackback/117

댓글을 달아 주세요