Tuesday, February 12, 2019

Why can I not assign exec permissions to a file on the SD card?


shell@android:/sdcard/SW # ls -l
-rw-rw-r-- root sdcard_rw 128 2012-09-22 11:42 usb0config.sh

shell@android:/sdcard/SW # chmod 777 usb0config.sh
shell@android:/sdcard/SW # ls -l
-rw-rw-r-- root sdcard_rw 128 2012-09-22 11:42 usb0config.sh
shell@android:/sdcard/SW #

Why can I not assign exec permissions to a file on the SD card?


$ adb shell su -c mount |grep -si sdcard
/dev/block/vold/179:97 /mnt/ext_sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /mnt/ext_sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/fuse /mnt/sdcard fuse rw,nosuid,nodev,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0



$ adb shell su -c "mount -t vfat -o umask=0000 /dev/fuse /mnt/sdcard"
mount: Block device required

Now it seems remount successfully.


$ adb shell su -c "mount -t vfat -o remount,umask=0000 /dev/fuse /mnt/sdcard"

but the file yet cannot be assigned 777 mode.


shell@android:/sdcard/Sw # ls -l

-rw-rw-r-- root sdcard_rw 128 2012-09-22 11:42 usb0config.sh
shell@android:/sdcard/Sw # chmod 777 usb0config.sh
shell@android:/sdcard/Sw # ls -l
-rw-rw-r-- root sdcard_rw 128 2012-09-22 11:42 usb0config.sh

The mount info doesn't change comparing to before remount's.


$ adb shell su -c mount |grep -si sdcard
/dev/block/vold/179:97 /mnt/ext_sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0002,dmask=0002,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /mnt/ext_sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/fuse /mnt/sdcard fuse rw,relatime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0


Answer



Unless you've done something unusual with your device, the SD card will be formatted as a FAT file system, which does not support *nix file permissions. This Linux FAQ entry from one of MIT's professors explains it a bit, and also explains how you can potentially use mount options to change the permission mode of the device (this would require root, though, and affect all files/folders on the device). Also, the SD card in Android is mounted by default with the -noexec flag.


For the exec bit you'd probably want to remount with a umask of 0000, since the umask is essentially a binary NOT of the permissions you want (so umask 0000 says don't mask out any permissions, allow them all). Untested, but doing it temporarily would be something along the lines of:


mount -t vfat -o umask=0000 /dev/your/sdcard/device /mnt/sdcard

The mount point may need to be changed from /mnt/sdcard to something slightly different depending on your device. Again, though, I believe mount requires that you have root permissions for this.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...