I'm converting files from an old application on OS X. For reasons that must have been good at the time, it records associated files in its database by their inode numbers. (I think Apple calls it a FileID.)
Given a file name, I can find the inode in Python using os.stat(). But is there a Python way to find the name given an inode number?
Failing that, I can think of two other ways:
Scan all the files in the folder to collect all their inode numbers, and save them in a dictionary for quick reference.
Use os.system('find /folder/folder -inum 1234') and parse the output for what I am after. I suppose this does the same thing as above really, but done by the operating system.
I would prefer a Python native solution, but would be grateful for any other suggestions.
This will be Python2 on OS X 10.5 or 6.
It looks like you'll have to bruteforce it. Filenames point to inodes. The inodes themselves don't contain a reference to the filename. Also you can have multiple hard links (locations in the file system, or file names) pointing to the same inode.
You can see the elements of an inode struct on this page. Filename isn't there.
There is the volfs
on OSX, but this might be actually slower than your 1. approach.
Hence, I'd use your 1. approach but with considering some important bits:
inode
can point to multiple files
(hardlinks).Your 2. approach is basically the same as the first one, except with additional forking overhead and more importantly basically running the same costly enumeration again and again, instead of populating a map once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With