source: client/engine/FileSystem.lib @ 6903f32

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 6903f32 was 6e390b1, checked in by ramon <ramongomez@…>, 13 years ago

Versión 1.0.4, #531: Retoques en ayudas y en código para Doxygen.

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

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