Función ogDiskToDev detecta volúmenes lógicos.
git-svn-id: https://opengnsys.es/svn/trunk@378 a21b9725-9963-47de-94b9-378ad31fedc9remotes/github/debian-pkg
parent
a3348ceb3f
commit
271729763c
|
@ -169,7 +169,7 @@ return $OG_ERR_NOTFOUND
|
|||
#@return Para 2 parametros: Devuelve la ruta de la particion indicada.
|
||||
#@exception OG_ERR_FORMAT Formato incorrecto.
|
||||
#@exception OG_ERR_NOTFOUND Dispositivo no detectado.
|
||||
#@note Requisitos: awk
|
||||
#@note Requisitos: awk, lvm
|
||||
#@version 0.9 - Primera versión para OpenGNSys
|
||||
#@author Ramon Gomez, ETSII Universidad Sevilla
|
||||
#@date 2009-07-20
|
||||
|
@ -177,7 +177,7 @@ return $OG_ERR_NOTFOUND
|
|||
function ogDiskToDev () {
|
||||
|
||||
# Variables locales
|
||||
local ALLDISKS DISK PART
|
||||
local ALLDISKS VOLGROUPS DISK PART
|
||||
|
||||
#/// Si se solicita, mostrar ayuda.
|
||||
if [ "$*" == "help" ]; then
|
||||
|
@ -190,28 +190,40 @@ fi
|
|||
|
||||
#/// Listar dispositivo para los discos duros (tipos: 3=hd, 8=sd).
|
||||
ALLDISKS=$(awk '($1==3 || $1==8) && $4!~/[0-9]/ {printf "/dev/%s ",$4}' /proc/partitions)
|
||||
VOLGROUPS=$(vgchange -ay &>/dev/null && vgs -a --noheadings | awk '{printf "/dev/%s ",$1}')
|
||||
ALLDISKS="$ALLDISKS $VOLGROUPS"
|
||||
|
||||
#/// Mostrar salidas segun el número de parametros.
|
||||
case $# in
|
||||
0) # Muestra todos los discos, separados por espacios.
|
||||
echo "$ALLDISKS"
|
||||
;;
|
||||
1) # Error si el parametro no es un digito.
|
||||
[ -z "${1/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT || return $?
|
||||
DISK=$(echo $ALLDISKS | awk -v n=$1 '{print $n}')
|
||||
# Error si no es fichero de bloques.
|
||||
[ -b "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
|
||||
echo "$DISK"
|
||||
;;
|
||||
2) # Error si los 2 parametros no son digitos.
|
||||
[ -z "${1/[1-9]/}" -a -z "${2/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT|| return $?
|
||||
PART=$(echo $ALLDISKS | awk -v n=$1 '{print $n}')$2
|
||||
# Error si no es fichero de bloques.
|
||||
[ -b "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
|
||||
echo "$PART"
|
||||
;;
|
||||
*) # Formato erroneo.
|
||||
ogRaiseError $OG_ERR_FORMAT
|
||||
0) # Muestra todos los discos, separados por espacios.
|
||||
echo $ALLDISKS
|
||||
;;
|
||||
1) # Error si el parámetro no es un digito.
|
||||
[ -z "${1/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT || return $?
|
||||
DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
|
||||
# Error si el fichero no existe.
|
||||
[ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
|
||||
echo "$DISK"
|
||||
;;
|
||||
2) # Error si los 2 parámetros no son digitos.
|
||||
[ -z "${1/[1-9]/}" -a -z "${2/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT|| return $?
|
||||
DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
|
||||
[ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
|
||||
PART="$DISK$2"
|
||||
#/// Comprobar si es partición.
|
||||
if [ -b "$PART" ]; then
|
||||
echo "$PART"
|
||||
elif [ -n "$VOLGROUPS" ]; then
|
||||
#/// Comprobar si volumen lógico.
|
||||
PART=$(lvscan -a 2>/dev/null | grep "'$DISK/" | awk -v n=$2 -F\' '{if (NR==n) print $2}')
|
||||
[ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
|
||||
echo "$PART"
|
||||
else
|
||||
ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
|
||||
fi
|
||||
;;
|
||||
*) # Formato erroneo.
|
||||
ogRaiseError $OG_ERR_FORMAT
|
||||
return $OG_ERR_FORMAT
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -87,7 +87,7 @@ return $ERRCODE
|
|||
function ogExtendFs () {
|
||||
|
||||
# Variables locales.
|
||||
local PART
|
||||
local PART PROG PARAMS
|
||||
|
||||
#/// Si se solicita, mostrar ayuda.
|
||||
if [ "$*" == "help" ]; then
|
||||
|
@ -105,16 +105,32 @@ ogUnmount $1 $2 >/dev/null
|
|||
#/// Redimensionar al tamano máximo según el tipo de partición.
|
||||
TYPE=$(ogGetFsType $1 $2)
|
||||
case "$TYPE" in
|
||||
EXT[234])
|
||||
resize2fs -f $PART ;;
|
||||
REISERFS)
|
||||
resize_reiserfs -f $PART ;;
|
||||
NTFS|HNTFS)
|
||||
ntfsresize -f $PART <<<"y" ;;
|
||||
*) ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
|
||||
return $? ;;
|
||||
EXT[234]) PROG="resize2fs"; PARAMS="-f" ;;
|
||||
REISERFS) PROG="resize_reiserfs"; PARAMS="-f" ;;
|
||||
NTFS|HNTFS) PROG="ntfsresize"; PARAMS="<<<\"y\" -f" ;;
|
||||
*) ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
|
||||
return $? ;;
|
||||
esac
|
||||
[ $? == 0 ] || ogRaiseError $OG_ERR_PARTITION "$1 $2"
|
||||
#/// Error si el sistema de archivos está montado o bloqueado.
|
||||
if ogIsMounted $1 $2; then
|
||||
ogRaiseError $OG_ERR_PARTITION "$1 $2" # Indicar nuevo error
|
||||
return $?
|
||||
fi
|
||||
if ogIsLocked $1 $2; then
|
||||
ogRaiseError $OG_ERR_LOCKED "$1 $2"
|
||||
return $?
|
||||
fi
|
||||
#/// Redimensionar en modo uso exclusivo.
|
||||
ogLock $1 $2
|
||||
eval $PROG $PARAMS $PART
|
||||
ERRCODE=$?
|
||||
case $ERRCODE in
|
||||
0) ;;
|
||||
127) ogRaiseError $OG_ERR_NOTEXEC "$PROG" ;;
|
||||
*) ogRaiseError $OG_ERR_PARTITION "$1 $2" ;;
|
||||
esac
|
||||
ogUnlock $1 $2
|
||||
return $ERRCODE
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue