In my understanding a file, as I can see it in file explorer, is basically a hard link to the actual data. When I move this to another directory, the data is moved as well to that location. What happens with the actual data if I move a second hard link to a different directory? It is going to be saved in the location of which one of the two hard links?
1 Answers
Thinking about it, I think this is what happens:
The actual location doesn't matter as long as there are more than one hard-links to a file. The file might be moved as well when any hard-links is moved but since they're INodes, they will always point to the right internal location of the hard drive even if any of them is deleted.
EDIT: And actually they may not even be moved at all which is why the move operation is nearly instantaneous (within the same logical disk) as opposed to copying. And if we wanted to "prove" some concept which file was actually moved across different disks, it won't work because
- hard-links cannot reference across different logical or physical disks
- if we still tried copying one of the hard-links to a different drive (from C:
to D:) by selecting
cutandpastetomoveit (NOT copy it), the data will still have no other option than to actually be created at the target locationD:and the chosen moved hard-link deleted (fromC:). But the first hard-link is still present inC:, so the actual data in C: will remain, so we'd end up with two different separate copies.
So the exact location depends on factors like
- The filesystems (ext4, btrfs, NTFS...)
- fragmentation
- disk type
- physical corruption
- the programs which do the writing
- atc..
When we save a file in windows - is actual location of file on hard disk random or deterministic?
- 140