source: client/engine/FileSystem.lib @ 039e025

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 039e025 was 7376c5b, checked in by ramon <ramongomez@…>, 12 years ago

#602: Función ogExtendFs comprueba correctamente que el sistema de ficheros se ha desmontado antes de extenderlo.

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

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