source: client/engine/FileSystem.lib @ a23fb1b

Last change on this file since a23fb1b was d0df50b6, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.4, #531: Integrar versión 1.0.4 en rama principal.

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

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