summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/udev/files/mount.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/udev/files/mount.sh')
-rw-r--r--meta/recipes-core/udev/files/mount.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/meta/recipes-core/udev/files/mount.sh b/meta/recipes-core/udev/files/mount.sh
new file mode 100644
index 0000000000..53fefa3681
--- /dev/null
+++ b/meta/recipes-core/udev/files/mount.sh
@@ -0,0 +1,68 @@
1#!/bin/sh
2#
3# Called from udev
4#
5# Attempt to mount any added block devices and umount any removed devices
6
7
8MOUNT="/bin/mount"
9PMOUNT="/usr/bin/pmount"
10UMOUNT="/bin/umount"
11
12for line in `cat /etc/udev/mount.blacklist`
13do
14 if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];
15 then
16 logger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring"
17 exit 0
18 fi
19done
20
21automount() {
22 name="`basename "$DEVNAME"`"
23
24 ! test -d "/media/$name" && mkdir -p "/media/$name"
25
26 if ! $MOUNT -t auto -o sync $DEVNAME "/media/$name"
27 then
28 #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/media/$name\" failed!"
29 rm_dir "/media/$name"
30 else
31 logger "mount.sh/automount" "Auto-mount of [/media/$name] successful"
32 touch "/tmp/.automount-$name"
33 fi
34}
35
36rm_dir() {
37 # We do not want to rm -r populated directories
38 if test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1"
39 then
40 ! test -z "$1" && rm -r "$1"
41 else
42 logger "mount.sh/automount" "Not removing non-empty directory [$1]"
43 fi
44}
45
46if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ]; then
47 if [ -x "$PMOUNT" ]; then
48 $PMOUNT $DEVNAME 2> /dev/null
49 elif [ -x $MOUNT ]; then
50 $MOUNT $DEVNAME 2> /dev/null
51 fi
52
53 # If the device isn't mounted at this point, it isn't configured in fstab
54 grep -q "^$DEVNAME " /proc/mounts || automount
55fi
56
57
58
59if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
60 for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
61 do
62 $UMOUNT $mnt
63 done
64
65 # Remove empty directories from auto-mounter
66 name="`basename "$DEVNAME"`"
67 test -e "/tmp/.automount-$name" && rm_dir "/media/$name"
68fi