#!/bin/bash

ROOT_PARTITION=`mount | grep " on / type" | awk '{ print $1 }'`

if [ "$ROOT_PARTITION" = "" ]; then
  echo "Can't find root device...\n";
  exit
fi

ROOT_DEVICE=${ROOT_PARTITION::-1}

TOTAL=`df | grep $ROOT_PARTITION | awk '{ print $2 }'`
USED=`df | grep $ROOT_PARTITION | awk '{ print $3 }'`
AVAILABLE=`df | grep $ROOT_PARTITION | awk '{ print $4 }'`

ROOT_DEVICE_SIMPLE=`echo $ROOT_DEVICE | cut -d/ -f3`

TOTAL=$(( $TOTAL / 1024 ))
USED=$(( $USED / 1024 ))
AVAILABLE=$(( $AVAILABLE / 1024 ))

if [ ! -e "/sys/block/$ROOT_DEVICE_SIMPLE/device/block/$ROOT_DEVICE_SIMPLE/size" ]; then
  exit
fi

REAL_SIZE=`sudo hdparm -I $ROOT_DEVICE | grep "device size with M = 1024" | awk '{ print $7 }'`

SIZE_DIFF=`expr $REAL_SIZE - $TOTAL`

#echo "#### $ROOT_PARTITION - $ROOT_DEVICE - $TOTAL - $USED - $AVAILABLE - $REAL_SIZE - $ROOT_DEVICE_SIMPLE - $SIZE_DIFF"

echo -n "$TOTAL#$REAL_SIZE#$SIZE_DIFF#$ROOT_PARTITION"

