source: client/engine/Disk.lib @ 16fc7ab

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 16fc7ab was 12d6d5b, checked in by ramon <ramongomez@…>, 9 years ago

#724: Sustituir sfdisk por partx en función ogGetPartitionsNumber debido al cambio en la salida del 1er comando a partir de Ubuntu 15.10.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4912 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 53.4 KB
Line 
1#!/bin/bash
2#/**
3#@file    Disk.lib
4#@brief   Librería o clase Disk
5#@class   Disk
6#@brief   Funciones para gestión de discos y particiones.
7#@version 1.1.0
8#@warning License: GNU GPLv3+
9#*/
10
11
12# Función ficticia para lanzar parted con timeout, evitando cuelgues del programa.
13function parted ()
14{
15timeout -k 5s -s KILL 3s $(which parted) "$@"
16}
17
18
19#/**
20#         ogCreatePartitions int_ndisk str_parttype:int_partsize ...
21#@brief   Define el conjunto de particiones de un disco.
22#@param   int_ndisk      nº de orden del disco
23#@param   str_parttype   mnemónico del tipo de partición
24#@param   int_partsize   tamaño de la partición (en KB)
25#@return  (nada, por determinar)
26#@exception OG_ERR_FORMAT    formato incorrecto.
27#@exception OG_ERR_NOTFOUND  disco o partición no detectado (no es un dispositivo).
28#@exception OG_ERR_PARTITION error en partición o en tabla de particiones.
29#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
30#@attention Pueden definirse particiones vacías de tipo \c EMPTY
31#@attention No puede definirse partición de cache y no se modifica si existe.
32#@note    Requisitos: sfdisk, parted, partprobe, awk
33#@todo    Definir atributos (arranque, oculta) y tamaños en MB, GB, etc.
34#@version 0.9 - Primera versión para OpenGnSys
35#@author  Ramon Gomez, ETSII Universidad de Sevilla
36#@date    2009/09/09
37#@version 0.9.1 - Corrección del redondeo del tamaño del disco.
38#@author  Ramon Gomez, ETSII Universidad de Sevilla
39#@date    2010/03/09
40#@version 1.0.4 - Llamada a función específica para tablas GPT.
41#@author  Universidad de Huelva
42#@date    2012/03/30
43#*/ ##
44function ogCreatePartitions ()
45{
46# Variables locales.
47local ND DISK PTTYPE PART SECTORS START SIZE TYPE CACHEPART CACHESIZE EXTSTART EXTSIZE tmpsfdisk
48# Si se solicita, mostrar ayuda.
49if [ "$*" == "help" ]; then
50    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \
51           "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
52    return
53fi
54# Error si no se reciben al menos 2 parámetros.
55[ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
56
57# Nº total de sectores, para evitar desbordamiento (evitar redondeo).
58ND="$1"
59DISK=$(ogDiskToDev "$ND") || return $?
60PTTYPE=$(ogGetPartitionTableType $1)
61PTTYPE=${PTTYPE:-"MSDOS"}               # Por defecto para discos vacíos.
62case "$PTTYPE" in
63    GPT)   ogCreateGptPartitions "$@"
64           return $? ;;
65    MSDOS) ;;
66    *)     ogRaiseError $OG_ERR_PARTITION "$PTTYPE"
67           return $? ;;
68esac
69SECTORS=$(ogGetLastSector $1)
70# Se recalcula el nº de sectores del disco 1, si existe partición de caché.
71CACHEPART=$(ogFindCache 2>/dev/null)
72[ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}')
73[ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE]
74# Sector de inicio (la partición 1 empieza en el sector 63).
75START=63
76PART=1
77
78# Fichero temporal de entrada para "sfdisk"
79tmpsfdisk=/tmp/sfdisk$$
80trap "rm -f $tmpsfdisk" 1 2 3 9 15
81
82echo "unit: sectors" >$tmpsfdisk
83echo                >>$tmpsfdisk
84
85# Generar fichero de entrada para "sfdisk" con las particiones.
86shift
87while [ $# -gt 0 ]; do
88    # Conservar los datos de la partición de caché.
89    if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then
90        echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk
91        PART=$[PART+1]
92    fi
93    # Leer formato de cada parámetro - Tipo:Tamaño
94    TYPE="${1%%:*}"
95    SIZE="${1#*:}"
96    # Obtener identificador de tipo de partición válido.
97    ID=$(ogTypeToId "$TYPE" MSDOS)
98    [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $?
99    # Comprobar tamaño numérico y convertir en sectores de 512 B.
100    [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $?
101    SIZE=$[SIZE*2]
102    # Comprobar si la partición es extendida.
103    if [ $ID = 5 ]; then
104        [ $PART -le 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
105        EXTSTART=$START
106        EXTSIZE=$SIZE
107    fi
108    # Incluir particiones lógicas dentro de la partición extendida.
109    if [ $PART = 5 ]; then
110        [ -n "$EXTSTART" ] || ogRaiseError $OG_ERR_FORMAT || return $?
111        START=$EXTSTART
112        SECTORS=$[EXTSTART+EXTSIZE]
113    fi
114    # Generar datos para la partición.
115    echo "$DISK$PART : start=$START, size=$SIZE, Id=$ID" >>$tmpsfdisk
116    # Error si se supera el nº total de sectores.
117    START=$[START+SIZE]
118    [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $?
119    PART=$[PART+1]
120    shift
121done
122# Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché.
123while [ $PART -le 4 ]; do
124    if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then
125        echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk
126    else
127        echo "$DISK$PART : start=0, size=0, Id=0" >>$tmpsfdisk
128    fi
129    PART=$[PART+1]
130done
131# Si se define partición extendida sin lógicas, crear particion 5 vacía.
132if [ $PART = 5 -a -n "$EXTSTART" ]; then
133    echo "${DISK}5 : start=$EXTSTART, size=$EXTSIZE, Id=0" >>$tmpsfdisk
134fi
135
136# Desmontar los sistemas de archivos del disco antes de realizar las operaciones.
137ogUnmountAll $ND 2>/dev/null
138[ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null
139
140# Si la tabla de particiones no es valida, volver a generarla.
141ogCreatePartitionTable $ND
142# Definir particiones y notificar al kernel.
143sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && partprobe $DISK
144rm -f $tmpsfdisk
145[ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null
146}
147
148
149#/**
150#         ogCreateGptPartitions int_ndisk str_parttype:int_partsize ...
151#@brief   Define el conjunto de particiones de un disco GPT
152#@param   int_ndisk      nº de orden del disco
153#@param   str_parttype   mnemónico del tipo de partición
154#@param   int_partsize   tamaño de la partición (en KB)
155#@return  (nada, por determinar)
156#@exception OG_ERR_FORMAT    formato incorrecto.
157#@exception OG_ERR_NOTFOUND  disco o partición no detectado (no es un dispositivo).
158#@exception OG_ERR_PARTITION error en partición o en tabla de particiones.
159#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
160#@attention Pueden definirse particiones vacías de tipo \c EMPTY
161#@attention No puede definirse partición de caché y no se modifica si existe.
162#@note    Requisitos: sfdisk, parted, partprobe, awk
163#@todo    Definir atributos (arranque, oculta) y tamaños en MB, GB, etc.
164#@version 1.0.4 - Primera versión para OpenGnSys
165#@author  Universidad de Huelva
166#@date    2012/03/30
167#*/ ##
168function ogCreateGptPartitions ()
169{
170# Variables locales.
171local ND DISK PART SECTORS ALIGN START SIZE TYPE CACHEPART CACHESIZE DELOPTIONS OPTIONS
172# Si se solicita, mostrar ayuda.
173if [ "$*" == "help" ]; then
174    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \
175           "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
176    return
177fi
178# Error si no se reciben menos de 2 parámetros.
179[ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
180
181# Nº total de sectores, para evitar desbordamiento (evitar redondeo).
182ND="$1"
183DISK=$(ogDiskToDev "$ND") || return $?
184# Se calcula el ultimo sector del disco (total de sectores usables)
185SECTORS=$(ogGetLastSector $1)
186# Se recalcula el nº de sectores del disco si existe partición de caché.
187CACHEPART=$(ogFindCache 2>/dev/null)
188[ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}')
189[ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE]
190# Si el disco es GPT empieza en el sector 2048  por defecto, pero podria cambiarse
191ALIGN=$(sgdisk -D $DISK 2>/dev/null)
192START=$ALIGN
193PART=1
194
195# Leer parámetros con definición de particionado.
196shift
197
198while [ $# -gt 0 ]; do
199    # Si PART es la cache, nos la saltamos y seguimos con el siguiente numero para conservar los datos de la partición de caché.
200    if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then
201        PART=$[PART+1]
202    fi
203    # Leer formato de cada parámetro - Tipo:Tamaño
204    TYPE="${1%%:*}"
205    SIZE="${1#*:}"
206    # Error si la partición es extendida (no válida en discos GPT).
207    if [ "$TYPE" == "EXTENDED" ]; then
208        ogRaiseError $OG_ERR_PARTITION "EXTENDED"
209        return $?
210    fi
211    # Comprobar si existe la particion actual, capturamos su tamaño para ver si cambio o no
212    PARTSIZE=$(ogGetPartitionSize $ND $PART 2>/dev/null)
213    # En sgdisk no se pueden redimensionar las particiones, es necesario borrarlas y volver a crealas
214    [ $PARTSIZE ] && DELOPTIONS="$DELOPTIONS -d$PART"
215    # Creamos la particion
216    # Obtener identificador de tipo de partición válido.
217    ID=$(ogTypeToId "$TYPE" GPT)
218    [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $?
219    # Comprobar tamaño numérico y convertir en sectores de 512 B.
220    [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $?
221    SIZE=$[SIZE*2]
222    # SIZE debe ser múltiplo de ALIGN, si no gdisk lo mueve automáticamente.
223    DIV=$[$SIZE/$ALIGN]
224    SIZE=$[$DIV*$ALIGN]
225    # En el caso de que la partición sea EMPTY no se crea nada
226    if [ "$TYPE" != "EMPTY" ]; then
227        OPTIONS="$OPTIONS -n$PART:$START:+$SIZE -t$PART:$ID "
228    fi
229    START=$[START+SIZE]
230    # Error si se supera el nº total de sectores.
231    [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $?
232    PART=$[PART+1]
233    shift
234done
235
236# Desmontar los sistemas de archivos del disco antes de realizar las operaciones.
237ogUnmountAll $ND 2>/dev/null
238[ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null
239
240# Si la tabla de particiones no es valida, volver a generarla.
241ogCreatePartitionTable $ND
242# Definir particiones y notificar al kernel.
243# Borramos primero las particiones y luego creamos las nuevas
244sgdisk $DELOPTIONS $OPTIONS $DISK 2>/dev/null && partprobe $DISK
245[ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null
246}
247
248
249#/**
250#         ogCreatePartitionTable int_ndisk [str_tabletype]
251#@brief   Genera una tabla de particiones en caso de que no sea valida, si es valida no hace nada.
252#@param   int_ndisk      nº de orden del disco
253#@param   str_tabletype  tipo de tabla de particiones (opcional)
254#@return  (por determinar)
255#@exception OG_ERR_FORMAT   Formato incorrecto.
256#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
257#@note    tabletype: { MSDOS, GPT }, MSDOS por defecto
258#@note    Requisitos: fdisk, gdisk, parted
259#@version 1.0.4 - Primera versión compatible con OpenGnSys.
260#@author  Universidad de Huelva
261#@date    2012/03/06
262#@version 1.0.6a - Adaptar creación de nueva tabla MSDOS.
263#@author  Ramon Gomez, ETSII Universidad de Sevilla
264#@date    2016/01/29
265#*/ ##
266function ogCreatePartitionTable ()
267{
268# Variables locales.
269local DISK PTTYPE CREATE CREATEPTT
270
271# Si se solicita, mostrar ayuda.
272if [ "$*" == "help" ]; then
273    ogHelp "$FUNCNAME int_ndisk [str_partype]" \
274           "$FUNCNAME 1 GPT" "$FUNCNAME 1"
275    return
276fi
277# Error si no se reciben 1 o 2 parámetros.
278case $# in
279    1)  CREATEPTT="" ;;
280    2)  CREATEPTT="$2" ;;
281    *)  ogRaiseError $OG_ERR_FORMAT
282        return $? ;;
283esac
284
285# Capturamos el tipo de tabla de particiones actual
286DISK=$(ogDiskToDev $1) || return $?
287PTTYPE=$(ogGetPartitionTableType $1)
288PTTYPE=${PTTYPE:-"MSDOS"}               # Por defecto para discos vacíos.
289CREATEPTT=${CREATEPTT:-"$PTTYPE"}
290
291# Si la tabla actual y la que se indica son iguales, se comprueba si hay que regenerarla.
292if [ "$CREATEPTT" == "$PTTYPE" ]; then
293    case "$PTTYPE" in
294        GPT)   [ ! $(sgdisk -p $DISK 2>&1 >/dev/null) ] || CREATE="GPT" ;;
295        MSDOS) [ $(parted -s $DISK print >/dev/null) ] || CREATE="MSDOS" ;;
296    esac
297else
298    CREATE="$CREATEPTT"
299fi
300# Dependiendo del valor de CREATE, creamos la tabla de particiones en cada caso.
301case "$CREATE" in
302    GPT)
303        # Si es necesario crear una tabla GPT pero la actual es MSDOS
304        if [ "$PTTYPE" == "MSDOS" ]; then
305            sgdisk -g $DISK
306        else
307            echo -e "2\nw\nY\n" | gdisk $DISK
308        fi
309        partprobe $DISK 2>/dev/null
310        ;;
311    MSDOS)
312        # Si es necesario crear una tabla MSDOS pero la actual es GPT
313        if [ "$PTTYPE" == "GPT" ]; then
314            sgdisk -Z $DISK
315        fi
316        # Crear y borrar una partición para que la tabla se genere bien.
317        echo -e "o\nn\np\n\n\n\nd\n\nw" | fdisk $DISK
318        partprobe $DISK 2>/dev/null
319        ;;
320esac
321}
322
323
324#/**
325#         ogDeletePartitionTable ndisk
326#@brief   Borra la tabla de particiones del disco.
327#@param   int_ndisk      nº de orden del disco
328#@return  la informacion propia del fdisk
329#@version 0.1 -  Integracion para OpenGnSys
330#@author  Antonio J. Doblas Viso. Universidad de Malaga
331#@date    2008/10/27
332#@version 1.0.4 - Adaptado para su uso con discos GPT
333#@author  Universidad de Huelva
334#@date    2012/03/13
335#*/ ##
336function ogDeletePartitionTable ()
337{
338# Variables locales.
339local DISK
340
341# Si se solicita, mostrar ayuda.
342if [ "$*" == "help" ]; then
343    ogHelp "$FUNCNAME int_ndisk" "$FUNCNAME 1"
344    return
345fi
346# Error si no se reciben 1 parámetros.
347[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
348
349# Obteniendo Identificador linux del disco.
350DISK=$(ogDiskToDev $1) || return $?
351# Crear una tabla de particiones vacía.
352case "$(ogGetPartitionTableType $1)" in
353    GPT)    sgdisk -o $DISK ;;
354    MSDOS)  echo -ne "o\nw" | fdisk $DISK ;;
355esac
356}
357
358
359#/**
360#         ogDevToDisk path_device | LABEL="str_label" | UUID="str_uuid"
361#@brief   Devuelve el nº de orden de dicso (y partición) correspondiente al nombre de fichero de dispositivo o a la etiqueta o UUID del sistema de archivos asociado.
362#@param   path_device  Camino del fichero de dispositivo.
363#@param   str_label    etiqueta de sistema de archivos.
364#@param   str_uuid     UUID de sistema de archivos.
365#@return  int_ndisk (para dispositivo de disco)
366#@return  int_ndisk int_npartition (para dispositivo de partición).
367#@exception OG_ERR_FORMAT   Formato incorrecto.
368#@exception OG_ERR_NOTFOUND Dispositivo no detectado.
369#@note    Solo se acepta en cada llamada 1 de los 3 tipos de parámetros.
370#@version 0.1 -  Integracion para Opengnsys  -  EAC: DiskEAC() en ATA.lib
371#@author  Antonio J. Doblas Viso, Universidad de Malaga
372#@date    2008/10/27
373#@version 0.9 - Primera version para OpenGnSys
374#@author  Ramon Gomez, ETSII Universidad Sevilla
375#@date    2009/07/20
376#@version 1.0.6 - Soporta parámetro con UIID o etiqueta.
377#@author  Ramon Gomez, ETSII Universidad Sevilla
378#@date    2014/07/13
379#*/ ##
380function ogDevToDisk ()
381{
382# Variables locales.
383local DEV d n
384# Si se solicita, mostrar ayuda.
385if [ "$*" == "help" ]; then
386    ogHelp "$FUNCNAME" "$FUNCNAME path_device | LABEL=str_label | UUID=str_uuid" \
387           "$FUNCNAME /dev/sda  =>  1" \
388           "$FUNCNAME /dev/sda1  =>  1 1" \
389           "$FUNCNAME LABEL=CACHE  =>  1 4"
390    return
391fi
392
393# Error si no se recibe 1 parámetro.
394[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
395
396# Obtener dispositivo a partir de camino, etiqueta o UUID.
397DEV="$1"
398case "$DEV" in
399    LABEL=*)    DEV=$(blkid -L "${1#*=}") ;;
400    UUID=*)     DEV=$(blkid -U "${1#*=}") ;;
401esac
402
403# Error si no es fichero de bloques.
404[ -b "$DEV" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
405
406# Procesa todos los discos para devolver su nº de orden y de partición.
407n=1
408for d in $(ogDiskToDev); do
409    [ -n "$(echo $DEV | grep $d)" ] && echo "$n ${DEV#$d}" && return
410    n=$[n+1]
411done
412ogRaiseError $OG_ERR_NOTFOUND "$1"
413return $OG_ERR_NOTFOUND
414}
415
416
417#/**
418#         ogDiskToDev [int_ndisk [int_npartition]]
419#@brief   Devuelve la equivalencia entre el nº de orden del dispositivo (dicso o partición) y el nombre de fichero de dispositivo correspondiente.
420#@param   int_ndisk      nº de orden del disco
421#@param   int_npartition nº de orden de la partición
422#@return  Para 0 parametros: Devuelve los nombres de ficheros  de los dispositivos sata/ata/usb linux encontrados.
423#@return  Para 1 parametros: Devuelve la ruta del disco duro indicado.
424#@return  Para 2 parametros: Devuelve la ruta de la particion indicada.
425#@exception OG_ERR_FORMAT   Formato incorrecto.
426#@exception OG_ERR_NOTFOUND Dispositivo no detectado.
427#@note    Requisitos: awk, lvm
428#@version 0.1 -  Integracion para Opengnsys  -  EAC: Disk() en ATA.lib;  HIDRA: DetectarDiscos.sh
429#@author Ramon Gomez, ETSII Universidad de Sevilla
430#@Date    2008/06/19
431#@author  Antonio J. Doblas Viso, Universidad de Malaga
432#@date    2008/10/27
433#@version 0.9 - Primera version para OpenGnSys
434#@author  Ramon Gomez, ETSII Universidad Sevilla
435#@date    2009-07-20
436#@version 1.0.5 - Comprobación correcta de parámetros para soportar valores > 9.
437#@author  Ramon Gomez, ETSII Universidad Sevilla
438#@date    2013-05-07
439#@version 1.0.6 - Soportar RAID hardware y Multipath.
440#@author  Ramon Gomez, ETSII Universidad Sevilla
441#@date    2014-09-23
442#@version 1.1.0 - Soportar pool de volúmenes ZFS.
443#@author  Ramon Gomez, ETSII Universidad Sevilla
444#@date    2014-11-14
445#*/ ##
446function ogDiskToDev ()
447{
448# Variables locales
449local ALLDISKS MPATH VOLGROUPS ZFSVOLS DISK PART ZPOOL i
450
451# Si se solicita, mostrar ayuda.
452if [ "$*" == "help" ]; then
453    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npartition]" \
454           "$FUNCNAME      =>  /dev/sda /dev/sdb" \
455           "$FUNCNAME 1    =>  /dev/sda" \
456           "$FUNCNAME 1 1  =>  /dev/sda1"
457    return
458fi
459
460# Listar dispositivos de discos duros.
461ALLDISKS=$(lsblk -n | awk '$6~/^disk$/ {gsub(/!/,"/"); printf "/dev/%s ",$1}')
462
463# Listar volúmenes lógicos.
464VOLGROUPS=$(vgs -a --noheadings 2>/dev/null | awk '{printf "/dev/%s ",$1}')
465ALLDISKS="$ALLDISKS $VOLGROUPS"
466
467# Detectar caminos múltiples (ignorar mensaje si no está configurado Multipath).
468if MPATH=$(multipath -l -v 1 2>/dev/null | awk '{printf "/dev/mapper/%s ",$1}'; exit ${PIPESTATUS[0]}); then
469    # Quitar de la lista los discos que forman parte de Multipath.
470    for i in $(multipath -ll | awk '$6=="ready" {printf "/dev/%s ",$3}'); do
471        ALLDISKS="${ALLDISKS//$i/}"
472    done
473    # Añadir caminos múltiples a los discos detectados.
474    ALLDISKS="$ALLDISKS $MPATH"
475fi
476
477# Detectar volúmenes ZFS.
478ZFSVOLS=$(blkid | awk -F: '/zfs/ {print $1}')
479ALLDISKS="$ALLDISKS $ZFSVOLS"
480
481# Mostrar salidas segun el número de parametros.
482case $# in
483    0)  # Muestra todos los discos, separados por espacios.
484        echo $ALLDISKS
485        ;;
486    1)  # Error si el parámetro no es un número positivo.
487        [[ "$1" =~ ^[1-9][0-9]*$ ]] || ogRaiseError $OG_ERR_FORMAT "$1" || return $?
488        DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
489        # Error si el fichero no existe.
490        [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
491        echo "$DISK"
492        ;;
493    2)  # Error si los 2 parámetros no son números positivos.
494        [[ "$1" =~ ^[1-9][0-9]*$ ]] && [[ "$2" =~ ^[1-9][0-9]*$ ]] || ogRaiseError $OG_ERR_FORMAT "$1 $2" || return $?
495        DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}')
496        [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $?
497        PART="$DISK$2"
498        # Comprobar si es partición.
499        if [ -b "$PART" ]; then
500            echo "$PART"
501        else
502            # Comprobar si RAID o Multipath (tener en cuenta enlace simbólico).
503            PART="${DISK}p$2"
504            if [ "$(stat -L -c "%A" "$PART" 2>/dev/null | cut -c1)" == "b" ]; then
505                echo "$PART"
506            else
507                PART=""
508                # Comprobar si volumen lógico.          /* (comentario Doxygen)
509                if ogCheckStringInGroup "$DISK" "$VOLGROUPS"; then
510                    PART=$(lvscan -a 2>/dev/null | \
511                           awk -F\' -v n=$2 "\$2~/^${DISK//\//\\/}\// {if (NR==n) print \$2}")
512                    [ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
513                    #                                   (comentario Doxygen) */
514                fi
515                # Comprobar si volumen ZFS que puede ser montado.
516                if ogCheckStringInGroup "$DISK" "$ZFSVOLS"; then
517                    zpool import -f -R /mnt -N -a 2>/dev/null
518                    ZPOOL=$(blkid -s LABEL -o value $DISK)
519                    PART=$(zfs list -Hp -o name,canmount,mountpoint -r $ZPOOL | \
520                           awk -v n=$2 '$2=="on" && $3!="none" {c++; if (c==n) print $1}')
521                fi
522                # Salir si no se encuentra dispositivo.
523                [ -n "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $?
524                # Devolver camino al dispositivo.
525                echo "$PART"
526            fi
527        fi
528        ;;
529    *)  # Formato erroneo.
530        ogRaiseError $OG_ERR_FORMAT
531        return $OG_ERR_FORMAT
532        ;;
533esac
534}
535
536
537#/**
538#         ogGetDiskSize int_ndisk
539#@brief   Muestra el tamaño en KB de un disco.
540#@param   int_ndisk   nº de orden del disco
541#@return  int_size  - Tamaño en KB del disco.
542#@exception OG_ERR_FORMAT   formato incorrecto.
543#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
544#@note    Requisitos: sfdisk, awk
545#@version 0.9.2 - Primera version para OpenGnSys
546#@author  Ramon Gomez, ETSII Universidad de Sevilla
547#@date    2010/09/15
548#@version 1.0.6 - Soportar LVM.
549#@author  Universidad de Huelva
550#@date    2014/09/04
551#*/ ##
552function ogGetDiskSize ()
553{
554# Variables locales.
555local DISK SIZE
556
557# Si se solicita, mostrar ayuda.
558if [ "$*" == "help" ]; then
559    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1  => 244198584"
560    return
561fi
562# Error si no se recibe 1 parámetro.
563[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
564
565# Obtener el tamaño del disco.
566DISK="$(ogDiskToDev $1)" || return $?
567SIZE=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3}}' /proc/partitions)
568# Si no, obtener tamaño del grupo de volúmenes.
569[ -z "$SIZE" ] && SIZE=$(vgs --noheadings --units=B -o dev_size $DISK 2>/dev/null | \
570                         awk '{print $1/1024}')
571
572# Mostrar salida.
573[ -n "$SIZE" ] && echo "$SIZE"
574}
575
576
577#/**
578#         ogGetDiskType path_device
579#@brief   Muestra el tipo de disco (real, RAID, meta-disco, etc.).
580#@warning Función en pruebas
581#*/ ##
582function ogGetDiskType ()
583{
584local DEV MAJOR TYPE
585
586# Obtener el driver del dispositivo de bloques.
587[ -b "$1" ] || ogRaiseError $OG_ERR_FORMAT || return $?
588DEV=${1#/dev/}
589MAJOR=$(awk -v D="$DEV" '{if ($4==D) print $1;}' /proc/partitions)
590TYPE=$(awk -v D=$MAJOR '/Block/ {bl=1} {if ($1==D&&bl) print toupper($2)}' /proc/devices)
591# Devolver mnemónico del driver de dispositivo.
592case "$TYPE" in
593    SD)            TYPE="DISK" ;;
594    SR|IDE*)       TYPE="CDROM" ;;         # FIXME Comprobar discos IDE.
595    MD|CCISS*)     TYPE="RAID" ;;
596    DEVICE-MAPPER) TYPE="MAPPER" ;;        # FIXME Comprobar LVM y RAID.
597esac
598echo $TYPE
599}
600
601
602#/**
603#         ogGetLastSector int_ndisk [int_npart]
604#@brief   Devuelve el último sector usable del disco o de una partición.
605#@param   int_ndisk      nº de orden del disco
606#@param   int_npart      nº de orden de la partición (opcional)
607#@return  Último sector usable.
608#@exception OG_ERR_FORMAT   Formato incorrecto.
609#@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo.
610#@note    Requisitos: sfdisk, sgdisk
611#@version 1.0.4 - Primera versión compatible con OpenGnSys.
612#@author  Universidad de Huelva
613#@date    2012/06/03
614#*/ ##
615
616function ogGetLastSector ()
617{
618# Variables locales
619local DISK PART PTTYPE LASTSECTOR SECTORS CYLS
620# Si se solicita, mostrar ayuda.
621if [ "$*" == "help" ]; then
622    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npart]" \
623           "$FUNCNAME 1  =>  488392064" \
624           "$FUNCNAME 1 1  =>  102400062"
625    return
626fi
627# Error si no se reciben 1 o 2 parámetros.
628case $# in
629    1)  DISK=$(ogDiskToDev $1) || return $?
630        ;;
631    2)  DISK=$(ogDiskToDev $1) || return $?
632        PART=$(ogDiskToDev $1 $2) || return $?
633        ;;
634    *)  ogRaiseError $OG_ERR_FORMAT
635        return $? ;;
636esac
637
638# Hay que comprobar si el disco es GPT
639PTTYPE=$(ogGetPartitionTableType $1)
640PTTYPE=${PTTYPE:-"MSDOS"}               # Por defecto para discos vacíos.
641case "$PTTYPE" in
642    GPT)
643        if [ $# == 1 ]; then
644            LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk '/last usable sector/ {print($(NF))}')
645        else
646            LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk -v P="$2" '{if ($1==P) print $3}')
647        fi
648        ;;
649    MSDOS)
650        if [ $# == 1 ]; then
651            SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions)
652            CYLS=$(sfdisk -g $DISK | cut -f2 -d" ")
653            LASTSECTOR=$[SECTORS/CYLS*CYLS-1]
654        else
655            LASTSECTOR=$(sfdisk -uS -l $DISK 2>/dev/null | \
656                         awk -v P="$PART" '{if ($1==P) {if ($2=="*") print $4; else print $3} }')
657        fi
658        ;;
659esac
660echo $LASTSECTOR
661}
662
663
664#/**
665#         ogGetPartitionActive int_ndisk
666#@brief   Muestra que particion de un disco esta marcada como de activa.
667#@param   int_ndisk   nº de orden del disco
668#@return  int_npart   Nº de partición activa
669#@exception OG_ERR_FORMAT Formato incorrecto.
670#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
671#@note    Requisitos: parted
672#@todo    Queda definir formato para atributos (arranque, oculta, ...).
673#@version 0.9 - Primera version compatible con OpenGnSys.
674#@author  Ramon Gomez, ETSII Universidad de Sevilla
675#@date    2009/09/17
676#*/ ##
677function ogGetPartitionActive ()
678{
679# Variables locales
680local DISK
681
682# Si se solicita, mostrar ayuda.
683if [ "$*" == "help" ]; then
684    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1  =>  1"
685    return
686fi
687# Error si no se recibe 1 parámetro.
688[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
689
690# Comprobar que el disco existe y listar su partición activa.
691DISK="$(ogDiskToDev $1)" || return $?
692LANG=C parted -sm $DISK print 2>/dev/null | awk -F: '$7~/boot/ {print $1}'
693}
694
695
696#/**
697#         ogGetPartitionId int_ndisk int_npartition
698#@brief   Devuelve el mnemónico con el tipo de partición.
699#@param   int_ndisk      nº de orden del disco
700#@param   int_npartition nº de orden de la partición
701#@return  Identificador de tipo de partición.
702#@exception OG_ERR_FORMAT   Formato incorrecto.
703#@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo.
704#@note    Requisitos: sfdisk
705#@version 0.9 - Primera versión compatible con OpenGnSys.
706#@author  Ramon Gomez, ETSII Universidad de Sevilla
707#@date    2009-03-25
708#@version 1.0.2 - Detectar partición vacía.
709#@author  Ramon Gomez, ETSII Universidad de Sevilla
710#@date    2011-12-23
711#@version 1.0.6 - Soportar LVM.
712#@author  Universidad de Huelva
713#@date    2014-09-04
714#@version 1.1.0 - Soportar pool de volúmenes ZFS.
715#@author  Ramon Gomez, ETSII Universidad Sevilla
716#@date    2014-11-14
717#*/ ##
718function ogGetPartitionId ()
719{
720# Variables locales.
721local DISK PART ID
722
723# Si se solicita, mostrar ayuda.
724if [ "$*" == "help" ]; then
725    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
726           "$FUNCNAME 1 1  =>  7"
727    return
728fi
729# Error si no se reciben 2 parámetros.
730[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
731
732# Detectar id. de tipo de partición y codificar al mnemónico.
733DISK=$(ogDiskToDev $1) || return $?
734PART=$(ogDiskToDev $1 $2) || return $?
735case "$(ogGetPartitionTableType $1)" in
736    GPT)    ID=$(sgdisk -p $DISK 2>/dev/null | awk -v p="$2" '{if ($1==p) print $6;}') || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $?
737            [ "$ID" == "8301" -a "$1 $2" == "$(ogFindCache)" ] && ID=CA00
738            ;;
739    MSDOS)  ID=$(sfdisk --id $DISK $2 2>/dev/null) || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $? ;;
740    LVM)    ID=10000 ;;
741    ZPOOL)  ID=10010 ;;
742esac
743echo $ID
744}
745
746
747#/**
748#         ogGetPartitionSize int_ndisk int_npartition
749#@brief   Muestra el tamano en KB de una particion determinada.
750#@param   int_ndisk      nº de orden del disco
751#@param   int_npartition nº de orden de la partición
752#@return  int_partsize - Tamaño en KB de la partición.
753#@exception OG_ERR_FORMAT   formato incorrecto.
754#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
755#@note    Requisitos: sfdisk, awk
756#@version 0.1 -  Integracion para Opengnsys  -  EAC: SizePartition () en ATA.lib
757#@author  Antonio J. Doblas Viso, Universidad de Malaga
758#@date    2008/10/27
759#@version 0.9 - Primera version para OpenGnSys
760#@author  Ramon Gomez, ETSII Universidad de Sevilla
761#@date    2009/07/24
762#@version 1.1.0 - Sustituir "sfdisk" por "partx".
763#@author  Ramon Gomez, ETSII Universidad de Sevilla
764#@date    2016/04/21
765#*/ ##
766function ogGetPartitionSize ()
767{
768# Variables locales.
769local PART
770
771# Si se solicita, mostrar ayuda.
772if [ "$*" == "help" ]; then
773    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
774           "$FUNCNAME 1 1  =>  10000000"
775    return
776fi
777# Error si no se reciben 2 parámetros.
778[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
779
780# Devolver tamaño de partición o del sistema de archivos (para ZFS).
781PART="$(ogDiskToDev $1 $2)" || return $?
782partx -gbo SIZE $PART 2>/dev/null | awk '{print $1/1024}'
783[ ${PIPESTATUS[0]} -ne 0 ] && ogGetFsSize $1 $2
784}
785
786
787#/**
788#         ogGetPartitionsNumber int_ndisk
789#@brief   Detecta el numero de particiones del disco duro indicado.
790#@param   int_ndisk      nº de orden del disco
791#@return  Devuelve el numero paritiones del disco duro indicado
792#@warning Salidas de errores no determinada
793#@attention Requisitos: parted
794#@note    Notas sin especificar
795#@version 0.1 -  Integracion para Opengnsys  -  EAC:  DetectNumberPartition () en ATA.lib
796#@author  Antonio J. Doblas Viso. Universidad de Malaga
797#@date    Date: 27/10/2008
798#@version 1.0 - Uso de sfdisk Primera version para OpenGnSys
799#@author  Ramon Gomez, ETSII Universidad de Sevilla
800#@date    2009-07-24
801#@version 1.0.4 - Uso de /proc/partitions para detectar el numero de particiones
802#@author  Universidad de Huelva
803#@date    2012-03-28
804#@version 1.0.6 - Soportar LVM.
805#@author  Universidad de Huelva
806#@date    2014-09-04
807#@version 1.1.0 - Soportar ZFS y sustituir "sfdisk" por "partx".
808#@author  Ramon Gomez, ETSII Universidad Sevilla
809#@date    2016-04-28
810#*/ ##
811function ogGetPartitionsNumber ()
812{
813# Variables locales.
814local DISK
815# Si se solicita, mostrar ayuda.
816if [ "$*" == "help" ]; then
817    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
818           "$FUNCNAME 1  =>  3"
819    return
820fi
821# Error si no se recibe 1 parámetro.
822[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
823
824# Contar el nº de veces que aparece el disco en su lista de particiones.
825DISK=$(ogDiskToDev $1) 2>/dev/null
826case "$(ogGetPartitionTableType $1)" in
827    GPT)    grep -c "${DISK#/dev/}." /proc/partitions ;;
828    MSDOS)  partx -gso NR $DISK 2>/dev/null | awk -v p=0 '{p=$1} END {print p}' ;;
829    LVM)    lvs --noheadings $DISK 2>/dev/null | wc -l ;;
830    ZPOOL)  zpool list &>/dev/null || modprobe zfs
831            zpool import -f -R /mnt -N -a 2>/dev/null
832            zfs list -Hp -o name,canmount,mountpoint -r $(blkid -s LABEL -o value $DISK) | \
833                    awk '$2=="on" && $3!="none" {c++}
834                         END {print c}'
835            ;;
836esac
837}
838
839
840#/**
841#         ogGetPartitionTableType int_ndisk
842#@brief   Devuelve el tipo de tabla de particiones del disco (GPT o MSDOS)
843#@param   int_ndisk       nº de orden del disco
844#@return  str_tabletype - Tipo de tabla de paritiones
845#@warning Salidas de errores no determinada
846#@note    tabletype = { MSDOS, GPT }
847#@note    Requisitos: parted
848#@version 1.0.4 - Primera versión para OpenGnSys
849#@author  Universidad de Huelva
850#@date    2012/03/01
851#@version 1.0.6 - Soportar LVM.
852#@author  Universidad de Huelva
853#@date    2014-09-04
854#@version 1.1.0 - Soportar ZFS.
855#@author  Ramon Gomez, ETSII Universidad Sevilla
856#@date    2014-11-14
857#*/ ##
858function ogGetPartitionTableType ()
859{
860# Variables locales.
861local DISK TYPE
862
863# Si se solicita, mostrar ayuda.
864if [ "$*" == "help" ]; then
865    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
866           "$FUNCNAME 1  =>  MSDOS"
867    return
868fi
869# Error si no se recibe 1 parámetro.
870[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
871
872# Sustituye n de disco por su dispositivo.
873DISK=$(ogDiskToDev $1) || return $?
874
875# Comprobar tabla de particiones.
876[ -b $DISK ] && TYPE=$(parted -sm $DISK print 2>/dev/null | awk -F: -v D=$DISK '{ if($1 == D) print toupper($6)}')
877# Comprobar si es volumen lógico.
878[ -d $DISK ] && vgs $DISK &>/dev/null && TYPE="LVM"
879# Comprobar si es pool de ZFS.
880[ -z "$TYPE" -o "$TYPE" == "UNKNOWN" ] && [ -n "$(blkid -s TYPE $DISK | grep zfs)" ] && TYPE="ZPOOL"
881
882# Mostrar salida.
883[ -n "$TYPE" ] && echo "$TYPE"
884}
885
886
887#/**
888#         ogGetPartitionType int_ndisk int_npartition
889#@brief   Devuelve el mnemonico con el tipo de partición.
890#@param   int_ndisk      nº de orden del disco
891#@param   int_npartition nº de orden de la partición
892#@return  Mnemonico
893#@note    Mnemonico: valor devuelto por ogIdToType.
894#@exception OG_ERR_FORMAT   Formato incorrecto.
895#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
896#@version 0.1 -  Integracion para Opengnsys  -  EAC:   TypeFS() en ATA.lib
897#@author  Antonio J. Doblas Viso. Universidad de Malaga
898#@date    2008-10-27
899#@version 0.9 - Primera adaptacion para OpenGnSys.
900#@author  Ramon Gomez, ETSII Universidad de Sevilla
901#@date    2009-07-21
902#@version 1.0.3 - Código trasladado de antigua función ogGetFsType.
903#@author  Ramon Gomez, ETSII Universidad de Sevilla
904#@date    2011-12-01
905#@version 1.0.5 - Usar función ogIdToType para hacer la conversión id. a tipo.
906#@author  Ramon Gomez, ETSII Universidad de Sevilla
907#@date    2013-09-19
908#*/ ##
909function ogGetPartitionType ()
910{
911# Variables locales.
912local ID TYPE
913
914# Si se solicita, mostrar ayuda.
915if [ "$*" == "help" ]; then
916    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
917           "$FUNCNAME 1 1  =>  NTFS"
918    return
919fi
920# Error si no se reciben 2 parámetros.
921[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
922
923# Detectar id. de tipo de partición y codificar al mnemonico.
924ID=$(ogGetPartitionId "$1" "$2") || return $?
925TYPE=$(ogIdToType "$ID")
926echo "$TYPE"
927}
928
929
930#/**
931#         ogHidePartition int_ndisk int_npartition
932#@brief   Oculta un apartición visible.
933#@param   int_ndisk      nº de orden del disco
934#@param   int_npartition nº de orden de la partición
935#@return  (nada)
936#@exception OG_ERR_FORMAT    formato incorrecto.
937#@exception OG_ERR_NOTFOUND  disco o particion no detectado (no es un dispositivo).
938#@exception OG_ERR_PARTITION tipo de partición no reconocido.
939#@version 1.0 - Versión en pruebas.
940#@author  Ramon Gomez, ETSII Universidad de Sevilla
941#@date    2010/01/12
942#*/ ##
943function ogHidePartition ()
944{
945# Variables locales.
946local PART TYPE NEWTYPE
947# Si se solicita, mostrar ayuda.
948if [ "$*" == "help" ]; then
949    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
950           "$FUNCNAME 1 1"
951    return
952fi
953# Error si no se reciben 2 parámetros.
954[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
955PART=$(ogDiskToDev "$1" "$2") || return $?
956
957# Obtener tipo de partición.
958TYPE=$(ogGetPartitionType "$1" "$2")
959case "$TYPE" in
960    NTFS)   NEWTYPE="HNTFS"  ;;
961    FAT32)  NEWTYPE="HFAT32" ;;
962    FAT16)  NEWTYPE="HFAT16" ;;
963    FAT12)  NEWTYPE="HFAT12" ;;
964    *)      ogRaiseError $OG_ERR_PARTITION "$TYPE"
965            return $? ;;
966esac
967# Cambiar tipo de partición.
968ogSetPartitionType $1 $2 $NEWTYPE
969}
970
971
972#/**
973#         ogIdToType int_idpart
974#@brief   Devuelve el identificador correspondiente a un tipo de partición.
975#@param   int_idpart    identificador de tipo de partición.
976#@return  str_parttype  mnemónico de tipo de partición.
977#@exception OG_ERR_FORMAT   Formato incorrecto.
978#@version 1.0.5 - Primera version para OpenGnSys
979#@author  Ramon Gomez, ETSII Universidad Sevilla
980#@date    2013-02-07
981#*/ ##
982function ogIdToType ()
983{
984# Variables locales
985local ID TYPE
986
987# Si se solicita, mostrar ayuda.
988if [ "$*" == "help" ]; then
989    ogHelp "$FUNCNAME" "$FUNCNAME int_idpart" \
990           "$FUNCNAME 83  =>  LINUX"
991    return
992fi
993# Error si no se recibe 1 parámetro.
994[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
995
996# Obtener valor hexadecimal de 4 caracteres rellenado con 0 por delante.
997ID=$(printf "%4s" "$1" | tr ' ' '0')
998case "${ID,,}" in
999     0000)      TYPE="EMPTY" ;;
1000     0001)      TYPE="FAT12" ;;
1001     0005|000f) TYPE="EXTENDED" ;;
1002     0006|000e) TYPE="FAT16" ;;
1003     0007)      TYPE="NTFS" ;;
1004     000b|000c) TYPE="FAT32" ;;
1005     0011)      TYPE="HFAT12" ;;
1006     0012)      TYPE="COMPAQDIAG" ;;
1007     0016|001e) TYPE="HFAT16" ;;
1008     0017)      TYPE="HNTFS" ;;
1009     001b|001c) TYPE="HFAT32" ;;
1010     0042)      TYPE="WIN-DYNAMIC" ;;
1011     0082|8200) TYPE="LINUX-SWAP" ;;
1012     0083|8300) TYPE="LINUX" ;;
1013     008e|8E00) TYPE="LINUX-LVM" ;;
1014     00a5|a503) TYPE="FREEBSD" ;;
1015     00a6)      TYPE="OPENBSD" ;;
1016     00a7)      TYPE="CACHE" ;;         # (compatibilidad con Brutalix)
1017     00af|af00) TYPE="HFS" ;;
1018     00be|be00) TYPE="SOLARIS-BOOT" ;;
1019     00bf|bf0[0145]) TYPE="SOLARIS" ;;
1020     00ca|ca00) TYPE="CACHE" ;;
1021     00da)      TYPE="DATA" ;;
1022     00ee)      TYPE="GPT" ;;
1023     00ef|ef00) TYPE="EFI" ;;
1024     00fb)      TYPE="VMFS" ;;
1025     00fd|fd00) TYPE="LINUX-RAID" ;;
1026     0700)      TYPE="WINDOWS" ;;
1027     0c01)      TYPE="WIN-RESERV" ;;
1028     7f00)      TYPE="CHROMEOS-KRN" ;;
1029     7f01)      TYPE="CHROMEOS" ;;
1030     7f02)      TYPE="CHROMEOS-RESERV" ;;
1031     8301)      TYPE="LINUX-RESERV" ;;
1032     a500)      TYPE="FREEBSD-DISK" ;;
1033     a501)      TYPE="FREEBSD-BOOT" ;;
1034     a502)      TYPE="FREEBSD-SWAP" ;;
1035     ab00)      TYPE="HFS-BOOT" ;;
1036     af01)      TYPE="HFS-RAID" ;;
1037     bf02)      TYPE="SOLARIS-SWAP" ;;
1038     bf03)      TYPE="SOLARIS-DISK" ;;
1039     ef01)      TYPE="MBR" ;;
1040     ef02)      TYPE="BIOS-BOOT" ;;
1041     *)         TYPE="UNKNOWN" ;;
1042esac
1043echo "$TYPE"
1044}
1045
1046
1047#         ogIsDiskLocked int_ndisk
1048#@brief   Comprueba si un disco está bloqueado por una operación de uso exclusivo.
1049#@param   int_ndisk      nº de orden del disco
1050#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
1051#@note    Los ficheros de bloqueo se localizan en \c /var/lock/dev, siendo \c dev el dispositivo de la partición o de su disco, sustituyendo el carácter "/" por "-".
1052#@version 1.1.0 - Primera versión para OpenGnSys.
1053#@author  Ramon Gomez, ETSII Universidad de Sevilla
1054#@date    2016-04-08
1055#*/ ##
1056function ogIsDiskLocked ()
1057{
1058# Variables locales
1059local DISK LOCKFILE
1060
1061# Si se solicita, mostrar ayuda.
1062if [ "$*" == "help" ]; then
1063    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
1064           "if $FUNCNAME 1; then ... ; fi"
1065    return
1066fi
1067# Falso, en caso de error.
1068[ $# == 1 ] || return 1
1069DISK="$(ogDiskToDev $1 2>/dev/null)" || return 1
1070
1071# Comprobar existencia de fichero de bloqueo para el disco.
1072LOCKFILE="/var/lock/lock${DISK//\//-}"
1073test -f $LOCKFILE
1074}
1075
1076
1077#/**
1078#         ogListPartitions int_ndisk
1079#@brief   Lista las particiones definidas en un disco.
1080#@param   int_ndisk  nº de orden del disco
1081#@return  str_parttype:int_partsize ...
1082#@exception OG_ERR_FORMAT   formato incorrecto.
1083#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
1084#@note    Requisitos: \c parted \c awk
1085#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
1086#@attention Las tuplas de valores están separadas por espacios.
1087#@version 0.9 - Primera versión para OpenGnSys
1088#@author  Ramon Gomez, ETSII Universidad de Sevilla
1089#@date    2009/07/24
1090#*/ ##
1091function ogListPartitions ()
1092{
1093# Variables locales.
1094local DISK PART NPARTS TYPE SIZE
1095
1096# Si se solicita, mostrar ayuda.
1097if [ "$*" == "help" ]; then
1098    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
1099           "$FUNCNAME 1  =>  NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000"
1100    return
1101fi
1102# Error si no se recibe 1 parámetro.
1103[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $?
1104
1105# Procesar la salida de \c parted .
1106DISK="$(ogDiskToDev $1)" || return $?
1107NPARTS=$(ogGetPartitionsNumber $1)
1108for (( PART = 1; PART <= NPARTS; PART++ )); do
1109    TYPE=$(ogGetPartitionType $1 $PART 2>/dev/null)
1110    if [ $? -eq 0 ]; then
1111        SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null)
1112        echo -n "$TYPE:$SIZE "
1113    else
1114        echo -n "EMPTY:0 "
1115    fi
1116done
1117echo
1118}
1119
1120
1121#/**
1122#         ogListPrimaryPartitions int_ndisk
1123#@brief   Metafunción que lista las particiones primarias no vacías de un disco.
1124#@param   int_ndisk  nº de orden del disco
1125#@see     ogListPartitions
1126#*/ ##
1127function ogListPrimaryPartitions ()
1128{
1129# Variables locales.
1130local PTTYPE PARTS
1131
1132PTTYPE=$(ogGetPartitionTableType $1) || return $?
1133PARTS=$(ogListPartitions "$@") || return $?
1134case "$PTTYPE" in
1135    GPT)    echo $PARTS | sed 's/\( EMPTY:0\)*$//' ;;
1136    MSDOS)  echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//' ;;
1137esac
1138}
1139
1140
1141#/**
1142#         ogListLogicalPartitions int_ndisk
1143#@brief   Metafunción que lista las particiones lógicas de una tabla tipo MSDOS.
1144#@param   int_ndisk  nº de orden del disco
1145#@see     ogListPartitions
1146#*/ ##
1147function ogListLogicalPartitions ()
1148{
1149# Variables locales.
1150local PTTYPE PARTS
1151
1152PTTYPE=$(ogGetPartitionTableType $1) || return $?
1153[ "$PTTYPE" == "MSDOS" ] || ogRaiseError $OG_ERR_PARTITION "" || return $?
1154PARTS=$(ogListPartitions "$@") || return $?
1155echo $PARTS | cut -sf5- -d" "
1156}
1157
1158
1159#/**
1160#         ogLockDisk int_ndisk
1161#@brief   Genera un fichero de bloqueo para un disco en uso exlusivo.
1162#@param   int_ndisk      nº de orden del disco
1163#@return  (nada)
1164#@exception OG_ERR_FORMAT    Formato incorrecto.
1165#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1166#@note    El fichero de bloqueo se localiza en \c /var/lock/disk, siendo \c disk el dispositivo del disco, sustituyendo el carácter "/" por "-".
1167#@version 1.1.0 - Primera versión para OpenGnSys.
1168#@author  Ramon Gomez, ETSII Universidad de Sevilla
1169#@date    2016-04-07
1170#*/ ##
1171function ogLockDisk ()
1172{
1173# Variables locales
1174local DISK LOCKFILE
1175
1176# Si se solicita, mostrar ayuda.
1177if [ "$*" == "help" ]; then
1178    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
1179           "$FUNCNAME 1"
1180    return
1181fi
1182# Error si no se recibe 1 parámetro.
1183[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1184
1185# Obtener partición.
1186DISK="$(ogDiskToDev $1)" || return $?
1187
1188# Crear archivo de bloqueo exclusivo.
1189LOCKFILE="/var/lock/lock${DISK//\//-}"
1190touch $LOCKFILE
1191}
1192
1193
1194#/**
1195#         ogSetPartitionActive int_ndisk int_npartition
1196#@brief   Establece cual es la partición activa de un disco.
1197#@param   int_ndisk      nº de orden del disco
1198#@param   int_npartition nº de orden de la partición
1199#@return  (nada).
1200#@exception OG_ERR_FORMAT   Formato incorrecto.
1201#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo.
1202#@note    Requisitos: parted
1203#@version 0.1 -  Integracion para Opengnsys  -  EAC: SetPartitionActive() en ATA.lib
1204#@author  Antonio J. Doblas Viso, Universidad de Malaga
1205#@date    2008/10/27
1206#@version 0.9 - Primera version compatible con OpenGnSys.
1207#@author  Ramon Gomez, ETSII Universidad de Sevilla
1208#@date    2009/09/17
1209#*/ ##
1210function ogSetPartitionActive ()
1211{
1212# Variables locales
1213local DISK PART
1214
1215# Si se solicita, mostrar ayuda.
1216if [ "$*" == "help" ]; then
1217    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
1218           "$FUNCNAME 1 1"
1219    return
1220fi
1221# Error si no se reciben 2 parámetros.
1222[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1223
1224# Comprobar que el disco existe y activar la partición indicada.
1225DISK="$(ogDiskToDev $1)" || return $?
1226PART="$(ogDiskToDev $1 $2)" || return $?
1227parted -s $DISK set $2 boot on 2>/dev/null
1228}
1229
1230
1231#/**
1232#         ogSetPartitionId int_ndisk int_npartition hex_partid
1233#@brief   Cambia el identificador de la partición.
1234#@param   int_ndisk      nº de orden del disco
1235#@param   int_npartition nº de orden de la partición
1236#@param   hex_partid     identificador de tipo de partición
1237#@return  (nada)
1238#@exception OG_ERR_FORMAT     Formato incorrecto.
1239#@exception OG_ERR_NOTFOUND   Disco o partición no corresponden con un dispositivo.
1240#@exception OG_ERR_OUTOFLIMIT Valor no válido.
1241#@exception OG_ERR_PARTITION  Error al cambiar el id. de partición.
1242#@attention Requisitos: fdisk, sgdisk
1243#@version 0.1 -  Integracion para Opengnsys  - SetPartitionType() en ATA.lib
1244#@author  Antonio J. Doblas Viso. Universidad de Malaga
1245#@date    2008/10/27
1246#@version 1.0.4 - Soporte para discos GPT.
1247#@author  Universidad de Huelva
1248#@date    2012/03/13
1249#@version 1.0.5 - Utiliza el id. de tipo de partición (no el mnemónico)
1250#@author  Universidad de Huelva
1251#@date    2012/05/14
1252#*/ ##
1253function ogSetPartitionId ()
1254{
1255# Variables locales
1256local DISK PART PTTYPE ID
1257
1258# Si se solicita, mostrar ayuda.
1259if [ "$*" == "help" ]; then
1260    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition hex_partid" \
1261           "$FUNCNAME 1 1 7"
1262    return
1263fi
1264# Error si no se reciben 3 parámetros.
1265[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1266
1267# Sustituye nº de disco y nº partición por su dispositivo.
1268DISK=$(ogDiskToDev $1) || return $?
1269PART=$(ogDiskToDev $1 $2) || return $?
1270# Error si el id. de partición no es hexadecimal.
1271ID="${3^^}"
1272[[ "$ID" =~ ^[0-9A-F]+$ ]] || ogRaiseError $OG_ERR_OUTOFLIMIT "$3" || return $?
1273
1274# Elección del tipo de partición.
1275PTTYPE=$(ogGetPartitionTableType $1)
1276case "$PTTYPE" in
1277    GPT)    sgdisk -t$2:$ID $DISK 2>/dev/null ;;
1278    MSDOS)  echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK | grep Syncing &>/dev/null ;;
1279    *)      ogRaiseError $OG_ERR_OUTOFLIMIT "$1,$PTTYPE"
1280            return $? ;;
1281esac
1282
1283# MSDOS) Correcto si fdisk sin error o con error pero realiza Syncing
1284if [ "${PIPESTATUS[1]}" == "0" -o $? -eq 0 ]; then
1285    partprobe $DISK 2>/dev/null
1286    return 0
1287else
1288    ogRaiseError $OG_ERR_PARTITION "$1,$2,$3"
1289    return $?
1290fi
1291}
1292
1293
1294#/**
1295#         ogSetPartitionSize int_ndisk int_npartition int_size
1296#@brief   Muestra el tamano en KB de una particion determinada.
1297#@param   int_ndisk      nº de orden del disco
1298#@param   int_npartition nº de orden de la partición
1299#@param   int_size       tamaño de la partición (en KB)
1300#@return  (nada)
1301#@exception OG_ERR_FORMAT   formato incorrecto.
1302#@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo).
1303#@note    Requisitos: sfdisk, awk
1304#@todo    Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición.
1305#@version 0.9 - Primera versión para OpenGnSys
1306#@author  Ramon Gomez, ETSII Universidad de Sevilla
1307#@date    2009/07/24
1308#*/ ##
1309function ogSetPartitionSize ()
1310{
1311# Variables locales.
1312local DISK PART SIZE
1313
1314# Si se solicita, mostrar ayuda.
1315if [ "$*" == "help" ]; then
1316    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_size" \
1317           "$FUNCNAME 1 1 10000000"
1318    return
1319fi
1320# Error si no se reciben 3 parámetros.
1321[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1322
1323# Obtener el tamaño de la partición.
1324DISK="$(ogDiskToDev $1)" || return $?
1325PART="$(ogDiskToDev $1 $2)" || return $?
1326# Convertir tamaño en KB a sectores de 512 B.
1327SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $?
1328# Redefinir el tamaño de la partición.
1329sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
1330partprobe $DISK 2>/dev/null
1331}
1332
1333
1334#/**
1335#         ogSetPartitionType int_ndisk int_npartition str_type
1336#@brief   Cambia el identificador de la partición.
1337#@param   int_ndisk      nº de orden del disco
1338#@param   int_npartition nº de orden de la partición
1339#@param   str_type       mnemónico de tipo de partición
1340#@return  (nada)
1341#@attention Requisitos: fdisk, sgdisk
1342#@version 0.1 -  Integracion para Opengnsys  - SetPartitionType() en ATA.lib
1343#@author  Antonio J. Doblas Viso. Universidad de Malaga
1344#@date    2008/10/27
1345#@version 1.0.4 - Soporte para discos GPT.
1346#@author  Universidad de Huelva
1347#@date    2012/03/13
1348#@version 1.0.5 - Renombrada de ogSetPartitionId.
1349#@author  Ramon Gomez, ETSII Universidad de Sevilla
1350#@date    2013/03/07
1351#*/ ##
1352function ogSetPartitionType ()
1353{
1354# Variables locales
1355local DISK PART PTTYPE ID
1356
1357# Si se solicita, mostrar ayuda.
1358if [ "$*" == "help" ]; then
1359    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_type" \
1360           "$FUNCNAME 1 1 NTFS"
1361    return
1362fi
1363# Error si no se reciben 3 parámetros.
1364[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1365
1366# Sustituye nº de disco por su dispositivo.
1367DISK=`ogDiskToDev $1` || return $?
1368PART=`ogDiskToDev $1 $2` || return $?
1369
1370# Elección del tipo de partición.
1371PTTYPE=$(ogGetPartitionTableType $1)
1372ID=$(ogTypeToId "$3" "$PTTYPE")
1373[ -n "$ID" ] || ogRaiseError $OG_ERR_FORMAT "$3,$PTTYPE" || return $?
1374ogSetPartitionId $1 $2 $ID
1375}
1376
1377
1378#/**
1379#         ogTypeToId str_parttype [str_tabletype]
1380#@brief   Devuelve el identificador correspondiente a un tipo de partición.
1381#@param   str_parttype  mnemónico de tipo de partición.
1382#@param   str_tabletype mnemónico de tipo de tabla de particiones (MSDOS por defecto).
1383#@return  int_idpart    identificador de tipo de partición.
1384#@exception OG_ERR_FORMAT   Formato incorrecto.
1385#@note    tabletype = { MSDOS, GPT },   (MSDOS, por defecto)
1386#@version 0.1 -  Integracion para Opengnsys  -  EAC: TypeFS () en ATA.lib
1387#@author  Antonio J. Doblas Viso, Universidad de Malaga
1388#@date    2008/10/27
1389#@version 0.9 - Primera version para OpenGnSys
1390#@author  Ramon Gomez, ETSII Universidad Sevilla
1391#@date    2009-12-14
1392#@version 1.0.4 - Soportar discos GPT (sustituye a ogFsToId).
1393#@author  Universidad de Huelva
1394#@date    2012/03/30
1395#*/ ##
1396function ogTypeToId ()
1397{
1398# Variables locales
1399local PTTYPE ID
1400
1401# Si se solicita, mostrar ayuda.
1402if [ "$*" == "help" ]; then
1403    ogHelp "$FUNCNAME" "$FUNCNAME str_parttype [str_tabletype]" \
1404           "$FUNCNAME LINUX  =>  83" \
1405           "$FUNCNAME LINUX MSDOS  =>  83"
1406    return
1407fi
1408# Error si no se reciben 1 o 2 parámetros.
1409[ $# -lt 1 -o $# -gt 2 ] && (ogRaiseError $OG_ERR_FORMAT; return $?)
1410
1411# Asociar id. de partición para su mnemónico.
1412PTTYPE=${2:-"MSDOS"}
1413case "$PTTYPE" in
1414    GPT) # Se incluyen mnemónicos compatibles con tablas MSDOS.
1415        case "$1" in
1416            EMPTY)      ID=0 ;;
1417            WINDOWS|NTFS|EXFAT|FAT32|FAT16|FAT12|HNTFS|HFAT32|HFAT16|HFAT12)
1418                        ID=0700 ;;
1419            WIN-RESERV) ID=0C01 ;;
1420            CHROMEOS-KRN) ID=7F00 ;;
1421            CHROMEOS)   ID=7F01 ;;
1422            CHROMEOS-RESERV) ID=7F02 ;;
1423            LINUX-SWAP) ID=8200 ;;
1424            LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS)
1425                        ID=8300 ;;
1426            LINUX-RESERV) ID=8301 ;;
1427            LINUX-LVM)  ID=8E00 ;;
1428            FREEBSD-DISK) ID=A500 ;;
1429            FREEBSD-BOOT) ID=A501 ;;
1430            FREEBSD-SWAP) ID=A502 ;;
1431            FREEBSD)    ID=A503 ;;
1432            HFS-BOOT)   ID=AB00 ;;
1433            HFS|HFS+)   ID=AF00 ;;
1434            HFSPLUS)    ID=AF00 ;;
1435            HFS-RAID)   ID=AF01 ;;
1436            SOLARIS-BOOT) ID=BE00 ;;
1437            SOLARIS)    ID=BF00 ;;
1438            SOLARIS-SWAP) ID=BF02 ;;
1439            SOLARIS-DISK) ID=BF03 ;;
1440            CACHE)      ID=CA00;;
1441            EFI)        ID=EF00 ;;
1442            LINUX-RAID) ID=FD00 ;;
1443            *)          ID="" ;;
1444        esac
1445        ;;
1446    MSDOS)
1447        case "$1" in
1448            EMPTY)      ID=0  ;;
1449            FAT12)      ID=1  ;;
1450            EXTENDED)   ID=5  ;;
1451            FAT16)      ID=6  ;;
1452            WINDOWS|NTFS|EXFAT)
1453                        ID=7  ;;
1454            FAT32)      ID=b  ;;
1455            HFAT12)     ID=11 ;;
1456            HFAT16)     ID=16 ;;
1457            HNTFS)      ID=17 ;;
1458            HFAT32)     ID=1b ;;
1459            LINUX-SWAP) ID=82 ;;
1460            LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS)
1461                        ID=83 ;;
1462            LINUX-LVM)  ID=8e ;;
1463            FREEBSD)    ID=a5 ;;
1464            OPENBSD)    ID=a6 ;;
1465            HFS|HFS+)   ID=af ;;
1466            SOLARIS-BOOT) ID=be ;;
1467            SOLARIS)    ID=bf ;;
1468            CACHE)      ID=ca ;;
1469            DATA)       ID=da ;;
1470            GPT)        ID=ee ;;
1471            EFI)        ID=ef ;;
1472            VMFS)       ID=fb ;;
1473            LINUX-RAID) ID=fd ;;
1474            *)          ID="" ;;
1475        esac
1476        ;;
1477esac
1478echo $ID
1479}
1480
1481
1482#/**
1483#         ogUnhidePartition int_ndisk int_npartition
1484#@brief   Hace visible una partición oculta.
1485#@param   int_ndisk      nº de orden del disco
1486#@param   int_npartition nº de orden de la partición
1487#@return  (nada)
1488#@exception OG_ERR_FORMAT    formato incorrecto.
1489#@exception OG_ERR_NOTFOUND  disco o particion no detectado (no es un dispositivo).
1490#@exception OG_ERR_PARTITION tipo de partición no reconocido.
1491#@version 1.0 - Versión en pruebas.
1492#@author  Ramon Gomez, ETSII Universidad de Sevilla
1493#@date    2010/01/12
1494#*/ ##
1495function ogUnhidePartition ()
1496{
1497# Variables locales.
1498local PART TYPE NEWTYPE
1499# Si se solicita, mostrar ayuda.
1500if [ "$*" == "help" ]; then
1501    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
1502           "$FUNCNAME 1 1"
1503    return
1504fi
1505# Error si no se reciben 2 parámetros.
1506[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1507PART=$(ogDiskToDev "$1" "$2") || return $?
1508
1509# Obtener tipo de partición.
1510TYPE=$(ogGetPartitionType "$1" "$2")
1511case "$TYPE" in
1512    HNTFS)   NEWTYPE="NTFS"  ;;
1513    HFAT32)  NEWTYPE="FAT32" ;;
1514    HFAT16)  NEWTYPE="FAT16" ;;
1515    HFAT12)  NEWTYPE="FAT12" ;;
1516    *)      ogRaiseError $OG_ERR_PARTITION "$TYPE"
1517            return $? ;;
1518esac
1519# Cambiar tipo de partición.
1520ogSetPartitionType $1 $2 $NEWTYPE
1521}
1522
1523
1524#/**
1525#         ogUnlockDisk int_ndisk
1526#@brief   Elimina el fichero de bloqueo para un disco.
1527#@param   int_ndisk      nº de orden del disco
1528#@return  (nada)
1529#@exception OG_ERR_FORMAT    Formato incorrecto.
1530#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1531#@note    El fichero de bloqueo se localiza en \c /var/lock/disk, siendo \c disk el dispositivo del disco, sustituyendo el carácter "/" por "-".
1532#@version 1.1.0 - Primera versión para OpenGnSys.
1533#@author  Ramon Gomez, ETSII Universidad de Sevilla
1534#@date    2016-04-08
1535#*/ ##
1536function ogUnlockDisk ()
1537{
1538# Variables locales
1539local DISK LOCKFILE
1540
1541# Si se solicita, mostrar ayuda.
1542if [ "$*" == "help" ]; then
1543    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \
1544           "$FUNCNAME 1"
1545    return
1546fi
1547# Error si no se recibe 1 parámetro.
1548[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1549
1550# Obtener partición.
1551DISK="$(ogDiskToDev $1)" || return $?
1552
1553# Borrar archivo de bloqueo exclusivo.
1554LOCKFILE="/var/lock/lock${DISK//\//-}"
1555rm -f $LOCKFILE
1556}
1557
1558
1559#/**
1560#         ogUpdatePartitionTable
1561#@brief   Fuerza al kernel releer la tabla de particiones de los discos duros
1562#@param   no requiere
1563#@return  informacion propia de la herramienta
1564#@note    Requisitos: \c partprobe
1565#@warning pendiente estructurar la funcion a opengnsys
1566#@version 0.1 -  Integracion para Opengnsys  -  EAC: UpdatePartitionTable() en ATA.lib
1567#@author  Antonio J. Doblas Viso. Universidad de Malaga
1568#@date    27/10/2008
1569#*/ ##
1570function ogUpdatePartitionTable ()
1571{
1572local i
1573for i in `ogDiskToDev`
1574do
1575        partprobe $i
1576done
1577}
Note: See TracBrowser for help on using the repository browser.