source: client/engine/FileSystem.lib @ d063c01

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 d063c01 was bec0f2f, checked in by ramon <ramongomez@…>, 8 years ago

#754: Aplicar r5159 en versión 1.1

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

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