source: client/engine/FileSystem.lib @ 5c8cf58c

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 5c8cf58c was ea8051a, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: función ogCheckFs devuelve códigos de error propios (antes daba la salida de la orden de comprobación).

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

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