2

I am trying to understand what an inode is. However, this passage from Wikipedia puzzles me:

Installation of new libraries is simple with inode filesystems. A running process can access a library file while another process replaces that file, creating a new inode, and an all new mapping will exist for the new file so that subsequent attempts to access the library get the new version. This facility eliminates the need to reboot to replace currently mapped libraries. For this reason, when updating programs, best practice is to delete the old executable first and create a new inode for the updated version, so that any processes executing the old version may proceed undisturbed.

1

1 Answer 1

4

In Unix-style file systems, everything the system knows about a file (except its name) is stored either in the inode or in a location pointed to by the inode. That includes its contents, ownership, modification dates, and permissions. A Unix directory entry is just a name and a pointer to the inode, and is only used when a process is opening a file. Once the file is open, the directory entry is irrelevant.

What that means is that it's possible to delete a file that's currently open without disturbing the processes that are reading or writing that file. Deleting the file simply removes the directory entry. The inode remains until all processes have closed the file, at which point the inode and all other file data are deleted (or at least marked as no longer in use and available for reclamation). This is handled by a field, called "link count", part of the inode structure.

Therefore, if you want to upgrade a shared library that's in use by a running program, you can just delete the library file. Since the program already has the file open, it won't be affected by this. Then you install the new version of the library as a new file (which gets a new inode).

5
  • And any program starting later picks up the new version, even while the processes started earlier continue using the old version.
    – vonbrand
    Commented Feb 13, 2013 at 3:50
  • Two observations: some file systems (ReiserFS) don't really have "inodes", but they do store a file's metadata separate from the file's data blocks, and separate from the directory entry. Second, what metadata is kept in a location pointed to by the inode, and not in the inode itself?
    – user732
    Commented Feb 13, 2013 at 4:45
  • @BruceEdiger, I wasn't speaking only about metadata but also the file's contents. However, extended attributes are metadata not necessarily stored in the inode.
    – cjm
    Commented Feb 13, 2013 at 5:05
  • @cjm, thank you for the clear and concise answer (I like it better than the accepted answer to the tread this one duplicates). I added one sentence for clarification - feel free to edit it freely to fit your stile.
    – Vorac
    Commented Feb 18, 2013 at 15:14
  • Normally instead of deleting the file you would use a rename call to atomically replace it.
    – plugwash
    Commented Aug 20, 2016 at 1:23

Not the answer you're looking for? Browse other questions tagged .