Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how are inode numbers generated in linux tmpfs?

It seems to me that tmpfs is not re-using inode numbers, but instead creates a new inode number via a +1 sequence everytime it needs a free inode.

Do you know how this is implemented / can you pin-point me to some source code where i could check the algorithm that is used in tmpfs ?

I need to understand this in order to bypass a limitation in a caching system that uses the inode number as its cache key (hence leading to rare, but occuring collisions when inodes are re-used too often). tmpfs could save my day if I can prove that it keeps creating unique inode numbers.

Thank you for your help,

Jerome Wagner

like image 796
Jerome WAGNER Avatar asked Dec 10 '10 17:12

Jerome WAGNER


People also ask

How are inode numbers generated?

inum or I-node number is an integer associated with a file. Whenever a new file is created, a unique integer number is generated in sequence and associated with the file. This number is nothing but the pointer to the inode structure which contains the meta data of the file.

How does Linux count inode?

To get the number of inodes of files in a directory, for example, the root directory, open a terminal window and run the following ls command, where the -l option means long listing format, -a means all files and -i mean to print the index number of each file.

How are inodes assigned?

As mentioned earlier, when you create a file system in UNIX, about 1 percent of the total disk space is allocated to the inode table. Every time you create a file in the file system, an inode is allocated to the file.

Why do inode numbers start from 1?

badblocks is actually present in the root directory as a regular file owned by root and mode 0. root can open it but reading or writing it is undefined. There is some ancient tradition that inodes start from 1, #1 is . badblocks , and #2 is the root directory.


1 Answers

I won't directly answer your question, so I apologize in advance for that.

The tmpfs idea is good, but I wouldn't have my program depend on a more or less obscure implementation detail for generating keys. Why don't you try another method, such as combining the inode number with some other information? Maybe modification date: it's impossible two files get the same inode number AND modification date at the time of key-generation, unless system date changes.

Cheers!

like image 131
slezica Avatar answered Nov 13 '22 18:11

slezica