source: MondoRescue/branches/2.05/mindi/aux-tools/sbin/calc-disk-size@ 196

Last change on this file since 196 was 196, checked in by bcornec, 18 years ago

Usage of parted2fdisk instead of fdisk everywhere.
on ia64 this is mandatory, and simplifies the infrastructure
on other archs, it doesn't change anything as parted2fdisk here is a link to fdisk

  • Property svn:keywords set to Id
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=`parted2fdisk -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=`parted2fdisk -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.