#!/bin/sh . /etc/init.d/globals MOUNTBASE=/mnt MOUNTPOINT="$MOUNTBASE/$MDEV" ROOTDEV=$(readlink /dev/root) BLOCKS="/sys/block/mmcblk0/mmcblk0p*/uevent" KERNELDEV="" K_PARTNAME="" ROOTFSDEV="" R_PARTNAME="" ROOTSUBDIR="" NEWLAYOUT=0 # to use partnames in old layout, set it to 1 USE_PARTNAMES=0 # check_mmcblk() { devname="" partname="" for i in $BLOCKS;do if [ "$i" != "$BLOCKS" ];then devname=$(cat $i | grep DEVNAME | cut -d '=' -f 2) if [ "$devname" == "$MDEV" ];then partname=$(cat $i | grep PARTNAME | cut -d '=' -f 2) if [ -n "$(echo $partname | grep 'kernel')" ];then KERNELDEV=$devname K_PARTNAME=$partname break elif [ -n "$(echo $partname | grep 'rootfs')" ];then ROOTFSDEV=$devname R_PARTNAME=$partname if [ -n "$(echo $partname | grep 'linuxrootfs')" ];then NEWLAYOUT=1 R_PARTNAME="linuxrootfs1" fi break elif [ -n "$(echo $partname | grep 'userdata')" ];then ROOTFSDEV=$devname R_PARTNAME=$partname NEWLAYOUT=1 break fi fi fi done [ "$partname" == "swap" -o "$partname" == "swapdata" ] && exit 0 [ "$NEWLAYOUT" == "1" -o "$USE_PARTNAMES" == "1" ] && MOUNTPOINT="$MOUNTBASE/$R_PARTNAME" } # read_cmdline() { for param in $(cat /proc/cmdline);do if [ -n "$(echo $param | grep rootsubdir)" ];then ROOTSUBDIR=$(echo $param | cut -d '=' -f 2) break fi done } # check partition names check_mmcblk # do not add or remove root device again... [ "$ROOTDEV" = "$MDEV" -a "$R_PARTNAME" != "userdata" ] && exit 0 if [ -e /tmp/.nomdevmount ]; then LOGINFO "no action on $MDEV -- /tmp/.nomdevmount exists" exit 0 fi case "$ACTION" in add) # do not mount kernel partitions if [ "$KERNELDEV" == "$MDEV" ];then LOGINFO "[$ACTION] /dev/$MDEV is a kernel partition [$K_PARTNAME] - not mounting." exit 0 fi # TODO: check for partitions if [ "$NEWLAYOUT" == "1" ];then if grep -q $MOUNTPOINT /proc/mounts; then LOGINFO "/dev/$MDEV already mounted [$R_PARTNAME] - not mounting again" exit 0 fi mkdir -p /tmp/$MDEV mount -t auto /dev/$MDEV /tmp/$MDEV 2>&1 >/dev/null RET=$? [ $RET != 0 ] && LOGWARN "mount /dev/$MDEV to /tmp/$MDEV failed with $RET" && rmdir /tmp/$MDEV if [ "$R_PARTNAME" == "linuxrootfs1" ];then LOGINFO "mounting /dev/$MDEV [$R_PARTNAME] to $MOUNTPOINT" mkdir -p $MOUNTPOINT mount --bind /tmp/$MDEV/linuxrootfs1 $MOUNTPOINT elif [ "$R_PARTNAME" == "userdata" ];then # parse cmdline for rootsubdir read_cmdline for i in /tmp/$MDEV/*;do if [ -n "$(echo $i | grep linuxrootfs)" ];then if [ "$ROOTSUBDIR" == "$(basename $i)" ];then LOGINFO "/dev/$MDEV rootsubdir [$ROOTSUBDIR] is already mounted as root" continue fi MOUNTPOINT="$MOUNTBASE/$(basename $i)" if grep -q $MOUNTPOINT /proc/mounts; then LOGINFO "/dev/$MDEV already mounted [$(basename $i)] - not mounting again" else LOGINFO "mounting /dev/$MDEV [$(basename $i)] to $MOUNTPOINT" mkdir -p $MOUNTPOINT mount --bind /tmp/$MDEV/$(basename $i) $MOUNTPOINT fi fi done fi umount -lf /tmp/$MDEV RET=$? if [ $RET = 0 ]; then rmdir /tmp/$MDEV else LOGWARN "umount /tmp/$MDEV failed with $RET" fi else if grep -q "/dev/$MDEV" /proc/mounts; then LOGINFO "/dev/$MDEV already mounted - not mounting again" exit 0 fi LOGINFO "[$ACTION] mounting /dev/$MDEV to $MOUNTPOINT" # remove old mountpoint symlinks we might have for this device rm -f $MOUNTPOINT mkdir -p $MOUNTPOINT mount -t auto /dev/$MDEV $MOUNTPOINT 2>&1 >/dev/null RET=$? if [ $RET != 0 ]; then LOGWARN "mount /dev/$MDEV $MOUNTPOINT failed with $RET" LOGWARN " $OUT1" rmdir $MOUNTPOINT fi fi ;; # I think never comes a 'remove' from mdev, because never the mmcblock will be removed # It can be used for manually ( or per script ) umounting remove) LOGINFO "[$ACTION] unmounting $MOUNTBASE/$MDEV" grep -q "$MOUNTBASE/$MDEV " /proc/mounts || exit 0 # not mounted... umount -lf $MOUNTBASE/$MDEV RET=$? if [ $RET = 0 ]; then rmdir $MOUNTBASE/$MDEV else LOGWARN "umount $MOUNTBASE/$MDEV failed with $RET" fi ;; esac