2

I'm working on an assignment for my college course, and one of the questions asks for the command used to create a hard link from one file to another so that they point to the same inode. We were linked a .pdf file to refer to, but it doesn't explain said process. Is it any different from creating a standard hard link?

5

Hard links are not "between" the files, there's one inode, with >1 entries in various directories all pointing to that one inode. ls -i should show the inodes, then experiment around with ln (hard link) and ln -s (soft or symbolic):

$ touch afile
$ ln -s afile symbolic
$ ln afile bfile
$ ls -1 -i afile symbolic bfile
7602191 afile
7602191 bfile
7602204 symbolic
$ readlink symbolic
afile
$
  • That's what I thought. I know ln-s creates a symbolic link, whereas ln creates a hard link. I just wasn't sure if there was an option I needed to include, or if it was just ln file1 file2 – Brad Boisen Sep 16 '15 at 19:01
  • See my answer: what you describe is true for historical filesystem implementations but not for modern filesystems. – schily Sep 16 '15 at 21:08
2

There is nothing called inode that is granted to exist.

What people usually believe about what an inode is, is an implementation detail of the UNIXv6/UNIXv7 filesystem that was re-implemented in UFS. Note that you cannot rely on implementation details.

There is no grant that there is an inode structure at all, what is granted to exist is just an inode number that may be used to identify a specific file.

When you "hard-link" a file, all the system does, is to arrange a directory entry in a way that grants you to get the the same inode number when issuing the stat() system call for all linked files.

On filesystems that still use inode structures, this is done by letting point the directory entries to the same inode structure.

On modern filesystems that use copy on write and thus have been derived from my WOFS paper from 1991 (ZFS is such a filesystem), there is no inode structure.

My WOFS uses gnodes with a gnode number that is replaced with a new number with every write operation to the file (as there is a new gnode written to a different location in such a case). There is however an additional inode number that is kept stable over the time. On WOFS, a "hard link" is implemented as a inode-relative symbolic link, while a "symlink" on WOFS is a name-relative symbolic link. Note that for a hard-linked file with 5 names that point to the same file, there exist 5 gnode structures.

ZFS uses a mixture of the inode and the gnode concept. ZFS as a modern filesystem, however does not work as things did work in the 1970s.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.