source: client/engine/FileSystem.lib @ c31a439

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 c31a439 was f2c8049, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.4, #526: Corregir erratas en librería Disk.

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

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