source: client/engine/FileSystem.lib @ 713af37

918-git-images-111dconfigure-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-instalacion
Last change on this file since 713af37 was f097c21, checked in by Irina Gómez <irinagomez@…>, 6 years ago

Fix initCache: if the size of the cache changes, it always formats the cache. ogCheckFs includes the CACHE file system type

  • Property mode set to 100755
File size: 39.2 KB
RevLine 
[2e15649]1#!/bin/bash
2#/**
3#@file    FileSystem.lib
[9f57de01]4#@brief   Librería o clase FileSystem
[2e15649]5#@class   FileSystem
6#@brief   Funciones para gestión de sistemas de archivos.
[0d6e7222]7#@version 1.1.0
[2e15649]8#@warning License: GNU GPLv3+
9#*/
10
11
[be81649]12#/**
[b6208d8]13#         ogCheckFs int_ndisk int_nfilesys
[be81649]14#@brief   Comprueba el estado de un sistema de archivos.
[42669ebf]15#@param   int_ndisk      nº de orden del disco
[b6208d8]16#@param   int_nfilesys   nº de orden del sistema de archivos
[be81649]17#@return  (nada)
18#@exception OG_ERR_FORMAT    Formato incorrecto.
19#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
20#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
21#@note    Requisitos: *fsck*
[a3348ce]22#@warning No se comprueban sistemas de archivos montados o bloqueados.
23#@todo    Definir salidas.
[1616b6e]24#@version 0.9 - Primera adaptación para OpenGnSys.
[be81649]25#@author  Ramon Gomez, ETSII Universidad de Sevilla
26#@date    2009-10-07
[1616b6e]27#@version 1.0.2 - Ignorar códigos de salida de comprobación (no erróneos).
28#@author  Ramon Gomez, ETSII Universidad de Sevilla
29#@date    2011-09-23
[02f271b]30#@version 1.0.4 - Soportar HFS/HFS+.
31#@author  Ramon Gomez, ETSII Universidad de Sevilla
32#@date    2012-05-21
[3198512]33#@version 1.0.5 - Desmontar antes de comprobar, soportar Btrfs y ExFAT.
[3011075]34#@author  Ramon Gomez, ETSII Universidad de Sevilla
35#@date    2012-09-05
[48c9e6e]36#@version 1.1.0 - Soportar F2FS.
37#@author  Ramon Gomez, ETSII Universidad de Sevilla
38#@date    2016-05-03
[6e390b1]39#*/ ##
[42669ebf]40function ogCheckFs ()
41{
[3458879]42# Variables locales.
[cbbb046]43local PART TYPE PROG PARAMS CODES ERRCODE
44# Si se solicita, mostrar ayuda.
45if [ "$*" == "help" ]; then
[e087194]46    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[cbbb046]47           "$FUNCNAME 1 1"
48    return
49fi
[be81649]50
[1616b6e]51# Error si no se reciben 2 parámetros.
[1956672]52[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[1616b6e]53# Obtener partición.
[1956672]54PART="$(ogDiskToDev $1 $2)" || return $?
[be81649]55
56TYPE=$(ogGetFsType $1 $2)
57case "$TYPE" in
[f097c21]58    EXT[234]|CACHE) PROG="e2fsck"; PARAMS="-y"; CODES=(1 2) ;;
59    BTRFS)          PROG="btrfsck"; CODES=(1) ;;
60    REISERFS)       PROG="fsck.reiserfs"; PARAMS="<<<\"Yes\""; CODES=(1 2) ;;
61    REISER4)        PROG="fsck.reiser4"; PARAMS="-ay" ;;
62    JFS)            PROG="fsck.jfs"; CODES=(1 2) ;;
63    XFS)            PROG="xfs_repair" ;;
64    F2FS)           PROG="fsck.f2fs" ;;
65    NTFS)           PROG="ntfsfix" ;;
66    EXFAT)          PROG="fsck.exfat" ;;
67    FAT32)          PROG="dosfsck"; PARAMS="-a"; CODES=(1) ;;
68    FAT16)          PROG="dosfsck"; PARAMS="-a"; CODES=(1) ;;
69    FAT12)          PROG="dosfsck"; PARAMS="-a"; CODES=(1) ;;
70    HFS)            PROG="fsck.hfs"; PARAMS="-f" ;;
71    HFSPLUS)        PROG="fsck.hfs"; PARAMS="-f" ;;
72    UFS)            PROG="fsck.ufs" ;;
73    ZFS)            PROG="fsck.zfs" ;;
74    *)              ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE"
75                    return $? ;;
[1956672]76esac
[1616b6e]77# Error si el sistema de archivos esta montado o bloqueado.
[3011075]78ogUnmount $1 $2
[a3348ce]79if ogIsMounted $1 $2; then
[7250491]80    ogRaiseError $OG_ERR_PARTITION "$1 $2"       # Indicar nuevo error
[a3348ce]81    return $?
82fi
83if ogIsLocked $1 $2; then
84    ogRaiseError $OG_ERR_LOCKED "$1 $2"
85    return $?
86fi
[1616b6e]87# Comprobar en modo uso exclusivo.
[a3348ce]88ogLock $1 $2
[7b9dedd]89trap "ogUnlock $1 $2" 1 2 3 6 9
[a3348ce]90eval $PROG $PARAMS $PART
91ERRCODE=$?
92case $ERRCODE in
[ea8051a]93    0|${CODES[*]})
94            ERRCODE=0 ;;
95    127)    ogRaiseError $OG_ERR_NOTEXEC "$PROG"
96            ERRCODE=$OG_ERR_NOTEXEC ;;
97    *)      ogRaiseError $OG_ERR_PARTITION "$1 $2"
98            ERRCODE=$OG_ERR_PARTITION ;;
[a3348ce]99esac
100ogUnlock $1 $2
101return $ERRCODE
[1956672]102}
103
104
[2e15649]105#/**
[e087194]106#         ogExtendFs int_ndisk int_nfilesys
[3f49cf7]107#@brief   Extiende un sistema de archivos al tamaño de su partición.
[42669ebf]108#@param   int_ndisk      nº de orden del disco
[b6208d8]109#@param   int_nfilesys   nº de orden del sistema de archivos
[3f49cf7]110#@return  (nada)
111#@exception OG_ERR_FORMAT   Formato incorrecto.
112#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
113#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
114#@note    Requisitos: *resize*
[985bef0]115#@version 0.1 -  Integracion para Opengnsys  -  EAC:   EnlargeFileSystem() en ATA.lib
116#@author  Antonio J. Doblas Viso. Universidad de Malaga
117#@date    2008-10-27
[b6208d8]118#@version 0.9 - Primera adaptacion para OpenGnSys.
[3f49cf7]119#@author  Ramon Gomez, ETSII Universidad de Sevilla
120#@date    2009-09-23
[452ade2]121#@version 1.0.5 - Soporte para BTRFS.
122#@author  Ramon Gomez, ETSII Universidad de Sevilla
123#@date    2012-06-28
[6e390b1]124#*/ ##
[42669ebf]125function ogExtendFs ()
126{
[3f49cf7]127# Variables locales.
[3198512]128local PART TYPE PROG PARAMS ERRCODE DOMOUNT
[3f49cf7]129
[1616b6e]130# Si se solicita, mostrar ayuda.
[3f49cf7]131if [ "$*" == "help" ]; then
[e087194]132    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[3f49cf7]133           "$FUNCNAME 1 1"
134    return
135fi
[1616b6e]136# Error si no se reciben 2 parámetros.
[3f49cf7]137[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
138
[1616b6e]139# Obtener partición.
[3f49cf7]140PART="$(ogDiskToDev $1 $2)" || return $?
141
[1616b6e]142# Redimensionar al tamano máximo según el tipo de partición.
[be81649]143TYPE=$(ogGetFsType $1 $2)
144case "$TYPE" in
[2717297]145    EXT[234])   PROG="resize2fs"; PARAMS="-f" ;;
[3198512]146    BTRFS)      PROG="btrfs"; PARAMS="filesystem resize max"
147                DOMOUNT=1     # Debe estar montado.
148                ;;
149    REISERFS|REISER4)
150                PROG="resize_reiserfs"; PARAMS="-f" ;;
[5bc8d01]151    F2FS)       ;;            # No se reduce (por el momento).
[c452625]152    JFS)        ;;            # No se reduce (por el momento).
[5bc8d01]153    NILFS2)     ;;            # No se reduce (probar "nilfs-resize").
[c452625]154    XFS)        ;;            # No se reduce (por el momento).
[5804229]155    NTFS)       PROG="ntfsresize"; PARAMS="<<<\"y\" -f" ;;
[c452625]156    EXFAT)      ;;            # No se reduce (por el momento).
157    FAT32|FAT16)  ;;          # No se reduce (probar "fatresize").
158    HFS|HFSPLUS)  ;;          # No se reduce (por el momento).
159    UFS)        ;;            # No se reduce (por el momento).
[2717297]160    *)          ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
161                return $? ;;
[3f49cf7]162esac
[c452625]163# Salida normal si no se va a aplicar la operación.
164[ -z "$PROG" ] && return
[3198512]165# Error si el sistema de archivos no se queda en el estado de montaje adecuado.
166if [ "$DOMOUNT" ]; then
[5962edd]167    PART=$(ogMount $1 $2) || return $?                      # Indicar nuevo error
[3198512]168else
169    ogUnmount $1 $2 2>/dev/null
[7376c5b]170    if ogIsMounted $1 $2; then
171         ogRaiseError $OG_ERR_PARTITION "$1 $2"             # Indicar nuevo error
172         return $?
173    fi
[2717297]174fi
[3198512]175# Error si el sistema de archivos está bloqueado.
[2717297]176if ogIsLocked $1 $2; then
177    ogRaiseError $OG_ERR_LOCKED "$1 $2"
178    return $?
179fi
[1616b6e]180# Redimensionar en modo uso exclusivo.
[2717297]181ogLock $1 $2
[7b9dedd]182trap "ogUnlock $1 $2" 1 2 3 6 9
[1c04494]183eval $PROG $PARAMS $PART &>/dev/null
[2717297]184ERRCODE=$?
185case $ERRCODE in
186    0)    ;;
[ea8051a]187    127)  ogRaiseError $OG_ERR_NOTEXEC "$PROG"
188          ERRCODE=$OG_ERR_NOTEXEC ;;
189    *)    ogRaiseError $OG_ERR_PARTITION "$1 $2"
190          ERRCODE=$OG_ERR_PARTITION ;;
[2717297]191esac
192ogUnlock $1 $2
193return $ERRCODE
[3f49cf7]194}
195
196
197#/**
[e087194]198#         ogFormat int_ndisk int_nfilesys | CACHE
[e09311f]199#@see     ogFormatFs ogFormatCache
[6e390b1]200#*/ ##
[42669ebf]201function ogFormat ()
202{
[e09311f]203case "$*" in
204    CACHE|cache)  ogFormatCache ;;
205    *)            ogFormatFs "$@" ;;
206esac
[40488da]207}
208
209
210#/**
[b6208d8]211#         ogFormatFs int_ndisk int_nfilesys [type_fstype] [str_label]
[40488da]212#@brief   Formatea un sistema de ficheros según el tipo de su partición.
[42669ebf]213#@param   int_ndisk      nº de orden del disco
[b6208d8]214#@param   int_nfilesys   nº de orden del sistema de archivos
[3198512]215#@param   type_fstype    mnemónico de sistema de ficheros a formatear (opcional al reformatear)
[42669ebf]216#@param   str_label      etiqueta de volumen (opcional)
[40488da]217#@return  (por determinar)
[3198512]218#@exception OG_ERR_FORMAT    Formato de ejecución incorrecto.
[40488da]219#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
220#@exception OG_ERR_PARTITION Partición no accesible o desconocida.
[a3348ce]221#@note    Requisitos:   mkfs*
222#@warning No formatea particiones montadas ni bloqueadas.
223#@todo    Definir salidas.
[b6208d8]224#@version 0.9 - Primera versión para OpenGnSys.
[40488da]225#@author  Ramon Gomez, ETSII Universidad de Sevilla
[a3348ce]226#@date    2009-10-08
[066fa01]227#@version 1.0.4 - Solucionado error cuando no se detecta tipo de sistema de ficheros pero si se indica.
[e068946]228#@author  Universidad de Huelva
229#@date    2012-04-11
[3198512]230#@version 1.0.5 - Comprobar errores al inicio e independizar del tipo de tabla de particiones.
[066fa01]231#@author  Universidad de Huelva
[3198512]232#@date    2013-05-16
[48c9e6e]233#@version 1.1.0 - Soportar F2FS y NILFS.
234#@author  Ramon Gomez, ETSII Universidad de Sevilla
235#@date    2016-05-03
[1e7eaab]236#*/ ##
[42669ebf]237function ogFormatFs ()
238{
[40488da]239# Variables locales
[0d6e7222]240local PART ID TYPE LABEL PROG PARAMS LABELPARAM ERRCODE
[40488da]241
[42669ebf]242# Si se solicita, mostrar ayuda.
[40488da]243if [ "$*" == "help" ]; then
[e087194]244    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys [str_label]" \
[40488da]245           "$FUNCNAME 1 1" \
[be81649]246           "$FUNCNAME 1 1 EXT4" \
[55ad138c]247           "$FUNCNAME 1 1 \"DATA\"" \
248           "$FUNCNAME 1 1 EXT4 \"DATA\""
[40488da]249    return
250fi
[1e7eaab]251# Error si no se reciben entre 2 y 4 parámetros.
[be81649]252[ $# -ge 2 -a $# -le 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[8e29877]253# Obtener fichero de dispositivo.
[40488da]254PART="$(ogDiskToDev $1 $2)" || return $?
[8e29877]255# Error si la partición está montada o bloqueada.
256if ogIsMounted $1 $2; then
[1a2fa9d8]257    ogRaiseError $OG_ERR_DONTFORMAT "$MSG_MOUNT: $1 $2"
[8e29877]258    return $?
259fi
260if ogIsLocked $1 $2; then
261    ogRaiseError $OG_ERR_LOCKED "$1 $2"
262    return $?
263fi
[3198512]264# Si no se indica el tipo de sisitema de archivos, intentar obtenerlo.
265TYPE="${3:-$(ogGetFsType $1 $2)}"
266# Error, si no especifica el tipo de sistema de archivos a formatear.
267[ -n "$TYPE" ] || ogRaiseError $OG_ERR_FORMAT "$1 $2 ..." || return $?
[be81649]268
[3198512]269# Elegir tipo de formato.
270case "$TYPE" in
[3d70f46]271    EXT2)         PROG="mkfs.ext2"; PARAMS="-F" ;;
272    EXT3)         PROG="mkfs.ext3"; PARAMS="-F" ;;
273    EXT4)         PROG="mkfs.ext4"; PARAMS="-F" ;;
274    BTRFS)        PROG="mkfs.btrfs"; PARAMS="-f" ;;
[3198512]275    REISERFS)     PROG="mkfs.reiserfs"; PARAMS="-f"; LABELPARAM="-l" ;;
[5bc8d01]276    REISER4)      PROG="mkfs.reiser4"; PARAMS="-f <<<\"y\"" ;;
[3198512]277    XFS)          PROG="mkfs.xfs"; PARAMS="-f" ;;
278    JFS)          PROG="mkfs.jfs"; PARAMS="<<<\"y\"" ;;
[48c9e6e]279    F2FS)         PROG="mkfs.f2fs"; LABELPARAM="-l" ;;
280    NILFS2)       PROG="mkfs.nilfs2"; PARAMS="-f" ;;
[3198512]281    LINUX-SWAP)   PROG="mkswap" ;;
282    NTFS)         PROG="mkntfs"; PARAMS="-f" ;;
283    EXFAT)        PROG="mkfs.exfat"; LABELPARAM="-n" ;;
284    FAT32)        PROG="mkdosfs"; PARAMS="-F 32"; LABELPARAM="-n" ;;
285    FAT16)        PROG="mkdosfs"; PARAMS="-F 16"; LABELPARAM="-n" ;;
286    FAT12)        PROG="mkdosfs"; PARAMS="-F 12"; LABELPARAM="-n" ;;
287    HFS)          PROG="mkfs.hfs" ;;
288    HFSPLUS)      PROG="mkfs.hfsplus"; LABELPARAM="-v" ;;
289    UFS)          PROG="mkfs.ufs"; PARAMS="-O 2" ;;
290    *)            ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
291                  return $? ;;
[40488da]292esac
[be81649]293
[1e7eaab]294# Etiquetas de particion.
[be81649]295if [ -z "$LABEL" ]; then
296    [ "$4" != "CACHE" ] || ogRaiseError $OG_ERR_FORMAT "$MSG_RESERVEDVALUE: CACHE" || return $?
[3198512]297    [ -n "$4" ] && PARAMS="$PARAMS ${LABELPARAM:-"-L"} $4"
[be81649]298else
[3198512]299    PARAMS="$PARAMS ${LABELPARAM:-"-L"} $LABEL"
[be81649]300fi
[40488da]301
[8e29877]302# Formatear en modo uso exclusivo (desmontar siempre).
[40488da]303ogLock $1 $2
[7b9dedd]304trap "ogUnlock $1 $2" 1 2 3 6 9
[3198512]305umount $PART 2>/dev/null
[a3348ce]306eval $PROG $PARAMS $PART 2>/dev/null
[be81649]307ERRCODE=$?
308case $ERRCODE in
309    0)    ;;
310    127)  ogRaiseError $OG_ERR_NOTEXEC "$PROG" ;;
311    *)    ogRaiseError $OG_ERR_PARTITION "$1 $2" ;;
312esac
[40488da]313ogUnlock $1 $2
[be81649]314return $ERRCODE
[40488da]315}
316
317
318#/**
[7b9dedd]319#         ogGetFsSize int_ndisk int_npartition [str_unit]
320#@brief Muestra el tamanio del sistema de archivos indicado, permite definir la unidad de medida, por defecto GB
321#@param   int_ndisk      nº de orden del disco
322#@param   int_npartition nº de orden de la partición
323#@param   str_unit       unidad (opcional, por defecto: KB)
324#@return  float_size - Tamaño del sistema de archivos
325#@note    str_unit = { KB, MB, GB, TB }
326#@exception OG_ERR_FORMAT   Formato incorrecto.
327#@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo.
328#@version 0.1 -  Integracion para Opengnsys  -  EAC:  SizeFileSystem() en FileSystem.lib
329#@author  Antonio J. Doblas Viso. Universidad de Malaga
330#@date    2008-10-27
331#@version 1.0.4 - Adaptación de las salidas.
332#@author  Ramon Gomez, ETSII Universidad de Sevilla
333#@date    2012-06-18
334#*/ ##
335function ogGetFsSize ()
336{
337# Variables locales.
[68f360e]338local MNTDIR UNIT VALUE FACTOR SIZE
[7b9dedd]339# Si se solicita, mostrar ayuda.
340if [ "$*" == "help" ]; then
341    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [str_unit]" \
342           "$FUNCNAME 1 1  =>  15624188" \
343           "$FUNCNAME 1 1 KB  =>  15624188"
344    return
345fi
346# Error si no se reciben 2 o 3 parámetros.
347[ $# == 2 ] || [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[68f360e]348# Obtener unidad y factor de medida.
[7b9dedd]349UNIT="$3"
350UNIT=${UNIT:-"KB"}
351case "$UNIT" in
352    [kK]B)
353        FACTOR=1 ;;
354    MB) FACTOR=1024 ;;
355    GB) FACTOR=$[1024*1024] ;;
356    TB) FACTOR=$[1024*1024*1024] ;;
357    *)  ogRaiseError $OG_ERR_FORMAT "$3 != { KB, MB, GB, TB }"
358        return $? ;;
359esac
[68f360e]360
361# Obtener el tamaño del sistema de archivo (si no está formateado; tamaño = 0).
362MNTDIR="$(ogMount $1 $2 2>/dev/null)"
363if [ -n "$MNTDIR" ]; then
364    VALUE=$(df -BK "$MNTDIR" | awk '{getline; print $2}')
365    SIZE=$(echo "$VALUE $FACTOR" | awk '{printf "%f\n", $1/$2}')
366else
367    SIZE=0
368fi
369# Devolver el tamaño (quitar decimales si son 0).
370echo ${SIZE%.0*}
[7b9dedd]371}
372
373
374#/**
[b6208d8]375#         ogGetFsType int_ndisk int_nfilesys
[9f57de01]376#@brief   Devuelve el mnemonico con el tipo de sistema de archivos.
[42669ebf]377#@param   int_ndisk      nº de orden del disco
[b6208d8]378#@param   int_nfilesys   nº de orden del sistema de archivos
[9f57de01]379#@return  Mnemonico
[264b1bc]380#@note    Mnemonico: { EXT2, EXT3, EXT4, BTRFS, REISERFS, XFS, JFS, FAT12, FAT16, FAT32, NTFS, LINUX-SWAP, LINUX-LVM, LINUX-RAID, HFS, HFSPLUS, CACHE }
[9f57de01]381#@exception OG_ERR_FORMAT   Formato incorrecto.
382#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
[985bef0]383#@version 0.1 -  Integracion para Opengnsys  -  EAC:   TypeFS() en ATA.lib
384#@author  Antonio J. Doblas Viso. Universidad de Malaga
385#@date    2008-10-27
[5804229]386#@version 0.9 - Primera adaptacion para OpenGnSys.
[9f57de01]387#@author  Ramon Gomez, ETSII Universidad de Sevilla
[5dbb046]388#@date    2009-07-21
[5804229]389#@version 1.0.2 - Obtención de datos reales de sistemas de ficheros.
390#@author  Ramon Gomez, ETSII Universidad de Sevilla
391#@date    2011-12-02
[264b1bc]392#@version 1.0.5 - Usar "blkid" para detectar tipo de sistema de archivo.
[b6208d8]393#@author  Ramon Gomez, ETSII Universidad de Sevilla
[264b1bc]394#@date    2014-06-10
[0d6e7222]395#@version 1.1.0 - Detectar volumen ZFS.
396#@author  Ramon Gomez, ETSII Universidad de Sevilla
397#@date    2014-11-14
[1e7eaab]398#*/ ##
[cbbb046]399function ogGetFsType ()
400{
[59f9ad2]401# Variables locales.
[9eaa464]402local PART TYPE
[1e7eaab]403# Si se solicita, mostrar ayuda.
[59f9ad2]404if [ "$*" == "help" ]; then
[e087194]405    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[59f9ad2]406           "$FUNCNAME 1 1  =>  NTFS"
407    return
408fi
[1e7eaab]409# Error si no se reciben 2 parámetros.
[a5df9b9]410[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[2e15649]411
[264b1bc]412# Detectar tipo de sistema de archivo (independientemente del tipo de partición).
[b6208d8]413PART=$(ogDiskToDev "$1" "$2") || return $?
[0d6e7222]414if [[ "$PART" =~ ^/ ]]; then
415    TYPE=$(blkid -o export $PART | awk -F= '$1~/^TYPE/ { print toupper($2) }')
416else
417    zfs mount $PART 2>/dev/null
418    TYPE=$(mount | awk "\$1==\"$PART\" { print toupper(\$5) }")
419fi
[264b1bc]420
421# Componer valores correctos.
422case "$TYPE" in
423    EXT4)      # Comprobar si es caché o Ext4.
[0d6e7222]424               if [ "$1 $2" == "$(ogFindCache)" ]; then
425                   ogIsFormated $1 $2 2>/dev/null && TYPE="CACHE"
426               fi
427               ;;
428    VFAT)      TYPE="$(blkid -po export $PART | awk -F= '$1~/^VERSION$/ { print toupper($2) }')" ;;
[264b1bc]429    SWAP)      TYPE="LINUX-SWAP" ;;
430    LVM*)      TYPE="LINUX-LVM" ;;
431    *RAID*)    TYPE="LINUX-RAID" ;;
[0d6e7222]432    ZFS_MEMBER) TYPE="ZVOL" ;;
[264b1bc]433    *_MEMBER)  TYPE="${TYPE/_MEMBER/}" ;;
[2e15649]434esac
[5804229]435
436[ -n "$TYPE" ] && echo "$TYPE"
[2e15649]437}
438
[aae34f6]439
[a3348ce]440#/**
[b6208d8]441#         ogGetMountPoint int_ndisk int_nfilesys
[a3348ce]442#@brief   Devuelve el punto de montaje de un sistema de archivos.
[42669ebf]443#@param   int_ndisk      nº de orden del disco
[b6208d8]444#@param   int_nfilesys   nº de orden del sistema de archivos
[f8f4dfa]445#@return  Punto de montaje
446#@exception OG_ERR_FORMAT    Formato incorrecto.
447#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[3458879]448#@note    Requisitos: \c mount* \c awk
[b6208d8]449#@version 0.9 - Primera versión para OpenGnSys.
[f8f4dfa]450#@author  Ramon Gomez, ETSII Universidad de Sevilla
451#@date    2009-10-15
[c632cca]452#@version 1.0.6 - Usar comando findmnt.
453#@author  Ramon Gomez, ETSII Universidad de Sevilla
454#@date    2014-09-04
[1e7eaab]455#*/ ##
[42669ebf]456function ogGetMountPoint ()
457{
[a3348ce]458# Variables locales
459local PART
[1e7eaab]460# Si se solicita, mostrar ayuda.
[a3348ce]461if [ "$*" == "help" ]; then
[e087194]462    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[a3348ce]463           "$FUNCNAME 1 1  =>  /mnt/sda1"
464    return
465fi
[1e7eaab]466# Error si no se reciben 2 parámetros.
[a3348ce]467[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[1e7eaab]468# Obtener partición.
[a3348ce]469PART="$(ogDiskToDev $1 $2)" || return $?
470
[c632cca]471# Devolver punto de montaje.
472findmnt -n -o TARGET $PART
[a3348ce]473}
474
475
476#/**
[b6208d8]477#         ogIsFormated int_ndisk int_nfilesys
[5a4f399]478#@brief   Comprueba si un sistema de archivos está formateado.
479#@param   int_ndisk      nº de orden del disco o volumen.
[b6208d8]480#@param   int_nfilesys   nº de orden del sistema de archivos
[7685100]481#@return  Código de salida: 0 - formateado, 1 - sin formato o error.
[5a4f399]482#@version 0.91 - Adaptación inicial para comprobar que existe caché.
483#@author  Ramon Gomez, ETSII Universidad de Sevilla
484#@date    2010-03-18
[7685100]485#@version 1.0.1 - Devolver falso en caso de error.
486#@author  Ramon Gomez, ETSII Universidad de Sevilla
487#@date    2011-05-18
[b6208d8]488#@version 1.0.5 - Dejar de usar "parted".
489#@author  Ramon Gomez, ETSII Universidad de Sevilla
[3011075]490#@date    2012-09-04
[3e3cfdb]491#@version 1.1.0 - Comprobar sin montar el sistema de ficheros.
492#@author  Ramon Gomez, ETSII Universidad de Sevilla
493#@date    2016-01-21
[5a4f399]494#*/ ##
495function ogIsFormated ()
496{
497# Variables locales
[3e3cfdb]498local PART
[5a4f399]499if [ "$*" == "help" ]; then
[e087194]500    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[5a4f399]501           "if $FUNCNAME 1 1; then ... ; fi"
502    return
503fi
[7685100]504# Falso, en caso de error.
505[ $# == 2 ] || return 1
[3e3cfdb]506PART="$(ogDiskToDev $1 $2 2>/dev/null)" || return 1
[5a4f399]507
[3e3cfdb]508# Revisar tipo de sistema de ficheros.
509if [[ "$PART" =~ ^/ ]]; then
510    # Sistemas de ficheros genéricos.
511    test -n "$(blkid -s TYPE $PART | egrep -vi "swap|_member")"
512else
513    # ZFS.
514    test "$(zfs list -Hp -o canmount $PART 2>/dev/null)" = "on"
515fi
[5a4f399]516}
517
518
519#/**
[b32f902]520#         ogIsLocked int_ndisk int_npartition
[858b1b0]521#@see     ogIsPartitionLocked
522#*/
523function ogIsLocked ()
524{
525ogIsPartitionLocked "$@"
526}
527
528#/**
529#         ogIsPartitionLocked int_ndisk int_npartition
530#@brief   Comprueba si una partición o su disco están bloqueados por una operación de uso exclusivo.
[b32f902]531#@param   int_ndisk      nº de orden del disco
532#@param   int_npartition nº de orden de la partición
533#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
[858b1b0]534#@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 "-".
[b32f902]535#@version 0.9 - Primera versión para OpenGnSys.
536#@author  Ramon Gomez, ETSII Universidad de Sevilla
537#@date    2009-09-03
538#@version 1.0.1 - Devolver falso en caso de error.
539#@author  Ramon Gomez, ETSII Universidad de Sevilla
540#@date    2011-05-18
[858b1b0]541#@version 1.1.0 - Comprobar si el disco está también bloqueado.
542#@author  Ramon Gomez, ETSII Universidad de Sevilla
543#@date    2016-04-08
[b32f902]544#*/ ##
[858b1b0]545function ogIsPartitionLocked ()
[b32f902]546{
547# Variables locales
[858b1b0]548local DISK PART LOCKDISK LOCKPART
[b32f902]549
550# Si se solicita, mostrar ayuda.
551if [ "$*" == "help" ]; then
552    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
553           "if $FUNCNAME 1 1; then ... ; fi"
554    return
555fi
556# Falso, en caso de error.
557[ $# == 2 ] || return 1
[3e3cfdb]558PART="$(ogDiskToDev $1 $2 2>/dev/null)" || return 1
[858b1b0]559DISK="$(ogDiskToDev $1)"
[b32f902]560
[858b1b0]561# Comprobar existencia de fichero de bloqueo de la partición o de su disco.
562LOCKDISK="/var/lock/lock${DISK//\//-}"
563LOCKPART="/var/lock/lock${PART//\//-}"
564test -f $LOCKDISK -o -f $LOCKPART
[b32f902]565}
566
567
568#/**
[b6208d8]569#         ogIsMounted int_ndisk int_nfilesys
[a3348ce]570#@brief   Comprueba si un sistema de archivos está montado.
[42669ebf]571#@param   int_ndisk      nº de orden del disco
[b6208d8]572#@param   int_nfilesys   nº de orden del sistema de archivos
[7685100]573#@return  Código de salida: 0 - montado, 1 - sin montar o error.
[b6208d8]574#@version 0.9 - Primera versión para OpenGnSys.
[f8f4dfa]575#@author  Ramon Gomez, ETSII Universidad de Sevilla
576#@date    2009-10-15
[7685100]577#@version 1.0.1 - Devolver falso en caso de error.
578#@author  Ramon Gomez, ETSII Universidad de Sevilla
579#@date    2011-05-18
[1e7eaab]580#*/ ##
[42669ebf]581function ogIsMounted ()
582{
583# Si se solicita, mostrar ayuda.
[a3348ce]584if [ "$*" == "help" ]; then
[e087194]585    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[a3348ce]586           "if $FUNCNAME 1 1; then ... ; fi"
587    return
588fi
[7685100]589# Falso, en caso de error.
590[ $# == 2 ] || return 1
[a3348ce]591
592test -n "$(ogGetMountPoint $1 $2)"
593}
594
595
[aae34f6]596#/**
[3249002]597#         ogIsReadonly int_ndisk int_nfilesys
598#@brief   Comprueba si un sistema de archivos está montado solo de lectura.
599#@param   int_ndisk      nº de orden del disco
600#@param   int_nfilesys   nº de orden del sistema de archivos
601#@return  Código de salida: 0 - montado solo de lectura, 1 - con escritura o no montado.
602#@version 1.1.0 - Primera versión para OpenGnsys.
603#@author  Ramon Gomez, ETSII Universidad de Sevilla
604#@date    2016-01-20
[d01525b]605#*/ ##
606
[3249002]607function ogIsReadonly ()
608{
609# Variables locales
610local PART
611
612# Si se solicita, mostrar ayuda.
613if [ "$*" == "help" ]; then
614    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys" \
615           "if $FUNCNAME 1 1; then ... ; fi"
616    return
617fi
618# Falso, en caso de error.
619[ $# == 2 ] || return 1
[3e3cfdb]620PART="$(ogDiskToDev $1 $2 2>/dev/null)" || return 1
[3249002]621
622test -n "$(findmnt -n -o OPTIONS $PART | awk 'BEGIN {RS=","} /^ro$/ {print}')"
623}
624
625
626#/**
[b32f902]627#         ogIsWritable int_ndisk int_nfilesys
628#@brief   Comprueba si un sistema de archivos está montado de lectura y escritura.
[42669ebf]629#@param   int_ndisk      nº de orden del disco
[b32f902]630#@param   int_nfilesys   nº de orden del sistema de archivos
631#@return  Código de salida: 0 - lectura y escritura, 1 - solo lectura o no montado.
632#@version 1.0.5 - Primera versión para OpenGnSys.
[7685100]633#@author  Ramon Gomez, ETSII Universidad de Sevilla
[b32f902]634#@date    2013-10-09
[d01525b]635#*/ ##
[b32f902]636function ogIsWritable ()
[42669ebf]637{
[59f9ad2]638# Variables locales
[b32f902]639local PART
[9d96c57]640
[1e7eaab]641# Si se solicita, mostrar ayuda.
[9d96c57]642if [ "$*" == "help" ]; then
[b32f902]643    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys" \
[a3348ce]644           "if $FUNCNAME 1 1; then ... ; fi"
[9d96c57]645    return
646fi
[7685100]647# Falso, en caso de error.
648[ $# == 2 ] || return 1
[3e3cfdb]649PART="$(ogDiskToDev $1 $2 2>/dev/null)" || return 1
[9d96c57]650
[b32f902]651test -n "$(findmnt -n -o OPTIONS $PART | awk 'BEGIN {RS=","} /^rw$/ {print}')"
[9d96c57]652}
653
654
655#/**
656#         ogLock int_ndisk int_npartition
[89403cd]657#@see     ogLockPartition
658#*/
[42669ebf]659function ogLock ()
660{
[89403cd]661ogLockPartition "$@"
662}
663
664#/**
665#         ogLockPartition int_ndisk int_npartition
[9d96c57]666#@brief   Genera un fichero de bloqueo para una partición en uso exlusivo.
[42669ebf]667#@param   int_ndisk      nº de orden del disco
668#@param   int_npartition nº de orden de la partición
[9d96c57]669#@return  (nada)
670#@exception OG_ERR_FORMAT    Formato incorrecto.
671#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]672#@note    El fichero de bloqueo se localiza en \c /var/lock/part, siendo \c part el dispositivo de la partición, sustituyendo el carácter "/" por "-".
[b6208d8]673#@version 0.9 - Primera versión para OpenGnSys.
[9d96c57]674#@author  Ramon Gomez, ETSII Universidad de Sevilla
675#@date    2009-09-03
[1e7eaab]676#*/ ##
[42669ebf]677function ogLockPartition ()
678{
[59f9ad2]679# Variables locales
680local PART LOCKFILE
[9d96c57]681
[1e7eaab]682# Si se solicita, mostrar ayuda.
[9d96c57]683if [ "$*" == "help" ]; then
684    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
685           "$FUNCNAME 1 1"
686    return
687fi
[1e7eaab]688# Error si no se reciben 2 parámetros.
[9d96c57]689[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
690
[1e7eaab]691# Obtener partición.
[9d96c57]692PART="$(ogDiskToDev $1 $2)" || return $?
693
[1e7eaab]694# Crear archivo de bloqueo exclusivo.
[73c8417]695LOCKFILE="/var/lock/lock${PART//\//-}"
696touch $LOCKFILE
[9d96c57]697}
698
699
700#/**
[b6208d8]701#         ogMount int_ndisk int_nfilesys
[3458879]702#@see     ogMountFs ogMountCache ogMountCdrom
[1e7eaab]703#*/ ##
[42669ebf]704function ogMount ()
705{
[ee4a96e]706case "$*" in
[18f4bc2]707    CACHE|cache)
708        ogMountCache ;;
[ee4a96e]709    CDROM|cdrom)
710        ogMountCdrom ;;
711    *)  ogMountFs "$@" ;;
712esac
[73c8417]713}
714
[ee4a96e]715
[73c8417]716#/**
[9eaa464]717#         ogMountFirstFs int_ndisk
718#@brief   Monta el primer sistema de archivos disponible en el disco.
719#@param   int_ndisk      nº de orden del disco
720#@return  Punto de montaje del primer sistema de archivos detectado
721#*/ ##
722function ogMountFirstFs ()
723{
724# Variables locales
725local PART NPARTS MNTDIR
726
727# Error si no se recibe 1 parámetro.
728[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
729
730# Obtener nº de particiones del disco.
731NPARTS=$(ogGetPartitionsNumber "$1") || return $?
732for (( PART = 1; PART <= NPARTS; PART++ )); do
733    MNTDIR=$(ogMount $1 $PART 2>/dev/null)
734    if [ -n "$MNTDIR" ]; then
735        echo "$MNTDIR"
736        return 0
737    fi
738done
739ogRaiseError $OG_ERR_NOTFOUND "$1"
740return $OG_ERR_NOTFOUND
741}
742
743
744#/**
[b6208d8]745#         ogMountFs int_ndisk int_nfilesys
[aae34f6]746#@brief   Monta un sistema de archivos.
[42669ebf]747#@param   int_ndisk      nº de orden del disco
[b6208d8]748#@param   int_nfilesys   nº de orden del sistema de archivos
[aae34f6]749#@return  Punto de montaje
750#@exception OG_ERR_FORMAT    Formato incorrecto.
751#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
752#@exception OG_ERR_PARTITION Tipo de particion desconocido o no se puede montar.
[985bef0]753#@version 0.1 -  Integracion para Opengnsys  -  EAC:   MountPartition() en FileSystem.lib
754#@author  Antonio J. Doblas Viso. Universidad de Malaga
755#@date    2008-10-27
[b6208d8]756#@version 0.9 - Primera version para OpenGnSys.
[aae34f6]757#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]758#@date    2009-09-28
[b6208d8]759#@version 1.0.5 - Independiente del tipo de sistema de ficheros.
[02f271b]760#@author  Ramon Gomez, ETSII Universidad de Sevilla
[3011075]761#@date    2012-09-04
[ae4c525]762#@version 1.1.0 - Montar sistema de archivos ZFS y NTFS hibernado.
[0d6e7222]763#@author  Ramon Gomez, ETSII Universidad de Sevilla
[ae4c525]764#@date    2016-09-19
[1e7eaab]765#*/ ##
[42669ebf]766function ogMountFs ()
767{
[1e7eaab]768# Variables locales
[b6208d8]769local PART MNTDIR
[aae34f6]770
[1e7eaab]771# Si se solicita, mostrar ayuda.
[aae34f6]772if [ "$*" == "help" ]; then
[e087194]773    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[aae34f6]774           "$FUNCNAME 1 1  =>  /mnt/sda1"
775    return
776fi
[1e7eaab]777# Error si no se reciben 2 parámetros.
[aae34f6]778[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
779
[1e7eaab]780# Obtener partición.
[b6208d8]781PART="$(ogDiskToDev "$1" "$2")" || return $?
[aae34f6]782
[1e7eaab]783# Comprobar si el sistema de archivos ya está montada.
[a3348ce]784MNTDIR="$(ogGetMountPoint $1 $2)"
[e2c805a]785# Si no, montarlo en un directorio de sistema.
[aae34f6]786if [ -z "$MNTDIR" ]; then
787    # Error si la particion esta bloqueada.
[52fa3da]788    if ogIsLocked $1 $2; then
789        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION, $1 $2"
790        return $?
791    fi
[0d6e7222]792    # El camino de un dispositivo normal comienza por el carácter "/".
793    if [[ "$PART" =~ ^/ ]]; then
794        # Crear punto de montaje o enlace simbólico para caché local.
795        MNTDIR=${PART/dev/mnt}
[3249002]796        DEBUG="no"
[0d6e7222]797        if [ "$(ogFindCache)" == "$1 $2" -a -n "$OGCAC" ]; then
798            mkdir -p $OGCAC
799            ln -fs $OGCAC $MNTDIR
800        else
801            mkdir -p $MNTDIR
802        fi
[3249002]803        unset DEBUG
[0d6e7222]804        # Montar sistema de archivos.
805        mount $PART $MNTDIR &>/dev/null || \
[ae4c525]806                    mount $PART $MNTDIR -o force,remove_hiberfile &>/dev/null
807        case $? in
808            0)  # Correcto.
809                ;;
810            14) # Intentar limpiar hibernación NTFS y montar.
811                ntfsfix -d $PART &>/dev/null && mount $PART $MNTDIR &>/dev/null || \
812                        ogRaiseError $OG_ERR_PARTITION "$1, $2" || return $?
813                ;;
814            *)  # Probar montaje de solo lectura.
815                mount $PART $MNTDIR -o ro &>/dev/null || \
816                        ogRaiseError $OG_ERR_PARTITION "$1, $2" || return $?
817                ;;
818        esac
[3249002]819        # Aviso de montaje de solo lectura.
820        if ogIsReadonly $1 $2; then
821            ogEcho warning "$FUNCNAME: $MSG_MOUNTREADONLY: \"$1, $2\""
822        fi
[e2c805a]823    else
[0d6e7222]824        # Montar sistema de archivos ZFS (un ZPOOL no comienza por "/").
825        zfs mount $PART 2>/dev/null
[e2c805a]826    fi
[aae34f6]827fi
[cbbb046]828echo "$MNTDIR"
[aae34f6]829}
830
831
[cade8c0]832#/**
833#         ogMountCdrom
834#@brief   Monta dispositivo óptico por defecto
835#@return  Punto de montaje
836#@exception OG_ERR_FORMAT    Formato incorrecto.
837#@exception OG_ERR_PARTITION Tipo de particion desconocido o no se puede montar.
838#@version
839#@author 
840#@date   
841#*/ ##
[42669ebf]842function ogMountCdrom ()
843{
[ee4a96e]844local DEV MNTDIR
[cade8c0]845# Si se solicita, mostrar ayuda.
846if [ "$*" == "help" ]; then
847    ogHelp "$FUNCNAME" "$FUNCNAME" "$FUNCNAME"
848    return
849fi
850# Error si se reciben parámetros.
851[ $# == 0 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[ee4a96e]852DEV="/dev/cdrom"            # Por defecto
853MNTDIR=$(mount | awk -v D=$DEV '{if ($1==D) {print $3}}')
854if [ -z "$MNTDIR" ]; then
855    MNTDIR=${DEV/dev/mnt}
856    mkdir -p $MNTDIR
857    mount -t iso9660 $DEV $MNTDIR || ogRaiseError $OG_ERR_PARTITION "cdrom" || return $?
858fi
859echo $MNTDIR
860}
861
[3f49cf7]862
863#/**
[b6208d8]864#         ogReduceFs int_ndisk int_nfilesys
[3f49cf7]865#@brief   Reduce el tamaño del sistema de archivos, sin tener en cuenta el espacio libre.
[42669ebf]866#@param   int_ndisk      nº de orden del disco
[b6208d8]867#@param   int_nfilesys   nº de orden del sistema de archivos
[d3669a2]868#@return  int_tamañoKB - tamaño en KB
[3f49cf7]869#@exception OG_ERR_FORMAT    Formato incorrecto.
870#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
871#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
[df097c2]872#@warning En Windows, se borran los ficheros de hiberanción y de paginación.
[d3669a2]873#@warning El sistema de archivos se amplía al mínimo + 10%.
[3458879]874#@note    Requisitos:   *resize*
[985bef0]875#@version 0.1 -  Integracion para Opengnsys  -  EAC:   ReduceFileSystem() en ATA.lib
876#@author  Antonio J. Doblas Viso. Universidad de Malaga
877#@date    2008-10-27
[b6208d8]878#@version 0.9 - Primera version para OpenGnSys.
[3f49cf7]879#@author  Ramon Gomez, ETSII Universidad de Sevilla
880#@date    2009-09-23
[d3669a2]881#@version 0.9.2 - Añadir un 10% al tamaño mínimo requerido.
882#@author  Ramon Gomez, ETSII Universidad de Sevilla
883#@date    2010-09-27
[c114529]884#@version 1.0 -  Deteccion automatica del tamaño minimo adecuado
885#@author  Antonio J. Doblas Viso. Universidad de Malaga
886#@date    2011-02-24
[3be0219]887#@version 1.0.6 - Integrar código de antigua función "ogReduceFsCheck".
888#@author  Ramon Gomez, ETSII Universidad de Sevilla
889#@date    2014-10-28
[1e7eaab]890#*/ ##
[42669ebf]891function ogReduceFs ()
892{
[3f49cf7]893# Variables locales
[3be0219]894local PART BLKS SIZE MAXSIZE EXTRASIZE=0 RETVAL
[3f49cf7]895
[1e7eaab]896# Si se solicita, mostrar ayuda.
[3f49cf7]897if [ "$*" == "help" ]; then
[e087194]898    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[3f49cf7]899           "$FUNCNAME 1 1"
900    return
901fi
[1e7eaab]902# Error si no se reciben 2 parámetros.
[3f49cf7]903[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
904
[1e7eaab]905# Obtener partición.
[3f49cf7]906PART="$(ogDiskToDev $1 $2)" || return $?
907
[1e7eaab]908# Redimensionar según el tipo de particion.
[3f49cf7]909case "$(ogGetFsType $1 $2)" in
[1c04494]910    EXT[234])
[3458879]911        ogUnmount $1 $2 2>/dev/null
[1c04494]912        # Ext2/3/4: Tamaño de los bloques del sistema de archivos
913        BLKS=$(tune2fs -l $PART | awk '/Block size/ {print int($3/512)}')
914        # Traduce el num. en sectores de 512B a tamano en MB.
[c114529]915        #SIZE=$(resize2fs -P $PART 2>/dev/null | \
916                #       awk -v B=$BLKS '/minimum size/ {print int($7*1.1*B/2048)}')
917        #resize2fs -fp $PART "${SIZE}M" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
918        resize2fs -fpM $PART  &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
[743257e]919        ;;
[3be0219]920
[3198512]921    BTRFS)
922        MNTDIR=$(ogMount $1 $2)
[5bc8d01]923        # Calcular tamaño ocupado + 10%, redondeado + 1 (incluyendo letra de unidad).
924        SIZE=$(btrfs filesystem show $MNTDIR | awk -v P=$PART '{ if ($8==P) printf ("%d%s", $6*1.1+1, substr($6,match($6,/[A-Z]/),1)) }')
925        btrfs filesystem resize ${SIZE} $MNTDIR 2>/dev/null
[3198512]926        ;;
927    REISERFS|REISER4)
928        # Calcular tamaño ocupado + 10%.
[3be0219]929        MNTDIR=$(ogMount $1 $2)
[3198512]930        SIZE=$[ $(df -k $MNTDIR | awk '{getline;print $3}') * 110 / 100 ]
931        ogUnmount $1 $2 2>/dev/null
[eb4614b]932        resize_reiserfs -s${SIZE}K $PART <<<"y"
[3198512]933        ;;
[3be0219]934
[5bc8d01]935    F2FS)   ;;          # No se reduce (por el momento).
[c452625]936    JFS)    ;;          # No se reduce (por el momento).
[5bc8d01]937    NILFS2) ;;          # No se reduce (probar "nilfs-resize").
[c452625]938    XFS)    ;;          # No se reduce (por el momento).
[3be0219]939
[b6208d8]940    NTFS)
[3be0219]941        # Calcular tamaño ocupado + 10%.
942        ogUnmount $1 $2 &>/dev/null
943        read -e MAXSIZE SIZE <<<$(ntfsresize -fi $PART | \
944                                  awk '/device size/ {d=$4}
945                                       /resize at/ {r=int($5*1.1/1024+1)*1024}
946                                       END { print d,r}')
947        # Error si no puede obtenerse el tamaño máximo del volumen.
[bec0f2f]948        [ -n "$MAXSIZE" -a -n "$SIZE" ] || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
[3be0219]949        # Simular la redimensión y comprobar si es necesario ampliarala.
950        RETVAL=1
951        while [ $RETVAL != 0 -a $[ SIZE+=EXTRASIZE ] -lt $MAXSIZE ]; do
952            # Obtener espacio de relocalización y devolver código de salida
953            # (ntfsresize devuelve 0 si no necesita relocalizar).
954            EXTRASIZE=$(ntfsresize -fns $SIZE $PART 2>/dev/null | \
955                        awk '/Needed relocations/ {print int($4*1.1/1024+1)*1024}'
956                        exit ${PIPESTATUS[0]})
957            RETVAL=$?
958        done
959        # Redimensionar solo si hace falta.
960        if [ $SIZE -lt $MAXSIZE ]; then
961            ntfsresize -fs $SIZE $PART <<<"y" >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
962        fi
[6277770]963        ;;
[3be0219]964
[c452625]965    EXFAT)  ;;          # No se reduce (por el momento).
966    FAT32|FAT16)  ;;    # No se reduce (probar "fatresize").
967    HFS|HFSPLUS)  ;;    # No se reduce (por el momento).
968    UFS)    ;;          # No se reduce (por el momento).
[3be0219]969
[1c04494]970    *)  ogRaiseError $OG_ERR_PARTITION "$1,$2"
[6277770]971        return $? ;;
[3f49cf7]972esac
[c114529]973
[3be0219]974# Devuelve tamaño del sistema de ficheros.
975ogGetFsSize $1 $2
[c114529]976}
977
978
[5dbb046]979#/**
[9d96c57]980#         ogUnlock int_ndisk int_npartition
[89403cd]981#@see     ogUnlockPartition
[6e390b1]982#*/ ##
[42669ebf]983function ogUnlock ()
984{
[89403cd]985ogUnlockPartition "$@"
986}
987
988#/**
989#         ogUnlockPartition int_ndisk int_npartition
[9d96c57]990#@brief   Elimina el fichero de bloqueo para una particion.
[42669ebf]991#@param   int_ndisk      nº de orden del disco
992#@param   int_npartition nº de orden de la partición
[9d96c57]993#@return  (nada)
994#@exception OG_ERR_FORMAT    Formato incorrecto.
995#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]996#@note    El fichero de bloqueo se localiza en \c /var/lock/part, siendo \c part el dispositivo de la partición, sustituyendo el carácter "/" por "-".
[b6208d8]997#@version 0.9 - Primera versión para OpenGnSys.
[9d96c57]998#@author  Ramon Gomez, ETSII Universidad de Sevilla
999#@date    2009-09-03
[1e7eaab]1000#*/ ##
[42669ebf]1001function ogUnlockPartition ()
1002{
[59f9ad2]1003# Variables locales
1004local PART LOCKFILE
[9d96c57]1005
[1e7eaab]1006# Si se solicita, mostrar ayuda.
[9d96c57]1007if [ "$*" == "help" ]; then
1008    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
1009           "$FUNCNAME 1 1"
1010    return
1011fi
[1e7eaab]1012# Error si no se reciben 2 parámetros.
[9d96c57]1013[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1014
[1e7eaab]1015# Obtener partición.
[9d96c57]1016PART="$(ogDiskToDev $1 $2)" || return $?
1017
[1e7eaab]1018# Borrar archivo de bloqueo exclusivo.
[73c8417]1019LOCKFILE="/var/lock/lock${PART//\//-}"
1020rm -f $LOCKFILE
[9d96c57]1021}
1022
1023
1024#/**
[5dbb046]1025#         ogUnmount int_ndisk int_npartition
[40488da]1026#@see     ogUnmountFs
[6e390b1]1027#*/ ##
[42669ebf]1028function ogUnmount ()
1029{
[40488da]1030ogUnmountFs "$@"
[89403cd]1031}
1032
1033#/**
[b6208d8]1034#         ogUnmountFs int_ndisk int_nfilesys
[5dbb046]1035#@brief   Desmonta un sistema de archivos.
[42669ebf]1036#@param   int_ndisk      nº de orden del disco
[b6208d8]1037#@param   int_nfilesys   nº de orden del sistema de archivos
[5dbb046]1038#@return  Nada
1039#@exception OG_ERR_FORMAT    Formato incorrecto.
1040#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1041#@warning La partición no está previamente montada o no se puede desmontar.
[985bef0]1042#@version 0.1 -  Integracion para Opengnsys  -  EAC:  UmountPartition() en FileSystem.lib
1043#@author  Antonio J. Doblas Viso. Universidad de Malaga
1044#@date    2008-10-27
[b6208d8]1045#@version 0.9 - Primera version para OpenGnSys.
[5dbb046]1046#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]1047#@date    2009-09-28
[1e7eaab]1048#*/ ##
[42669ebf]1049function ogUnmountFs ()
1050{
[59f9ad2]1051# Variables locales
[c56dec5]1052local PART MNTDIR
[5dbb046]1053
[1e7eaab]1054# Si se solicita, mostrar ayuda.
[5dbb046]1055if [ "$*" == "help" ]; then
1056    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" "$FUNCNAME 1 1"
1057    return
1058fi
[1e7eaab]1059# Error si no se reciben 2 parámetros.
[5dbb046]1060[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1061
[1e7eaab]1062# Obtener partición y punto de montaje.
[5dbb046]1063PART="$(ogDiskToDev $1 $2)" || return $?
[a3348ce]1064MNTDIR="$(ogGetMountPoint $1 $2)"
[5dbb046]1065
[1e7eaab]1066# Si está montada, desmontarla.
[c56dec5]1067if [ -n "$MNTDIR" ]; then
[5a4f399]1068    # Error si la particion está bloqueada.
[52fa3da]1069    if ogIsLocked $1 $2; then
1070        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $1, $2"
1071        return $?
1072    fi
[5a4f399]1073    # Desmontar y borrar punto de montaje.
[52fa3da]1074    umount $PART 2>/dev/null || ogEcho warning "$FUNCNAME: $MSG_DONTUNMOUNT: \"$1, $2\""
[5a4f399]1075    rmdir $MNTDIR 2>/dev/null || rm -f $MNTDIR 2>/dev/null
[5dbb046]1076else
1077    ogEcho warning "$MSG_DONTMOUNT: \"$1,$2\""
1078fi
1079}
1080
[ee4a96e]1081
[be81649]1082#/**
1083#         ogUnmountAll int_ndisk
1084#@brief   Desmonta todos los sistema de archivos de un disco, excepto el caché local.
[42669ebf]1085#@param   int_ndisk      nº de orden del disco
[be81649]1086#@return  Nada
1087#@exception OG_ERR_FORMAT    Formato incorrecto.
1088#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1089#@warning No se desmonta la partición marcada como caché local.
[b6208d8]1090#@version 0.9 - Versión para OpenGnSys.
[be81649]1091#@author  Ramon Gomez, ETSII Universidad de Sevilla
1092#@date    2009/10/07
[1e7eaab]1093#*/ ##
[42669ebf]1094function ogUnmountAll ()
1095{
[be81649]1096# Variables locales
[18f4bc2]1097local DISK PART
[1e7eaab]1098# Si se solicita, mostrar ayuda.
[18f4bc2]1099if [ "$*" == "help" ]; then
1100    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
1101    return
1102fi
[1e7eaab]1103# Error si no se recibe 1 parámetro.
[18f4bc2]1104[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1105
[1e7eaab]1106# Obtener partición y punto de montaje.
[18f4bc2]1107DISK="$(ogDiskToDev $1)" || return $?
1108for ((PART=1; PART<=$(ogGetPartitionsNumber $1); PART++)); do
1109    case "$(ogGetFsType $1 $PART)" in
[5804229]1110        CACHE) ;;
[7c52c30]1111        *)     ogUnmount $1 $PART 2>/dev/null ;;
[7250491]1112    esac
[18f4bc2]1113done
1114}
1115
[62c18f0]1116#/**
1117#         ogUnsetDirtyBit int_ndisk int_npart
1118#@brief   Inhabilita el Dirty Bit del sistema de ficheros NTFS para evitar un CHKDSK en el primer arranque
1119#@param   int_ndisk      nº de orden del disco
1120#@param   int_npart      nº de orden de partición
1121#@return  Nada
1122#@exception OG_ERR_FORMAT    Formato incorrecto.
1123#@version 0.1 - Versión para OpenGnSys.
1124#@author  Carmelo Cabezuelo, ASIC Universidad Politécnica de Valencia
1125#@date    2016/04/20
1126#*/ ##
1127function ogUnsetDirtyBit ()
1128{
1129# Variables locales
1130local PART
1131# Si se solicita, mostrar ayuda.
1132if [ "$*" == "help" ]; then
1133    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
1134    return
1135fi
1136# Error si no se reciben 2 parámetros.
1137[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1138
1139# Obtener partición y punto de montaje.
1140case "$(ogGetFsType $1 $2)" in
1141    NTFS)
1142        ogUnmount $1 $2 2>/dev/null
1143        PART="$(ogDiskToDev $1 $2)" || return $?
1144        ntfsfix -d $PART ;;
1145    *) ;;
1146esac
1147}
[c114529]1148
[d01525b]1149
1150#/**
1151#         ogGetFreeSize int_disco int_partition str_SizeOutput
1152#@brief   muestra informacion del tamaño total, datos y libre.
1153#@param   int_ndisk     nº de orden del disco
1154#@param   int_npart     nº de orden de partición
1155#@param   str_unitSize      unidad mostrada
1156#@return  int_size:int_data:int_free
1157#@TODO  Componer corretcamente esta función.
1158#@exception OG_ERR_FORMAT    Formato incorrecto.
1159#@version
1160#@author 
1161#@date   
1162#*/ ##
1163
1164function ogGetFreeSize ()
1165{
[d5fc0dc]1166local particion unit factor valor
[c114529]1167if [ $# = 0 ]
1168then
1169        echo "sintaxis: ogGetFreeSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
1170        echo "devuelve int_size : int_data : int_free" red
1171return
1172fi
1173if [ $# -ge 2 ]
1174then
1175        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
1176        if [ -z $3 ]
1177                then
1178                        unit=kB  # s B kB MB GB TB %
1179                else
1180                        unit=$3
1181        fi
1182        case $unit in
1183                kB)
1184                        factor="1.024";
1185                        #valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d:%d:%d", size,used,free}'`
1186                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", free}'`
1187                        ;;
[a957f02]1188                MB)
1189                        factor="1.024/1000";
1190                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024/1000; used=$3*1.024/1000; free=$4*1.024/1000; printf "%d:%d:%d", size,used,free}'`
1191                ;;
1192                GB)
1193                        factor="1.024/1000000";
1194                        valor=`df | grep $particion | awk -F" " '{size=$2*1.024/1000000; used=$3*1.024/1000000; free=$4*1.024/1000000; printf "%f:%f:%f", size,used,free}'`
1195                ;;
1196        esac
1197        #echo $valor
1198        #NumberRound $valor
1199        #valor=`NumberRound $valor`;
1200        echo $valor
1201fi
[c114529]1202}
1203
Note: See TracBrowser for help on using the repository browser.