source: client/engine/FileSystem.lib @ 900be258

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 900be258 was 0d6e7222, checked in by ramon <ramongomez@…>, 10 years ago

#676: Integrar código desarrollado para el ticket:676 en rama de versión 1.1.

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

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