source: client/engine/FileSystem.lib @ 1616b6e

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

Versión 1.0.2: función ogCheckFs solo devuelve errores de ejecución e ignora los códigos de salida de comprobación de sistema de archivos; función ogFormatFs inicia partición de swap.

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

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