문제

I am working on Linux kernel programming which need to track the file(inode) path.

I know some functions such as S_ISDIR, S_ISLNK to judge if a file is a directory or soft link. But I don't know how to judge if a file(inode) is the ".." file, i.e., the file points to the parent directory?

도움이 되었습니까?

해결책

AFAIK there is no inode with name as '..'. When you access a file such as /etc/passwd, there is a process called path name lookup which translates each '/', 'etc' and 'passwd' to inodes. When it encounters '.' or '/' or '..' there is a special processing. For '.' and '/', it's kind of no-op and continues to use same inode. For '..' it goes back to fetch parent inode it had come from. This is explained very clearly in Understanding the Linux Kernel Chapter 12, Virtual File System. I strongly recommend going through it. Also see http://www.mjmwired.net/kernel/Documentation/filesystems/path-lookup.txt

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top