source: client/engine/FileSystem.lib @ 3d70f46

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 3d70f46 was 3d70f46, checked in by ramon <ramongomez@…>, 9 years ago

#724: Adaptar formateos a nuevas versiones del comando mke2fs para evitar preguntas.

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

  • Property mode set to 100755
File size: 34.7 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
[5a4f399]480#*/ ##
481function ogIsFormated ()
482{
483# Variables locales
484local DISK
485if [ "$*" == "help" ]; then
[e087194]486    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[5a4f399]487           "if $FUNCNAME 1 1; then ... ; fi"
488    return
489fi
[7685100]490# Falso, en caso de error.
491[ $# == 2 ] || return 1
[5a4f399]492
[5962edd]493test -n "$(ogMount "$1" "$2" 2>/dev/null)"
[5a4f399]494}
495
496
497#/**
[b32f902]498#         ogIsLocked int_ndisk int_npartition
499#@brief   Comprueba si una partición está bloqueada por una operación de uso exclusivo.
500#@param   int_ndisk      nº de orden del disco
501#@param   int_npartition nº de orden de la partición
502#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
503#@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 "-".
504#@version 0.9 - Primera versión para OpenGnSys.
505#@author  Ramon Gomez, ETSII Universidad de Sevilla
506#@date    2009-09-03
507#@version 1.0.1 - Devolver falso en caso de error.
508#@author  Ramon Gomez, ETSII Universidad de Sevilla
509#@date    2011-05-18
510#*/ ##
511function ogIsLocked ()
512{
513# Variables locales
514local PART LOCKFILE
515
516# Si se solicita, mostrar ayuda.
517if [ "$*" == "help" ]; then
518    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
519           "if $FUNCNAME 1 1; then ... ; fi"
520    return
521fi
522# Falso, en caso de error.
523[ $# == 2 ] || return 1
524
525# Obtener partición.
526PART="$(ogDiskToDev $1 $2)" || return 1
527
528# Comprobar existencia del fichero de bloqueo.
529LOCKFILE="/var/lock/lock${PART//\//-}"
530test -f $LOCKFILE
531}
532
533
534#/**
[b6208d8]535#         ogIsMounted int_ndisk int_nfilesys
[a3348ce]536#@brief   Comprueba si un sistema de archivos está montado.
[42669ebf]537#@param   int_ndisk      nº de orden del disco
[b6208d8]538#@param   int_nfilesys   nº de orden del sistema de archivos
[7685100]539#@return  Código de salida: 0 - montado, 1 - sin montar o error.
[b6208d8]540#@version 0.9 - Primera versión para OpenGnSys.
[f8f4dfa]541#@author  Ramon Gomez, ETSII Universidad de Sevilla
542#@date    2009-10-15
[7685100]543#@version 1.0.1 - Devolver falso en caso de error.
544#@author  Ramon Gomez, ETSII Universidad de Sevilla
545#@date    2011-05-18
[1e7eaab]546#*/ ##
[42669ebf]547function ogIsMounted ()
548{
549# Si se solicita, mostrar ayuda.
[a3348ce]550if [ "$*" == "help" ]; then
[e087194]551    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[a3348ce]552           "if $FUNCNAME 1 1; then ... ; fi"
553    return
554fi
[7685100]555# Falso, en caso de error.
556[ $# == 2 ] || return 1
[a3348ce]557
558test -n "$(ogGetMountPoint $1 $2)"
559}
560
561
[aae34f6]562#/**
[3249002]563#         ogIsReadonly int_ndisk int_nfilesys
564#@brief   Comprueba si un sistema de archivos está montado solo de lectura.
565#@param   int_ndisk      nº de orden del disco
566#@param   int_nfilesys   nº de orden del sistema de archivos
567#@return  Código de salida: 0 - montado solo de lectura, 1 - con escritura o no montado.
568#@version 1.1.0 - Primera versión para OpenGnsys.
569#@author  Ramon Gomez, ETSII Universidad de Sevilla
570#@date    2016-01-20
571#/**
572function ogIsReadonly ()
573{
574# Variables locales
575local PART
576
577# Si se solicita, mostrar ayuda.
578if [ "$*" == "help" ]; then
579    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys" \
580           "if $FUNCNAME 1 1; then ... ; fi"
581    return
582fi
583# Falso, en caso de error.
584[ $# == 2 ] || return 1
585
586# Obtener partición.
587PART="$(ogDiskToDev $1 $2)" || return 1
588
589test -n "$(findmnt -n -o OPTIONS $PART | awk 'BEGIN {RS=","} /^ro$/ {print}')"
590}
591
592
593#/**
[b32f902]594#         ogIsWritable int_ndisk int_nfilesys
595#@brief   Comprueba si un sistema de archivos está montado de lectura y escritura.
[42669ebf]596#@param   int_ndisk      nº de orden del disco
[b32f902]597#@param   int_nfilesys   nº de orden del sistema de archivos
598#@return  Código de salida: 0 - lectura y escritura, 1 - solo lectura o no montado.
599#@version 1.0.5 - Primera versión para OpenGnSys.
[7685100]600#@author  Ramon Gomez, ETSII Universidad de Sevilla
[b32f902]601#@date    2013-10-09
602#/**
603function ogIsWritable ()
[42669ebf]604{
[59f9ad2]605# Variables locales
[b32f902]606local PART
[9d96c57]607
[1e7eaab]608# Si se solicita, mostrar ayuda.
[9d96c57]609if [ "$*" == "help" ]; then
[b32f902]610    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_filesys" \
[a3348ce]611           "if $FUNCNAME 1 1; then ... ; fi"
[9d96c57]612    return
613fi
[7685100]614# Falso, en caso de error.
615[ $# == 2 ] || return 1
[9d96c57]616
[1e7eaab]617# Obtener partición.
[7685100]618PART="$(ogDiskToDev $1 $2)" || return 1
[9d96c57]619
[b32f902]620test -n "$(findmnt -n -o OPTIONS $PART | awk 'BEGIN {RS=","} /^rw$/ {print}')"
[9d96c57]621}
622
623
624#/**
625#         ogLock int_ndisk int_npartition
[89403cd]626#@see     ogLockPartition
627#*/
[42669ebf]628function ogLock ()
629{
[89403cd]630ogLockPartition "$@"
631}
632
633#/**
634#         ogLockPartition int_ndisk int_npartition
[9d96c57]635#@brief   Genera un fichero de bloqueo para una partición en uso exlusivo.
[42669ebf]636#@param   int_ndisk      nº de orden del disco
637#@param   int_npartition nº de orden de la partición
[9d96c57]638#@return  (nada)
639#@exception OG_ERR_FORMAT    Formato incorrecto.
640#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]641#@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]642#@version 0.9 - Primera versión para OpenGnSys.
[9d96c57]643#@author  Ramon Gomez, ETSII Universidad de Sevilla
644#@date    2009-09-03
[1e7eaab]645#*/ ##
[42669ebf]646function ogLockPartition ()
647{
[59f9ad2]648# Variables locales
649local PART LOCKFILE
[9d96c57]650
[1e7eaab]651# Si se solicita, mostrar ayuda.
[9d96c57]652if [ "$*" == "help" ]; then
653    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
654           "$FUNCNAME 1 1"
655    return
656fi
[1e7eaab]657# Error si no se reciben 2 parámetros.
[9d96c57]658[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
659
[1e7eaab]660# Obtener partición.
[9d96c57]661PART="$(ogDiskToDev $1 $2)" || return $?
662
[1e7eaab]663# Crear archivo de bloqueo exclusivo.
[73c8417]664LOCKFILE="/var/lock/lock${PART//\//-}"
665touch $LOCKFILE
[9d96c57]666}
667
668
669#/**
[b6208d8]670#         ogMount int_ndisk int_nfilesys
[3458879]671#@see     ogMountFs ogMountCache ogMountCdrom
[1e7eaab]672#*/ ##
[42669ebf]673function ogMount ()
674{
[ee4a96e]675case "$*" in
[18f4bc2]676    CACHE|cache)
677        ogMountCache ;;
[ee4a96e]678    CDROM|cdrom)
679        ogMountCdrom ;;
680    *)  ogMountFs "$@" ;;
681esac
[73c8417]682}
683
[ee4a96e]684
[73c8417]685#/**
[b6208d8]686#         ogMountFs int_ndisk int_nfilesys
[aae34f6]687#@brief   Monta un sistema de archivos.
[42669ebf]688#@param   int_ndisk      nº de orden del disco
[b6208d8]689#@param   int_nfilesys   nº de orden del sistema de archivos
[aae34f6]690#@return  Punto de montaje
691#@exception OG_ERR_FORMAT    Formato incorrecto.
692#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
693#@exception OG_ERR_PARTITION Tipo de particion desconocido o no se puede montar.
[985bef0]694#@version 0.1 -  Integracion para Opengnsys  -  EAC:   MountPartition() en FileSystem.lib
695#@author  Antonio J. Doblas Viso. Universidad de Malaga
696#@date    2008-10-27
[b6208d8]697#@version 0.9 - Primera version para OpenGnSys.
[aae34f6]698#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]699#@date    2009-09-28
[b6208d8]700#@version 1.0.5 - Independiente del tipo de sistema de ficheros.
[02f271b]701#@author  Ramon Gomez, ETSII Universidad de Sevilla
[3011075]702#@date    2012-09-04
[0d6e7222]703#@version 1.1.0 - Montar sistema de archivos ZFS.
704#@author  Ramon Gomez, ETSII Universidad de Sevilla
705#@date    2014-11-14
[1e7eaab]706#*/ ##
[42669ebf]707function ogMountFs ()
708{
[1e7eaab]709# Variables locales
[b6208d8]710local PART MNTDIR
[aae34f6]711
[1e7eaab]712# Si se solicita, mostrar ayuda.
[aae34f6]713if [ "$*" == "help" ]; then
[e087194]714    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[aae34f6]715           "$FUNCNAME 1 1  =>  /mnt/sda1"
716    return
717fi
[1e7eaab]718# Error si no se reciben 2 parámetros.
[aae34f6]719[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
720
[1e7eaab]721# Obtener partición.
[b6208d8]722PART="$(ogDiskToDev "$1" "$2")" || return $?
[aae34f6]723
[1e7eaab]724# Comprobar si el sistema de archivos ya está montada.
[a3348ce]725MNTDIR="$(ogGetMountPoint $1 $2)"
[e2c805a]726# Si no, montarlo en un directorio de sistema.
[aae34f6]727if [ -z "$MNTDIR" ]; then
728    # Error si la particion esta bloqueada.
[52fa3da]729    if ogIsLocked $1 $2; then
730        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION, $1 $2"
731        return $?
732    fi
[0d6e7222]733    # El camino de un dispositivo normal comienza por el carácter "/".
734    if [[ "$PART" =~ ^/ ]]; then
735        # Crear punto de montaje o enlace simbólico para caché local.
736        MNTDIR=${PART/dev/mnt}
[3249002]737        DEBUG="no"
[0d6e7222]738        if [ "$(ogFindCache)" == "$1 $2" -a -n "$OGCAC" ]; then
739            mkdir -p $OGCAC
740            ln -fs $OGCAC $MNTDIR
741        else
742            mkdir -p $MNTDIR
743        fi
[3249002]744        unset DEBUG
[0d6e7222]745        # Montar sistema de archivos.
746        mount $PART $MNTDIR &>/dev/null || \
[45dad2c]747                   mount $PART $MNTDIR -o force,remove_hiberfile &>/dev/null || \
[3249002]748                   mount $PART $MNTDIR -o ro &>/dev/null || \
[ee0377b]749                   ogRaiseError $OG_ERR_PARTITION "$1, $2" || return $?
[3249002]750        # Aviso de montaje de solo lectura.
751        if ogIsReadonly $1 $2; then
752            ogEcho warning "$FUNCNAME: $MSG_MOUNTREADONLY: \"$1, $2\""
753        fi
[e2c805a]754    else
[0d6e7222]755        # Montar sistema de archivos ZFS (un ZPOOL no comienza por "/").
756        zfs mount $PART 2>/dev/null
[e2c805a]757    fi
[aae34f6]758fi
[cbbb046]759echo "$MNTDIR"
[aae34f6]760}
761
762
[ee4a96e]763#####  PRUEBAS
764# Montar CDROM
[42669ebf]765function ogMountCdrom ()
766{
[ee4a96e]767local DEV MNTDIR
768DEV="/dev/cdrom"            # Por defecto
769MNTDIR=$(mount | awk -v D=$DEV '{if ($1==D) {print $3}}')
770if [ -z "$MNTDIR" ]; then
771    MNTDIR=${DEV/dev/mnt}
772    mkdir -p $MNTDIR
773    mount -t iso9660 $DEV $MNTDIR || ogRaiseError $OG_ERR_PARTITION "cdrom" || return $?
774fi
775echo $MNTDIR
776}
777
[3f49cf7]778
779#/**
[b6208d8]780#         ogReduceFs int_ndisk int_nfilesys
[3f49cf7]781#@brief   Reduce el tamaño del sistema de archivos, sin tener en cuenta el espacio libre.
[42669ebf]782#@param   int_ndisk      nº de orden del disco
[b6208d8]783#@param   int_nfilesys   nº de orden del sistema de archivos
[d3669a2]784#@return  int_tamañoKB - tamaño en KB
[3f49cf7]785#@exception OG_ERR_FORMAT    Formato incorrecto.
786#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
787#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
[df097c2]788#@warning En Windows, se borran los ficheros de hiberanción y de paginación.
[d3669a2]789#@warning El sistema de archivos se amplía al mínimo + 10%.
[3458879]790#@note    Requisitos:   *resize*
[985bef0]791#@version 0.1 -  Integracion para Opengnsys  -  EAC:   ReduceFileSystem() en ATA.lib
792#@author  Antonio J. Doblas Viso. Universidad de Malaga
793#@date    2008-10-27
[b6208d8]794#@version 0.9 - Primera version para OpenGnSys.
[3f49cf7]795#@author  Ramon Gomez, ETSII Universidad de Sevilla
796#@date    2009-09-23
[d3669a2]797#@version 0.9.2 - Añadir un 10% al tamaño mínimo requerido.
798#@author  Ramon Gomez, ETSII Universidad de Sevilla
799#@date    2010-09-27
[c114529]800#@version 1.0 -  Deteccion automatica del tamaño minimo adecuado
801#@author  Antonio J. Doblas Viso. Universidad de Malaga
802#@date    2011-02-24
[3be0219]803#@version 1.0.6 - Integrar código de antigua función "ogReduceFsCheck".
804#@author  Ramon Gomez, ETSII Universidad de Sevilla
805#@date    2014-10-28
[1e7eaab]806#*/ ##
[42669ebf]807function ogReduceFs ()
808{
[3f49cf7]809# Variables locales
[3be0219]810local PART BLKS SIZE MAXSIZE EXTRASIZE=0 RETVAL
[3f49cf7]811
[1e7eaab]812# Si se solicita, mostrar ayuda.
[3f49cf7]813if [ "$*" == "help" ]; then
[e087194]814    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_nfilesys" \
[3f49cf7]815           "$FUNCNAME 1 1"
816    return
817fi
[1e7eaab]818# Error si no se reciben 2 parámetros.
[3f49cf7]819[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
820
[1e7eaab]821# Obtener partición.
[3f49cf7]822PART="$(ogDiskToDev $1 $2)" || return $?
823
[1e7eaab]824# Redimensionar según el tipo de particion.
[3f49cf7]825case "$(ogGetFsType $1 $2)" in
[1c04494]826    EXT[234])
[3458879]827        ogUnmount $1 $2 2>/dev/null
[1c04494]828        # Ext2/3/4: Tamaño de los bloques del sistema de archivos
829        BLKS=$(tune2fs -l $PART | awk '/Block size/ {print int($3/512)}')
830        # Traduce el num. en sectores de 512B a tamano en MB.
[c114529]831        #SIZE=$(resize2fs -P $PART 2>/dev/null | \
832                #       awk -v B=$BLKS '/minimum size/ {print int($7*1.1*B/2048)}')
833        #resize2fs -fp $PART "${SIZE}M" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
834        resize2fs -fpM $PART  &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
[743257e]835        ;;
[3be0219]836
[3198512]837    BTRFS)
838        MNTDIR=$(ogMount $1 $2)
839        # Calcular tamaño ocupado + 10%.
840        SIZE=$[ $(df -k $MNTDIR | awk '{getline;print $3}') * 110 / 100 ]
841        btrfs filesystem resize ${SIZE}k $MNTDIR
842        ;;
843    REISERFS|REISER4)
844        # Calcular tamaño ocupado + 10%.
[3be0219]845        MNTDIR=$(ogMount $1 $2)
[3198512]846        SIZE=$[ $(df -k $MNTDIR | awk '{getline;print $3}') * 110 / 100 ]
847        ogUnmount $1 $2 2>/dev/null
[eb4614b]848        resize_reiserfs -s${SIZE}K $PART <<<"y"
[3198512]849        ;;
[3be0219]850
[c452625]851    JFS)    ;;          # No se reduce (por el momento).
852    XFS)    ;;          # No se reduce (por el momento).
[3be0219]853
[b6208d8]854    NTFS)
[3be0219]855        # Calcular tamaño ocupado + 10%.
856        ogUnmount $1 $2 &>/dev/null
857        read -e MAXSIZE SIZE <<<$(ntfsresize -fi $PART | \
858                                  awk '/device size/ {d=$4}
859                                       /resize at/ {r=int($5*1.1/1024+1)*1024}
860                                       END { print d,r}')
861        # Error si no puede obtenerse el tamaño máximo del volumen.
862        [ -n "$MAXSIZE" ] || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
863        # Simular la redimensión y comprobar si es necesario ampliarala.
864        RETVAL=1
865        while [ $RETVAL != 0 -a $[ SIZE+=EXTRASIZE ] -lt $MAXSIZE ]; do
866            # Obtener espacio de relocalización y devolver código de salida
867            # (ntfsresize devuelve 0 si no necesita relocalizar).
868            EXTRASIZE=$(ntfsresize -fns $SIZE $PART 2>/dev/null | \
869                        awk '/Needed relocations/ {print int($4*1.1/1024+1)*1024}'
870                        exit ${PIPESTATUS[0]})
871            RETVAL=$?
872        done
873        # Redimensionar solo si hace falta.
874        if [ $SIZE -lt $MAXSIZE ]; then
875            ntfsresize -fs $SIZE $PART <<<"y" >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
876        fi
[6277770]877        ;;
[3be0219]878
[c452625]879    EXFAT)  ;;          # No se reduce (por el momento).
880    FAT32|FAT16)  ;;    # No se reduce (probar "fatresize").
881    HFS|HFSPLUS)  ;;    # No se reduce (por el momento).
882    UFS)    ;;          # No se reduce (por el momento).
[3be0219]883
[1c04494]884    *)  ogRaiseError $OG_ERR_PARTITION "$1,$2"
[6277770]885        return $? ;;
[3f49cf7]886esac
[c114529]887
[3be0219]888# Devuelve tamaño del sistema de ficheros.
889ogGetFsSize $1 $2
[c114529]890}
891
892
[5dbb046]893#/**
[9d96c57]894#         ogUnlock int_ndisk int_npartition
[89403cd]895#@see     ogUnlockPartition
[6e390b1]896#*/ ##
[42669ebf]897function ogUnlock ()
898{
[89403cd]899ogUnlockPartition "$@"
900}
901
902#/**
903#         ogUnlockPartition int_ndisk int_npartition
[9d96c57]904#@brief   Elimina el fichero de bloqueo para una particion.
[42669ebf]905#@param   int_ndisk      nº de orden del disco
906#@param   int_npartition nº de orden de la partición
[9d96c57]907#@return  (nada)
908#@exception OG_ERR_FORMAT    Formato incorrecto.
909#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]910#@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]911#@version 0.9 - Primera versión para OpenGnSys.
[9d96c57]912#@author  Ramon Gomez, ETSII Universidad de Sevilla
913#@date    2009-09-03
[1e7eaab]914#*/ ##
[42669ebf]915function ogUnlockPartition ()
916{
[59f9ad2]917# Variables locales
918local PART LOCKFILE
[9d96c57]919
[1e7eaab]920# Si se solicita, mostrar ayuda.
[9d96c57]921if [ "$*" == "help" ]; then
922    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
923           "$FUNCNAME 1 1"
924    return
925fi
[1e7eaab]926# Error si no se reciben 2 parámetros.
[9d96c57]927[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
928
[1e7eaab]929# Obtener partición.
[9d96c57]930PART="$(ogDiskToDev $1 $2)" || return $?
931
[1e7eaab]932# Borrar archivo de bloqueo exclusivo.
[73c8417]933LOCKFILE="/var/lock/lock${PART//\//-}"
934rm -f $LOCKFILE
[9d96c57]935}
936
937
938#/**
[5dbb046]939#         ogUnmount int_ndisk int_npartition
[40488da]940#@see     ogUnmountFs
[6e390b1]941#*/ ##
[42669ebf]942function ogUnmount ()
943{
[40488da]944ogUnmountFs "$@"
[89403cd]945}
946
947#/**
[b6208d8]948#         ogUnmountFs int_ndisk int_nfilesys
[5dbb046]949#@brief   Desmonta un sistema de archivos.
[42669ebf]950#@param   int_ndisk      nº de orden del disco
[b6208d8]951#@param   int_nfilesys   nº de orden del sistema de archivos
[5dbb046]952#@return  Nada
953#@exception OG_ERR_FORMAT    Formato incorrecto.
954#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
955#@warning La partición no está previamente montada o no se puede desmontar.
[985bef0]956#@version 0.1 -  Integracion para Opengnsys  -  EAC:  UmountPartition() en FileSystem.lib
957#@author  Antonio J. Doblas Viso. Universidad de Malaga
958#@date    2008-10-27
[b6208d8]959#@version 0.9 - Primera version para OpenGnSys.
[5dbb046]960#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]961#@date    2009-09-28
[1e7eaab]962#*/ ##
[42669ebf]963function ogUnmountFs ()
964{
[59f9ad2]965# Variables locales
[c56dec5]966local PART MNTDIR
[5dbb046]967
[1e7eaab]968# Si se solicita, mostrar ayuda.
[5dbb046]969if [ "$*" == "help" ]; then
970    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" "$FUNCNAME 1 1"
971    return
972fi
[1e7eaab]973# Error si no se reciben 2 parámetros.
[5dbb046]974[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
975
[1e7eaab]976# Obtener partición y punto de montaje.
[5dbb046]977PART="$(ogDiskToDev $1 $2)" || return $?
[a3348ce]978MNTDIR="$(ogGetMountPoint $1 $2)"
[5dbb046]979
[1e7eaab]980# Si está montada, desmontarla.
[c56dec5]981if [ -n "$MNTDIR" ]; then
[5a4f399]982    # Error si la particion está bloqueada.
[52fa3da]983    if ogIsLocked $1 $2; then
984        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $1, $2"
985        return $?
986    fi
[5a4f399]987    # Desmontar y borrar punto de montaje.
[52fa3da]988    umount $PART 2>/dev/null || ogEcho warning "$FUNCNAME: $MSG_DONTUNMOUNT: \"$1, $2\""
[5a4f399]989    rmdir $MNTDIR 2>/dev/null || rm -f $MNTDIR 2>/dev/null
[5dbb046]990else
991    ogEcho warning "$MSG_DONTMOUNT: \"$1,$2\""
992fi
993}
994
[ee4a96e]995
[be81649]996#/**
997#         ogUnmountAll int_ndisk
998#@brief   Desmonta todos los sistema de archivos de un disco, excepto el caché local.
[42669ebf]999#@param   int_ndisk      nº de orden del disco
[be81649]1000#@return  Nada
1001#@exception OG_ERR_FORMAT    Formato incorrecto.
1002#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
1003#@warning No se desmonta la partición marcada como caché local.
[b6208d8]1004#@version 0.9 - Versión para OpenGnSys.
[be81649]1005#@author  Ramon Gomez, ETSII Universidad de Sevilla
1006#@date    2009/10/07
[1e7eaab]1007#*/ ##
[42669ebf]1008function ogUnmountAll ()
1009{
[be81649]1010# Variables locales
[18f4bc2]1011local DISK PART
[1e7eaab]1012# Si se solicita, mostrar ayuda.
[18f4bc2]1013if [ "$*" == "help" ]; then
1014    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
1015    return
1016fi
[1e7eaab]1017# Error si no se recibe 1 parámetro.
[18f4bc2]1018[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1019
[1e7eaab]1020# Obtener partición y punto de montaje.
[18f4bc2]1021DISK="$(ogDiskToDev $1)" || return $?
1022for ((PART=1; PART<=$(ogGetPartitionsNumber $1); PART++)); do
1023    case "$(ogGetFsType $1 $PART)" in
[5804229]1024        CACHE) ;;
[7c52c30]1025        *)     ogUnmount $1 $PART 2>/dev/null ;;
[7250491]1026    esac
[18f4bc2]1027done
1028}
1029
[c114529]1030
[0390d46]1031# AVISO:  Componer corretcamente esta función.
[c114529]1032function ogGetFreeSize () {
[d5fc0dc]1033local particion unit factor valor
[c114529]1034if [ $# = 0 ]
1035then
1036        echo "sintaxis: ogGetFreeSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
1037        echo "devuelve int_size : int_data : int_free" red
1038return
1039fi
1040if [ $# -ge 2 ]
1041then
1042        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
1043        if [ -z $3 ]
1044                then
1045                        unit=kB  # s B kB MB GB TB %
1046                else
1047                        unit=$3
1048        fi
1049        case $unit in
1050                kB)
1051                        factor="1.024";
1052                        #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}'`
1053                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", free}'`
1054                        ;;
[a957f02]1055                MB)
1056                        factor="1.024/1000";
1057                        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}'`
1058                ;;
1059                GB)
1060                        factor="1.024/1000000";
1061                        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}'`
1062                ;;
1063        esac
1064        #echo $valor
1065        #NumberRound $valor
1066        #valor=`NumberRound $valor`;
1067        echo $valor
1068fi
[c114529]1069}
1070
Note: See TracBrowser for help on using the repository browser.