source: client/engine/FileSystem.lib @ 20a91aa

Last change on this file since 20a91aa was 71643c0, checked in by ramon <ramongomez@…>, 13 years ago

Integrar versión 1.0.2 en rama trunk (modificar #464).

git-svn-id: https://opengnsys.es/svn/trunk@2404 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 31.6 KB
RevLine 
[2e15649]1#!/bin/bash
2#/**
3#@file    FileSystem.lib
[9f57de01]4#@brief   Librería o clase FileSystem
[2e15649]5#@class   FileSystem
6#@brief   Funciones para gestión de sistemas de archivos.
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.
[71643c0]24#@version 0.9 - Primera adaptación para OpenGnSys.
[be81649]25#@author  Ramon Gomez, ETSII Universidad de Sevilla
26#@date    2009-10-07
[71643c0]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.
[71643c0]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
[71643c0]42# Error si no se reciben 2 parámetros.
[1956672]43[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[71643c0]44# Obtener partición.
[1956672]45PART="$(ogDiskToDev $1 $2)" || return $?
[be81649]46
47TYPE=$(ogGetFsType $1 $2)
48case "$TYPE" in
[71643c0]49    EXT[234])     PROG="e2fsck"; PARAMS="-y"; CODES=(1 2) ;;
50    REISERFS)     PROG="fsck.reiserfs"; PARAMS="<<<\"Yes\""; CODES=(1 2) ;;
51    REISER4)      PROG="fsck.reiser4"; PARAMS="-ay" ;;
52    JFS)          PROG="fsck.jfs"; CODES=(1 2) ;;
[a3348ce]53    XFS)          PROG="fsck.xfs" ;;
54    NTFS|HNTFS)   PROG="ntfsfix" ;;
[71643c0]55    FAT32|HFAT32) PROG="dosfsck"; PARAMS="-a"; CODES=1 ;;
56    FAT16|HFAT16) PROG="dosfsck"; PARAMS="-a"; CODES=1 ;;
57    FAT12|HFAT12) PROG="dosfsck"; PARAMS="-a"; CODES=1 ;;
[c7d9af7]58    *)            ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE"
[71643c0]59                  return $? ;;
[1956672]60esac
[71643c0]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
[71643c0]70# Comprobar en modo uso exclusivo.
[a3348ce]71ogLock $1 $2
72eval $PROG $PARAMS $PART
73ERRCODE=$?
74case $ERRCODE in
[71643c0]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.
[71643c0]107local PART TYPE PROG PARAMS ERRCODE
[3f49cf7]108
[71643c0]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
[71643c0]115# Error si no se reciben 2 parámetros.
[3f49cf7]116[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
117
[71643c0]118# Obtener partición.
[3f49cf7]119PART="$(ogDiskToDev $1 $2)" || return $?
120
[1c04494]121ogUnmount $1 $2 2>/dev/null
[71643c0]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" ;;
127    NTFS|HNTFS) PROG="ntfsresize"; PARAMS="<<<\"y\" -f" ;;
128    *)          ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
129                return $? ;;
[3f49cf7]130esac
[71643c0]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
[71643c0]140# Redimensionar en modo uso exclusivo.
[2717297]141ogLock $1 $2
[1c04494]142eval $PROG $PARAMS $PART &>/dev/null
[2717297]143ERRCODE=$?
144case $ERRCODE in
145    0)    ;;
[71643c0]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" ;;
[71643c0]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
[3458879]287#@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]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
293#@version 0.9 - Primera adaptacion para OpenGNSys.
[9f57de01]294#@author  Ramon Gomez, ETSII Universidad de Sevilla
[5dbb046]295#@date    2009-07-21
[1e7eaab]296#*/ ##
[71643c0]297function ogGetFsType ()
298{
[59f9ad2]299# Variables locales.
[71643c0]300local DISK ID TYPE
[1e7eaab]301# Si se solicita, mostrar ayuda.
[59f9ad2]302if [ "$*" == "help" ]; then
303    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
304           "$FUNCNAME 1 1  =>  NTFS"
305    return
306fi
[1e7eaab]307# Error si no se reciben 2 parámetros.
[a5df9b9]308[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[2e15649]309
[1e7eaab]310# Detectar id. de tipo de partición y codificar al mnemonico.
[4395836]311DISK=$(ogDiskToDev "$1") || return $?
[3458879]312ID=$(ogGetPartitionId "$1" "$2") || return $?
[2e15649]313case "$ID" in
[b550747]314     0)         TYPE="EMPTY" ;;
[f8f4dfa]315     1)         TYPE="FAT12" ;;
[b550747]316     5|f)       TYPE="EXTENDED" ;;
317     [6e])      TYPE="FAT16" ;;
318     7)         TYPE="NTFS" ;;          # Nota: también puede ser EXFAT
319     [bc])      TYPE="FAT32" ;;
[f8f4dfa]320     11)        TYPE="HFAT12" ;;
[b550747]321     12)        TYPE="COMPAQDIAG" ;;
322     1[6e])     TYPE="HFAT16" ;;
323     17)        TYPE="HNTFS" ;;
324     1[bc])     TYPE="HFAT32" ;;
325     42)        TYPE="WIN-DYNAMIC" ;;
326     82)        TYPE="LINUX-SWAP" ;;
[697a9ee]327     83)        TYPE="$(parted -sm $DISK print 2>/dev/null | \
328                            awk -F: -v fs=$2 '{if ($1==fs) {print toupper($5)}}')"
[8971dc86]329                # Si el tipo no es válido para partición Linux, Ext3 por defecto.
330                case "$TYPE" in
331                     EXT[234]|REISERFS|REISER4|BTRFS|JFS|XFS)
332                         ;;
333                     *)  TYPE="EXT3" ;;
334                esac
[42669ebf]335                ;;
[b550747]336     8e)        TYPE="LINUX-LVM" ;;
[ee4a96e]337     a7)        TYPE="CACHE" ;;         # (compatibilidad con Brutalix)
[697a9ee]338     af)        TYPE="HFS" ;;
[b550747]339     bf)        TYPE="SOLARIS" ;;
[ee4a96e]340     ca)        TYPE="CACHE" ;;
[b550747]341     fd)        TYPE="LINUX-RAID" ;;
342     *)         TYPE="UNKNOWN" ;;
[2e15649]343esac
[71643c0]344echo "$TYPE"
[2e15649]345}
346
[aae34f6]347
[a3348ce]348#/**
349#         ogGetMountPoint int_ndisk int_npartition
350#@brief   Devuelve el punto de montaje de un sistema de archivos.
[42669ebf]351#@param   int_ndisk      nº de orden del disco
352#@param   int_npartition nº de orden de la partición
[f8f4dfa]353#@return  Punto de montaje
354#@exception OG_ERR_FORMAT    Formato incorrecto.
355#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[3458879]356#@note    Requisitos: \c mount* \c awk
[f8f4dfa]357#@version 0.9 - Primera versión para OpenGNSys.
358#@author  Ramon Gomez, ETSII Universidad de Sevilla
359#@date    2009-10-15
[1e7eaab]360#*/ ##
[42669ebf]361function ogGetMountPoint ()
362{
[a3348ce]363# Variables locales
364local PART
[1e7eaab]365# Si se solicita, mostrar ayuda.
[a3348ce]366if [ "$*" == "help" ]; then
367    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
368           "$FUNCNAME 1 1  =>  /mnt/sda1"
369    return
370fi
[1e7eaab]371# Error si no se reciben 2 parámetros.
[a3348ce]372[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[1e7eaab]373# Obtener partición.
[a3348ce]374PART="$(ogDiskToDev $1 $2)" || return $?
375
[2af9738]376mount | awk -v P=$PART '{if ($1==P) {print $3}}'
[a3348ce]377}
378
379
380#/**
[5a4f399]381#         ogIsFormated int_ndisk int_npartition
382#@brief   Comprueba si un sistema de archivos está formateado.
383#@param   int_ndisk      nº de orden del disco o volumen.
384#@param   int_npartition nº de orden del sistema de archivos.
[ecd8d9a]385#@return  Código de salida: 0 - formateado, 1 - sin formato o error.
[5a4f399]386#@version 0.91 - Adaptación inicial para comprobar que existe caché.
387#@author  Ramon Gomez, ETSII Universidad de Sevilla
388#@date    2010-03-18
[ecd8d9a]389#@version 1.0.1 - Devolver falso en caso de error.
390#@author  Ramon Gomez, ETSII Universidad de Sevilla
391#@date    2011-05-18
[5a4f399]392#*/ ##
393function ogIsFormated ()
394{
395# Variables locales
396local DISK
397if [ "$*" == "help" ]; then
398    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
399           "if $FUNCNAME 1 1; then ... ; fi"
400    return
401fi
[ecd8d9a]402# Falso, en caso de error.
403[ $# == 2 ] || return 1
[5a4f399]404
[ecd8d9a]405DISK=$(ogDiskToDev "$1") || return 1
[5a4f399]406test -n "$(parted -sm $DISK print 2>/dev/null | \
[697a9ee]407                      awk -F: -v fs=$2 '{if ($1==fs) print $5}')"
[5a4f399]408}
409
410
411#/**
[a3348ce]412#         ogIsMounted int_ndisk int_npartition
413#@brief   Comprueba si un sistema de archivos está montado.
[42669ebf]414#@param   int_ndisk      nº de orden del disco
415#@param   int_npartition nº de orden de la partición
[ecd8d9a]416#@return  Código de salida: 0 - montado, 1 - sin montar o error.
[f8f4dfa]417#@version 0.9 - Primera versión para OpenGNSys.
418#@author  Ramon Gomez, ETSII Universidad de Sevilla
419#@date    2009-10-15
[ecd8d9a]420#@version 1.0.1 - Devolver falso en caso de error.
421#@author  Ramon Gomez, ETSII Universidad de Sevilla
422#@date    2011-05-18
[1e7eaab]423#*/ ##
[42669ebf]424function ogIsMounted ()
425{
426# Si se solicita, mostrar ayuda.
[a3348ce]427if [ "$*" == "help" ]; then
428    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
429           "if $FUNCNAME 1 1; then ... ; fi"
430    return
431fi
[ecd8d9a]432# Falso, en caso de error.
433[ $# == 2 ] || return 1
[a3348ce]434
435test -n "$(ogGetMountPoint $1 $2)"
436}
437
438
[aae34f6]439#/**
[9d96c57]440#         ogIsLocked int_ndisk int_npartition
441#@brief   Comprueba si una partición está bloqueada por una operación de uso exclusivo.
[42669ebf]442#@param   int_ndisk      nº de orden del disco
443#@param   int_npartition nº de orden de la partición
[ecd8d9a]444#@return  Código de salida: 0 - bloqueado, 1 - sin bloquear o error.
[73c8417]445#@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]446#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]447#@author  Ramon Gomez, ETSII Universidad de Sevilla
448#@date    2009-09-03
[ecd8d9a]449#@version 1.0.1 - Devolver falso en caso de error.
450#@author  Ramon Gomez, ETSII Universidad de Sevilla
451#@date    2011-05-18
[1e7eaab]452#*/ ##
[42669ebf]453function ogIsLocked ()
454{
[59f9ad2]455# Variables locales
[73c8417]456local PART LOCKFILE
[9d96c57]457
[1e7eaab]458# Si se solicita, mostrar ayuda.
[9d96c57]459if [ "$*" == "help" ]; then
460    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
[a3348ce]461           "if $FUNCNAME 1 1; then ... ; fi"
[9d96c57]462    return
463fi
[ecd8d9a]464# Falso, en caso de error.
465[ $# == 2 ] || return 1
[9d96c57]466
[1e7eaab]467# Obtener partición.
[ecd8d9a]468PART="$(ogDiskToDev $1 $2)" || return 1
[9d96c57]469
[1e7eaab]470# Comprobar existencia del fichero de bloqueo.
[73c8417]471LOCKFILE="/var/lock/lock${PART//\//-}"
472test -f $LOCKFILE
[9d96c57]473}
474
475
476#/**
477#         ogLock int_ndisk int_npartition
[89403cd]478#@see     ogLockPartition
479#*/
[42669ebf]480function ogLock ()
481{
[89403cd]482ogLockPartition "$@"
483}
484
485#/**
486#         ogLockPartition int_ndisk int_npartition
[9d96c57]487#@brief   Genera un fichero de bloqueo para una partición en uso exlusivo.
[42669ebf]488#@param   int_ndisk      nº de orden del disco
489#@param   int_npartition nº de orden de la partición
[9d96c57]490#@return  (nada)
491#@exception OG_ERR_FORMAT    Formato incorrecto.
492#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]493#@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]494#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]495#@author  Ramon Gomez, ETSII Universidad de Sevilla
496#@date    2009-09-03
[1e7eaab]497#*/ ##
[42669ebf]498function ogLockPartition ()
499{
[59f9ad2]500# Variables locales
501local PART LOCKFILE
[9d96c57]502
[1e7eaab]503# Si se solicita, mostrar ayuda.
[9d96c57]504if [ "$*" == "help" ]; then
505    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
506           "$FUNCNAME 1 1"
507    return
508fi
[1e7eaab]509# Error si no se reciben 2 parámetros.
[9d96c57]510[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
511
[1e7eaab]512# Obtener partición.
[9d96c57]513PART="$(ogDiskToDev $1 $2)" || return $?
514
[1e7eaab]515# Crear archivo de bloqueo exclusivo.
[73c8417]516LOCKFILE="/var/lock/lock${PART//\//-}"
517touch $LOCKFILE
[9d96c57]518}
519
520
521#/**
[aae34f6]522#         ogMount int_ndisk int_npartition
[3458879]523#@see     ogMountFs ogMountCache ogMountCdrom
[1e7eaab]524#*/ ##
[42669ebf]525function ogMount ()
526{
[ee4a96e]527case "$*" in
[18f4bc2]528    CACHE|cache)
529        ogMountCache ;;
[ee4a96e]530    CDROM|cdrom)
531        ogMountCdrom ;;
532    *)  ogMountFs "$@" ;;
533esac
[73c8417]534}
535
[ee4a96e]536
[73c8417]537#/**
[40488da]538#         ogMountFs int_ndisk int_npartition
[aae34f6]539#@brief   Monta un sistema de archivos.
[42669ebf]540#@param   int_ndisk      nº de orden del disco
541#@param   int_npartition nº de orden de la partición
[aae34f6]542#@return  Punto de montaje
543#@exception OG_ERR_FORMAT    Formato incorrecto.
544#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
545#@exception OG_ERR_PARTITION Tipo de particion desconocido o no se puede montar.
[985bef0]546#@version 0.1 -  Integracion para Opengnsys  -  EAC:   MountPartition() en FileSystem.lib
547#@author  Antonio J. Doblas Viso. Universidad de Malaga
548#@date    2008-10-27
549#@version 0.9 - Primera version para OpenGNSys.
[aae34f6]550#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]551#@date    2009-09-28
[1e7eaab]552#*/ ##
[42669ebf]553function ogMountFs ()
554{
[1e7eaab]555# Variables locales
[049eadbe]556local PART TYPE MNTDIR MOUNT PARAMS
[aae34f6]557
[1e7eaab]558# Si se solicita, mostrar ayuda.
[aae34f6]559if [ "$*" == "help" ]; then
560    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
561           "$FUNCNAME 1 1  =>  /mnt/sda1"
562    return
563fi
[1e7eaab]564# Error si no se reciben 2 parámetros.
[aae34f6]565[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
566
[1e7eaab]567# Obtener partición.
[aae34f6]568PART="$(ogDiskToDev $1 $2)" || return $?
569
[1e7eaab]570# Comprobar si el sistema de archivos ya está montada.
[a3348ce]571MNTDIR="$(ogGetMountPoint $1 $2)"
[1e7eaab]572# Si no, montarla en un directorio de sistema
[aae34f6]573if [ -z "$MNTDIR" ]; then
574    # Error si la particion esta bloqueada.
[52fa3da]575    if ogIsLocked $1 $2; then
576        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION, $1 $2"
577        return $?
578    fi
[5a4f399]579    # Crear punto de montaje o enlace símbolico para Caché local.
[aae34f6]580    MNTDIR=${PART/dev/mnt}
581    TYPE="$(ogGetFsType $1 $2)" || return $?
[5a4f399]582    if [ "$TYPE" == "CACHE" -a -n "$OGCAC" ]; then
583        ln -fs $OGCAC $MNTDIR
584    else
585        mkdir -p $MNTDIR
586    fi
587    # Montar según el tipo de sitema de archivos.
[aae34f6]588    case "$TYPE" in
[cb167ee0]589        CACHE)      MOUNT=mount ;;
590        EXT[234])   MOUNT=mount ;;
591        REISERFS)   insmod /lib/modules/$(uname -r)/kernel/fs/reiserfs/reiserfs.ko 2>/dev/null
[7250491]592                    MOUNT=mount ;;
[cb167ee0]593        JFS)        insmod /lib/modules/$(uname -r)/kernel/fs/jfs/jfs.ko 2>/dev/null
[7250491]594                    MOUNT=mount ;;
[cb167ee0]595        XFS)        insmod /lib/modules/$(uname -r)/kernel/fs/xfs/xfs.ko 2>/dev/null
[7250491]596                    MOUNT=mount ;;
[cb167ee0]597        NTFS|HNTFS) MOUNT=ntfs-3g ;;
[b550747]598        FAT16|FAT32|HFAT16|HFAT32)
[049eadbe]599                    MOUNT=mount; PARAMS="-t vfat" ;;
[5dbb046]600        *)  #/// Error, si la partición no es montable.
[aae34f6]601            rmdir $MNTDIR
602            ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE"
[3458879]603            return $OG_ERR_PARTITION
604            ;;
[aae34f6]605    esac
[2af9738]606    $MOUNT $PARAMS $PART $MNTDIR 2>/dev/null || \
607               $MOUNT $PARAMS $PART $MNTDIR -o force,remove_hiberfile 2>/dev/null || \
608               ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE" || return $?
[aae34f6]609fi
[71643c0]610echo "$MNTDIR"
[aae34f6]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
[c114529]701ogGetFsSize $1 $2
[3f49cf7]702}
703
704
[c114529]705function ogReduceFsCheck ()
706{
707#IMPORTANTE: retorna el valor en MB que podrá reducir el FS de una particion ntfs
708#valor devuelto 0, y codigo error 1. No se puede reducir, probar a reiniciar windows y chkdsk
709
710
711local  PART RC MODE SIZE SIZEDATA
712[ $# == 2 ] && MODE=STAGE1
713[ $# == 3 ] && MODE=STAGE2
714[ -z $MODE ] && return
715
716PART="$(ogDiskToDev $1 $2)" || return $?
717ogUnmount $1 $2 &>/dev/null
718
719
720case $MODE in
721        STAGE1)
722        #       echo "primera etapa $*"
723                ntfsresize -fi $PART &>/dev/null
724                RC=`echo $?`
725        #       echo "RC es" $RC
726                if [ "$RC" -eq "1" ]
727                then
728                        echo "0"
729                        return 1       
730                fi 
731                SIZEDATA=$(ntfsresize -fi $PART | awk '/resize at/ {print $8+1000}')
732        #       echo "salida" $?
733        #       echo $SIZEDATA
734                ogReduceFsCheck $1 $2 $SIZEDATA
735                return 0
736       ;;
737        STAGE2)
738        #       echo "segunda etapa $*"
739                SIZEDATA=$3
740                ntfsresize -fns "${SIZEDATA}M" $PART &>/tmp/ntfsresize.txt
741                RC=$?
742                if [ "$RC" == "0" ]
743                then 
744                        SIZE=$SIZEDATA 
745                        echo $SIZE     
746                else
747                        SIZEEXTRA=$(cat /tmp/ntfsresize.txt | awk '/Needed relocations :/ {print $0}' | awk -F"(" '{print $2}' | awk '{print $1+500}')
748                        SIZE=$(expr $SIZEDATA + $SIZEEXTRA)
749                        ogReduceFsCheck $1 $2 $SIZE
750                        return 0
751                fi
752        ;;
753        *)
754        return
755        ;;
756esac
757}
758
759
760
[5dbb046]761#/**
[9d96c57]762#         ogUnlock int_ndisk int_npartition
[89403cd]763#@see     ogUnlockPartition
764#*/
[42669ebf]765function ogUnlock ()
766{
[89403cd]767ogUnlockPartition "$@"
768}
769
770#/**
771#         ogUnlockPartition int_ndisk int_npartition
[9d96c57]772#@brief   Elimina el fichero de bloqueo para una particion.
[42669ebf]773#@param   int_ndisk      nº de orden del disco
774#@param   int_npartition nº de orden de la partición
[9d96c57]775#@return  (nada)
776#@exception OG_ERR_FORMAT    Formato incorrecto.
777#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]778#@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]779#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]780#@author  Ramon Gomez, ETSII Universidad de Sevilla
781#@date    2009-09-03
[1e7eaab]782#*/ ##
[42669ebf]783function ogUnlockPartition ()
784{
[59f9ad2]785# Variables locales
786local PART LOCKFILE
[9d96c57]787
[1e7eaab]788# Si se solicita, mostrar ayuda.
[9d96c57]789if [ "$*" == "help" ]; then
790    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
791           "$FUNCNAME 1 1"
792    return
793fi
[1e7eaab]794# Error si no se reciben 2 parámetros.
[9d96c57]795[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
796
[1e7eaab]797# Obtener partición.
[9d96c57]798PART="$(ogDiskToDev $1 $2)" || return $?
799
[1e7eaab]800# Borrar archivo de bloqueo exclusivo.
[73c8417]801LOCKFILE="/var/lock/lock${PART//\//-}"
802rm -f $LOCKFILE
[9d96c57]803}
804
805
806#/**
[5dbb046]807#         ogUnmount int_ndisk int_npartition
[40488da]808#@see     ogUnmountFs
[89403cd]809#*/
[42669ebf]810function ogUnmount ()
811{
[40488da]812ogUnmountFs "$@"
[89403cd]813}
814
815#/**
[40488da]816#         ogUnmountFs int_ndisk int_npartition
[5dbb046]817#@brief   Desmonta un sistema de archivos.
[42669ebf]818#@param   int_ndisk      nº de orden del disco
819#@param   int_npartition nº de orden de la partición
[5dbb046]820#@return  Nada
821#@exception OG_ERR_FORMAT    Formato incorrecto.
822#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
823#@warning La partición no está previamente montada o no se puede desmontar.
[985bef0]824#@version 0.1 -  Integracion para Opengnsys  -  EAC:  UmountPartition() en FileSystem.lib
825#@author  Antonio J. Doblas Viso. Universidad de Malaga
826#@date    2008-10-27
827#@version 0.9 - Primera version para OpenGNSys.
[5dbb046]828#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]829#@date    2009-09-28
[1e7eaab]830#*/ ##
[42669ebf]831function ogUnmountFs ()
832{
[59f9ad2]833# Variables locales
[c56dec5]834local PART MNTDIR
[5dbb046]835
[1e7eaab]836# Si se solicita, mostrar ayuda.
[5dbb046]837if [ "$*" == "help" ]; then
838    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" "$FUNCNAME 1 1"
839    return
840fi
[1e7eaab]841# Error si no se reciben 2 parámetros.
[5dbb046]842[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
843
[1e7eaab]844# Obtener partición y punto de montaje.
[5dbb046]845PART="$(ogDiskToDev $1 $2)" || return $?
[a3348ce]846MNTDIR="$(ogGetMountPoint $1 $2)"
[5dbb046]847
[1e7eaab]848# Si está montada, desmontarla.
[c56dec5]849if [ -n "$MNTDIR" ]; then
[5a4f399]850    # Error si la particion está bloqueada.
[52fa3da]851    if ogIsLocked $1 $2; then
852        ogRaiseError $OG_ERR_LOCKED "$MSG_PARTITION $1, $2"
853        return $?
854    fi
[5a4f399]855    # Desmontar y borrar punto de montaje.
[52fa3da]856    umount $PART 2>/dev/null || ogEcho warning "$FUNCNAME: $MSG_DONTUNMOUNT: \"$1, $2\""
[5a4f399]857    rmdir $MNTDIR 2>/dev/null || rm -f $MNTDIR 2>/dev/null
[5dbb046]858else
859    ogEcho warning "$MSG_DONTMOUNT: \"$1,$2\""
860fi
861}
862
[ee4a96e]863
[be81649]864#/**
865#         ogUnmountAll int_ndisk
866#@brief   Desmonta todos los sistema de archivos de un disco, excepto el caché local.
[42669ebf]867#@param   int_ndisk      nº de orden del disco
[be81649]868#@return  Nada
869#@exception OG_ERR_FORMAT    Formato incorrecto.
870#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
871#@warning No se desmonta la partición marcada como caché local.
872#@version 0.9 - Versión para OpenGNSys.
873#@author  Ramon Gomez, ETSII Universidad de Sevilla
874#@date    2009/10/07
[1e7eaab]875#*/ ##
[42669ebf]876function ogUnmountAll ()
877{
[be81649]878# Variables locales
[18f4bc2]879local DISK PART
[1e7eaab]880# Si se solicita, mostrar ayuda.
[18f4bc2]881if [ "$*" == "help" ]; then
882    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
883    return
884fi
[1e7eaab]885# Error si no se recibe 1 parámetro.
[18f4bc2]886[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
887
[1e7eaab]888# Obtener partición y punto de montaje.
[18f4bc2]889DISK="$(ogDiskToDev $1)" || return $?
890for ((PART=1; PART<=$(ogGetPartitionsNumber $1); PART++)); do
891    case "$(ogGetFsType $1 $PART)" in
892        CACHE|LINUX-SWAP)
893           ;;
894        *)
895           ogUnmount $1 $PART ;;
[7250491]896    esac
[18f4bc2]897done
898}
899
[a957f02]900#/**  @function ogGetFsSize: @brief Muestra el tamanio del sistema de archivos indicado, permite definir la unidad de medida, por defecto GB
901#@param  $1 int_diskEAC
902#@param $2 int_PartitionEAC
903#@param $3 str_UnidadMediada            parametro opcional, admite [ kB MB GB -default GB]
904#@return  cadena con int_TotalSize:int_DataSize:int_DataFree
905#@warning  Salidas de errores no determinada
906#@warning
907#@attention
[985bef0]908#@version 0.1 -  Integracion para Opengnsys  -  EAC:  SizeFileSystem() en FileSystem.lib
909#@author  Antonio J. Doblas Viso. Universidad de Malaga
910#@date    2008-10-27
[a957f02]911#*/
[985bef0]912function ogGetFsSize () {
[a957f02]913if [ $# = 0 ]
914then
915        echo "sintaxis: ogGetFsSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
916        echo "devuelve int_size : int_data : int_free" red
917return
918fi
919if [ $# -ge 2 ]
920then
921        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
922        if [ -z $3 ]
923                then
[c114529]924                        unit=kB  # s B kB MB GB TB %
[a957f02]925                else
926                        unit=$3
927        fi
928        case $unit in
929                kB)
930                        factor="1.024";
[c114529]931                #       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}'`
932                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", size}'`
933                ;;
934                MB)
935                        factor="1.024/1000";
936                        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}'`
937                ;;
938                GB)
939                        factor="1.024/1000000";
940                        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]941                ;;
[c114529]942        esac
943        #echo $valor
944        #NumberRound $valor
945        #valor=`NumberRound $valor`;
946        ogUnmount $1 $2 1>/dev/null 2>&1
947        echo $valor
948
949fi
950}
951
952function ogGetFreeSize () {
953if [ $# = 0 ]
954then
955        echo "sintaxis: ogGetFreeSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
956        echo "devuelve int_size : int_data : int_free" red
957return
958fi
959if [ $# -ge 2 ]
960then
961        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
962        if [ -z $3 ]
963                then
964                        unit=kB  # s B kB MB GB TB %
965                else
966                        unit=$3
967        fi
968        case $unit in
969                kB)
970                        factor="1.024";
971                        #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}'`
972                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", free}'`
973                        ;;
[a957f02]974                MB)
975                        factor="1.024/1000";
976                        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}'`
977                ;;
978                GB)
979                        factor="1.024/1000000";
980                        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}'`
981                ;;
982        esac
983        #echo $valor
984        #NumberRound $valor
985        #valor=`NumberRound $valor`;
986        ogUnmount $1 $2 1>/dev/null 2>&1
987        echo $valor
988
989fi
[c114529]990}
991
992
993
994function ogDeletePartitionsLabels ()
995{
996# Si se solicita, mostrar ayuda.
997if [ "$*" == "help" ]; then
998    ogHelp "$FUNCNAME" "$FUNCNAME " \
999           "$FUNCNAME "
1000    return
1001fi
1002rm /dev/disk/by-label/* 2>/dev/null   # */ COMENTARIO OBLIGATORIO PARA DOXYGEN
1003}
1004
1005function ogDeletePartitionTable ()
1006{
1007
1008# Variables locales.
1009local DISK
1010
1011# Si se solicita, mostrar ayuda.
1012if [ "$*" == "help" ]; then
1013    ogHelp "$FUNCNAME int_disk"  \
1014           "$FUNCNAME 1"
1015    return
1016fi
1017# Error si no se reciben 1 parámetros.
1018[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
1019
1020# Obteniendo Identificador linux de la particion.
1021DISK=$(ogDiskToDev $1) || return $?
[a957f02]1022
[c114529]1023# Elimando las particiones con fdisk
1024echo -ne "o\nw" | fdisk $DISK
[a957f02]1025}
Note: See TracBrowser for help on using the repository browser.