close Warning: Failed to sync with repository "ogBrowser-Git": (1366, "Incorrect string value: '\\xF0\\x9F\\x93\\xA6 I...' for column 'message' at row 1"); repository information may be out of date. Look in the Trac log for more information including mitigation strategies.

source: client/engine/FileSystem.lib @ 279dcb69

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 279dcb69 was eb4614b, checked in by ramon <ramongomez@…>, 12 years ago

Evitar cuelgue de función ogReduceFs al reducir sistema de archivo ReiserFS esperando confirmación por teclado.

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

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