-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfind-mmc-bypartlabel
56 lines (51 loc) · 1.78 KB
/
find-mmc-bypartlabel
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
#!/bin/sh
#
# Tool for finding mmc device node path based on it's part label.
#
# Copyright (C) 2015 Jolla Ltd.
# Contact: Kalle Jokiniemi <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# Pass the partition label name as $1
if [ -z "$1" ]; then
echo "$0: Error, no label name given!" > /dev/kmsg
exit 1
fi
if [ ! -d /sys/class/block ]; then
echo "$0: Error, please mount sysfs" > /dev/kmsg
exit 1
fi
while [ ! -d /sys/class/block/mmcblk[01]p* ] && [ ! -d /sys/class/block/sda ] ; do
echo "find-mmc-bypartlabel: Waiting for /sys/class/block/mmcblk[01]p*..." > /dev/kmsg
i=$(( ${i:-0} + 1 ))
sleep 0.5
if [ $i -eq 10 ]; then
echo "find-mmc-bypartlabel: Error: timeout waiting for /sys/class/block/mmcblk[01]p*" > /dev/kmsg
exit 1
fi
done
while [ ${i:-0} -le 50 ] ; do
for mmc_sysfs in /sys/class/block/mmcblk[01]p*/ /sys/class/block/sda*/; do
if grep -q -w PARTNAME="$1" "$mmc_sysfs"/uevent 2> /dev/null; then
FIMAGE_DEV_NAME=$(echo $mmc_sysfs | cut -d "/" -f 5)
echo "/dev/$FIMAGE_DEV_NAME"
exit 0
fi
done
sleep 0.1
i=$(( ${i:-0} + 1 ))
done
echo "$0: Error, could not find partition label \"$1\"" > /dev/kmsg
exit 1