source: client/engine/FileSystem.lib @ 308f61c

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

Versión 1.0.4, #518: Corregir errata en función ogFormatFs aplicacando cambios de revisión r2998.

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

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