[toolchain] uClibc: enhance debug support (closes: #6118)
[openwrt.git] / package / block-mount / files / block.sh
1 #!/bin/sh
2 # Copyright 2010 Vertical Communications
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
5 #
6
7 . /etc/functions.sh
8
9 reset_block_cb() {
10 mount_cb() {
11 dmc_mount_cfg="$1"
12 shift # skip optional param
13 dmc_target="$2"
14 dmc_mount_device="$3"
15 dmc_fstype="$4"
16 dmc_options="$5"
17 dmc_enabled="$6"
18 dmc_enabled_fsck="$7"
19 dmc_uuid="$8"
20 dmc_label="$9"
21 shift
22 dmc_is_rootfs="$9"
23 return 0
24 }
25 swap_cb() {
26 dsc_swap_cfg="$1"
27 shift # skip optional param
28 dsc_swap_device="$2"
29 dsc_enabled="$3"
30 dsc_uuid="$4"
31 dsc_label="$5"
32 return 0
33 }
34 }
35 reset_block_cb
36
37 reset_dev_section_cb() {
38 mount_dev_section_cb() {
39 dmds_mount_cfg="$1"
40 dmds_mount_target="$2"
41 dmds_mount_device="$3"
42 dmds_mount_fstype="$4"
43 dmds_mount_options="$5"
44 dmds_mount_enabled="$6"
45 dmds_mount_enabled_fsck="$7"
46 dmds_mount_uuid="$8"
47 dmds_mount_label="$9"
48 shift
49 dmds_is_rootfs="$9"
50 return 0
51 }
52 swap_dev_section_cb() {
53 dsds_swap_cfg="$1"
54 dsds_swap_device="$2"
55 dsds_swap_enabled="$3"
56 dsds_swap_uuid="$4"
57 dsds_swap_label="$5"
58 return 0
59 }
60 }
61 reset_dev_section_cb
62
63 config_get_mount() {
64 local gm_cfg="$1"
65 local gm_param="$2"
66 local gm_target
67 local gm_device
68 local gm_fstype
69 local gm_options
70 local gm_enabled
71 local gm_enabled_fsck
72 local gm_uuid
73 local gm_label
74 local gm_is_rootfs
75 config_get gm_target "$1" target
76 config_get gm_device "$1" device
77 config_get gm_fstype "$1" fstype 'auto'
78 config_get gm_options "$1" options 'rw'
79 config_get_bool gm_enabled "$1" enabled 1
80 config_get_bool gm_enabled_fsck "$1" enabled_fsck 0
81 config_get gm_uuid "$1" uuid
82 config_get gm_label "$1" label
83 config_get_bool gm_is_rootfs "$1" is_rootfs 0
84 mount_cb "$gm_cfg" "$gm_param" "$gm_target" "$gm_device" "$gm_fstype" "$gm_options" "$gm_enabled" "$gm_enabled_fsck" "$gm_uuid" "$gm_label" "$gm_is_rootfs"
85 }
86
87 config_get_swap() {
88 local gs_cfg="$1"
89 local gs_param="$2"
90 local gs_device
91 local gs_enabled
92 local gs_uuid
93 local gs_label
94 config_get gs_device "$1" device
95 config_get_bool gs_enabled "$1" enabled 1
96 config_get gs_uuid "$1" uuid
97 config_get gs_label "$1" label
98
99 swap_cb "$gs_cfg" "$gs_param" "$gs_device" "$gs_enabled" "$gs_uuid" "$gs_label"
100 }
101
102 config_get_automount() {
103 config_load fstab
104 config_get_bool from_fstab "automount" from_fstab 1
105 config_get_bool anon_mount "automount" anon_mount 1
106 config_get_bool anon_fsck "automount" anon_fsck 0
107 }
108
109 config_get_autoswap() {
110 config_load fstab
111 config_get_bool from_fstab "autoswap" from_fstab 1
112 config_get_bool anon_swap "autoswap" anon_swap 0
113 }
114
115 config_create_swap_fstab_entry() {
116 local device="$1"
117 local enabled="$2"
118
119 [ -n "$device" ] || return 0
120
121 local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
122
123 mkdir -p /var/lock
124 lock /var/lock/fstab.lck
125 cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" >>"$fstabnew"
126 [ "$enabled" -eq 1 ] && echo "$device none swap sw 0 0" >> "$fstabnew"
127 cat "$fstabnew" >/tmp/fstab
128 lock -u /var/lock/fstab.lck
129 rm -f $fstabnew
130 }
131
132 config_create_mount_fstab_entry() {
133 local device="$1"
134 local target="$2"
135 local fstype="$3"
136 local options="$4"
137 local enabled="$5"
138 options="${options:-rw}"
139 [ "$enabled" -eq 0 ] && options="noauto,$options"
140 [ -n "$target" ] || return 0
141 [ -n "$device" ] || return 0
142
143 local fstabnew="$(mktemp -t '.fstab.XXXXXXXX')"
144
145 mkdir -p /var/lock
146 lock /var/lock/fstab.lck
147 cat /tmp/fstab | grep -E -v "^$device[[:blank:]]" | grep -v "$target" >>"$fstabnew"
148 echo "$device $target $fstype $options 0 0" >>"$fstabnew"
149 cat "$fstabnew" >/tmp/fstab
150 lock -u /var/lock/fstab.lck
151 rm -f $fstabnew
152 }
153
154 libmount_find_token() {
155 local token="$1"
156 local value="$2"
157 local device
158 device="$(blkid | grep "$token=\"$value\"" | cut -f1 -d:)"
159 echo "$device"
160 }
161
162 libmount_find_device_by_id() {
163 local uuid="$1"
164 local label="$2"
165 local device="$3"
166 local cfg_device="$4"
167 local found_device
168
169 if [ -n "$uuid" ]; then
170 found_device="$(libmount_find_token "UUID" "$uuid")"
171 elif [ -n "$label" ]; then
172 found_device="$(libmount_find_token "LABEL" "$label")"
173 elif [ "$device" = "$cfg_device" ]; then
174 found_device="$device"
175 elif [ -z "$device" ] && [ -e "$cfg_device" ]; then
176 found_device="$cfg_device"
177 fi
178 [ -n "$device" ] && [ "$device" != "$found_device" ] && {
179 found_device=""
180 }
181 echo "$found_device"
182 }
183
184 config_get_mount_section_by_device() {
185 local msbd_device="$1"
186 local msbd_mount_cfg=
187 local msbd_target=
188 local msbd_mount_device=
189 local msbd_fstype=
190 local msbd_options=
191 local msbd_enabled=
192 local msbd_enabled_fsck=
193 local msbd_uuid=
194 local msbd_label=
195 local msbd_is_rootfs
196 local msbd_blkid_fstype_match=
197 mount_cb() {
198 local mc_cfg="$1"
199 local mc_device="$2"
200 shift
201 local mc_target="$2"
202 local mc_cfgdevice="$3"
203 local mc_fstype="$4"
204 local mc_uuid="$8"
205 local mc_label="$9"
206 shift
207 local mc_is_rootfs="$9"
208 local mc_found_device=""
209
210 mc_found_device="$(libmount_find_device_by_id "$mc_uuid" "$mc_label" "$mc_device" "$mc_cfgdevice")"
211 if [ -n "$mc_found_device" ]; then
212 msbd_mount_cfg="$mc_cfg"
213 msbd_target="$mc_target"
214 msbd_mount_device="$mc_found_device"
215 msbd_fstype="$mc_fstype"
216 msbd_options="$4"
217 msbd_enabled="$5"
218 msbd_enabled_fsck="$6"
219 msbd_uuid="$7"
220 msbd_label="$8"
221 msbd_is_rootfs="$9"
222 fi
223 return 0
224 }
225 config_foreach config_get_mount mount "$msbd_device"
226 [ -n "$msbd_mount_device" ] && config_create_mount_fstab_entry "$msbd_mount_device" "$msbd_target" "$msbd_fstype" "$msbd_options" "$msbd_enabled"
227 mount_dev_section_cb "$msbd_mount_cfg" "$msbd_target" "$msbd_mount_device" "$msbd_fstype" "$msbd_options" "$msbd_enabled" "$msbd_enabled_fsck" "$msbd_uuid" "$msbd_label" "$msbd_is_rootfs"
228 reset_block_cb
229 }
230
231 config_get_swap_section_by_device() {
232 local ssbd_device="$1"
233 local ssbd_swap_cfg=
234 local ssbd_swap_device=
235 local ssbd_enabled=
236 local ssbd_uuid=
237 local ssbd_label=
238 swap_cb() {
239 local sc_cfg="$1"
240 local sc_device="$2"
241 local sc_uuid="$5"
242 local sc_label="$6"
243 local sc_cfgdevice="$3"
244 local sc_found_device
245
246 sc_found_device="$(libmount_find_device_by_id "$sc_uuid" "$sc_label" "$sc_device" "$sc_cfgdevice")"
247 if [ -n "$sc_found_device" ]; then
248 ssbd_swap_cfg="$sc_cfg"
249 ssbd_swap_device="$sc_found_device"
250 ssbd_enabled="$4"
251 ssbd_uuid="$5"
252 ssbd_label="$6"
253 fi
254 return 0
255 }
256 config_foreach config_get_swap swap "$ssbd_device"
257 [ -n "$ssbd_swap_device" ] && config_create_swap_fstab_entry "$ssbd_swap_device" "$ssbd_enabled"
258 swap_dev_section_cb "$ssbd_swap_cfg" "$ssbd_swap_device" "$ssbd_enabled" "$ssbd_uuid" "$ssbd_label"
259 reset_block_cb
260 }
261
262
This page took 0.067173 seconds and 5 git commands to generate.