summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/udev/udev-extraconf/mount.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/udev/udev-extraconf/mount.sh')
-rw-r--r--meta/recipes-core/udev/udev-extraconf/mount.sh83
1 files changed, 66 insertions, 17 deletions
diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh
index d760328a09..067d4e2a16 100644
--- a/meta/recipes-core/udev/udev-extraconf/mount.sh
+++ b/meta/recipes-core/udev/udev-extraconf/mount.sh
@@ -4,10 +4,28 @@
4# 4#
5# Attempt to mount any added block devices and umount any removed devices 5# Attempt to mount any added block devices and umount any removed devices
6 6
7BASE_INIT="`readlink "@base_sbindir@/init"`"
8INIT_SYSTEMD="@systemd_unitdir@/systemd"
9
10if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then
11 # systemd as init uses systemd-mount to mount block devices
12 MOUNT="/usr/bin/systemd-mount"
13 UMOUNT="/usr/bin/systemd-umount"
14
15 if [ -x $MOUNT ] && [ -x $UMOUNT ];
16 then
17 logger "Using systemd-mount to finish mount"
18 else
19 logger "Linux init is using systemd, so please install systemd-mount to finish mount"
20 exit 1
21 fi
22else
23 MOUNT="/bin/mount"
24 UMOUNT="/bin/umount"
25fi
7 26
8MOUNT="/bin/mount"
9PMOUNT="/usr/bin/pmount" 27PMOUNT="/usr/bin/pmount"
10UMOUNT="/bin/umount" 28
11for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*` 29for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*`
12do 30do
13 if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ]; 31 if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];
@@ -17,7 +35,35 @@ do
17 fi 35 fi
18done 36done
19 37
20automount() { 38automount_systemd() {
39 name="`basename "$DEVNAME"`"
40
41 [ -d "/run/media/$name" ] || mkdir -p "/run/media/$name"
42
43 MOUNT="$MOUNT -o silent"
44
45 # If filesystemtype is vfat, change the ownership group to 'disk', and
46 # grant it with w/r/x permissions.
47 case $ID_FS_TYPE in
48 vfat|fat)
49 MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`"
50 ;;
51 # TODO
52 *)
53 ;;
54 esac
55
56 if ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name"
57 then
58 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"
59 rm_dir "/run/media/$name"
60 else
61 logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"
62 touch "/tmp/.automount-$name"
63 fi
64}
65
66automount() {
21 name="`basename "$DEVNAME"`" 67 name="`basename "$DEVNAME"`"
22 68
23 ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" 69 ! test -d "/run/media/$name" && mkdir -p "/run/media/$name"
@@ -26,7 +72,7 @@ automount() {
26 then 72 then
27 MOUNT="$MOUNT -o silent" 73 MOUNT="$MOUNT -o silent"
28 fi 74 fi
29 75
30 # If filesystem type is vfat, change the ownership group to 'disk', and 76 # If filesystem type is vfat, change the ownership group to 'disk', and
31 # grant it with w/r/x permissions. 77 # grant it with w/r/x permissions.
32 case $ID_FS_TYPE in 78 case $ID_FS_TYPE in
@@ -68,23 +114,26 @@ if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_t
68 elif [ -x $MOUNT ]; then 114 elif [ -x $MOUNT ]; then
69 $MOUNT $DEVNAME 2> /dev/null 115 $MOUNT $DEVNAME 2> /dev/null
70 fi 116 fi
71 117
72 # If the device isn't mounted at this point, it isn't 118 # If the device isn't mounted at this point, it isn't
73 # configured in fstab (note the root filesystem can show up as 119 # configured in fstab (note the root filesystem can show up as
74 # /dev/root in /proc/mounts, so check the device number too) 120 # /dev/root in /proc/mounts, so check the device number too)
75 if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then 121 if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then
76 grep -q "^$DEVNAME " /proc/mounts || automount 122 if [ "`basename $MOUNT`" = "systemd-mount" ];then
77 fi 123 grep -q "^$DEVNAME " /proc/mounts || automount_systemd
124 else
125 grep -q "^$DEVNAME " /proc/mounts || automount
126 fi
127 fi
78fi 128fi
79 129
80
81if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then 130if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
82 for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " ` 131 for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
83 do 132 do
84 $UMOUNT $mnt 133 $UMOUNT $mnt
85 done 134 done
86 135
87 # Remove empty directories from auto-mounter 136 # Remove empty directories from auto-mounter
88 name="`basename "$DEVNAME"`" 137 name="`basename "$DEVNAME"`"
89 test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name" 138 test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name"
90fi 139fi