Linux C之判断外部设备是否挂载
1 static bool OutDeviceMountStateChk() 2 { 3 FILE *fstream = NULL; 4 char infotime[30]; 5 6 char errMessage[48]; 7 int nRet = -1; 8 9 struct mntent *entry; 10 eBOOL mount_status = FALSE; 11 12 fstream = setmntent("/proc/mounts", "r"); 13 if (NULL == fstream) { 14 printf("setmntent NG : %s", strerror(errno)); 15 return FALSE; 16 } 17 18 while (NULL != (entry = getmntent(fstream))) { 19 // entry->mnt_dir; 20 if (0 == strcmp(entry->mnt_dir, sgOutsideDevice)) { 21 printf("entry->mnt_dir : %s", entry->mnt_dir); 22 printf("entry->mnt_fsname : %s", entry->mnt_fsname); 23 mount_status = TRUE; 24 break; 25 } 26 } 27 endmntent(fstream); 28 return mount_status; 29 }