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
121 local fstabnew
="$(mktemp -t '.fstab.XXXXXXXX')"
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
132 config_create_mount_fstab_entry
() {
138 options
="${options:-rw}"
139 [ "$enabled" -eq 0 ] && options
="noauto,$options"
140 [ -n "$target" ] ||
return 0
141 [ -n "$device" ] ||
return 0
143 local fstabnew
="$(mktemp -t '.fstab.XXXXXXXX')"
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
154 libmount_find_token
() {
158 device
="$(blkid | grep "$token=\"$value\"" | cut -f1 -d:)"
162 libmount_find_device_by_id
() {
166 local cfg_device
="$4"
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"
178 [ -n "$device" ] && [ "$device" != "$found_device" ] && {
184 config_get_mount_section_by_device
() {
185 local msbd_device
="$1"
186 local msbd_mount_cfg
=
188 local msbd_mount_device
=
192 local msbd_enabled_fsck
=
196 local msbd_blkid_fstype_match
=
202 local mc_cfgdevice
="$3"
207 local mc_is_rootfs
="$9"
208 local mc_found_device
=""
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"
218 msbd_enabled_fsck
="$6"
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"
231 config_get_swap_section_by_device
() {
232 local ssbd_device
="$1"
234 local ssbd_swap_device
=
243 local sc_cfgdevice
="$3"
244 local sc_found_device
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"
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"