-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
147 lines (109 loc) · 4.53 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
getDeviceFile() {
local device=$1
local option=$2
local name=$3
local i
if [ -n "$device" ]; then
if [ -e "$device" ] && echo "$device" | grep -qe '^\/dev\/'; then
device="$(readlink -f "$device")"
local dev="/dev/block/$(basename "$device")"
if [ ! -e "$dev" ]; then
ln -s "$device" "$dev"
fi
echo "$dev"
return 0
elif [ -f "$SRCDST/$(echo "$device" | sed 's/^\///')" ] || [ -f "$device" ]; then
if [ -f "$SRCDST/$(echo "$device" | sed 's/^\///')" ]; then
device="$SRCDST/$(echo "$device" | sed 's/^\///')"
fi
# Check to see if this file is an actual file system contained file
# or something like a cpio.gz file (ramdisk)
if [ "$option" != "nodev" ] || ! zcat -t "$device" > /dev/null 2>&1; then
for i in `seq 0 9`; do
if ! losetup /dev/loop$i > /dev/null 2>&1; then
if losetup /dev/loop$i "$(readlink -f "$device")" > /dev/null 2>&1; then
local dev="/dev/block/loop$i"
ln -s "/dev/loop$i" "$dev"
echo "$dev";
return 0
fi
fi
done
else
echo "$(readlink -f "$device")"; return 0
fi
return 1
fi
# So far I have never seen any x86 android kernels that supports /dev/disk/
# but in case there is one or there will be in the future, let's
# start by checking that, before using blkid to do a search.
if echo "$device" | grep -qe '^LABEL='; then
local label="$(echo $device | cut -d '=' -f 2)"
if [ -e "/dev/disk/by-label/$label" ]; then
echo $(getDeviceFile "/dev/disk/by-label/$label" "$option" "$name"); return $?
fi
device="LABEL=\"$label\""
elif echo "$device" | grep -qe '^UUID='; then
local uuid="$(echo $device | cut -d '=' -f 2)"
if [ -e "/dev/disk/by-uuid/$uuid" ]; then
echo $(getDeviceFile "/dev/disk/by-uuid/$uuid" "$option" "$name"); return $?
fi
device="UUID=\"$uuid\""
elif echo "$device" | grep -qe '^PARTLABEL='; then
local label="$(echo $device | cut -d '=' -f 2)"
if [ -e "/dev/disk/by-partlabel/$label" ]; then
echo $(getDeviceFile "/dev/disk/by-partlabel/$label" "$option" "$name"); return $?
fi
device="PARTLABEL=\"$label\""
elif echo "$device" | grep -qe '^PARTUUID=='; then
local uuid="$(echo $device | cut -d '=' -f 2)"
if [ -e "/dev/disk/by-partuuid/$uuid" ]; then
echo $(getDeviceFile "/dev/disk/by-partuuid/$uuid" "$option" "$name"); return $?
fi
device="PARTUUID=\"$uuid\""
else
device=
fi
if [ -n "$device" ]; then
for i in `blkid | grep "$device" | cut -d ':' -f 1`; do
if [ -e "$i" ] && echo "$i" | grep -qe '^\/dev\/'; then
echo $(getDeviceFile "$i" "$option" "$name"); return $?
fi
done
fi
# We are looking for the root partition, the one we booted from
if [ "$name" = "root" ] && [ "$option" != "internal" ]; then
for i in `blkid | cut -d ':' -f 1`; do
if mount "$i" "$SRCDST" > /dev/null 2>&1; then
if [ -f "${SRCDST}${BOOT_IMAGE:-/kernel}" ]; then
echo $(getDeviceFile "$i" "internal" "$name");
local res=$?
umount "$SRCDST" > /dev/null 2>&1
return $res
fi
umount "$SRCDST" > /dev/null 2>&1
fi
done
fi
fi
if [ -n "$FSTAB" ] && device="$(grep -e "\(\s\)\+/$name\(\s\)\+" "$FSTAB")"; then
echo $(getDeviceFile "$(echo "$device" | sed 's/^\([^ \t]\+\).*/\1/')" "$option" "$name"); return $?
fi
return 1
}
getDeviceType() {
local device="$1"
if entry="$(blkid "$device" 2> /dev/null | grep TYPE)"; then
echo "$(echo "$entry" | sed 's/.*TYPE=\"\([^\"]\+\)\".*/\1/')"
else
echo "ext4"
fi
return 0
}
printLog() {
local str="$1"
if [ "$DEBUG" = "1" ]; then
echo -e "$str" >> /debug.log
fi
echo -e "$str"
}