I know of this command:
find /path/to/mountpoint -inum <inode number>
but it is a very slow search, I feel like there has to be a faster way to do this. Does anybody know a faster method?
For an ext4 filesystem, you can use
debugfs as in the following example:
$ sudo debugfs -R 'ncheck 393094' /dev/sda2 2>/dev/null Inode Pathname 393094 /home/enzotib/examples.desktop
The answer is not immediate, but seem to be better than
The output obtained can be easily parsed to obtain the filename.
inode-resolve [-v] <ino> <path> (needs root privileges) resolve paths to all files with given inode number ino in a given subvolume at path, ie. all hardlinks Options -v verbose mode, print count of returned paths and ioctl() return value
sudo btrfs inspect-internal inode-resolve 15380 /home
You could look at the fsdb command, found on most Unices, and available somewhere for Linux I am sure. This is a powerful command allowing you to to access the in-core inode structure of files, so be careful. The syntax is also very terse.
While fsdb won't actually let you discover the filename of the inode, it does allow you to directly access the inode when you specify it, in essence "porting" you to the file itself (or at least it's data block pointers) so it's quicker in that respect than the find ;-).
Your question doesn't specify what you want to do with the file. Are you perchance decoding NFS filehandles?
Somewhere in the machine, there is a list of all INODEs.
This problem is analogous to a phone book. It is a list of names, and the phone numbers might be used by more than one person. If you want to look up by number, to see who shares that number, it's going to take a long time to unless somebody creates a reverse-lookup phone book.
Better to create a reverser-lookup database, organized like the reverse-lookup phone book.
This problem can be solved with two scripts (I'm not much of a programmer... you'd probably laugh at that code I write).
SCRIPT1: Create the reverse-lookup table. Do a "find" on all files, and make a two column table of INODE,FILENAME. Sort and combine into an array, the FILENAMES which share the same INODE number.
(you could build a binary tree, and make access to your new list screaming fast).
SCRIPT2: Searches your new reverse-list, and pulls out the array of FILENAMES.
The only real drawback, is that you can't do this in real-time. INODES always change, and if you need up-to-the-minute information, you'll have to re-generate your table.