Comment by drdexebtjl

3 hours ago

Hardlinks are the wrong abstraction. You modify one copy and it changes on all linked paths. You want reflinks instead.

edit: spellchecker corrected reflinks, this is what I meant.

I believe you're wrong here. If you modify a hardlinked file, the FS will create new inodes under the hood, leaving existing ones intact. So it's like CoW. At least on ext4.

// Didn't double-check, but I've held this belief for over decade now, would be surprised to be proven wrong

  • You're about to be very surprised!

      echo old > a
      ln a b
      echo new > a  
      cat a b                   # prints "new" and "new"
    

    Some programs like GNU sed [1] do create new inodes, but that is a property of the application, not the filesystem:

      echo old > a
      ln a b
      sed -i 'c new' a
      cat a b                   # prints "new" and "old"
    

    With reflinks in a CoW filesystem the inodes are different from the start, but share the same underlying blocks:

      echo old > a
      cp --reflink=always a b
      ls -i a b                 # prints different inodes
      echo new > a
      cat a b                   # prints "new" and "old"
    

    [1] https://www.gnu.org/software/sed/manual/html_node/Command_00...

  • No this is completely incorrect. The filesystem doesn’t break a link just if you open it. Your editor or higher level utility is free to do so (by unlinking and copying the data into a new file/inode), but this is not how the filesystem works.

  • Changing a hardlinked file changes it everywhere, unless your specific editor happens to create a new inode. Thus it depends on your editor.

    CoW is similar except the new inode is created by the file system itself and is independent of the editor.