Uses for file version/generation number?

Jerry Peek
2008-04-23
2012-11-28
  • Jerry Peek
    Jerry Peek
    2008-04-23

    I write the monthly Power Tools column for Linux Magazine (the US version).  I've just written the rough draft of a column about file attributes, chattr(1) and lsattr(1).

    Though I've used attributes for years, I've never used "chattr -v" to set a file version/generation number or "lsattr -v" to list it.  I haven't been able to find any examples, either.  I'd guess that it's useful for maintaining some state information about a file -- such as its version number ;-) -- outside of a revision-control system like Subversion or RCS.  I'm also guessing that users can change a file's version number whenever they want to without causing any filesystem problems.  True?

    If you have any other info or examples, I'd appreciate it -- and so would people who read the column!  (By the way, it should be online at http://www.linux-mag.com/ a few months after print publication.)

    Thanks,
    Jerry

     
    • The "version" in question is the inode generation.  This is normally not intended to be on par with revision control.  Inode generation is changed whenever inode changes state from "free" to "allocated".  In other words, whenever an inode is reused.  I suspect the only kind of software that cares about inode generation is backup/restore software.  What a normal user perceives as a "file" is really 2 parts:  a directory entry, and an inode.  Directory entry (dentry) is a tuple of {name, inode number} and that's what gives the file its name.  Furthermore, a dentry exists in some specific directory, which gives the file its full path.  The actual data block pointers and attributes are stored in the inode itself.  Renaming the file only changes the dentry, not the inode.  So onward to backup/restore example:  imagine you back up a file on Monday.  On Tuesday you rename it.  On Wednesday you modify it.  On Thursday you realize that your modifications were a bad idea, so you'd like to restore it from tape.  The difficulty is that on tape it has the old name, so if name is the only thing your backup software keeps track of, then you are out of luck.  Granted, if you remembered the old name then no problem, but hopefully you can see the peril in a name-only scheme.  But if your backup s/w is more intelligent, then it keeps track of inode number as well, so it would be possible to automatically detect that you really do have a backup of the file on tape based on matching inode numbers, even though the name has changed.  But imagine what happens if the file was deleted since backup:  the inode would be freed, and could potentially be reallocated to some newly created file.  Now you've got a problem:  does the inode on tape really represent an older copy of the same-numbered inode in your live filesystem?  To answer this question each inode has a generation.  So if backup s/w records inode number + generation on tape, then it can easily resolve this ambiguity.

      Whew.  That was a bit long-winded and a little over-simplified, but hopefully conveys the purpose of inode generation.  The only useful case I see for explicitly setting it is again with restore:  if your disk drive failed, and you wanted to format a new drive and recreate an ext3 filesystem to match verbatim what is on your last backup tape, then you need the ability to set inode generation.

      Regards, Vitaly

       
    • Jerry Peek
      Jerry Peek
      2008-04-24

      Thanks very much, Vitaly!  I don't remember where I got my ideas, but they were obviously wrong.  The tie-in to ext3 makes sense, too... I understand about directory entries and inodes, but you make it clear why generation is important.

      It's good that you've written such a detailed explanation here.  If anyone else has anything to add, it would be great to have it "on the record" here in this forum.  Since I didn't find any documentation for this SourceForge project (http://sourceforge.net/docman/?group_id=2406, I think it is?), the info here will help other people too.

      Thanks again,
      Jerry

       
      • Glad to help.

         
    • Jerry Peek
      Jerry Peek
      2008-05-10

      For the record, here are a few other pages I've found that discuss the version/generation number.  FYI, I haven't checked any of them for accuracy...

      - The section ``"Advanced" Ext2fs features'' of http://e2fsprogs.sourceforge.net/ext2intro.html#section:ext2fs

      - The section ``History'' of http://www.win.tue.nl/~aeb/linux/lk/lk-7.html#ss7.2

      - The first comment, http://lwn.net/Articles/266368/, in the article http://lwn.net/Articles/266274/

      - The discussion at http://osdir.com/ml/linux.file-systems/2002-11/msg00044.html

      Jerry