Filesystem links on a FAT32 formatted storage

2020-05-24 21:13发布

问题:

I know FAT32, as well as FAT16/12 neither support symbolic links nor hard-links. However I came up with this idea:

The FAT specification describes that every file is associated with a directory-entry. In my understanding, one could say that a file-entry in a directory somehow or other points to the file's content.

So, how can I define two directory-entries which point to the same file-content? Or, what could prevent me from doing so?

Use case: I have a USB mass storage device for my car radio, and I want to use directories as playlists since the radio software doesn't support playlists. So it isn't important to me how Windows behaves when doing this.

回答1:

What you are talking about ("two directory-entries which are pointing to the same file-content") are hard links. chkdsk will report them as cross-links and break them, "repairing" the files (in fact making the copies).



回答2:

This should work for simple issues. I.e. it works as a hack / workaround and I don't know what happens if you rename / move / remove files. So, you should not do this on your main hdd.

I edited the directory-entries manually using a hex editor. I modified clusters as well as file-sizes and successfully faked hardlinks. My car-radio and even Windows (7, 64Bit) have no problems with playing back the original and "hard-linked" mp3-Files I used.

When I'm opening the device again in the hex-editor none of my modifications are changed back (See chkdsk issue in answer #1 - but as far as I know chkdsk has to be started manually, anyways.



回答3:

MichaelPh posted instructions on SuperUser:

https://superuser.com/a/486829/51237

It's possible to use Disk Probe (on XP only, I've yet to get it to write the changes on Win7) to modify the cluster a FAT Directory references. This method can be used to redirect the DCIM folder (or a subfolder) to point to the folder used by a different scan device.

Whether this is a good idea or not is a different matter and you use this at your own risk.

  1. Insert the Eye-Fi card either in it's USB Card Reader or directly into an SSD slot and note the drive letter it's installed as (assumed to be F:\ for simplicity)
  2. Ensure all Windows Explorer windows for the card and sub-directories are closed.
  3. Run Disk Probe
  4. Select Drives->Logical Volume
  5. In the Open Logical Volume dialog double-click F:\ in the Logical Volumes list
  6. Click the Set Active button for the Handle F: has been selected as. You can leave the handle as read-only for now.
  7. Select Tools->Search Sectors...
  8. Check Exhaustive Search, enter DCIM in Enter characters to search for and Search
  9. You should find a match (mine is at 8192). Select No on the "Found match..." dialog to cancel the rest of the search.
  10. Select Sectors->Read and increase Number of Sectors to at least two so that the whole directory table is included.
  11. Find DCIM in the ASCII on the right of the Disk Probe screen, this is the start of the FAT entry for the directory. Make a note of the hex value of the 27th byte of the record (each entry is 32bytes), this is the directory cluster reference. This value is require to revert the DCIM directory back to normal use if required.
  12. Find the entry for the directory you want to redirect DCIM to and again make a note of the 27th byte in the record.
  13. Go back to the 27th byte of the DCIM record and change it to the value noted in step 11.
  14. Select Sectors->Write and then click Write it on the Write Sector dialog. A warning will come up if you opened the sectors as read-only. Yes to overwrite if you're happy to make the change.

Opening the DCIM directory in Windows Explorer will now show the contents of the target directory.