source: client/engine/Disk.lib @ b670227

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 b670227 was d891c09, checked in by irina <irinagomez@…>, 9 years ago

#724 En el nuevo cliente el inicio de la primera partición logica es el de la extendida más 4x512

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

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