source: client/engine/FileSystem.lib @ 161d1ec

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 161d1ec was 452ade2, checked in by ramon <ramongomez@…>, 13 years ago

#142: Preparar soporte para sistemas de archivos ZFS, montar BTRFS, UFS y ZFS y extender BTRFS.

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

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