0

Development environment: mobile app in Android

I'm looking for a way to uniquely identify files in a FAT32/VFAT file system (which has no inodes). I thought about hashing (SHA1?) the full path. The problem with this solution is that it doesn't support moving/renaming.

Is there something better, that will hold even when moving/renaming the file?

Thanks

HyBRiD
  • 688
  • 4
  • 23
  • Hashing the file name will not be unique - you could have more than one `README.TXT`... Similarly, hashing the contents of the file might run into collisions if two files have the same content (but I'm not sure how "unique" you need to be - perhaps that would be acceptable), but it would be fine for moving/renaming a file. You could use the starting block number of the file, but that will change the ID if the file is moved/copied. That would be the closest you could get to an i-node number (which would also change on move/rename). – twalberg Aug 28 '14 at 16:32
  • @twalberg I meant hashing the full-path filename, not just the filename itself. What do you mean by "starting block number"? Is it guranteed that there can't be 2 files in the same block? How do I get that information in C/C++ or POSIX? – HyBRiD Aug 31 '14 at 12:24

1 Answers1

0

Unfortunately FAT doesn't have Unique file IDs and when they are needed, various system components emulate them by maintaining the list of all files of the filesystem in memory (thus the ID is unique and valid only when the system is running).

Depending on what you control (either you have a filesystem driver, a filter or just a user-mode application) potentially you can do the same - have a list of files and provide some unique ID based on that list.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • yes it's a user-mode application, but I need the IDs to persist between sessions. Listing the files-to-IDs mapping in memory does not solve the persistence problem. – HyBRiD Aug 31 '14 at 10:47
  • @HyBRiD persistence is another topic. If the file is moved using copy/delete operation, will it be the same file? If the file is ZIPed and then unziped in another folder, is it the same file? – Eugene Mayevski 'Callback Aug 31 '14 at 12:08
  • copy/delete and zip/unzip creates a new file on disk, but move/rename is the same file and so it should keep the previous file ID. – HyBRiD Aug 31 '14 at 12:19
  • @HyBRiD Depends on the task, really. in DLP solutions copy/delete and zip/unzip maintain the protected information and as such the result must be considered the same file. – Eugene Mayevski 'Callback Aug 31 '14 at 12:59
  • I see. Still the problem with this approach is that once the application is not running anymore, and some changes happen in the file system, the list becomes outdated. – HyBRiD Aug 31 '14 at 13:51
  • @HyBRiD One option is to employ some kind of virtual filesystem, where you can track the files and control them, but applicability of this option depends on the task. – Eugene Mayevski 'Callback Aug 31 '14 at 13:54