參考
實現
執行fdisk -l
命令,可以看到在Type列,顯示出了文件系統的類型,ext文件系統對應Linux,NTFS對應HPFS/NTFS,程序拿到shell的輸出,判斷文件系統類型,執行對應的mount -t
,
zc@ubuntu:~$ sudo fdisk -l
[sudo] password for zc:
Disk /dev/sda: 120 GiB, 128849018880 bytes, 251658240 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa976b913
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 247463935 247461888 118G 83 Linux
/dev/sda2 247463936 251658239 4194304 2G 5 Extended
/dev/sda5 247465984 251658239 4192256 2G 82 Linux swap / Solaris