Rick Green
I guess I need to do some reading on the internal structure of ext2.
It's helpful but the concept of inodes is a part of the VFS (Virtual File System) layer. It is not specific for ext2.
I was thinking that the 'inode' was roughly equivalent to the 'FAT' in the dos world, and contained nothing more than a pointer to a physical cluster(s).
No. In the case of ext2, an inode contains pointers to data blocks and some other metadata. The "stat" command lists them: # stat /etc/passwd File: "/etc/passwd" Size: 3490 Blocks: 8 Regular File Device: 303h/771d Inode: 212979 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: Fri Dec 28 22:24:17 2001 Modify: Sat Dec 22 15:50:44 2001 Change: Sat Dec 22 15:50:44 2001 (The file name is not there!). # rpm -qf /usr/bin/stat stat-2.4-84
So the directory contains a name and owner, pointing to an inode, which contains permissions, and points to a physical sector?
Each directory in ext2 contains _only_ file names and inode numbers: # /bin/ls -i /bin | head -4 275265 . 2 .. 275321 arch 275267 ash
If the permissions of the parent directories are important, then it seems the access to a linked file is much more complicated than necessary.
It's more complicated but it's worth the trouble.
A hard link points directly to an inode, which may be in a much different part of the filesystem tree (although on the same partition). So if I'm accessing /home/rtg/bin/foo which is a link to /usr/X11/bin/bar, I chase the filesystem down the directory path to /home/rtg/bin/foo, then get a pointer to inode 12345. At this point, how am I supposed to find out what the 'real' parent directories of this file are?
The system doesn't search for 'real' parent directories, it knows them. Each process knows its CWD (current working directory), e.g. /usr/X11/bin. So if you access a file from a process by specifying a relative path only, the CWD is used to get the full path name and the access is granted according to this full path. If symbolic links are involved, then you can imagine they are dereferenced to a full path (which doesn't contain them) first and the full path is checked then.
Does the inode also contain reverse or upward pointers to its parents?
An inode doesn't contain any information about the file name or parent directories. It's directories' business. They contain the file name and the parent directory ("..") item. So the path can be traversed backward and all directory permissions determined.
Even in the case of a symbolic link, where you will be chasing the filesystem down the full path to the target, it seems like a lot of IO to have to read every directory and it's inode in the path, just to find out if its permissible to read the data.
Yes, it may be a lot of IO. But as far as I know there is a directory cache in the kernel so some disk access may be avoided. -- Alexandr.Malusek@imv.liu.se