如何使用lstat()确定是否进行硬链接 [英] how to use lstat() to determine if hard link or not

查看:160
本文介绍了如何使用lstat()确定是否进行硬链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是linux.我用C编程.我知道我可以使用lstat()来识别软链接,即使用S_ISLNK(st.st_mode).但是如何识别链接是硬链接?如果链接是硬链接,则将其视为常规文件.但是,我也想将常规文件与硬链接区分开.有什么办法可以处理这种情况?

My OS is linux. I program in C. I know I can use the lstat() to recognize the soft link, i.e., use S_ISLNK(st.st_mode). But how can I recognize the link is hard link? if the link is hard link, it will be thought of as regular file. However, I also want to distinguish the regular file from the hard link. Are there any ways to handle this case?

推荐答案

但是如何识别链接是硬链接?

But how can I recognize the link is hard link?

你不能.

硬链接"实际上并没有什么特别的.它只是一个目录条目,恰好指向磁盘上与其他位置的目录条目相同的数据.可靠地识别硬链接的唯一方法是将文件系统上的 all 路径映射到inode,然后查看哪些指向相同的值.

A "hard link" isn't actually anything special. It's just a directory entry that happens to point to the same data on disk as a directory entry somewhere else. The only way to reliably identify hard links is to map all the paths on your filesystem to inodes, and then see which ones point to the same value.

这篇关于如何使用lstat()确定是否进行硬链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆