From d2e3c016d7dc89001f68df48b02a592f31bdfa82 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Mon, 28 Jan 2013 20:57:00 -0700 Subject: [PATCH] esata: new known state partitioned Properly determines a registered state independently of a partitioned drive. Before, the script simply looked for /dev/sdX2 to determine registration state. This would be inaccurate when a drive with no partition table was registered. --- esata | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/esata b/esata index 87f08ae..f95995a 100755 --- a/esata +++ b/esata @@ -5,13 +5,16 @@ # # Add, remove, mount, and unmount external SATA drives -DEV=/dev/sdb2 +BASEDEV=/dev/sdc +PARTITION=2 MNT=/media/esata +SCSIDEV=3 # This can change based on OS, bus enumeration, etc. +# ---- +DEV=${BASEDEV}${PARTITION} DELAY=5 -SCSIDEV=1 # This can change based on OS, etc. registered() { - if [ -b "$DEV" ]; then + if [ -b "$BASEDEV" ]; then [ -n "$VERBOSE" ] && echo "registered" return 0 else @@ -20,6 +23,16 @@ registered() { fi } +partitioned() { + if [ -b "$DEV" ]; then + [ -n "$VERBOSE" ] && echo "partitioned" + return 0 + else + [ -n "$VERBOSE" ] && echo "not partitioned" + return 1 + fi +} + mounted() { if mount | grep -q "$MNT"; then [ -n "$VERBOSE" ] && echo "mounted" @@ -43,6 +56,7 @@ doregister() { domount() { mounted && return 0 doregister || return 1 + partitioned || return 1 [ -n "$VERBOSE" ] && echo "mount SATA $DEV" mkdir -p "$MNT" || return 1 mount "$DEV" "$MNT" || return 1 @@ -94,7 +108,8 @@ elif [ "$1" = "umount" -o "$1" = "unmount" ]; then fi elif [ "$1" = "register" ]; then if doregister; then - echo "esata registered as $DEV" + echo "esata drive registered as $BASEDEV" + partitioned || echo "WARNING: drive is not partitioned" else echo "$0: cannot register esata" >&2 exit 1 @@ -103,7 +118,8 @@ elif [ "$1" = "status" ]; then if mounted; then echo "esata mounted on $MNT" elif registered; then - echo "esata registered as $DEV but not mounted" + echo "esata registered as $BASEDEV but not mounted" + partitioned || echo "WARNING: drive is not partitioned" else echo "esata is unregistered" fi -- 2.39.2