[kernel] refresh 3.0 patches
[openwrt.git] / package / block-mount / files / 10-swap
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
12 if [ `basename $blkdev` != "block" ]; then
13
14 device=`basename $DEVPATH`
15
16
17 case "$ACTION" in
18 add)
19 local autoswap_from_fstab
20 local automount_from_fstab
21 local from_fstab
22 local anon_mount
23 local anon_swap
24 local anon_fsck
25 local mds_mount_device
26 local sds_swap_device
27 local sds_swap_enabled
28 local use_device
29 local do_swap=0
30
31 mount_dev_section_cb() {
32 mds_mount_device="$3"
33 }
34
35 swap_dev_section_cb() {
36 sds_swap_device="$2"
37 sds_swap_enabled="$3"
38 return 0
39 }
40
41 config_get_automount
42 automount_from_fstab="$from_fstab"
43
44 [ "$automount_from_fstab" -eq 1 ] && {
45 config_get_mount_section_by_device "/dev/$device"
46 }
47
48 # skip trying swap if this device is defined as a mount point
49 [ -z "$mds_mount_device" ] && {
50 config_get_autoswap
51 autoswap_from_fstab="$from_fstab"
52
53 [ "$autoswap_from_fstab" -eq 1 ] && {
54 config_get_swap_section_by_device "/dev/$device"
55 use_device="$sds_swap_device"
56 do_swap="$sds_swap_enabled"
57 }
58
59 [ -z "$use_device" ] && [ "$anon_swap" -eq 1 ] && {
60 use_device="/dev/$device" && do_swap=1
61 }
62 }
63
64 [ -n "$use_device" ] && [ "$do_swap" -eq 1 ] && {
65 grep -q "$use_device" /proc/swaps || grep -q "$use_device" /proc/mounts || {
66 swapon "$use_device"
67 }
68 }
69 reset_dev_section_cb
70 ;;
71 remove)
72 grep -q "/dev/$device" /proc/swaps && {
73 swapoff "/dev/$device"
74 }
75 ;;
76 esac
77 fi
78
This page took 0.073831 seconds and 5 git commands to generate.