-2

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?

SamTest
  • 299
  • 3
  • 13

1 Answers1

1

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

bladeWalker
  • 978
  • 1
  • 13
  • 30
  • To be specific I am writing a security model which will block the operation if it wants to follow either a symbolic link, or ".." under certain circumstance. I can tell if it wants to visit a slink using S_ISLNK(inode->i_mode), but how can I tell if it wants to visit ".."? Thanks for your answer anyway, I'm new in this and your reference helped me a lot. – SamTest Jan 30 '14 at 00:15
  • Then I guess you will have to update this part of pathname lookup: http://lxr.free-electrons.com/source/fs/namei.c#L1745 Note that this is VFS code and would affect all filesystems. – bladeWalker Jan 30 '14 at 00:41