打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
利用/proc/mounts检查已经被系统挂载的设备

介绍/proc/mounts

如何利用/proc/mounts知道已经挂载上的设备呢,我们先来看看/proc/mounts都有啥东西


解释一下,第一列是设备路径,比如说/dev/sda1  第二列是挂载点(即设备挂载到的目录)  第三列是以什么文件系统挂载

2 编代码读取前3列

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int read_proc_mounts()
  5. {
  6. FILE *fp = NULL;
  7. int i = 0;
  8. int nSscanfNum = 0;
  9. char chDevicePath[255] = {0};
  10. char chMountPath[255] = {0};
  11. char chFsTypeName[255]= {0};
  12. char chBuffer[1024] = {0};
  13. fp = fopen("/proc/mounts","r");
  14. if (NULL == fp)
  15. {
  16. printf("\n read /proc/mounts error! \n");
  17. return -1;
  18. }
  19. while(1)
  20. {
  21. memset(chBuffer,0,sizeof(chBuffer));
  22. if(NULL == fgets(chBuffer,sizeof(chBuffer),fp))
  23. {
  24. break;
  25. }
  26. memset(chDevicePath,0,sizeof(chDevicePath));
  27. memset(chMountPath,0,sizeof(chMountPath));
  28. memset(chFsTypeName,0,sizeof(chFsTypeName));
  29. nSscanfNum = sscanf(chBuffer ,"%[^' '] %[^' '] %[^' ']",chDevicePath,chMountPath,chFsTypeName );
  30. if(3 != nSscanfNum)
  31. {
  32. continue;
  33. }
  34. printf("\nchDevicePath[%s],chMountPath[%s],chFstypeName[%s]\n",chDevicePath,chMountPath,chFsTypeName);
  35. }
  36. fclose(fp);
  37. return 0;
  38. }
  39. int main()
  40. {
  41. read_proc_mounts();
  42. return 0;
  43. }


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$ 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
升级Red Hat 9.0(Kernel 2.4.20-8) 至 Linux Kernel2.6.18
ubuntu /proc/bus/usb 没有的解决方法
Linux文件系统简介
mount 中文手册-挂载设备指南(转载内容较长)
CentOS 5.5下搭建Mysql DRBD Heartbeat
开机启动挂载设置/etc/fstab
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服