3

I have a rooted OnePlus One running LineageOS 15.1 (Oreo 8.1). I am trying to adjust some file permissions/ownerships on the emulated sdcard partition.
The partition seems to be mounted as an sdcardfs:

A0001:/ # mount | grep /storage/emulated                                                                                                                                                           
/data/media on /storage/emulated type sdcardfs (rw,nosuid,nodev,noexec,noatime,fsuid=1023,fsgid=1023,gid=1015,multiuser,mask=6,derive_gid)

I'm not sure what that means. Some people suggest that Android used to use mount then switched to fuse and now with Oero uses sdcardfs. I'm not sure if that makes any sense, but I'm a bit scared that something like mount -o remount, rw /mnt/sdcard/ (which apparently is what you had to do in the past to be able to set file permissions on the emulated sdcard partition).

Short demonstration showing that file permissions won't be applied:

A0001:/ $ su
A0001:/ # ls -la /storage/emulated                                                                                                                                                                 
total 12
drwx--x--x  4 root sdcard_rw 4096 2018-07-24 17:44 .
drwxr-xr-x  4 root root        80 2018-07-24 17:21 ..
drwxrwx--x 14 root sdcard_rw 4096 2018-07-24 17:20 0
drwxrwx--x  2 root sdcard_rw 4096 1970-01-01 01:12 obb
A0001:/ # touch /storage/emulated/a
A0001:/ # ls -la /storage/emulated/a
-rw------- 1 root sdcard_rw 0 2018-07-24 17:44 /storage/emulated/a
A0001:/ # chmod 777 /storage/emulated/a
A0001:/ # ls -la /storage/emulated/a                                                                                                                                                               
-rw------- 1 root sdcard_rw 0 2018-07-24 17:44 /storage/emulated/a

(Note: the same happens if I use /storage/emulated/0 instead of /storage/emulated)

My question is: What do I have to run in order to be able to change the file permissions and file ownerships on this weird sdcardfs partition.

2

You cannot change permissions and ownerships of files on sdcardfs.

On all operating systems based on Linux kernel - like Android is - it's possible to set permissions on files (including directories) provided that filesystem supports UNIX permissions (uid, gid, mode). Common examples of such filesystems are ext4 and f2fs.

However Android's internal (confusingly called external) storage which is accessible by installed apps at /sdcard, is not an actual but virtual / emulated filesystem exposing /data/media (which is a real filesystem) through sdcardfs. sdcardfs and its predecessor FUSE expose the emulated filesystem with a fixed set of uid, gid and mask (mode). So the commands chmod and chown have no impact, whether executed through CLI (adb shell or terminal emulator) or GUI (file explorer).

It's possible to change permission bits of file on underlying actual filesystem, but accessing /data/media requires root access because only UID/GID 1023 (aid_media_rw) has read access to the directory. And still the permissions will remain same when viewed from emulated view /sdcard.

Further reading:

Related:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.