source: client/engine/FileSystem.lib @ e928e32

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

#724 #740: Usar parclone.imager en vez de partclone.dd para crear imágenes raw; comenzar a soportar nuevos sistemas de archivos como F2FS y NILFS.

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

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