source: client/engine/FileSystem.lib @ 1c9ef24

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 1c9ef24 was 858b1b0, checked in by ramon <ramongomez@…>, 9 years ago

#744: Nueva función ogIsDiskLocked; renombrada función ogIsLocked como ogIsPartitionLocked, manteniendo alias con nombre antiguo y adaptándola para comprobar también bloqueo de su disco.

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

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