source: trunk/mindi/aux-tools/sbin/calc-disk-size @ 1

Last change on this file since 1 was 1, checked in by bcornec, 14 years ago

Initial import from latest mondo-2.04_cvs_20050503/mindi-1.04_cvs_20050503 on http://www.mondorescue.org

File size: 1.3 KB
Line 
1#!/bin/sh
2
3# patched by Doug Nordwall, June 28th 2000, to fix a SCSI disk size
4# calculation bug; nice one, Doug! :-)      - HR
5
6CalcDiskSize() {
7    local res cylinders sectorsize disksize i curr stub out
8    res=`fdisk -l $1 2> /dev/null | grep -i "cylinders of"`
9    cylinders=`echo "$res" | cut -d' ' -f5`
10    sectorsize=`echo "$res" | cut -d' ' -f7`
11    cylindermod=`fdisk -l $1 2> /dev/null | grep -i $1:`; # note colon at end to make sure it's not the /dev/sda# partition info
12    cylnum=`echo "$cylindermod" | cut -d' ' -f7`
13    predisksize=$(($cylinders*$sectorsize/1024))
14    disksize=$(($predisksize*$cylnum/1024)); # this works on larger drives; I imagine it'll work on smaller drives with fewer cylinders...
15
16#echo "cylinders = $cylinders; sectorsize = $sectorsize"
17#echo "cylnum = $cylnum"
18#echo "predisksize = $predisksize; disksize = $disksize"
19
20    if [ "$disksize" = "" ] ; then
21    return 1
22    else
23    echo "$disksize"
24        return 0
25    fi
26}
27
28# ---------------- main ---------------
29
30if [ "$#" -ne "1" ] || [ "`echo "$1" |grep -x "/dev/[a-z]*"`" = "" ]; then
31    LogIt "calc-disk-size <device>" 1
32    exit 1
33fi
34
35LogIt "calc-disk-size --- starting"
36out=`CalcDiskSize $1`
37if [ "$out" = "" ] ; then
38    echo "-1"
39else
40    echo "$out"
41fi
42
43LogIt "calc-disk-size --- leaving"
44
45exit
46
47
Note: See TracBrowser for help on using the repository browser.