How are Mac apps able to track a file's location?
macos has a special /.vol/
system mapped to the actual directory and files. The files and directories are accessible via /.vol/<device_id>/<inode_number>
, regardless of where the files are on the file system.
It is a nice little system.
So, programs can for example get the inode number of /Users/jdoe/someFile.txt
and then open it via /.vol/12345/6789
(in this case, device id is 12345 and inode number 6789). You then move /Users/jdoe/someFile.txt
anywhere you want (on the same volume) and everything just works. You can even write a shell script that supports this magic
.
ls -di <file>
to get inode number.
$ ls -di /User/jdoe/someFile.txt
6789 /User/jdoe/someFile.txt
EDIT:
You use stat
to get the id of the volume and inode number, according to linked answer as highlighted by IMSoP.
GetFileInfo /.vol/12345/6789
would return the current location of the file previously located in /Users/jdoe/someFile.txt
.
See https://stackoverflow.com/questions/11951328/is-there-any-function-to-retrieve-the-path-associated-with-an-inode for more information.