1

When a file is updated then the corresponding inode gets updated. But sometimes the following condition occurs

  1. file is same and inode is new
  2. file gets changed but corresponding inode is older

Why ?

1 Answers1

4

Your question is a bit unclear, but I'll give it a shot...


If you edit a file with an editor and such, often a new file (with a new inode) will be created - but containing the same/edited data. The original file (with original inode) may be retained as back-up.

The shell redirections (> and >>) on the other hand, reuse the inode, so the inode remains the same after you overwrite/add to the file. (The drawback being that the old content typically will be overwritten, so there is no way of rescuing the old content if you overwrote it by mistake.)


There is no guarantee that inodes are used "in order" with the lowest available inode used first. Nor will the "oldest" (first deleted) inode necessarily be used before a "newer" inode. When you delete a file, the resources freed are added to two lists the file system maintains: one with free blocks (i.e. space on the disk) and one with free inodes. These lists are not in any particular order — freed resources are just added as files are deleted.

Often these two lists are maintained in "blocks" so that a number of inodes or a number of free blocks are loosely grouped together. When needing resources for a new file, the filesystem will often finish using the resources in the "block" its in, before moving to the next one.

So, to summarise, you don't know in which order a inode or a block of space will be reused. It's not sorted by inode number or by the order in which it was deleted. Nor will all inodes or all space have to "wait" equally long before being reused. Some will be used again almost immediately, while others won't be reused for a long time (this will depend on which "block" in the list it ended in).

muru
  • 72,889