source: client/engine/FileSystem.lib @ 6277770

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

Versión 1.0.4, #530: Corregida errata para eliminar el fichero hiberfil.sys en función ogReduceFs.

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

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