| http://leedd.com/2010/04/how-to-mount-device-and-works/ 
 
 要了解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 既是不再需要时候取消该挂载位置 
 
 |