I'm currently working on a Rust program where I need to retrieve a file's path by its inode and volume serial number, similar to how the GetFileInfo
utility works in Xcode.
For example, in a macOS, after creating a file (hello.txt
) and then renaming it (mv hello.txt world.txt
), you can use GetFileInfo
to retrieve the new file path:
$ /usr/bin/GetFileInfo /.vol/16777229/25468225
file: "/Users/user/world.txt"
The file's inode and volume serial number can be retrieved from the output of the stat command:
$ stat hello.txt
16777229 25468225 -rw-r--r-- 1 user staff 0 6 "May 13 22:09:46 2024" "May 13 22:09:45 2024" "May 13 22:09:45 2024" "May 13 22:09:45 2024" 4096 8 0 hello.txt
I'd like to achieve similar functionality in Rust. Is there a Rust library or a combination of libraries that can help me achieve this? If not, what would be the best approach to implement this functionality in Rust?
Any help or guidance would be greatly appreciated. Thank you!
I found a solution and created a Rust crate that achieves cross-platform functionality. In short, on Windows, it uses GetFileByID
, and on macOS, it uses the .vol
directory and fcntl
with F_GETPATH
.
You can find the crate here: refind.