Student question: Change the name change the hash?

I was asked a good question yesterday. "If I change the name of a file in Linux, will the hash change?"

According to (Design and Implementation of the Second Extended Filesystem) the name of a file is stored in a directory along with its inode number. A directory is simply a file that is a list of contents, and an inode number is the way in which data on a disk is referenced.

When a file is called, the kernel looks in the directory for this name and gets the inode from there. Then the kernel can get to the data where it is stored. This would mean that changing the name of a file should not at all affect the file itself, because the name is not a part of the data.

This also helps explain the concept of hard links. If the location of a file is merely a mapping to an inode number listed in a directory, one path might be /home/ethyl/foo and another might be /home/fred/fuu but when the directories are consulted foo and fuu can point to the same inode number and it would be the same data on the disk. That is a hard link.

So changing the name of a file would change the hash of the directory in which it is stored, but not the file itself.






<< Home

This page is powered by Blogger. Isn't yours?