Вопрос

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