[backfire] merge r27226
[openwrt-10.03/.git] / package / block-mount / files / fstab.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 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
9 START=20
10
11 do_mount() {
12         local cfg="$1"
13         config_mount_by_section "$cfg"
14 }
15
16 do_swapon() {
17         local cfg="$1"
18         config_swapon_by_section "$cfg"
19 }
20
21 do_unmount() {
22         local cfg="$1"
23
24         config_get target "$cfg" target
25         config_get_bool enabled "$cfg" "enabled" '1'
26         [ -n "$target" -a "$enabled" -gt 0 ] || return 0
27         umount $target
28 }
29         
30 do_swapoff() {
31         local cfg="$1"
32
33         config_get device "$cfg" device
34         config_get_bool enabled "$cfg" "enabled" '1'
35         [ -n "$device" -a  "$enabled" -gt 0 ] && type swapoff >/dev/null || return 0
36         swapoff $device
37 }
38
39 start() {
40         . /lib/functions/mount.sh
41
42         config_load fstab
43         mkdir -p /var/lock
44         lock /var/lock/fstab.lck
45         [ -e /tmp/fstab ] || {
46                 echo '# WARNING: this is an auto generated file, please use uci to set defined filesystems' > /tmp/fstab
47         }
48         lock -u /var/lock/fstab.lck
49         config_foreach do_swapon swap
50         config_foreach do_mount mount
51         config_foreach do_swapon swap  # do swap a second time so that swap on filesystems is enabled
52 }
53
54 stop() {
55         . /lib/functions/mount.sh
56
57         config_load fstab
58         config_foreach do_unmount mount
59         config_foreach do_swapoff swap
60         swapoff -a
61 }
62
63