| 1 | #!/bin/sh |
| 2 | # Copyright (C) 2009-2010 OpenWrt.org |
| 3 | # Copyright (C) 2010 Vertical Communications |
| 4 | # This is free software, licensed under the GNU General Public License v2. |
| 5 | # See /LICENSE for more information. |
| 6 | # |
| 7 | |
| 8 | . /lib/functions/block.sh |
| 9 | |
| 10 | blkdev=`dirname $DEVPATH` |
| 11 | if [ `basename $blkdev` != "block" ]; then |
| 12 | |
| 13 | device=`basename $DEVPATH` |
| 14 | |
| 15 | case "$ACTION" in |
| 16 | add) |
| 17 | |
| 18 | local from_fstab |
| 19 | local anon_mount |
| 20 | local anon_swap |
| 21 | local anon_fsck |
| 22 | local mds_mount_target |
| 23 | local mds_mount_device |
| 24 | local mds_mount_fstype |
| 25 | local sds_swap_device |
| 26 | local use_device |
| 27 | local do_fsck=0 |
| 28 | local fsck_type |
| 29 | |
| 30 | local autoswap_from_fstab |
| 31 | local automount_from_fstab |
| 32 | |
| 33 | mount_dev_section_cb() { |
| 34 | mds_mount_target="$2" |
| 35 | mds_mount_device="$3" |
| 36 | mds_mount_fstype="$4" |
| 37 | mds_mount_enabled="$6" |
| 38 | } |
| 39 | |
| 40 | swap_dev_section_cb() { |
| 41 | sds_swap_device="$2" |
| 42 | return 0 |
| 43 | } |
| 44 | |
| 45 | config_get_automount |
| 46 | automount_from_fstab="$from_fstab" |
| 47 | [ "$automount_from_fstab" -eq 1 ] && { |
| 48 | config_get_mount_section_by_device "/dev/$device" |
| 49 | use_device="$mds_mount_device" |
| 50 | [ "$mds_mount_enabled" -eq 1 ] && { |
| 51 | if [ -n "$mds_mount_target" ]; then |
| 52 | grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || { |
| 53 | ( mkdir -p "$mds_mount_target" && mount "$mds_mount_target" ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab' |
| 54 | } |
| 55 | else |
| 56 | logger -t 'fstab' "Mount enabled for $mds_mount_device but it doesn't have a defined mountpoint (target)" |
| 57 | fi |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | [ -z "$use_device" ] && { |
| 62 | config_get_autoswap |
| 63 | autoswap_from_fstab="$from_fstab" |
| 64 | |
| 65 | [ "$autoswap_from_fstab" -eq 1 ] && { |
| 66 | config_get_swap_section_by_device "/dev/$device" |
| 67 | use_device="$sds_swap_device" |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || { |
| 72 | [ "$anon_mount" -eq 1 ] && [ -z "$use_device" ] && { |
| 73 | ( mkdir -p /mnt/$device && mount /dev/$device /mnt/$device ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab' |
| 74 | } |
| 75 | } |
| 76 | reset_dev_section_cb |
| 77 | ;; |
| 78 | remove) |
| 79 | umount /dev/$device |
| 80 | ;; |
| 81 | esac |
| 82 | |
| 83 | fi |
| 84 | |
| 85 | |