doumeng3080
2013-10-22 09:23
浏览 54

挂载点归因

I'm reading the source code of docker,and it checks if one directory has been mounted by such a test condition,what's the principle behind it?

func Mounted(mountpoint string) (bool, error) {
    mntpoint, err := os.Stat(mountpoint)
    if err != nil {
        if os.IsNotExist(err) {
                return false, nil
        }
        return false, err
    }
    parent, err := os.Stat(filepath.Join(mountpoint, ".."))
    if err != nil {
        return false, err
    }
    mntpointSt := mntpoint.Sys().(*syscall.Stat_t)
    parentSt := parent.Sys().(*syscall.Stat_t)
    return mntpointSt.Dev != parentSt.Dev, nil
}

图片转代码服务由CSDN问答提供 功能建议

我正在读取docker的源代码,它会检查这种测试条件是否已挂载一个目录 ,其背后的原理是什么?</ p>

  func Mounted(mountpoint string)(bool,error){
 mntpoint,err:= os.Stat(mountpoint)
 if err  != nil {
如果os.IsNotExist(err){
返回false,nil 
} 
返回false,err 
} 
父级,err:= os.Stat(filepath.Join(mountpoint,“  ..“))
如果err!= nil {
返回false,err 
} 
 mntpointSt:= mntpoint.Sys()。(* syscall.Stat_t)
 parentSt:= parent.Sys()。  (* syscall.Stat_t)
返回mntpointSt.Dev!= parentSt.Dev,nil 
} 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题