Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../lib/dracut
File: dracut-functions.sh
#!/bin/bash
[0] Fix | Delete
#
[1] Fix | Delete
# functions used by dracut and other tools.
[2] Fix | Delete
#
[3] Fix | Delete
# Copyright 2005-2009 Red Hat, Inc. All rights reserved.
[4] Fix | Delete
#
[5] Fix | Delete
# This program is free software; you can redistribute it and/or modify
[6] Fix | Delete
# it under the terms of the GNU General Public License as published by
[7] Fix | Delete
# the Free Software Foundation; either version 2 of the License, or
[8] Fix | Delete
# (at your option) any later version.
[9] Fix | Delete
#
[10] Fix | Delete
# This program is distributed in the hope that it will be useful,
[11] Fix | Delete
# but WITHOUT ANY WARRANTY; without even the implied warranty of
[12] Fix | Delete
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[13] Fix | Delete
# GNU General Public License for more details.
[14] Fix | Delete
#
[15] Fix | Delete
# You should have received a copy of the GNU General Public License
[16] Fix | Delete
# along with this program. If not, see <http://www.gnu.org/licenses/>.
[17] Fix | Delete
#
[18] Fix | Delete
export LC_MESSAGES=C
[19] Fix | Delete
[20] Fix | Delete
# is_func <command>
[21] Fix | Delete
# Check whether $1 is a function.
[22] Fix | Delete
is_func() {
[23] Fix | Delete
[[ "$(type -t "$1")" = "function" ]]
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
# Generic substring function. If $2 is in $1, return 0.
[28] Fix | Delete
strstr() { [[ $1 = *"$2"* ]]; }
[29] Fix | Delete
# Generic glob matching function. If glob pattern $2 matches anywhere in $1, OK
[30] Fix | Delete
strglobin() { [[ $1 = *$2* ]]; }
[31] Fix | Delete
# Generic glob matching function. If glob pattern $2 matches all of $1, OK
[32] Fix | Delete
strglob() { [[ $1 = $2 ]]; }
[33] Fix | Delete
# returns OK if $1 contains literal string $2 at the beginning, and isn't empty
[34] Fix | Delete
str_starts() { [ "${1#"$2"*}" != "$1" ]; }
[35] Fix | Delete
# returns OK if $1 contains literal string $2 at the end, and isn't empty
[36] Fix | Delete
str_ends() { [ "${1%*"$2"}" != "$1" ]; }
[37] Fix | Delete
[38] Fix | Delete
# find a binary. If we were not passed the full path directly,
[39] Fix | Delete
# search in the usual places to find the binary.
[40] Fix | Delete
find_binary() {
[41] Fix | Delete
if [[ -z ${1##/*} ]]; then
[42] Fix | Delete
if [[ -x $1 ]] || { [[ "$1" == *.so* ]] && ldd "$1" &>/dev/null; }; then
[43] Fix | Delete
printf "%s\n" "$1"
[44] Fix | Delete
return 0
[45] Fix | Delete
fi
[46] Fix | Delete
fi
[47] Fix | Delete
[48] Fix | Delete
type -P "${1##*/}"
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
ldconfig_paths()
[52] Fix | Delete
{
[53] Fix | Delete
ldconfig -pN 2>/dev/null | grep -E -v '/(lib|lib64|usr/lib|usr/lib64)/[^/]*$' | sed -n 's,.* => \(.*\)/.*,\1,p' | sort | uniq
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
# Version comparision function. Assumes Linux style version scheme.
[57] Fix | Delete
# $1 = version a
[58] Fix | Delete
# $2 = comparision op (gt, ge, eq, le, lt, ne)
[59] Fix | Delete
# $3 = version b
[60] Fix | Delete
vercmp() {
[61] Fix | Delete
local _n1=(${1//./ }) _op=$2 _n2=(${3//./ }) _i _res
[62] Fix | Delete
[63] Fix | Delete
for ((_i=0; ; _i++))
[64] Fix | Delete
do
[65] Fix | Delete
if [[ ! ${_n1[_i]}${_n2[_i]} ]]; then _res=0
[66] Fix | Delete
elif ((${_n1[_i]:-0} > ${_n2[_i]:-0})); then _res=1
[67] Fix | Delete
elif ((${_n1[_i]:-0} < ${_n2[_i]:-0})); then _res=2
[68] Fix | Delete
else continue
[69] Fix | Delete
fi
[70] Fix | Delete
break
[71] Fix | Delete
done
[72] Fix | Delete
[73] Fix | Delete
case $_op in
[74] Fix | Delete
gt) ((_res == 1));;
[75] Fix | Delete
ge) ((_res != 2));;
[76] Fix | Delete
eq) ((_res == 0));;
[77] Fix | Delete
le) ((_res != 1));;
[78] Fix | Delete
lt) ((_res == 2));;
[79] Fix | Delete
ne) ((_res != 0));;
[80] Fix | Delete
esac
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
# Create all subdirectories for given path without creating the last element.
[84] Fix | Delete
# $1 = path
[85] Fix | Delete
mksubdirs() {
[86] Fix | Delete
[[ -e ${1%/*} ]] || mkdir -m 0755 -p -- "${1%/*}"
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
# Function prints global variables in format name=value line by line.
[90] Fix | Delete
# $@ = list of global variables' name
[91] Fix | Delete
print_vars() {
[92] Fix | Delete
local _var _value
[93] Fix | Delete
[94] Fix | Delete
for _var in "$@"
[95] Fix | Delete
do
[96] Fix | Delete
eval printf -v _value "%s" \""\$$_var"\"
[97] Fix | Delete
[[ ${_value} ]] && printf '%s="%s"\n' "$_var" "$_value"
[98] Fix | Delete
done
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
# normalize_path <path>
[102] Fix | Delete
# Prints the normalized path, where it removes any duplicated
[103] Fix | Delete
# and trailing slashes.
[104] Fix | Delete
# Example:
[105] Fix | Delete
# $ normalize_path ///test/test//
[106] Fix | Delete
# /test/test
[107] Fix | Delete
normalize_path() {
[108] Fix | Delete
shopt -q -s extglob
[109] Fix | Delete
set -- "${1//+(\/)//}"
[110] Fix | Delete
shopt -q -u extglob
[111] Fix | Delete
printf "%s\n" "${1%/}"
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
# convert_abs_rel <from> <to>
[115] Fix | Delete
# Prints the relative path, when creating a symlink to <to> from <from>.
[116] Fix | Delete
# Example:
[117] Fix | Delete
# $ convert_abs_rel /usr/bin/test /bin/test-2
[118] Fix | Delete
# ../../bin/test-2
[119] Fix | Delete
# $ ln -s $(convert_abs_rel /usr/bin/test /bin/test-2) /usr/bin/test
[120] Fix | Delete
convert_abs_rel() {
[121] Fix | Delete
local __current __absolute __abssize __cursize __newpath
[122] Fix | Delete
local -i __i __level
[123] Fix | Delete
[124] Fix | Delete
set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
[125] Fix | Delete
[126] Fix | Delete
# corner case #1 - self looping link
[127] Fix | Delete
[[ "$1" == "$2" ]] && { printf "%s\n" "${1##*/}"; return; }
[128] Fix | Delete
[129] Fix | Delete
# corner case #2 - own dir link
[130] Fix | Delete
[[ "${1%/*}" == "$2" ]] && { printf ".\n"; return; }
[131] Fix | Delete
[132] Fix | Delete
IFS="/" __current=($1)
[133] Fix | Delete
IFS="/" __absolute=($2)
[134] Fix | Delete
[135] Fix | Delete
__abssize=${#__absolute[@]}
[136] Fix | Delete
__cursize=${#__current[@]}
[137] Fix | Delete
[138] Fix | Delete
while [[ "${__absolute[__level]}" == "${__current[__level]}" ]]
[139] Fix | Delete
do
[140] Fix | Delete
(( __level++ ))
[141] Fix | Delete
if (( __level > __abssize || __level > __cursize ))
[142] Fix | Delete
then
[143] Fix | Delete
break
[144] Fix | Delete
fi
[145] Fix | Delete
done
[146] Fix | Delete
[147] Fix | Delete
for ((__i = __level; __i < __cursize-1; __i++))
[148] Fix | Delete
do
[149] Fix | Delete
if ((__i > __level))
[150] Fix | Delete
then
[151] Fix | Delete
__newpath=$__newpath"/"
[152] Fix | Delete
fi
[153] Fix | Delete
__newpath=$__newpath".."
[154] Fix | Delete
done
[155] Fix | Delete
[156] Fix | Delete
for ((__i = __level; __i < __abssize; __i++))
[157] Fix | Delete
do
[158] Fix | Delete
if [[ -n $__newpath ]]
[159] Fix | Delete
then
[160] Fix | Delete
__newpath=$__newpath"/"
[161] Fix | Delete
fi
[162] Fix | Delete
__newpath=$__newpath${__absolute[__i]}
[163] Fix | Delete
done
[164] Fix | Delete
[165] Fix | Delete
printf "%s\n" "$__newpath"
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
[169] Fix | Delete
# get_fs_env <device>
[170] Fix | Delete
# Get and the ID_FS_TYPE variable from udev for a device.
[171] Fix | Delete
# Example:
[172] Fix | Delete
# $ get_fs_env /dev/sda2
[173] Fix | Delete
# ext4
[174] Fix | Delete
get_fs_env() {
[175] Fix | Delete
local evalstr
[176] Fix | Delete
local found
[177] Fix | Delete
[178] Fix | Delete
[[ $1 ]] || return
[179] Fix | Delete
unset ID_FS_TYPE
[180] Fix | Delete
ID_FS_TYPE=$(blkid -u filesystem -o export -- "$1" \
[181] Fix | Delete
| while read line || [ -n "$line" ]; do
[182] Fix | Delete
if [[ "$line" == TYPE\=* ]]; then
[183] Fix | Delete
printf "%s" "${line#TYPE=}";
[184] Fix | Delete
exit 0;
[185] Fix | Delete
fi
[186] Fix | Delete
done)
[187] Fix | Delete
if [[ $ID_FS_TYPE ]]; then
[188] Fix | Delete
printf "%s" "$ID_FS_TYPE"
[189] Fix | Delete
return 0
[190] Fix | Delete
fi
[191] Fix | Delete
return 1
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
# get_maj_min <device>
[195] Fix | Delete
# Prints the major and minor of a device node.
[196] Fix | Delete
# Example:
[197] Fix | Delete
# $ get_maj_min /dev/sda2
[198] Fix | Delete
# 8:2
[199] Fix | Delete
get_maj_min() {
[200] Fix | Delete
local _majmin
[201] Fix | Delete
local _out
[202] Fix | Delete
[203] Fix | Delete
if [[ $get_maj_min_cache_file ]]; then
[204] Fix | Delete
_out="$(grep -m1 -oP "^$1 \K\S+$" "$get_maj_min_cache_file")"
[205] Fix | Delete
fi
[206] Fix | Delete
[207] Fix | Delete
if ! [[ "$_out" ]]; then
[208] Fix | Delete
_majmin="$(stat -L -c '%t:%T' "$1" 2>/dev/null)"
[209] Fix | Delete
_out="$(printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))")"
[210] Fix | Delete
if [[ $get_maj_min_cache_file ]]; then
[211] Fix | Delete
echo "$1 $_out" >> "$get_maj_min_cache_file"
[212] Fix | Delete
fi
[213] Fix | Delete
fi
[214] Fix | Delete
echo -n "$_out"
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
# get_devpath_block <device>
[218] Fix | Delete
# get the DEVPATH in /sys of a block device
[219] Fix | Delete
get_devpath_block() {
[220] Fix | Delete
local _majmin _i
[221] Fix | Delete
_majmin=$(get_maj_min "$1")
[222] Fix | Delete
[223] Fix | Delete
for _i in /sys/block/*/dev /sys/block/*/*/dev; do
[224] Fix | Delete
[[ -e "$_i" ]] || continue
[225] Fix | Delete
if [[ "$_majmin" == "$(<"$_i")" ]]; then
[226] Fix | Delete
printf "%s" "${_i%/dev}"
[227] Fix | Delete
return 0
[228] Fix | Delete
fi
[229] Fix | Delete
done
[230] Fix | Delete
return 1
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
# get a persistent path from a device
[234] Fix | Delete
get_persistent_dev() {
[235] Fix | Delete
local i _tmp _dev _pol
[236] Fix | Delete
[237] Fix | Delete
_dev=$(get_maj_min "$1")
[238] Fix | Delete
[ -z "$_dev" ] && return
[239] Fix | Delete
[240] Fix | Delete
if [[ -n "$persistent_policy" ]]; then
[241] Fix | Delete
_pol="/dev/disk/${persistent_policy}/*"
[242] Fix | Delete
else
[243] Fix | Delete
_pol=
[244] Fix | Delete
fi
[245] Fix | Delete
[246] Fix | Delete
for i in \
[247] Fix | Delete
$_pol \
[248] Fix | Delete
/dev/mapper/* \
[249] Fix | Delete
/dev/disk/by-uuid/* \
[250] Fix | Delete
/dev/disk/by-label/* \
[251] Fix | Delete
/dev/disk/by-partuuid/* \
[252] Fix | Delete
/dev/disk/by-partlabel/* \
[253] Fix | Delete
/dev/disk/by-id/* \
[254] Fix | Delete
/dev/disk/by-path/* \
[255] Fix | Delete
; do
[256] Fix | Delete
[[ -e "$i" ]] || continue
[257] Fix | Delete
[[ $i == /dev/mapper/control ]] && continue
[258] Fix | Delete
[[ $i == /dev/mapper/mpath* ]] && continue
[259] Fix | Delete
_tmp=$(get_maj_min "$i")
[260] Fix | Delete
if [ "$_tmp" = "$_dev" ]; then
[261] Fix | Delete
printf -- "%s" "$i"
[262] Fix | Delete
return
[263] Fix | Delete
fi
[264] Fix | Delete
done
[265] Fix | Delete
printf -- "%s" "$1"
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
expand_persistent_dev() {
[269] Fix | Delete
local _dev=$1
[270] Fix | Delete
[271] Fix | Delete
case "$_dev" in
[272] Fix | Delete
LABEL=*)
[273] Fix | Delete
_dev="/dev/disk/by-label/${_dev#LABEL=}"
[274] Fix | Delete
;;
[275] Fix | Delete
UUID=*)
[276] Fix | Delete
_dev="${_dev#UUID=}"
[277] Fix | Delete
_dev="${_dev,,}"
[278] Fix | Delete
_dev="/dev/disk/by-uuid/${_dev}"
[279] Fix | Delete
;;
[280] Fix | Delete
PARTUUID=*)
[281] Fix | Delete
_dev="${_dev#PARTUUID=}"
[282] Fix | Delete
_dev="${_dev,,}"
[283] Fix | Delete
_dev="/dev/disk/by-partuuid/${_dev}"
[284] Fix | Delete
;;
[285] Fix | Delete
PARTLABEL=*)
[286] Fix | Delete
_dev="/dev/disk/by-partlabel/${_dev#PARTLABEL=}"
[287] Fix | Delete
;;
[288] Fix | Delete
esac
[289] Fix | Delete
printf "%s" "$_dev"
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
shorten_persistent_dev() {
[293] Fix | Delete
local _dev="$1"
[294] Fix | Delete
case "$_dev" in
[295] Fix | Delete
/dev/disk/by-uuid/*)
[296] Fix | Delete
printf "%s" "UUID=${_dev##*/}";;
[297] Fix | Delete
/dev/disk/by-label/*)
[298] Fix | Delete
printf "%s" "LABEL=${_dev##*/}";;
[299] Fix | Delete
/dev/disk/by-partuuid/*)
[300] Fix | Delete
printf "%s" "PARTUUID=${_dev##*/}";;
[301] Fix | Delete
/dev/disk/by-partlabel/*)
[302] Fix | Delete
printf "%s" "PARTLABEL=${_dev##*/}";;
[303] Fix | Delete
*)
[304] Fix | Delete
printf "%s" "$_dev";;
[305] Fix | Delete
esac
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
# find_block_device <mountpoint>
[309] Fix | Delete
# Prints the major and minor number of the block device
[310] Fix | Delete
# for a given mountpoint.
[311] Fix | Delete
# Unless $use_fstab is set to "yes" the functions
[312] Fix | Delete
# uses /proc/self/mountinfo as the primary source of the
[313] Fix | Delete
# information and only falls back to /etc/fstab, if the mountpoint
[314] Fix | Delete
# is not found there.
[315] Fix | Delete
# Example:
[316] Fix | Delete
# $ find_block_device /usr
[317] Fix | Delete
# 8:4
[318] Fix | Delete
find_block_device() {
[319] Fix | Delete
local _dev _majmin _find_mpt
[320] Fix | Delete
_find_mpt="$1"
[321] Fix | Delete
if [[ $use_fstab != yes ]]; then
[322] Fix | Delete
[[ -d $_find_mpt/. ]]
[323] Fix | Delete
findmnt -e -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
[324] Fix | Delete
while read _majmin _dev || [ -n "$_dev" ]; do
[325] Fix | Delete
if [[ -b $_dev ]]; then
[326] Fix | Delete
if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
[327] Fix | Delete
_majmin=$(get_maj_min $_dev)
[328] Fix | Delete
fi
[329] Fix | Delete
if [[ $_majmin ]]; then
[330] Fix | Delete
printf "%s\n" "$_majmin"
[331] Fix | Delete
else
[332] Fix | Delete
printf "%s\n" "$_dev"
[333] Fix | Delete
fi
[334] Fix | Delete
return 0
[335] Fix | Delete
fi
[336] Fix | Delete
if [[ $_dev = *:* ]]; then
[337] Fix | Delete
printf "%s\n" "$_dev"
[338] Fix | Delete
return 0
[339] Fix | Delete
fi
[340] Fix | Delete
done; return 1; } && return 0
[341] Fix | Delete
fi
[342] Fix | Delete
# fall back to /etc/fstab
[343] Fix | Delete
[344] Fix | Delete
findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' --target "$_find_mpt" | { \
[345] Fix | Delete
while read _majmin _dev || [ -n "$_dev" ]; do
[346] Fix | Delete
if ! [[ $_dev ]]; then
[347] Fix | Delete
_dev="$_majmin"
[348] Fix | Delete
unset _majmin
[349] Fix | Delete
fi
[350] Fix | Delete
if [[ -b $_dev ]]; then
[351] Fix | Delete
[[ $_majmin ]] || _majmin=$(get_maj_min $_dev)
[352] Fix | Delete
if [[ $_majmin ]]; then
[353] Fix | Delete
printf "%s\n" "$_majmin"
[354] Fix | Delete
else
[355] Fix | Delete
printf "%s\n" "$_dev"
[356] Fix | Delete
fi
[357] Fix | Delete
return 0
[358] Fix | Delete
fi
[359] Fix | Delete
if [[ $_dev = *:* ]]; then
[360] Fix | Delete
printf "%s\n" "$_dev"
[361] Fix | Delete
return 0
[362] Fix | Delete
fi
[363] Fix | Delete
done; return 1; } && return 0
[364] Fix | Delete
[365] Fix | Delete
return 1
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
# find_mp_fstype <mountpoint>
[369] Fix | Delete
# Echo the filesystem type for a given mountpoint.
[370] Fix | Delete
# /proc/self/mountinfo is taken as the primary source of information
[371] Fix | Delete
# and /etc/fstab is used as a fallback.
[372] Fix | Delete
# No newline is appended!
[373] Fix | Delete
# Example:
[374] Fix | Delete
# $ find_mp_fstype /;echo
[375] Fix | Delete
# ext4
[376] Fix | Delete
find_mp_fstype() {
[377] Fix | Delete
local _fs
[378] Fix | Delete
[379] Fix | Delete
if [[ $use_fstab != yes ]]; then
[380] Fix | Delete
findmnt -e -v -n -o 'FSTYPE' --target "$1" | { \
[381] Fix | Delete
while read _fs || [ -n "$_fs" ]; do
[382] Fix | Delete
[[ $_fs ]] || continue
[383] Fix | Delete
[[ $_fs = "autofs" ]] && continue
[384] Fix | Delete
printf "%s" "$_fs"
[385] Fix | Delete
return 0
[386] Fix | Delete
done; return 1; } && return 0
[387] Fix | Delete
fi
[388] Fix | Delete
[389] Fix | Delete
findmnt --fstab -e -v -n -o 'FSTYPE' --target "$1" | { \
[390] Fix | Delete
while read _fs || [ -n "$_fs" ]; do
[391] Fix | Delete
[[ $_fs ]] || continue
[392] Fix | Delete
[[ $_fs = "autofs" ]] && continue
[393] Fix | Delete
printf "%s" "$_fs"
[394] Fix | Delete
return 0
[395] Fix | Delete
done; return 1; } && return 0
[396] Fix | Delete
[397] Fix | Delete
return 1
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
# find_dev_fstype <device>
[401] Fix | Delete
# Echo the filesystem type for a given device.
[402] Fix | Delete
# /proc/self/mountinfo is taken as the primary source of information
[403] Fix | Delete
# and /etc/fstab is used as a fallback.
[404] Fix | Delete
# No newline is appended!
[405] Fix | Delete
# Example:
[406] Fix | Delete
# $ find_dev_fstype /dev/sda2;echo
[407] Fix | Delete
# ext4
[408] Fix | Delete
find_dev_fstype() {
[409] Fix | Delete
local _find_dev _fs
[410] Fix | Delete
_find_dev="$1"
[411] Fix | Delete
if ! [[ "$_find_dev" = /dev* ]]; then
[412] Fix | Delete
[[ -b "/dev/block/$_find_dev" ]] && _find_dev="/dev/block/$_find_dev"
[413] Fix | Delete
fi
[414] Fix | Delete
[415] Fix | Delete
if [[ $use_fstab != yes ]]; then
[416] Fix | Delete
findmnt -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
[417] Fix | Delete
while read _fs || [ -n "$_fs" ]; do
[418] Fix | Delete
[[ $_fs ]] || continue
[419] Fix | Delete
[[ $_fs = "autofs" ]] && continue
[420] Fix | Delete
printf "%s" "$_fs"
[421] Fix | Delete
return 0
[422] Fix | Delete
done; return 1; } && return 0
[423] Fix | Delete
fi
[424] Fix | Delete
[425] Fix | Delete
findmnt --fstab -e -v -n -o 'FSTYPE' --source "$_find_dev" | { \
[426] Fix | Delete
while read _fs || [ -n "$_fs" ]; do
[427] Fix | Delete
[[ $_fs ]] || continue
[428] Fix | Delete
[[ $_fs = "autofs" ]] && continue
[429] Fix | Delete
printf "%s" "$_fs"
[430] Fix | Delete
return 0
[431] Fix | Delete
done; return 1; } && return 0
[432] Fix | Delete
[433] Fix | Delete
return 1
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
# find_mp_fsopts <mountpoint>
[437] Fix | Delete
# Echo the filesystem options for a given mountpoint.
[438] Fix | Delete
# /proc/self/mountinfo is taken as the primary source of information
[439] Fix | Delete
# and /etc/fstab is used as a fallback.
[440] Fix | Delete
# No newline is appended!
[441] Fix | Delete
# Example:
[442] Fix | Delete
# $ find_mp_fsopts /;echo
[443] Fix | Delete
# rw,relatime,discard,data=ordered
[444] Fix | Delete
find_mp_fsopts() {
[445] Fix | Delete
if [[ $use_fstab != yes ]]; then
[446] Fix | Delete
findmnt -e -v -n -o 'OPTIONS' --target "$1" 2>/dev/null && return 0
[447] Fix | Delete
fi
[448] Fix | Delete
[449] Fix | Delete
findmnt --fstab -e -v -n -o 'OPTIONS' --target "$1"
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
# find_dev_fsopts <device>
[453] Fix | Delete
# Echo the filesystem options for a given device.
[454] Fix | Delete
# /proc/self/mountinfo is taken as the primary source of information
[455] Fix | Delete
# and /etc/fstab is used as a fallback.
[456] Fix | Delete
# Example:
[457] Fix | Delete
# $ find_dev_fsopts /dev/sda2
[458] Fix | Delete
# rw,relatime,discard,data=ordered
[459] Fix | Delete
find_dev_fsopts() {
[460] Fix | Delete
local _find_dev _opts
[461] Fix | Delete
_find_dev="$1"
[462] Fix | Delete
if ! [[ "$_find_dev" = /dev* ]]; then
[463] Fix | Delete
[[ -b "/dev/block/$_find_dev" ]] && _find_dev="/dev/block/$_find_dev"
[464] Fix | Delete
fi
[465] Fix | Delete
[466] Fix | Delete
if [[ $use_fstab != yes ]]; then
[467] Fix | Delete
findmnt -e -v -n -o 'OPTIONS' --source "$_find_dev" 2>/dev/null && return 0
[468] Fix | Delete
fi
[469] Fix | Delete
[470] Fix | Delete
findmnt --fstab -e -v -n -o 'OPTIONS' --source "$_find_dev"
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
[474] Fix | Delete
# finds the major:minor of the block device backing the root filesystem.
[475] Fix | Delete
find_root_block_device() { find_block_device /; }
[476] Fix | Delete
[477] Fix | Delete
# for_each_host_dev_fs <func>
[478] Fix | Delete
# Execute "<func> <dev> <filesystem>" for every "<dev> <fs>" pair found
[479] Fix | Delete
# in ${host_fs_types[@]}
[480] Fix | Delete
for_each_host_dev_fs()
[481] Fix | Delete
{
[482] Fix | Delete
local _func="$1"
[483] Fix | Delete
local _dev
[484] Fix | Delete
local _ret=1
[485] Fix | Delete
[486] Fix | Delete
[[ "${#host_fs_types[@]}" ]] || return 2
[487] Fix | Delete
[488] Fix | Delete
[489] Fix | Delete
for _dev in "${!host_fs_types[@]}"; do
[490] Fix | Delete
$_func "$_dev" "${host_fs_types[$_dev]}" && _ret=0
[491] Fix | Delete
done
[492] Fix | Delete
return $_ret
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
host_fs_all()
[496] Fix | Delete
{
[497] Fix | Delete
printf "%s\n" "${host_fs_types[@]}"
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function