#!/bin/sh SFDISK="`which sfdisk`" DMSETUP="`which dmsetup`" if test -z "$1"; then echo "Syntax: $0 " exit 1 fi DEVDIR="`dirname \"\$1\"`" DEVFILE="`basename \"\$1\"`" if ! echo "$DEVDIR" | grep '^/' &> /dev/null; then DEVDIR="`pwd`/$DEVDIR/" else DEVDIR="$DEVDIR/" fi while echo "$DEVDIR" | grep '/\./' &> /dev/null; do DEVDIR="`echo \"\$DEVDIR\" | sed -e 's/\/\.\//\//g'`" done while echo "$DEVDIR" | grep '/[^/][^/]*/\.\./' &> /dev/null; do DEVDIR="`echo \"\$DEVDIR\" | sed -e 's/\/[^/][^/]*\/\.\.\//\//g'`" done DEVICE="$DEVDIR$DEVFILE" if ! test -b "$DEVICE" -a -r "$DEVICE"; then echo "Error: Block device $1 can't be accessed" exit 1 fi if ! test -n "$SFDISK" -a -x "$SFDISK"; then echo "Error: sfdisk utility not found" exit 1 fi if ! test -n "$DMSETUP" -a -x "$DMSETUP"; then echo "Error: dmsetup utility not found" exit 1 fi if test -L "$DEVICE"; then DEVICE_="`readlink \"\$DEVICE\"`" DEVDIR_="`dirname \"\$DEVICE_\"`" DEVFILE_="`basename \"\$DEVICE_\"`" if ! echo "$DEVDIR_" | grep '^/' &> /dev/null; then DEVDIR_="$DEVDIR$DEVDIR_/" else DEVDIR_="$DEVDIR_/" fi while echo "$DEVDIR_" | grep '/\./' &> /dev/null; do DEVDIR_="`echo \"\$DEVDIR_\" | sed -e 's/\/\.\//\//g'`" done while echo "$DEVDIR_" | grep '/[^/][^/]*/\.\./' &> /dev/null; do DEVDIR_="`echo \"\$DEVDIR_\" | sed -e 's/\/[^/][^/]*\/\.\.\//\//g'`" done DEVICE_="$DEVDIR_$DEVFILE_" else DEVICE_="$DEVICE" fi TMP="/tmp/partscript.$$" "$SFDISK" -d "$DEVICE" | grep "^ *$DEVDIR" | sed -e 's/[=,]/ /g' | awk '{ print $1 " " $4 " " $6 }' | \ while read DEV START SIZE; do DEV="`echo \"\$DEV\" | sed -e 's/^\/dev\///' -e 's/\//-/g'`" test "$SIZE" -gt 0 || continue echo $DEV $START $SIZE echo "0 $SIZE linear $DEVICE_ $START" > $TMP "$DMSETUP" create $DEV $TMP done