Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the data structure of the Inode number like?

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?

like image 803
Léo Léopold Hertz 준영 Avatar asked Dec 22 '22 11:12

Léo Léopold Hertz 준영


1 Answers

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...)

like image 110
bdonlan Avatar answered Jan 17 '23 05:01

bdonlan