[OE-core] [PATCH 3/3] udev-extraconf:fix rootless X write to usb storage failed

Hongxu Jia hongxu.jia at windriver.com
Mon Apr 15 06:22:32 UTC 2013


Rootless X is owned by xuser, the problem is xuser doesn't have permissions to
write usb storage when the type of filesystem is not one of ext2/3/4 and btrfs.
...
mount
/dev/sdb1 on /media/sdb1 type ext4
/dev/sdb2 on /media/sdb2 type vfat
/dev/sdb3 on /media/sdb3 type ntfs
/dev/sdb4 on /media/sdb4 type btrfs
/dev/sdb2 on /media/sdb5 type jfs
/dev/sdb1 on /media/sdb6 type xfs
...
ls /media/ -al
drwx------    3 xuser    xuser         1024 Apr 10 09:08 sdb1
drwxr-xr-x    2 root     root         16384 Jan  1  1970 sdb2
drwx------    1 root     root          4096 Apr 10 09:12 sdb3
drwx------    1 xuser    xuser            0 Apr 10 09:14 sdb4
drwxr-xr-x    2 root     root             6 Apr 10 09:39 sdb5
drwxr-xr-x    2 root     root           256 Apr 10 09:39 sdb6
...

The usb storage is mounted to dir `/media/sd**' by a udev's mount.sh script,
Modify the script to change the group owner of dir to `disk', and grant w/r/x
permissions to it, so the one (such as xuser) in the disk group could access
the storage.

There are two solutions to do according to the type of USB's filesystem.
1, For vfat, fat, ntfs, add mount option `gid' and `umask'.
2, For others, invoke chgrp and chmod after mount.

[YOCTO #4004]

Signed-off-by: Hongxu Jia <hongxu.jia at windriver.com>
---
 meta/recipes-core/udev/udev-extraconf/mount.sh |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh
index 97af608..fbec5b4 100644
--- a/meta/recipes-core/udev/udev-extraconf/mount.sh
+++ b/meta/recipes-core/udev/udev-extraconf/mount.sh
@@ -27,11 +27,30 @@ automount() {
 		MOUNT="$MOUNT -o silent"
 	fi
 	
+	local invoke_chown=""
+	# According to the type of filesystem, there are two solutions to change
+	# the group owner of storage to `disk' and grant w/r/x permissions.
+	case $ID_FS_TYPE in
+	vfat|fat|ntfs)
+		# By mount.
+		MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`"
+		;;
+	# Such as btrfs, minix, xfs, jfs, ext2, ext3, ext4, nilfs2.
+	*)
+		# By invoking chgrp and chmod after mount.
+		invoke_chgrp="1"
+		;;
+	esac
+
 	if ! $MOUNT -t auto $DEVNAME "/media/$name"
 	then
 		#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/media/$name\" failed!"
 		rm_dir "/media/$name"
 	else
+		if [ "$invoke_chgrp" = "1" ]; then
+			chgrp "disk" "/media/$name"
+			chmod g+wrx "/media/$name"
+		fi
 		logger "mount.sh/automount" "Auto-mount of [/media/$name] successful"
 		touch "/tmp/.automount-$name"
 	fi
-- 
1.7.10.4





More information about the Openembedded-core mailing list