views:

491

answers:

2

I am flabbergasted by the definition of the inode number:

An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An inode stores basic information about a regular file, directory, or other file system object. Source

So there must be a logical order in every inode number. Can you conclude something directly from the numbers in the front?

4214970 0 drwx------  102 user  staff   3.4K Feb  2 22:34 new
5728909 0 drwx------    3 user  staff   102B Mar 25 22:11 new_new
5415906 0 drwx------   15 user  staff   510B Mar 19 02:28 stdout_TEST

If not, what kind of things you can know thanks to the data structure?

+5  A: 

An inode number is not an inode. :) You can think of the inode number as the inode's primary key.

As for how the inode numbers are decided, it depends on the filesystem. Some filesystems might even make inode numbers out of thin air (particularly some FUSE filesystems). Other times it may map directly to the location on disk. The unfortunate fact is, it's a somewhat outdated concept, and many modern filesystems have difficulty compacting their internal location information into a 32-bit number these days.

In any case, as an application programmer, one should treat the inode number as an opaque value, suitable for equality comparison only (and only if you're sure the file wasn't deleted, as inode numbers may be reused...)

bdonlan
Do you refer to "inodes in virtual memory" by the phrase "inode numbers out of thin air"?
Masi
I mean the inode number itself. With some filesystems there's no reasonable way of creating an inode number - for example, a FUSE filesystem built on top of FTP to a windows server. These filesystems really do need to make the inode _numbers_ up - _hopefully_ keeping them unique - because they don't have the necessary information to make them unique. Likewise, a virtual filesystem with (potentially) over 2^32 inodes will have trouble assigning unique inode numbers
bdonlan
+2  A: 

Can you conclude something directly from the numbers in the front?

Not necessarily. Inodes are recycled.

If not, what kind of things you can know thanks to the data structure?

Check the header file containing the definition of the struct appropriate to the specific filesystem (e.g. /usr/include/linux/ext2_fs.h for ext2 and ext3).

mlp
+1 for the path
Masi