%20%E9%99%84%E5%AE%89%E8%A3%9D%E5%BA%A7(2).png)
我有一個軟體可以以程式設計方式卸載分割區(如果不忙)並在所有工作完成後再次安裝它。
如果我在終端中運行:
sudo mount /dev/sdb1 /mnt/fat32 -o sync,dirsync,rw,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro -t vfat
我得到這個/proc/self/mountinfo
:
100 24 8:17 / /mnt/fat32 rw,relatime shared:61 - vfat /dev/sdb1 rw,sync,dirsync,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro
所以我製作了一個 mountinfo 解析器並獲取資料來恢復安裝,但我正在使用 和 轉換安裝選項(rw,relatime
)和超級選項(最後一部分/mountinfo
:... rw,sync,dirsync,
)mountoptions
:data
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
我的方法是將安裝選項轉換為適當的選項mountflags
,並直接向 提供特殊選項data
,但隨後出現此錯誤:
[62857.390803] FAT-fs (sdb1): Unrecognized mount option "rw" or missing value
因此,我創建了一個函數來複製超級選項中的屬性,它們恰好與檔案系統特定資料相匹配,現在它可以工作了。但我仍然有一個問題:例如,如果它們不在安裝選項標誌中並且它們不是 vfat 特定屬性,我該如何sync
設定dirsync
?
如果可以透過命令列掛載來製作,那麼也可以在命令列版本中製作,對嗎?
答案1
答案2
所以我做了一個
mountinfo
解析器[…]
您最好使用GNU C 運行時庫中提供的setmntent()
和。getmntent()
我的方法是將安裝選項轉換為適當的選項
mountflags
,並直接提供特殊選項data
[…]
您需要做的是將給mnt_opts
定的getmntent()
和 處理為flags
和data
。套件mount
中的命令依賴util-linux
一個庫,名為庫掛載。其中一些是表驅動的,來自冗長的 Linux 特定表。