Skip to content

Commit

Permalink
Fix error opening volumes on USB drives on Android
Browse files Browse the repository at this point in the history
Android complains when you try to stat() /mnt/media_rw. So we avoid
doing that so we can access volumes on USB drives without errors.

Fixes hardcore-sushi/DroidFS#281
  • Loading branch information
intergalacticmonkey committed Apr 24, 2024
1 parent 6388eaf commit 4884654
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cryfs/impl/localstate/BasedirMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ void _save(const bf::path &metadataFilePath, const ptree& data) {
}

string jsonPathForBasedir(const bf::path &basedir) {
#ifdef __ANDROID__
// if basedir starts with /mnt/media_rw
if (basedir.string().rfind("/mnt/media_rw", 0) == 0) {
// Android returns permission denied when attempting to stat() /mnt/media_rw for some reason
// (even with "all files access") so checking if /mnt/media_rw is a symlink, as canonical()
// would, results in an error. Because we know /mnt/media_rw is not a symlink, and Android
// doesn't support removable storage filesystems that support symlinks, the canonical path
// for any path starting with /mnt/media_rw is equal to the absolute path after normalization
// (removal of "../" and "./" elements).
// See: https://github.com/hardcore-sushi/DroidFS/issues/281
return bf::absolute(basedir).lexically_normal().string() + ".filesystemId";
}
#endif
return bf::canonical(basedir).string() + ".filesystemId";
}

Expand Down

0 comments on commit 4884654

Please sign in to comment.