source: client/engine/FileSystem.lib @ 0b8a1f1

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 0b8a1f1 was 7c52c30, checked in by ramon <ramongomez@…>, 13 years ago

#553: Borrar y crear la clave de registro en función ogInstallFirstBoot para evitar errores con chntpw; función ogUnmountAll no muestra errores para sistemas de ficheros no montados.

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

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