base-files: add mtd_find_chardev helper
authorGabor Juhos <juhosg@openwrt.org>
Wed, 12 Dec 2012 16:49:50 +0000 (16:49 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 12 Dec 2012 16:49:50 +0000 (16:49 +0000)
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 34648

package/base-files/files/lib/functions.sh

index b3a3885f2d62c0e6ad182351e60a50a25b507047..b924fce2858ccdb976c371995898610df404f09b 100755 (executable)
@@ -220,13 +220,27 @@ include() {
        done
 }
 
-find_mtd_part() {
+find_mtd_index() {
        local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
+       local INDEX="${PART##mtd}"
+
+       echo ${INDEX}
+}
+
+find_mtd_part() {
+       local INDEX=$(find_mtd_index "$1")
        local PREFIX=/dev/mtdblock
 
-       PART="${PART##mtd}"
        [ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
-       echo "${PART:+$PREFIX$PART}"
+       echo "${INDEX:+$PREFIX$INDEX}"
+}
+
+find_mtd_chardev() {
+       local INDEX=$(find_mtd_index "$1")
+       local PREFIX=/dev/mtd
+
+       [ -d /dev/mtd ] && PREFIX=/dev/mtd/
+       echo "${INDEX:+$PREFIX$INDEX}"
 }
 
 strtok() { # <string> { <variable> [<separator>] ... }