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
}
  • 写回答

1条回答 默认 最新

  • duanjiao3754 2013-10-22 09:37
    关注

    From the stat(2) man page on Linux:

    The st_dev field describes the device on which this file resides. (The major(3) and minor(3) macros may be useful to decompose the device ID in this field.)

    So what the code in question is doing is invoking the stat system call on the directory and its parent and checking whether they reside on different devices. This can only be true if they are on different file systems, which would indicate that the directory in question is a mount point.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决,来真人,不要ai!
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法