Android filesystem and inodes
-
30-06-2021 - |
Pergunta
I have recently learned about Unix inodes and their purpose. In particular, I learned that an.inode is unique across a filesystem.
My question is: if a user inserts a Micro SD card into their Android device, does that card become part of the existing filesystem or does it become a separate filesystem?
or, to put it another way: can inodes be duplicated across the internal and external storages?
Many thanks, P
Solução
Micro SD cards usually use FAT32, a file system which store no inodes. The Linux kernel is creating a random inode number that is different from other ones when a new file is accessed.
On a FAT32 file system, a pathname is enough to uniquely identify a file, unlike with other file systems where a file can have any number of pathnames including none at all.
These FAT32 fake inode numbers are dropped:
- when the file system is unmounted
- when the OS reboots
- when the fixed size cache where they are stored is full
Should you want a reliable way to identify files on FAT32, don't use their inodes.
I would suggest to use a hash of their pathname, combined with their size if you want to be really sure to avoid collision.
Outras dicas
It's a separate filesystem. So yes, a file on the internal storage can have the same inode number as a file on the external storage, even though they are distinct files.
In case your real question is how to uniquely identify a file, you need both the inode number and the device id number. Both can be retrieved with the *stat() family syscalls, specifically the st_dev and st_ino fields of the stat struct.