I observe behavior such as this on my Mac:
- Open a PDF with PDF Expert, make some changes to the file, move the file in Finder, save it in PDF Expert and it'll be correctly saved to the new place.
- Open a shell in a directory like
~/foo
, trash the directory with another app and the shell's pwd correctly outputs~/.Trash/foo
.
What's happening under the hood? These cases seem to indicate apps don't just hold an absolute path of the file like emacs (am I right with this?), or is it a totally differently mechanism?
Best Answer
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 thismagic
.ls -di <file>
to get inode number.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.