161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#!/usr/bin/perl -w
261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   Copyright (c) International Business Machines  Corp., 2000
461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   This program is free software;  you can redistribute it and/or modify
661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   it under the terms of the GNU General Public License as published by
761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   the Free Software Foundation; either version 2 of the License, or
861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   (at your option) any later version.
961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
1061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   This program is distributed in the hope that it will be useful,
1161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
1261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
1361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   the GNU General Public License for more details.
1461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
1561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   You should have received a copy of the GNU General Public License
1661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#   along with this program;  if not, write to the Free Software
174548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
1961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
2061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
2161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#  FILE(s)     : maimparts
2237550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman#  DESCRIPTION : Takes the disk device name (ex: hda) and number of iterations
2337550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman#                to run thru and then rips the drive into a defined number of
2437550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman#                partitions ($parts).  This sets up the device for partbeat
2561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#                and backbeat which are called after setup occurs.
2661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
2761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#  WARNING!!!  : The device you specify on the command line (hda/sda/etc) will be
2861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#                blown away...smoking any important data, programs, OS, etc.
2961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#                Don't specify a device name that you don't want to wipe out.
3061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#                YOU HAVE BEEN WARNED!
3161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
3261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#  AUTHOR      : Jeff Martin (martinjn@us.ibm.com)
3337550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman#  HISTORY     :
3461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#
3561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
3661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# target is device to split into partions
3761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$target=$ARGV[0];
3861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$iterations=$ARGV[1];
3961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# part is the number of partitions to split the drive into (max is 4)
4061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$parts=3;
4161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# fsid is the partition id or type (83 is linux native)
4261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$fstype=$ARGV[2];
4361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$fsid=0x83;
4461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
4561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaoif (!$ARGV[0]) {
4661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    print "Usage: maimparts [target device ie: hda or sda] [iterations]\n";
4761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    exit;
4837550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman    }
4937550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman# run sfdisk to display device geometry and rip out info
5061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# (specifically cylinders)
5161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$Geom = `/sbin/sfdisk -g /dev/$target`;
5261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaochomp $Geom;
5361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao($Junk,$Temp1) = split(/\: /,$Geom,2);
5461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao($Cyl,$Heads,$Sec) = split(/\, /,$Temp1,3);
5561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao($Cyl,$Junk) = split(/ /,$Cyl,2);
5661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao($Heads,$Junk) = split(/ /,$Heads,2);
5761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao($Sec,$Junk) = split(/ /,$Sec,2);
5861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
5937550cf5a86c7ca7424a2a318dd64e550f13f5dfChris Dearman# determine partition size to create (force int so we don't
6061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# try to use 1/2 a cylinder!)
6161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$psize = int($Cyl/$parts);
6261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
6361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# create a config file in /tmp for sfdisk creation run
6461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaoopen(CONFIG,">/tmp/part.cfg") ||
6561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    die "Couldn't create /tmp/part.cfg\n";
6661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaofor($i=1;$i<=$parts;$i++) {
6761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    printf(CONFIG ",%d,%x\n",$psize,$fsid); # write the lines in cfg
6861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    }
6961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaoclose(CONFIG);
7061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
7161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao# create the partitions!
7261037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao`sfdisk --force /dev/$target < /tmp/part.cfg`;
7361037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao
7461037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao#run partbeat on the partitions
7561037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaofor ($k=1;$k<=$parts;$k++) {
7661037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    $part[$k] = sprintf("%s%d",$target,$k);
7761037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    $tmp = `./partbeat /dev/$target$k $iterations $fstype`;
7861037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    print $tmp;
7961037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao    }
8061037e1eb051a155908f1d038b5b156a3f661023Wanlong Gao$tmp = `./backbeat /dev/$part[1] /dev/$part[2] /dev/$part[3]`;
8161037e1eb051a155908f1d038b5b156a3f661023Wanlong Gaoprint $tmp;
82