source: client/engine/FileSystem.lib @ 1c04494

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 1c04494 was 1c04494, checked in by ramon <ramongomez@…>, 16 years ago

Correcciones en scripts; metafunción ogGetOsType.

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

  • Property mode set to 100755
File size: 26.1 KB
RevLine 
[2e15649]1#!/bin/bash
2#/**
3#@file    FileSystem.lib
[9f57de01]4#@brief   Librería o clase FileSystem
[2e15649]5#@class   FileSystem
6#@brief   Funciones para gestión de sistemas de archivos.
7#@version 0.9
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.
15#@arg  \c int_ndisk      nº de orden del disco
16#@arg  \c int_npartition nº de orden de la partición
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.
[be81649]24#@version 0.9 - Primera adaptación para OpenGNSys.
25#@author  Ramon Gomez, ETSII Universidad de Sevilla
26#@date    2009-10-07
27#*/
[1956672]28function ogCheckFs () {
[be81649]29
30# Variables locales
31local PART TYPE
32
[1956672]33#/// Error si no se reciben 2 parámetros.
34[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
35#/// Obtener partición.
36PART="$(ogDiskToDev $1 $2)" || return $?
[be81649]37
38TYPE=$(ogGetFsType $1 $2)
39case "$TYPE" in
[a3348ce]40    EXT[234])     PROG="e2fsck" ;;
41    REISERFS)     PROG="reiserfsck"; PARAMS="<<<\"Yes\"" ;;
42    JFS)          PROG="fsck.jfs" ;;
43    XFS)          PROG="fsck.xfs" ;;
44    NTFS|HNTFS)   PROG="ntfsfix" ;;
45    FAT32|FAT32)  PROG="fsck.vfat" ;;
46    FAT16|FAT16)  PROG="fsck.msdos" ;;
47    *)            ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
[cb167ee0]48                      return $? ;;
[1956672]49esac
[a3348ce]50#/// Error si el sistema de archivos esta montado o bloqueado.
51if ogIsMounted $1 $2; then
52    ogRaiseError $OG_ERR_PARTITION "$1 $2"       # Indicar nuevo error
53    return $?
54fi
55if ogIsLocked $1 $2; then
56    ogRaiseError $OG_ERR_LOCKED "$1 $2"
57    return $?
58fi
59#/// Comprobar en modo uso exclusivo.
60ogLock $1 $2
61eval $PROG $PARAMS $PART
62ERRCODE=$?
63case $ERRCODE in
64    0)    ;;
65    127)  ogRaiseError $OG_ERR_NOTEXEC "$PROG" ;;
66    *)    ogRaiseError $OG_ERR_PARTITION "$1 $2" ;;
67esac
68ogUnlock $1 $2
69return $ERRCODE
[1956672]70}
71
72
[2e15649]73#/**
[3f49cf7]74#         ogExtendFs int_ndisk int_npartition
75#@brief   Extiende un sistema de archivos al tamaño de su partición.
[be81649]76#@arg  \c int_ndisk      nº de orden del disco
[3f49cf7]77#@arg  \c npartition nº de orden de la partición
78#@return  (nada)
79#@exception OG_ERR_FORMAT   Formato incorrecto.
80#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
81#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
82#@note    Requisitos: *resize*
83#@version 0.9 - Primera adaptación para OpenGNSys.
84#@author  Ramon Gomez, ETSII Universidad de Sevilla
85#@date    2009-09-23
86#*/
87function ogExtendFs () {
88
89# Variables locales.
[2717297]90local PART PROG PARAMS
[3f49cf7]91
92#/// Si se solicita, mostrar ayuda.
93if [ "$*" == "help" ]; then
94    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
95           "$FUNCNAME 1 1"
96    return
97fi
98#/// Error si no se reciben 2 parámetros.
99[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
100
101#/// Obtener partición.
102PART="$(ogDiskToDev $1 $2)" || return $?
103
[1c04494]104ogUnmount $1 $2 2>/dev/null
[3f49cf7]105#/// Redimensionar al tamano máximo según el tipo de partición.
[be81649]106TYPE=$(ogGetFsType $1 $2)
107case "$TYPE" in
[2717297]108    EXT[234])   PROG="resize2fs"; PARAMS="-f" ;;
109    REISERFS)   PROG="resize_reiserfs"; PARAMS="-f" ;;
110    NTFS|HNTFS) PROG="ntfsresize"; PARAMS="<<<\"y\" -f" ;;
111    *)          ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
112                return $? ;;
[3f49cf7]113esac
[2717297]114#/// Error si el sistema de archivos está montado o bloqueado.
115if ogIsMounted $1 $2; then
116    ogRaiseError $OG_ERR_PARTITION "$1 $2"       # Indicar nuevo error
117    return $?
118fi
119if ogIsLocked $1 $2; then
120    ogRaiseError $OG_ERR_LOCKED "$1 $2"
121    return $?
122fi
123#/// Redimensionar en modo uso exclusivo.
124ogLock $1 $2
[1c04494]125eval $PROG $PARAMS $PART &>/dev/null
[2717297]126ERRCODE=$?
127case $ERRCODE in
128    0)    ;;
129    127)  ogRaiseError $OG_ERR_NOTEXEC "$PROG" ;;
130    *)    ogRaiseError $OG_ERR_PARTITION "$1 $2" ;;
131esac
132ogUnlock $1 $2
133return $ERRCODE
[3f49cf7]134}
135
136
137#/**
[40488da]138#         ogFormat int_ndisk int_npartition
139#@see     ogFormatFs
140#*/
141function ogFormat () {
[1956672]142ogFormatFs "$@"
[40488da]143}
144
145
146#/**
[be81649]147#         ogFoarmatFs int_ndisk int_npartition [type_fstype] [str_label]
[40488da]148#@brief   Formatea un sistema de ficheros según el tipo de su partición.
[be81649]149#@arg  \c int_ndisk      nº de orden del disco
150#@arg  \c int_npartition nº de orden de la partición
151#@arg  \c type_fstype  mnemónico de sistema de ficheros a formatear
152#@arg  \c str_label      etiqueta de volumen (opcional)
[40488da]153#@return  (por determinar)
154#@exception OG_ERR_FORMAT    Formato incorrecto.
155#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
156#@exception OG_ERR_PARTITION Partición no accesible o desconocida.
[a3348ce]157#@note    Requisitos:   mkfs*
158#@warning No formatea particiones montadas ni bloqueadas.
159#@todo    Definir salidas.
160#@version 0.9 - Primera versión para OpenGNSys.
[40488da]161#@author  Ramon Gomez, ETSII Universidad de Sevilla
[a3348ce]162#@date    2009-10-08
[40488da]163#*/
164function ogFormatFs () {
165
166# Variables locales
[be81649]167local PART ID TYPE LABEL PROG PARAMS ERRCODE
[40488da]168
169#/// Si se solicita, mostrar ayuda.
170if [ "$*" == "help" ]; then
171    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition [str_label]" \
172           "$FUNCNAME 1 1" \
[be81649]173           "$FUNCNAME 1 1 EXT4" \
174           "$FUNCNAME 1 1 DATA" \
175           "$FUNCNAME 1 1 EXT4 DATA"
[40488da]176    return
177fi
[be81649]178#/// Error si no se reciben entre 2 y 4 parámetros.
179[ $# -ge 2 -a $# -le 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
180#/// Obtener dispositivo y tipo de sisitema de archivos.
[40488da]181PART="$(ogDiskToDev $1 $2)" || return $?
[be81649]182TYPE="$(ogGetFsType $1 $2)" || return $?
183
184#/// Elegir tipo de formato segun el tipo de particion.
185case "$3" in
[a3348ce]186    EXT2)      ID=83; PROG="mkfs.ext2";;
187    EXT3)      ID=83; PROG="mkfs.ext3";;
188    EXT4)      ID=83; PROG="mkfs.ext4";;
189    REISERFS)  ID=83; PROG="mkfs.reiserfs"; PARAMS="-f" ;;
190    REISER4)   ID=83; PROG="mkfs.reiser4";;
191    XFS)       ID=83; PROG="mkfs.xfs"; PARAMS="-f" ;;
192    JFS)       ID=83; PROG="mkfs.jfs"; PARAMS="<<<\"y\"";;
193    NTFS)      ID=7; PROG="mkntfs"; PARAMS="-f" ;;
194    HNTFS)     ID=17; PROG="mkntfs"; PARAMS="-f" ;;
195    FAT32)     ID=b; PROG="mkfs.vfat" ;;
196    HFAT32)    ID=1b; PROG="mkfs.vfat" ;;
197    FAT16)     ID=6; PROG="mkfs.msdos" ;;
198    HFAT16)    ID=16; PROG="mkfs.msdos" ;;
[be81649]199    *)         LABEL="$3" ;;
[40488da]200esac
[be81649]201#/// Si no se indica explícitamente, detectar el tipo de sistema de archivos.
202if [ -z "$PROG" ]; then
203    case "$TYPE" in
204        EXT2)         PROG="mkfs.ext2";;
205        EXT3)         PROG="mkfs.ext3";;
206        EXT4)         PROG="mkfs.ext4";;
[a3348ce]207        REISERFS)     PROG="mkfs.reiserfs"; PARAMS="-f" ;;
[be81649]208        REISER4)      PROG="mkfs.reiser4";;
[a3348ce]209        XFS)          PROG="mkfs.xfs"; PARAMS="-f" ;;
210        JFS)          PROG="mkfs.jfs"; PARAMS="<<<\"y\"";;
[be81649]211        NTFS|HNTFS)   PROG="mkntfs"; PARAMS="-f" ;;
212        FAT32|HFAT32) PROG="mkfs.vfat" ;;
213        FAT16|HFAT16) PROG="mkfs.msdos" ;;
214        *)            ogRaiseError $OG_ERR_PARTITION "$1 $2 $TYPE"
215                      return $? ;;
216    esac
217else
[a3348ce]218    [ $TYPE == "$3" -o $ID == "$(ogGetPartitionId $1 $2)" ] || ogRaiseError $OG_ERR_PARTITION "$3 != $TYPE" || return $?
[be81649]219fi
220#/// Comprobar consistencia entre id. de partición y tipo de sistema de archivos.
221[ -n "$PROG" ] || ogRaiseError $OG_ERR_PARTITION "$3 != $TYPE" || return $?
222
223#/// Etiquetas de particion.
224if [ -z "$LABEL" ]; then
225    [ "$4" != "CACHE" ] || ogRaiseError $OG_ERR_FORMAT "$MSG_RESERVEDVALUE: CACHE" || return $?
226    [ -n "$4" ] && PARAMS="$PARAMS -L $4"
227else
228    PARAMS="$PARAMS -L $LABEL"
229fi
[40488da]230
[a3348ce]231#/// Error si la particion esta montada o está bloqueada.
232if ogIsMounted $1 $2; then
233    ogRaiseError $OG_ERR_PARTITION "$1 $2"       # Indicar nuevo error
234    return $?
235fi
[40488da]236if ogIsLocked $1 $2; then
[be81649]237    ogRaiseError $OG_ERR_LOCKED "$1 $2"
[40488da]238    return $?
239fi
[a3348ce]240#/// Formatear en modo uso exclusivo.
[40488da]241ogLock $1 $2
[a3348ce]242eval $PROG $PARAMS $PART 2>/dev/null
[be81649]243ERRCODE=$?
244case $ERRCODE in
245    0)    ;;
246    127)  ogRaiseError $OG_ERR_NOTEXEC "$PROG" ;;
247    *)    ogRaiseError $OG_ERR_PARTITION "$1 $2" ;;
248esac
[40488da]249ogUnlock $1 $2
[be81649]250return $ERRCODE
[40488da]251}
252
253
254#/**
[9f57de01]255#         ogGetFsType int_ndisk int_npartition
256#@brief   Devuelve el mnemonico con el tipo de sistema de archivos.
[aae34f6]257#@arg  \c ndisk      nº de orden del disco
258#@arg  \c npartition nº de orden de la partición
[9f57de01]259#@return  Mnemonico
[b550747]260#@note    Mnemonico: { EXT2, EXT3, EXT4, REISERFS, LINUX-SWAP, LINUX-LVM, LINUX-RAID, FAT16, HFAT16, FAT32, HFAT32, NTFS, HNTFS, WIN-DYNAMIC, CACHE, EMPTY, EXTENDED, UNKNOWN }
[9f57de01]261#@exception OG_ERR_FORMAT   Formato incorrecto.
262#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
263#@version 0.9 - Primera adaptación para OpenGNSys.
264#@author  Ramon Gomez, ETSII Universidad de Sevilla
[5dbb046]265#@date    2009-07-21
[2e15649]266#*/
[9f57de01]267function ogGetFsType () {
[2e15649]268
[59f9ad2]269# Variables locales.
[b550747]270local DISK ID TYPE
271
[59f9ad2]272#/// Si se solicita, mostrar ayuda.
273if [ "$*" == "help" ]; then
274    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
275           "$FUNCNAME 1 1  =>  NTFS"
276    return
277fi
[a5df9b9]278#/// Error si no se reciben 2 parámetros.
279[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
[2e15649]280
[b550747]281#/// Detectar id. de tipo de partición y codificar al mnemonico.
282DISK=$(ogDiskToDev $1) || return $?
283ID=$(ogGetPartitionId $1 $2) || return $?
[2e15649]284case "$ID" in
[b550747]285     0)         TYPE="EMPTY" ;;
[f8f4dfa]286     1)         TYPE="FAT12" ;;
[b550747]287     5|f)       TYPE="EXTENDED" ;;
288     [6e])      TYPE="FAT16" ;;
289     7)         TYPE="NTFS" ;;          # Nota: también puede ser EXFAT
290     [bc])      TYPE="FAT32" ;;
[f8f4dfa]291     11)        TYPE="HFAT12" ;;
[b550747]292     12)        TYPE="COMPAQDIAG" ;;
293     1[6e])     TYPE="HFAT16" ;;
294     17)        TYPE="HNTFS" ;;
295     1[bc])     TYPE="HFAT32" ;;
296     42)        TYPE="WIN-DYNAMIC" ;;
297     82)        TYPE="LINUX-SWAP" ;;
298     83)        TYPE="$(parted -s $DISK print | awk -v var=$2 '{if ($1==var) {print toupper($6)}}')"
299                TYPE=${TYPE:-"EXT3"}
[2e15649]300                ;;
[b550747]301     8e)        TYPE="LINUX-LVM" ;;
[ee4a96e]302     a7)        TYPE="CACHE" ;;         # (compatibilidad con Brutalix)
[b550747]303     bf)        TYPE="SOLARIS" ;;
[ee4a96e]304     ca)        TYPE="CACHE" ;;
[b550747]305     fd)        TYPE="LINUX-RAID" ;;
306     *)         TYPE="UNKNOWN" ;;
[2e15649]307esac
[b550747]308echo $TYPE
[2e15649]309}
310
[aae34f6]311
[a3348ce]312#/**
313#         ogGetMountPoint int_ndisk int_npartition
314#@brief   Devuelve el punto de montaje de un sistema de archivos.
[f8f4dfa]315#@arg  \c int_ndisk      nº de orden del disco
316#@arg  \c int_npartition nº de orden de la partición
317#@return  Punto de montaje
318#@exception OG_ERR_FORMAT    Formato incorrecto.
319#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
320#@version 0.9 - Primera versión para OpenGNSys.
321#@author  Ramon Gomez, ETSII Universidad de Sevilla
322#@date    2009-10-15
[a3348ce]323#*/
324function ogGetMountPoint () {
325
326# Variables locales
327local PART
328#/// Si se solicita, mostrar ayuda.
329if [ "$*" == "help" ]; then
330    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
331           "$FUNCNAME 1 1  =>  /mnt/sda1"
332    return
333fi
334#/// Error si no se reciben 2 parámetros.
335[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
336#/// Obtener partición.
337PART="$(ogDiskToDev $1 $2)" || return $?
338
339echo $(mount | awk -v P=$PART '{if ($1==P) {print $3}}')
340}
341
342
343#/**
344#         ogIsMounted int_ndisk int_npartition
345#@brief   Comprueba si un sistema de archivos está montado.
[f8f4dfa]346#@arg  \c int_ndisk      nº de orden del disco
347#@arg  \c int_npartition nº de orden de la partición
348#@return  Código de salida: 0 - sin montar, 1 - montado.
349#@version 0.9 - Primera versión para OpenGNSys.
350#@author  Ramon Gomez, ETSII Universidad de Sevilla
351#@date    2009-10-15
[a3348ce]352#*/
353function ogIsMounted () {
354
355#/// Si se solicita, mostrar ayuda.
356if [ "$*" == "help" ]; then
357    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
358           "if $FUNCNAME 1 1; then ... ; fi"
359    return
360fi
361#/// Error si no se reciben 2 parámetros.
362[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
363
364test -n "$(ogGetMountPoint $1 $2)"
365}
366
367
[aae34f6]368#/**
[9d96c57]369#         ogIsLocked int_ndisk int_npartition
370#@brief   Comprueba si una partición está bloqueada por una operación de uso exclusivo.
[f8f4dfa]371#@arg  \c int_ndisk      nº de orden del disco
372#@arg  \c int_npartition nº de orden de la partición
373#@return  Código de salida: 0 - sin bloquear, 1 - bloqueada.
[73c8417]374#@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]375#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]376#@author  Ramon Gomez, ETSII Universidad de Sevilla
377#@date    2009-09-03
378#*/
379function ogIsLocked () {
380
[59f9ad2]381# Variables locales
[73c8417]382local PART LOCKFILE
[9d96c57]383
384#/// Si se solicita, mostrar ayuda.
385if [ "$*" == "help" ]; then
386    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
[a3348ce]387           "if $FUNCNAME 1 1; then ... ; fi"
[9d96c57]388    return
389fi
390#/// Error si no se reciben 2 parámetros.
391[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
392
393#/// Obtener partición.
394PART="$(ogDiskToDev $1 $2)" || return $?
395
396#/// Comprobar existencia del fichero de bloqueo.
[73c8417]397LOCKFILE="/var/lock/lock${PART//\//-}"
398test -f $LOCKFILE
[9d96c57]399}
400
401
402#/**
403#         ogLock int_ndisk int_npartition
[89403cd]404#@see     ogLockPartition
405#*/
406function ogLock () {
407ogLockPartition "$@"
408}
409
410#/**
411#         ogLockPartition int_ndisk int_npartition
[9d96c57]412#@brief   Genera un fichero de bloqueo para una partición en uso exlusivo.
413#@arg  \c ndisk      nº de orden del disco
414#@arg  \c npartition nº de orden de la partición
415#@return  (nada)
416#@exception OG_ERR_FORMAT    Formato incorrecto.
417#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]418#@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 "-".
[9d96c57]419#@version 0.1 - En pruebas para adaptarla a OpenGNSys.
420#@author  Ramon Gomez, ETSII Universidad de Sevilla
421#@date    2009-09-03
422#*/
[89403cd]423function ogLockPartition () {
[9d96c57]424
[59f9ad2]425# Variables locales
426local PART LOCKFILE
[9d96c57]427
428#/// Si se solicita, mostrar ayuda.
429if [ "$*" == "help" ]; then
430    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
431           "$FUNCNAME 1 1"
432    return
433fi
434#/// Error si no se reciben 2 parámetros.
435[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
436
437#/// Obtener partición.
438PART="$(ogDiskToDev $1 $2)" || return $?
439
440#/// Crear archivo de bloqueo exclusivo.
[73c8417]441LOCKFILE="/var/lock/lock${PART//\//-}"
442touch $LOCKFILE
[9d96c57]443}
444
445
446#/**
[aae34f6]447#         ogMount int_ndisk int_npartition
[ee4a96e]448#@see     ogMountFs ogMountCdrom
[d071d9b]449#*/
[73c8417]450function ogMount () {
[ee4a96e]451case "$*" in
[18f4bc2]452    CACHE|cache)
453        ogMountCache ;;
[ee4a96e]454    CDROM|cdrom)
455        ogMountCdrom ;;
456    *)  ogMountFs "$@" ;;
457esac
[73c8417]458}
459
[ee4a96e]460
[73c8417]461#/**
[40488da]462#         ogMountFs int_ndisk int_npartition
[aae34f6]463#@brief   Monta un sistema de archivos.
464#@arg  \c ndisk      nº de orden del disco
465#@arg  \c npartition nº de orden de la partición
466#@return  Punto de montaje
467#@exception OG_ERR_FORMAT    Formato incorrecto.
468#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
469#@exception OG_ERR_PARTITION Tipo de particion desconocido o no se puede montar.
[40488da]470#@version 0.9 - Primera versión para OpenGNSys.
[aae34f6]471#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]472#@date    2009-09-28
[aae34f6]473#*/
[40488da]474function ogMountFs () {
[aae34f6]475
476#/// Variables locales
477local PART TYPE MNTDIR MOUNT
478
479#/// Si se solicita, mostrar ayuda.
480if [ "$*" == "help" ]; then
481    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
482           "$FUNCNAME 1 1  =>  /mnt/sda1"
483    return
484fi
485#/// Error si no se reciben 2 parámetros.
486[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
487
488#/// Obtener partición.
489PART="$(ogDiskToDev $1 $2)" || return $?
490
[a3348ce]491#/// Comprobar si el sistema de archivos ya está montada.
492MNTDIR="$(ogGetMountPoint $1 $2)"
[aae34f6]493#/// Si no, montarla en un directorio de sistema
494if [ -z "$MNTDIR" ]; then
495    # Error si la particion esta bloqueada.
[59f9ad2]496    ogIsLocked $1 $2 && ogRaiseError $OG_ERR_LOCKED "$1 $2" && return $?
[aae34f6]497    #/// Crear punto de montaje.
498    MNTDIR=${PART/dev/mnt}
499    mkdir -p $MNTDIR
500    #/// Montar según el tipo de sitema de archivos.
501    TYPE="$(ogGetFsType $1 $2)" || return $?
502    case "$TYPE" in
[cb167ee0]503        CACHE)      MOUNT=mount ;;
504        EXT[234])   MOUNT=mount ;;
505        REISERFS)   insmod /lib/modules/$(uname -r)/kernel/fs/reiserfs/reiserfs.ko 2>/dev/null
506                    MOUNT=mount ;;
507        JFS)        insmod /lib/modules/$(uname -r)/kernel/fs/jfs/jfs.ko 2>/dev/null
508                    MOUNT=mount ;;
509        XFS)        insmod /lib/modules/$(uname -r)/kernel/fs/xfs/xfs.ko 2>/dev/null
510                    MOUNT=mount ;;
511        NTFS|HNTFS) MOUNT=ntfs-3g ;;
[b550747]512        FAT16|FAT32|HFAT16|HFAT32)
[cb167ee0]513                    MOUNT=mount; ARGS="-t vfat" ;;
[5dbb046]514        *)  #/// Error, si la partición no es montable.
[aae34f6]515            rmdir $MNTDIR
516            ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE"
517            return $OG_ERR_PARTITION
518            ;;
519    esac
[1956672]520    $MOUNT $ARGS $PART $MNTDIR || $MOUNT $ARGS $PART $MNTDIR -o force,remove_hiberfile || ogRaiseError $OG_ERR_PARTITION "$1, $2, $TYPE" || return $?
[f5a77d7]521        # linea temporal durante desarrollo para poder usar el cliente completo nfs y testeas nuevas herramientas.
[40488da]522    if grep -q nfsroot /proc/cmdline; then
523                echo "$PART $MNTDIR" >> /etc/mtab
[f5a77d7]524        fi
525        # fin linea temporal.
[aae34f6]526fi
527echo $MNTDIR
528}
529
530
[ee4a96e]531#####  PRUEBAS
532# Montar CDROM
533function ogMountCdrom () {
534local DEV MNTDIR
535DEV="/dev/cdrom"            # Por defecto
536MNTDIR=$(mount | awk -v D=$DEV '{if ($1==D) {print $3}}')
537if [ -z "$MNTDIR" ]; then
538    MNTDIR=${DEV/dev/mnt}
539    mkdir -p $MNTDIR
540    mount -t iso9660 $DEV $MNTDIR || ogRaiseError $OG_ERR_PARTITION "cdrom" || return $?
541fi
542echo $MNTDIR
543}
544
[3f49cf7]545
546#/**
547#         ogReduceFs int_ndisk int_npartition
548#@brief   Reduce el tamaño del sistema de archivos, sin tener en cuenta el espacio libre.
549#@arg  \c ndisk      nº de orden del disco
550#@arg  \c npartition nº de orden de la partición
551#@return  tamañoKB
552#@exception OG_ERR_FORMAT    Formato incorrecto.
553#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
554#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
555#@warning   El sistema de archivos se amplía al mínimo + 1 KB.
556#@note      Requisitos: *resize*
557#@version 0.1 - En pruebas para adaptarla a OpenGNSys.
558#@author  Ramon Gomez, ETSII Universidad de Sevilla
559#@date    2009-09-23
560#*/
561function ogReduceFs () {
562
563# Variables locales
564local PART BLKS SIZE
565
566#/// Si se solicita, mostrar ayuda.
567if [ "$*" == "help" ]; then
568    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
569           "$FUNCNAME 1 1"
570    return
571fi
572#/// Error si no se reciben 2 parámetros.
573[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
574
575#/// Obtener partición.
576PART="$(ogDiskToDev $1 $2)" || return $?
577
578#/// Redimensionar según el tipo de particion.
579case "$(ogGetFsType $1 $2)" in
[1c04494]580    EXT[234])
581        ogUnmount $1 $2 >/dev/null
582        # Ext2/3/4: Tamaño de los bloques del sistema de archivos
583        BLKS=$(tune2fs -l $PART | awk '/Block size/ {print int($3/512)}')
584        # Traduce el num. en sectores de 512B a tamano en MB.
585        SIZE=$(resize2fs -P $PART 2>/dev/null | \
586                       awk -v B=$BLKS '/minimum size/ {print int($7*B/2048+1000)}')
587        resize2fs -fp $PART "${SIZE}M" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
588            ;;
589    REISERFS)           # Usar "resize_reiserfs"
590            ;;
591    NTFS|HNTFS)
592        rm -f $(ogGetPath $1 $2 pagefile.sys)
593        ogUnmount $1 $2 >/dev/null
594        # NTFS: Obtiene tamaño mínimo en MB.
595        SIZE=$(ntfsresize -fi $PART | awk '/resize at/ {print $8+1000}')
596        ntfsresize -fns "${SIZE}M" $PART >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
597        ntfsresize -fs "${SIZE}M" $PART <<<"y" >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
598            ;;
599    *)  ogRaiseError $OG_ERR_PARTITION "$1,$2"
600            return $? ;;
[3f49cf7]601esac
602#/// Mostrar nuevo tamaño en KB.
603echo $[SIZE*1024]
604}
605
606
[5dbb046]607#/**
[9d96c57]608#         ogUnlock int_ndisk int_npartition
[89403cd]609#@see     ogUnlockPartition
610#*/
611function ogUnlock () {
612ogUnlockPartition "$@"
613}
614
615#/**
616#         ogUnlockPartition int_ndisk int_npartition
[9d96c57]617#@brief   Elimina el fichero de bloqueo para una particion.
618#@arg  \c ndisk      nº de orden del disco
619#@arg  \c npartition nº de orden de la partición
620#@return  (nada)
621#@exception OG_ERR_FORMAT    Formato incorrecto.
622#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]623#@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 "-".
[9d96c57]624#@version 0.1 - En pruebas para adaptarla a OpenGNSys.
625#@author  Ramon Gomez, ETSII Universidad de Sevilla
626#@date    2009-09-03
627#*/
[89403cd]628function ogUnlockPartition () {
[9d96c57]629
[59f9ad2]630# Variables locales
631local PART LOCKFILE
[9d96c57]632
633#/// Si se solicita, mostrar ayuda.
634if [ "$*" == "help" ]; then
635    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
636           "$FUNCNAME 1 1"
637    return
638fi
639#/// Error si no se reciben 2 parámetros.
640[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
641
642#/// Obtener partición.
643PART="$(ogDiskToDev $1 $2)" || return $?
644
645#/// Borrar archivo de bloqueo exclusivo.
[73c8417]646LOCKFILE="/var/lock/lock${PART//\//-}"
647rm -f $LOCKFILE
[9d96c57]648}
649
650
651
652#/**
[5dbb046]653#         ogUnmount int_ndisk int_npartition
[40488da]654#@see     ogUnmountFs
[89403cd]655#*/
656function ogUnmount () {
[40488da]657ogUnmountFs "$@"
[89403cd]658}
659
660#/**
[40488da]661#         ogUnmountFs int_ndisk int_npartition
[5dbb046]662#@brief   Desmonta un sistema de archivos.
663#@arg  \c ndisk      nº de orden del disco
664#@arg  \c npartition nº de orden de la partición
665#@return  Nada
666#@exception OG_ERR_FORMAT    Formato incorrecto.
667#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
668#@warning La partición no está previamente montada o no se puede desmontar.
[40488da]669#@version 0.9 - Primera versión para OpenGNSys.
[5dbb046]670#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]671#@date    2009-09-28
[5dbb046]672#*/
[40488da]673function ogUnmountFs () {
[5dbb046]674
[59f9ad2]675# Variables locales
[c56dec5]676local PART MNTDIR
[5dbb046]677
678#/// Si se solicita, mostrar ayuda.
679if [ "$*" == "help" ]; then
680    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" "$FUNCNAME 1 1"
681    return
682fi
683#/// Error si no se reciben 2 parámetros.
684[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
685
686#/// Obtener partición y punto de montaje.
687PART="$(ogDiskToDev $1 $2)" || return $?
[a3348ce]688MNTDIR="$(ogGetMountPoint $1 $2)"
[5dbb046]689
690#/// Si está montada, desmontarla.
[c56dec5]691if [ -n "$MNTDIR" ]; then
[5dbb046]692    # Error si la particion esta bloqueada.
[59f9ad2]693    ogIsLocked $1 $2 && ogRaiseError $OG_ERR_LOCKED "$1 $2" && return $?
[5dbb046]694    #/// Crear punto de montaje.
695    umount $PART 2>/dev/null && rmdir $MNTDIR || ogEcho warning "$FUNCNAME: $MSG_DONTUNMOUNT: \"$1,$2\""
[5ef521e]696        # linea temporal durante desarrollo para testear nuevas herramientas con el cliente completo nfs
[40488da]697    if grep -q nfsroot /proc/cmdline; then
[5ef521e]698                cat /etc/mtab | grep -v $PART > /var/tmp/mtab.temporal && cp /var/tmp/mtab.temporal /var/tmp/mtab && rm /var/tmp/mtab.temporal
699        fi
700        # fin linea temporal.
[5dbb046]701else
702    ogEcho warning "$MSG_DONTMOUNT: \"$1,$2\""
703fi
704}
705
[ee4a96e]706
[be81649]707#/**
708#         ogUnmountAll int_ndisk
709#@brief   Desmonta todos los sistema de archivos de un disco, excepto el caché local.
710#@arg  \c int_ndisk      nº de orden del disco
711#@return  Nada
712#@exception OG_ERR_FORMAT    Formato incorrecto.
713#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
714#@warning No se desmonta la partición marcada como caché local.
715#@version 0.9 - Versión para OpenGNSys.
716#@author  Ramon Gomez, ETSII Universidad de Sevilla
717#@date    2009/10/07
718#*/
[18f4bc2]719function ogUnmountAll () {
[be81649]720
721# Variables locales
[18f4bc2]722local DISK PART
723#/// Si se solicita, mostrar ayuda.
724if [ "$*" == "help" ]; then
725    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
726    return
727fi
728#/// Error si no se recibe 1 parámetro.
729[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
730
731#/// Obtener partición y punto de montaje.
732DISK="$(ogDiskToDev $1)" || return $?
733for ((PART=1; PART<=$(ogGetPartitionsNumber $1); PART++)); do
734    case "$(ogGetFsType $1 $PART)" in
735        CACHE|LINUX-SWAP)
736           ;;
737        *)
738           ogUnmount $1 $PART ;;
739    esac
740done
741}
742
743
[b29ee26]744function ogFindCache () {
745#/**  @function ogFindCache: @brief Detecta la particion CACHE EAC seg�n tipo a7 o label CACHE sobre particion ext3.
746#@param  no requiere parametros
747#@return  devuelve el identificador linux de la particion CACHE.
748#@warning  si no hay cache no devuelve nada
749#@attention Requisitos: la salida de fdisk de la cache a7 debe ser NeXTSTEP
750#@note    Notas sin especificar
751#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
752#*/
753#
754if [ $# != 0 ]
755then
756        Msg "FindCache detecta la particion tipo a7 o aquella que tenga el label CACHE" info
757        Msg "devuelve /dev/sda3" info2
758        Msg "sintaxis: FindCache   --- Ejemplo: FindCache -> /dev/sda3/ " example
759        return
760fi
[6a222b2]761end=`ogDiskToDev | wc -w`
[b29ee26]762unset cache
763for (( disk = 1; disk <= $end; disk++))
764do
[6a222b2]765        disco=`ogDiskToDev $disk`
[b29ee26]766        totalpart=`parted $disco print | egrep ^" [0123456789] " -c`
767        #echo Buscando en disco: $disco con $totalpart particiones
768        if [ `fdisk -l $disco | egrep ^/dev | grep NeXTSTEP | cut -f1 -d" "` ]
769        then
770        #       echo comprobando si es particion a7
771                cache=`fdisk -l $disco | egrep ^/dev | grep NeXTSTEP | cut -f1 -d" "`
772        else
773                #echo comprobando si existe la etiqueta cache
[8e9af1c]774                if find /dev/disk | grep CACHE > /dev/null
[b29ee26]775                then
776                        devcache=`ls -ls /dev/disk/by-label/CACHE | awk -F..\/..\/ '{print $2}'`
777                        cache=/dev/$devcache
778                fi
779        fi
780done
781if [ -n "$cache" ]
782then
783        echo $cache
784else
785        return 1
786fi
787}
[5dbb046]788
[ac99761]789function ogMountCache () {
[c717ce3]790#/**  @function ogMountCache: @brief Monta la particion Cache y exporta la variable $OGCAC
[ac99761]791#@param  sin parametros
[c717ce3]792#@return Punto de montaje dentro de mnt, ejemplo con un parametro: ogMountCache => /mnt/sda3
[ac99761]793#@warning  Salidas de errores no determinada
[c717ce3]794#@warning
[ac99761]795#@attention
796#@version 0.1   Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga. Proyecto EAC
797#@note
798#*/
[e95307c]799CACHELINUX=`ogFindCache`
800CACHEOG=`ogDevToDisk $CACHELINUX`
[ee4a96e]801OGCAC=`ogMount $CACHEOG`
[e95307c]802echo $OGCAC
803export OGCAC
[ac99761]804}
[0185f71]805
[e6f3c01]806function ogUnmountCache () {
[f0cc1ab]807#/**  @function UmountCache: @brief Desmonta la particion Cache y elimina la variable $OGCAC
[e6f3c01]808#@param  sin parametros
809#@return nada
810#@warning  Salidas de errores no determinada
811#@warning
812#@attention
813#@version 1.0   Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga. Proyecto EAC
814#@note
815#*/
[f0cc1ab]816CACHELINUX=`ogFindCache`
817CACHEOG=`ogDevToDisk $CACHELINUX`
[e6f3c01]818#echo ogUnmountPartition $cacheeac
[f0cc1ab]819ogUnmountPartition $CACHEOG
820unset OGCAC
[e6f3c01]821}
822
[0185f71]823
824function ogFormatCache () {
825#/**  @function ogFormatCache: @brief Formatea la Cache EAC y le asigna el label CACHE
826#@param  No requiere
827#@return   la propia del mkfs.ext3
828#@warning
829#@attention
830#@note
831#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
832#*/
833
834if [ $# = 0 ]
835then
836        cd /
[28a2fee]837        ogUnmountCache
[0185f71]838        dev=`ogFindCache`
839        Msg "Iniciando el formateo de la particion CACHE, ubicada en $dev, y asignandole el label CACHE" red
840        mkfs.ext3 $dev -L CACHE
841        ogInfoCache
842fi
843if [ $# = 1 ]
844then
845        mkfs.ext3 $1 -L CACHE
846fi
847}
Note: See TracBrowser for help on using the repository browser.