source: client/engine/Disk.lib @ d5cbfa8

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 d5cbfa8 was 5bfead0, checked in by ramon <ramongomez@…>, 8 years ago

#730: Sustitución del nombre del proyecto en el resto de ficheros del cliente.

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

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