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.sh107
1 files changed, 84 insertions, 23 deletions
diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh
index b23731870e..c19e2aa68a 100644
--- a/meta/recipes-core/udev/udev-extraconf/mount.sh
+++ b/meta/recipes-core/udev/udev-extraconf/mount.sh
@@ -6,6 +6,7 @@
6 6
7BASE_INIT="`readlink -f "@base_sbindir@/init"`" 7BASE_INIT="`readlink -f "@base_sbindir@/init"`"
8INIT_SYSTEMD="@systemd_unitdir@/systemd" 8INIT_SYSTEMD="@systemd_unitdir@/systemd"
9MOUNT_BASE="@MOUNT_BASE@"
9 10
10if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then 11if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then
11 # systemd as init uses systemd-mount to mount block devices 12 # systemd as init uses systemd-mount to mount block devices
@@ -26,24 +27,44 @@ fi
26 27
27PMOUNT="/usr/bin/pmount" 28PMOUNT="/usr/bin/pmount"
28 29
29for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*` 30for line in `grep -h -v ^# /etc/udev/mount.ignorelist /etc/udev/mount.ignorelist.d/*`
30do 31do
31 if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ]; 32 if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];
32 then 33 then
33 logger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring" 34 logger "udev/mount.sh" "[$DEVNAME] is marked to ignore"
34 exit 0 35 exit 0
35 fi 36 fi
36done 37done
37 38
39is_filesystem_supported() {
40 while read -r fs; do
41 if [ "${fs#nodev}" = "$1" ];
42 then
43 return 0
44 fi
45 done < "/proc/filesystems"
46 return 1
47}
48
38automount_systemd() { 49automount_systemd() {
39 name="`basename "$DEVNAME"`" 50 name="`basename "$DEVNAME"`"
40 51
41 # Skip already mounted partitions 52 # Skip already mounted partitions
42 if [ -f /run/systemd/transient/run-media-$name.mount ]; then 53 if [ -f /run/systemd/transient/$(echo $MOUNT_BASE | cut -d '/' -f 2- | sed 's#/#-#g')-*$name.mount ]; then
43 logger "mount.sh/automount" "/run/media/$name already mounted" 54 logger "mount.sh/automount" "$MOUNT_BASE/$name already mounted"
44 return 55 return
45 fi 56 fi
46 57
58 # Get the unique name for mount point
59 get_label_name "${DEVNAME}"
60
61 # Only go for auto-mounting when the device has been cleaned up in remove
62 # or has not been identified yet
63 if [ -e "/tmp/.automount-$name" ]; then
64 logger "mount.sh/automount" "[$MOUNT_BASE/$name] is already cached"
65 return
66 fi
67
47 # Skip the partition which are already in /etc/fstab 68 # Skip the partition which are already in /etc/fstab
48 grep "^[[:space:]]*$DEVNAME" /etc/fstab && return 69 grep "^[[:space:]]*$DEVNAME" /etc/fstab && return
49 for n in LABEL PARTLABEL UUID PARTUUID; do 70 for n in LABEL PARTLABEL UUID PARTUUID; do
@@ -53,7 +74,12 @@ automount_systemd() {
53 grep "^[[:space:]]*$tmp" /etc/fstab && return 74 grep "^[[:space:]]*$tmp" /etc/fstab && return
54 done 75 done
55 76
56 [ -d "/run/media/$name" ] || mkdir -p "/run/media/$name" 77 if ! is_filesystem_supported $ID_FS_TYPE; then
78 logger "mount.sh/automount" "Filesystem '$ID_FS_TYPE' on '${DEVNAME}' is unsupported"
79 return
80 fi
81
82 [ -d "$MOUNT_BASE/$name" ] || mkdir -p "$MOUNT_BASE/$name"
57 83
58 MOUNT="$MOUNT -o silent" 84 MOUNT="$MOUNT -o silent"
59 85
@@ -65,18 +91,20 @@ automount_systemd() {
65 ;; 91 ;;
66 swap) 92 swap)
67 return ;; 93 return ;;
94 lvm*|LVM*)
95 return ;;
68 # TODO 96 # TODO
69 *) 97 *)
70 ;; 98 ;;
71 esac 99 esac
72 100
73 if ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name" 101 if ! $MOUNT --no-block -t auto $DEVNAME "$MOUNT_BASE/$name"
74 then 102 then
75 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!" 103 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"$MOUNT_BASE/$name\" failed!"
76 rm_dir "/run/media/$name" 104 rm_dir "$MOUNT_BASE/$name"
77 else 105 else
78 logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful" 106 logger "mount.sh/automount" "Auto-mount of [$MOUNT_BASE/$name] successful"
79 touch "/tmp/.automount-$name" 107 echo "$name" > "/tmp/.automount-$name"
80 fi 108 fi
81} 109}
82 110
@@ -93,7 +121,17 @@ automount() {
93 # configured in fstab 121 # configured in fstab
94 grep -q "^$DEVNAME " /proc/mounts && return 122 grep -q "^$DEVNAME " /proc/mounts && return
95 123
96 ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" 124 # Get the unique name for mount point
125 get_label_name "${DEVNAME}"
126
127 # Only go for auto-mounting when the device has been cleaned up in remove
128 # or has not been identified yet
129 if [ -e "/tmp/.automount-$name" ]; then
130 logger "mount.sh/automount" "[$MOUNT_BASE/$name] is already cached"
131 return
132 fi
133
134 ! test -d "$MOUNT_BASE/$name" && mkdir -p "$MOUNT_BASE/$name"
97 # Silent util-linux's version of mounting auto 135 # Silent util-linux's version of mounting auto
98 if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ; 136 if [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ;
99 then 137 then
@@ -108,18 +146,23 @@ automount() {
108 ;; 146 ;;
109 swap) 147 swap)
110 return ;; 148 return ;;
149 lvm*|LVM*)
150 return ;;
111 # TODO 151 # TODO
112 *) 152 *)
113 ;; 153 ;;
114 esac 154 esac
115 155
116 if ! $MOUNT -t auto $DEVNAME "/run/media/$name" 156 if ! $MOUNT -t auto $DEVNAME "$MOUNT_BASE/$name"
117 then 157 then
118 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!" 158 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"$MOUNT_BASE/$name\" failed!"
119 rm_dir "/run/media/$name" 159 rm_dir "$MOUNT_BASE/$name"
120 else 160 else
121 logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful" 161 logger "mount.sh/automount" "Auto-mount of [$MOUNT_BASE/$name] successful"
122 touch "/tmp/.automount-$name" 162 # The actual device might not be present in the remove event so blkid cannot
163 # be used to calculate what name was generated here. Simply save the mount
164 # name in our tmp file.
165 echo "$name" > "/tmp/.automount-$name"
123 fi 166 fi
124} 167}
125 168
@@ -133,6 +176,18 @@ rm_dir() {
133 fi 176 fi
134} 177}
135 178
179get_label_name() {
180 # Get the LABEL or PARTLABEL
181 LABEL=`/sbin/blkid | grep "$1:" | grep -o 'LABEL=".*"' | cut -d '"' -f2`
182 # If the $DEVNAME has a LABEL or a PARTLABEL
183 if [ -n "$LABEL" ]; then
184 # Set the mount location dir name to LABEL appended
185 # with $name e.g. label-sda. That would avoid overlapping
186 # mounts in case two devices have same LABEL
187 name="${LABEL}-${name}"
188 fi
189}
190
136# No ID_FS_TYPE for cdrom device, yet it should be mounted 191# No ID_FS_TYPE for cdrom device, yet it should be mounted
137name="`basename "$DEVNAME"`" 192name="`basename "$DEVNAME"`"
138[ -e /sys/block/$name/device/media ] && media_type=`cat /sys/block/$name/device/media` 193[ -e /sys/block/$name/device/media ] && media_type=`cat /sys/block/$name/device/media`
@@ -150,12 +205,18 @@ if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_t
150fi 205fi
151 206
152if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then 207if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
153 for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
154 do
155 $UMOUNT $mnt
156 done
157
158 # Remove empty directories from auto-mounter
159 name="`basename "$DEVNAME"`" 208 name="`basename "$DEVNAME"`"
160 test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name" 209 tmpfile=`find /tmp | grep "\.automount-.*${name}$"`
210 if [ ! -e "/sys/$DEVPATH" -a -e "$tmpfile" ]; then
211 logger "mount.sh/remove" "cleaning up $DEVNAME, was mounted by the auto-mounter"
212 for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
213 do
214 $UMOUNT "`printf $mnt`"
215 done
216 # Remove mount directory created by the auto-mounter
217 # and clean up our tmp cache file
218 mntdir=`cat "$tmpfile"`
219 rm_dir "$MOUNT_BASE/$mntdir"
220 rm "$tmpfile"
221 fi
161fi 222fi