[package] block-mount: fix fstab.init for IB and buildroot
[openwrt/svn-archive/archive.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 -w /var/lock/fstab.lck && {
45 lock /var/lock/fstab.lck
46 [ -e /tmp/fstab ] || {
47 echo '# WARNING: this is an auto generated file, please use uci to set defined filesystems' > /tmp/fstab
48 }
49 lock -u /var/lock/fstab.lck
50 }
51 config_foreach do_swapon swap
52 config_foreach do_mount mount
53 config_foreach do_swapon swap # do swap a second time so that swap on filesystems is enabled
54 }
55
56 stop() {
57 . /lib/functions/mount.sh
58
59 config_load fstab
60 config_foreach do_unmount mount
61 config_foreach do_swapoff swap
62 swapoff -a
63 }
64
65