2 # Copyright 2010 Vertical Communications
3 # This is free software, licensed under the GNU General Public License v2.
4 # See /LICENSE for more information.
12 shift # skip optional param
27 shift # skip optional param
37 reset_dev_section_cb
() {
38 mount_dev_section_cb
() {
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"
52 swap_dev_section_cb
() {
55 dsds_swap_enabled
="$3"
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"
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
99 swap_cb
"$gs_cfg" "$gs_param" "$gs_device" "$gs_enabled" "$gs_uuid" "$gs_label"
102 config_get_automount
() {
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
109 config_get_autoswap
() {
111 config_get_bool from_fstab
"autoswap" from_fstab
1
112 config_get_bool anon_swap
"autoswap" anon_swap
0
115 config_create_swap_fstab_entry
() {
119 [ -n "$device" ] ||
return 0
124 lock
/var
/lock
/fstab.lck
125 fstabnew
="$(mktemp -t '.fstab.XXXXXXXX')"
126 cat /tmp
/fstab |
grep -E -v "^$device[[:blank:]]" >>"$fstabnew"
127 [ "$enabled" -eq 1 ] && echo "$device none swap sw 0 0" >> "$fstabnew"
128 cat "$fstabnew" >/tmp
/fstab
130 lock
-u /var
/lock
/fstab.lck
133 config_create_mount_fstab_entry
() {
139 options
="${options:-rw}"
140 [ "$enabled" -eq 0 ] && options
="noauto,$options"
141 [ -n "$target" ] ||
return 0
142 [ -n "$device" ] ||
return 0
147 lock
/var
/lock
/fstab.lck
148 fstabnew
="$(mktemp -t '.fstab.XXXXXXXX')"
149 cat /tmp
/fstab |
grep -E -v "^$device[[:blank:]]" |
grep -v "$target" >>"$fstabnew"
150 echo "$device $target $fstype $options 0 0" >>"$fstabnew"
151 cat "$fstabnew" >/tmp
/fstab
153 lock
-u /var
/lock
/fstab.lck
156 libmount_find_token
() {
160 device
="$(blkid | grep "$token=\"$value\"" | cut -f1 -d:)"
164 libmount_find_device_by_id
() {
168 local cfg_device
="$4"
171 if [ -n "$uuid" ]; then
172 found_device
="$(libmount_find_token "UUID
" "$uuid")"
173 elif [ -n "$label" ]; then
174 found_device
="$(libmount_find_token "LABEL
" "$label")"
175 elif [ "$device" = "$cfg_device" ]; then
176 found_device
="$device"
177 elif [ -z "$device" ] && [ -e "$cfg_device" ]; then
178 found_device
="$cfg_device"
180 [ -n "$device" ] && [ "$device" != "$found_device" ] && {
186 config_get_mount_section_by_device
() {
187 local msbd_device
="$1"
188 local msbd_mount_cfg
=
190 local msbd_mount_device
=
194 local msbd_enabled_fsck
=
198 local msbd_blkid_fstype_match
=
204 local mc_cfgdevice
="$3"
209 local mc_is_rootfs
="$9"
210 local mc_found_device
=""
212 mc_found_device
="$(libmount_find_device_by_id "$mc_uuid" "$mc_label" "$mc_device" "$mc_cfgdevice")"
213 if [ -n "$mc_found_device" ]; then
214 msbd_mount_cfg
="$mc_cfg"
215 msbd_target
="$mc_target"
216 msbd_mount_device
="$mc_found_device"
217 msbd_fstype
="$mc_fstype"
220 msbd_enabled_fsck
="$6"
227 config_foreach config_get_mount mount
"$msbd_device"
228 [ -n "$msbd_mount_device" ] && config_create_mount_fstab_entry
"$msbd_mount_device" "$msbd_target" "$msbd_fstype" "$msbd_options" "$msbd_enabled"
229 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"
233 config_get_swap_section_by_device
() {
234 local ssbd_device
="$1"
236 local ssbd_swap_device
=
245 local sc_cfgdevice
="$3"
246 local sc_found_device
248 sc_found_device
="$(libmount_find_device_by_id "$sc_uuid" "$sc_label" "$sc_device" "$sc_cfgdevice")"
249 if [ -n "$sc_found_device" ]; then
250 ssbd_swap_cfg
="$sc_cfg"
251 ssbd_swap_device
="$sc_found_device"
258 config_foreach config_get_swap swap
"$ssbd_device"
259 [ -n "$ssbd_swap_device" ] && config_create_swap_fstab_entry
"$ssbd_swap_device" "$ssbd_enabled"
260 swap_dev_section_cb
"$ssbd_swap_cfg" "$ssbd_swap_device" "$ssbd_enabled" "$ssbd_uuid" "$ssbd_label"