linux获取磁盘信息
来源:互联网 发布:js 控制 embed翻页 编辑:程序博客网 时间:2024/05/29 14:28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <utmp.h>
#include <sys/vfs.h>
#include <mntent.h>
static const char *ignore_fs[] ={
"none", "proc", "sysfs", "devpts", "usbfs", "usbdevfs", NULL};
typedef struct devInfo_t devInfo_t;
struct devInfo_t
{
char source[256];
unsigned long totalSize;
unsigned long availSize;
};
int getDevMnt(char *target, devInfo_t *pu);
int main(int argc, char *argv[])
{
devInfo_t pu;
getDevMnt(argv[1], &pu);
return 0;
}
static unsigned long kScale(unsigned long b, unsigned long bs)
{
return (b * (unsigned long long) bs + 1024/2) / 1024;
}
int getDevMnt(char *target, devInfo_t *pu)
{
int flag = 0;
char **p;
char *table ="/proc/mounts"; //这个可以根据自己的需要修改
char buf[BUFSIZ];
memset (buf, 0, BUFSIZ);
struct mntent *mnt;
struct statvfs statbuf;
FILE*fp;
fp = setmntent(table, "r");
if(fp == NULL)
{
return -1;
}
while((mnt = getmntent(fp)))
{
for(p =(char **)ignore_fs; *p; p++)
{
if(!strcmp(mnt->mnt_fsname, *p))
{
flag =1;
break;
}
}
if(flag)
{
flag =0;
continue;
}
if(0 > statvfs(mnt->mnt_dir, &statbuf))
{
return -1;
}
else
{
if(!strcmp(mnt->mnt_dir, target))
{
sprintf(pu->source, "%s", mnt->mnt_fsname);
pu->availSize = kScale(statbuf.f_bavail, statbuf.f_bsize);
pu->totalSize = kScale(statbuf.f_blocks, statbuf.f_bsize);
printf("getDevMnt(). %s---%9lu---%9lu\n",
mnt->mnt_fsname, pu->totalSize, pu->availSize);
}
}
}
endmntent (fp);
return 0;
}
- linux获取磁盘信息
- linux 获取文件系统信息(磁盘信息)
- Linux下应如何获取磁盘信息
- Linux C++ 获取磁盘 大小 格式 信息
- Linux下使用Sigar 获取磁盘信息
- MFC--获取磁盘信息
- WMI获取磁盘信息
- 获取磁盘信息
- 获取磁盘信息
- 获取磁盘容量信息
- Sigar获取磁盘信息
- SDK获取磁盘信息
- 获取磁盘符信息
- c#获取磁盘信息
- c++获取磁盘信息
- MFC获取磁盘信息
- Windows获取磁盘信息
- QStorageInfo获取磁盘信息
- Linux curses库(ubuntu)
- c陷进与缺陷笔记(2)
- 一个通用工厂模式的优雅实现。。。= =
- JSP内置对象request的方法的使用
- 感受
- linux获取磁盘信息
- sqlserver2005/2008----JDBC连接数据库方法
- xcode4.2中storyboard实现一个简单的跳转 iOS 5的StoryBoard
- win7 共享网络
- 虚拟机里在ubuntu linux上搭建Eclipse的HBase 开发环境
- memcached多线程模型 & nginx 多进程模型
- ExtJS 4.x 第一搞,经典的Hello World !!!
- 什么是 Schottky diode
- 程序员面试题精选100题(42)-旋转数组的最小元素