利用/proc/mounts检查已经被系统挂载的设备
来源:互联网 发布:淘宝签约卖家 编辑:程序博客网 时间:2024/06/05 01:17
1 介绍/proc/mounts
如何利用/proc/mounts知道已经挂载上的设备呢,我们先来看看/proc/mounts都有啥东西
解释一下,第一列是设备路径,比如说/dev/sda1 第二列是挂载点(即设备挂载到的目录) 第三列是以什么文件系统挂载
2 编代码读取前3列
#include <stdio.h>#include <stdlib.h>#include <string.h>int read_proc_mounts(){FILE *fp = NULL;int i = 0;int nSscanfNum = 0;char chDevicePath[255] = {0};char chMountPath[255] = {0};char chFsTypeName[255]= {0};char chBuffer[1024] = {0};fp = fopen("/proc/mounts","r");if (NULL == fp){printf("\n read /proc/mounts error! \n");return -1;}while(1){memset(chBuffer,0,sizeof(chBuffer));if(NULL == fgets(chBuffer,sizeof(chBuffer),fp)){break;}memset(chDevicePath,0,sizeof(chDevicePath));memset(chMountPath,0,sizeof(chMountPath));memset(chFsTypeName,0,sizeof(chFsTypeName));nSscanfNum = sscanf(chBuffer ,"%[^' '] %[^' '] %[^' ']",chDevicePath,chMountPath,chFsTypeName );if(3 != nSscanfNum) {continue;}printf("\nchDevicePath[%s],chMountPath[%s],chFstypeName[%s]\n",chDevicePath,chMountPath,chFsTypeName);}fclose(fp);return 0;}int main(){ read_proc_mounts(); return 0;}
3.运行结果
-bash-3.2$
-bash-3.2$ gcc test_proc_mounts.c
-bash-3.2$
-bash-3.2$
-bash-3.2$ ./a.out
chDevicePath[rootfs],chMountPath[/],chFstypeName[rootfs]
chDevicePath[/dev/root],chMountPath[/],chFstypeName[ext3]
chDevicePath[/dev],chMountPath[/dev],chFstypeName[tmpfs]
chDevicePath[/proc],chMountPath[/proc],chFstypeName[proc]
chDevicePath[/sys],chMountPath[/sys],chFstypeName[sysfs]
chDevicePath[/proc/bus/usb],chMountPath[/proc/bus/usb],chFstypeName[usbfs]
chDevicePath[devpts],chMountPath[/dev/pts],chFstypeName[devpts]
chDevicePath[/dev/sda6],chMountPath[/home],chFstypeName[ext3]
chDevicePath[/dev/sda5],chMountPath[/var],chFstypeName[ext3]
chDevicePath[/dev/sda1],chMountPath[/boot],chFstypeName[ext3]
chDevicePath[tmpfs],chMountPath[/dev/shm],chFstypeName[tmpfs]
chDevicePath[/dev/sdb1],chMountPath[/homesec],chFstypeName[ext4]
chDevicePath[/dev/sda6],chMountPath[/home_mount],chFstypeName[ext3]
chDevicePath[/dev/sdb1],chMountPath[/homesec_mount],chFstypeName[ext4]
chDevicePath[none],chMountPath[/proc/sys/fs/binfmt_misc],chFstypeName[binfmt_misc]
chDevicePath[sunrpc],chMountPath[/var/lib/nfs/rpc_pipefs],chFstypeName[rpc_pipefs]
chDevicePath[nfsd],chMountPath[/proc/fs/nfsd],chFstypeName[nfsd]
chDevicePath[/etc/auto.misc],chMountPath[/misc],chFstypeName[autofs]
chDevicePath[-hosts],chMountPath[/net],chFstypeName[autofs]
chDevicePath[/root],chMountPath[/root],chFstypeName[esn_cfs]
chDevicePath[/home],chMountPath[/home],chFstypeName[esn_cfs]
chDevicePath[/homesec],chMountPath[/homesec],chFstypeName[esn_cfs]
-bash-3.2$
- 利用/proc/mounts检查已经被系统挂载的设备
- /proc/mounts和/etc/mtab的区别
- 关于 /proc/mounts
- 关于 /proc/mounts
- /etc/mtab与/proc/mounts
- Linux中/etc/fstab /etc/mtab /proc/mounts这三个文件的分析与比较
- umount /** was not found in /proc/mounts
- 利用/proc虚拟文件作虚拟设备
- 枚举系统中已经安装的所有硬件设备
- 如何列举你系统已经安装的设备(视频压缩设备,视频捕获设备...)!
- 如何列举你系统已经安装的设备(视频压缩设备,视频捕获设备...)
- 如何列举你系统已经安装的设备(视频压缩设备,视频捕获设备...)!
- fdisk, mkfd.ext3, /proc/partitions, /proc/filesystems, /etc/fstab, /proc/mounts
- 利用proc工具解决系统(solaris)问题
- 在系统中检测指定的窗口是否已经打开,检查某进程是否存在
- 在系统中检测指定的窗口是否已经打开,检查某进程是否存在
- 如何利用/proc/filesystems的信息预先知道支持的U盘挂载系统
- USB 设备的自动检测 /proc/bus/usb
- Python生成任意范围任意精度的随机数
- js缓存客户端浏览器用户网页浏览时间等信息数据实例
- postgreSql jsonb 类型
- 使用git时遇到的问题总结及处理方法
- 小printf的故事:真正的程序员?
- 利用/proc/mounts检查已经被系统挂载的设备
- spring报错问题Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/expression/
- Glide图片缓存
- BZOJ4865: [Ynoi2017]由乃运椰子 分块
- 文章标题
- Liunx 随手记
- Disruptor学习总结(一):Disruptor的使用
- [bigdata-096] slf4j 一个抽象的java log 框架
- Linux下高并发socket最大连接数所受的各种限制 标签: linuxsockettcplinux内核网络通讯 2011-07-19 08:10 95938人阅读 评论(21) 收藏 举报 版