b96e0c8a54850a9078ab7375d668ea078cd53b7a
[openwrt/svn-archive/archive.git] / package / base-files / files / etc / init.d / fstab
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
3
4 START=20
5
6 do_mount() {
7 local cfg="$1"
8 config_get fstype "$cfg" fstype
9 fstype="${fstype:-auto}"
10 config_get options "$cfg" options
11 options="${options:-rw}"
12 config_get device "$cfg" device
13 [ -n "device" ] || return 0
14 config_get target "$cfg" target
15 [ -n "target" ] || return 0
16 mkdir -p $target
17 config_get_bool enabled "$cfg" "enabled" '1'
18 [ "$enabled" -gt 0 ] && {
19 /bin/mount -t $fstype -o $options $device $target
20 }
21 }
22
23 do_swapon() {
24 local cfg="$1"
25 config_get device "$cfg" device
26 [ -n "device" ] || return 0
27 config_get_bool enabled "$cfg" "enabled" '1'
28 [ "$enabled" -gt 0 ] && [ -x /usr/sbin/swapon ] && {
29 /usr/sbin/swapon $device
30 }
31 }
32
33 do_unmount() {
34 local cfg="$1"
35 config_get target "$cfg" target
36 [ -n "target" ] || return 0
37 config_get_bool enabled "$cfg" "enabled" '1'
38 [ "$enabled" -gt 0 ] && {
39 /bin/umount $target
40 }
41 }
42
43 do_swapoff() {
44 local cfg="$1"
45 config_get device "$cfg" device
46 [ -n "device" ] || return 0
47 config_get_bool enabled "$cfg" "enabled" '1'
48 [ "$enabled" -gt 0 ] && [ -x /usr/sbin/swapoff ] && {
49 /usr/sbin/swapoff $device
50 }
51 }
52
53 start() {
54 config_load fstab
55 config_foreach do_mount mount
56 config_foreach do_swapon swap
57 }
58
59 stop() {
60 config_load fstab
61 config_foreach do_unmount mount
62 config_foreach do_swapoff swap
63 }
64