source: client/engine/FileSystem.lib @ e35b5ad

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

version 1.0.1: adaptar funciones ogIs... a valores de la API 1.0: 0=true, 1=false (cerrar #396).

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