woff 發表於 2013-10-24 13:03:52

Mount命令掛載設備的實現原理

要了解linux下的mount命令是如何掛載設備的工作原理,首先我們要回答以下四個問題:1.怎麼知道應該去掛載?2.掛載的幾種文件格式3.如何去掛載?4.掛載的位置如何確定?弄明白了這四個問題,就能知道monut的實現原理及工作過程。下面我們來詳細分析下
下載並獲得nautilsu源碼:[Lee@leedd.com ~]$ yumdownloader --source nautilus載入插件: refresh-packagekitnautilus-2.24.2-5_nd5_8.src.rpm | 5.2 MB 00:00[Lee@leedd.com ~]$ rpm -ivh nautilus-2.24.2-5_nd5_8.src.rpm[Lee@leedd.com rpmbuild]$ rpmbuild -bp SPECS/nautilus.spec[Lee@leedd.com rpmbuild]$cd BUILD[Lee@leedd.com BUILD]$ pwd/home/Lee/rpmbuild/BUILD在nautilus-2.24.2/libnautilus-private/nautilus-autorun.c中定位mount實現相關的函數用函數: should_autorun_mount (GMount *mount)來實現自動掛載,其中: enclosing_volume = g_mount_get_volume (mount) ;                     //用g_mount_get_volume (mount)來獲取需要mount的對象,返回Gvolume或NULL if (enclosing_volume != NULL)                           //如果該介質(封閉的捲)非空,並且如下:if (g_object_get_data (G_OBJECT (enclosing_volume), "nautilus-allow-autorun") != NULL) {                            //獲取封閉數據卷的類型,非空ignore_autorun = FALSE; g_object_set_data (G_OBJECT (enclosing_volume), "nautilus-allow-autorun", NULL); } } if (ignore_autorun) { if (enclosing_volume != NULL) { g_object_unref ( enclosing_volume);                            //,對封閉的捲(enlosing_volume)進行引用計數並排列位置} return FALSE; } 通過上面的簡單分析,我們可以知道mount工作原理及流程,並回答上面四個問題1.怎麼知道應該去掛載?—————-g_mount_get_volume (mount)函數獲取需要mount的對象來實現(返回值為Gvolume或NULL)2. 掛載的幾種文件格式 g_object_get_data (G_OBJECT (enclosing_volume), “nautilus-allow-autorun”)獲取nautilus-allow-autorun的數據文件類型可以掛載的文件類型: iso9660 ext ext2 ext3 fat fhs hpfs jfs ntfs ufs vfat等等—-通過man mount獲得3.如何去掛載?用什麼掛載:用函數: should_autorun_mount (GMount *mount)來判斷實現自動掛載具體參考本文上方函數解釋4.掛載的位置如何確定:用g_object_unref(enclosing_volume)來對封閉的捲(enlosing_volume)進行引用計數,當g_object_unref()值為unreffed既是不再需要時候取消該掛載位置

a5423381 發表於 2013-11-9 00:59:43

不錯不錯.,..我喜歡

kf1ukl 發表於 2013-11-9 00:59:43

寫得好啊 估計有馬甲
頁: [1]
查看完整版本: Mount命令掛載設備的實現原理