source: client/engine/FileSystem.lib @ 3458879

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

Correcciones en varias funciones; función en pruebas ogGetIpAddress.

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

  • Property mode set to 100755
File size: 26.3 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
[3458879]30# Variables locales.
31local PART TYPE PROG PARAMS
[be81649]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
[3458879]77#@arg  \c int_npartition nº de orden de la partición
[3f49cf7]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
[3458879]151#@arg  \c type_fstype    mnemónico de sistema de ficheros a formatear
[be81649]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\"";;
[3458879]193    NTFS)      ID=7;  PROG="mkntfs"; PARAMS="-f" ;;
[a3348ce]194    HNTFS)     ID=17; PROG="mkntfs"; PARAMS="-f" ;;
[3458879]195    FAT32)     ID=b;  PROG="mkfs.vfat" ;;
[a3348ce]196    HFAT32)    ID=1b; PROG="mkfs.vfat" ;;
[3458879]197    FAT16)     ID=6;  PROG="mkfs.msdos" ;;
[a3348ce]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.
[3458879]257#@arg  \c int_ndisk      nº de orden del disco
258#@arg  \c int_npartition nº de orden de la partición
[9f57de01]259#@return  Mnemonico
[3458879]260#@note    Mnemonico: { EXT2, EXT3, EXT4, REISERFS, XFS, JFS, LINUX-SWAP, LINUX-LVM, LINUX-RAID, SOLARIS, 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.
[3458879]270local ID TYPE
[b550747]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.
[3458879]282ID=$(ogGetPartitionId "$1" "$2") || return $?
[2e15649]283case "$ID" in
[b550747]284     0)         TYPE="EMPTY" ;;
[f8f4dfa]285     1)         TYPE="FAT12" ;;
[b550747]286     5|f)       TYPE="EXTENDED" ;;
287     [6e])      TYPE="FAT16" ;;
288     7)         TYPE="NTFS" ;;          # Nota: también puede ser EXFAT
289     [bc])      TYPE="FAT32" ;;
[f8f4dfa]290     11)        TYPE="HFAT12" ;;
[b550747]291     12)        TYPE="COMPAQDIAG" ;;
292     1[6e])     TYPE="HFAT16" ;;
293     17)        TYPE="HNTFS" ;;
294     1[bc])     TYPE="HFAT32" ;;
295     42)        TYPE="WIN-DYNAMIC" ;;
296     82)        TYPE="LINUX-SWAP" ;;
297     83)        TYPE="$(parted -s $DISK print | awk -v var=$2 '{if ($1==var) {print toupper($6)}}')"
[3458879]298            TYPE=${TYPE:-"EXT3"}
299            ;;
[b550747]300     8e)        TYPE="LINUX-LVM" ;;
[ee4a96e]301     a7)        TYPE="CACHE" ;;         # (compatibilidad con Brutalix)
[b550747]302     bf)        TYPE="SOLARIS" ;;
[ee4a96e]303     ca)        TYPE="CACHE" ;;
[b550747]304     fd)        TYPE="LINUX-RAID" ;;
305     *)         TYPE="UNKNOWN" ;;
[2e15649]306esac
[b550747]307echo $TYPE
[2e15649]308}
309
[aae34f6]310
[a3348ce]311#/**
312#         ogGetMountPoint int_ndisk int_npartition
313#@brief   Devuelve el punto de montaje de un sistema de archivos.
[f8f4dfa]314#@arg  \c int_ndisk      nº de orden del disco
315#@arg  \c int_npartition nº de orden de la partición
316#@return  Punto de montaje
317#@exception OG_ERR_FORMAT    Formato incorrecto.
318#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[3458879]319#@note    Requisitos: \c mount* \c awk
[f8f4dfa]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.
[3458879]413#@arg  \c int_ndisk      nº de orden del disco
414#@arg  \c int_npartition nº de orden de la partición
[9d96c57]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 "-".
[3458879]419#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]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
[3458879]448#@see     ogMountFs ogMountCache 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.
[3458879]464#@arg  \c int_ndisk      nº de orden del disco
465#@arg  \c int_npartition nº de orden de la partición
[aae34f6]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"
[3458879]517            return $OG_ERR_PARTITION
518            ;;
[aae34f6]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.
[3458879]549#@arg  \c int_ndisk      nº de orden del disco
550#@arg  \c int_npartition nº de orden de la partición
[3f49cf7]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.
[3458879]555#@warning En Windows, se borran los ficheros pagefile.sys e hiberfile.sys
556#@warning El sistema de archivos se amplía al mínimo + 1 KB.
557#@note    Requisitos:   *resize*
558#@version 0.9 - Primera versión para OpenGNSys.
[3f49cf7]559#@author  Ramon Gomez, ETSII Universidad de Sevilla
560#@date    2009-09-23
561#*/
562function ogReduceFs () {
563
564# Variables locales
565local PART BLKS SIZE
566
567#/// Si se solicita, mostrar ayuda.
568if [ "$*" == "help" ]; then
569    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
570           "$FUNCNAME 1 1"
571    return
572fi
573#/// Error si no se reciben 2 parámetros.
574[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
575
576#/// Obtener partición.
577PART="$(ogDiskToDev $1 $2)" || return $?
578
579#/// Redimensionar según el tipo de particion.
580case "$(ogGetFsType $1 $2)" in
[1c04494]581    EXT[234])
[3458879]582        ogUnmount $1 $2 2>/dev/null
[1c04494]583        # Ext2/3/4: Tamaño de los bloques del sistema de archivos
584        BLKS=$(tune2fs -l $PART | awk '/Block size/ {print int($3/512)}')
585        # Traduce el num. en sectores de 512B a tamano en MB.
586        SIZE=$(resize2fs -P $PART 2>/dev/null | \
587                       awk -v B=$BLKS '/minimum size/ {print int($7*B/2048+1000)}')
588        resize2fs -fp $PART "${SIZE}M" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
589            ;;
590    REISERFS)           # Usar "resize_reiserfs"
591            ;;
592    NTFS|HNTFS)
[3458879]593        ogDeleteFile $1 $2 pagefile.sys
594        ogDeleteFile $1 $2 hiberfile.sys
595        ogUnmount $1 $2 2>/dev/null
[1c04494]596        # NTFS: Obtiene tamaño mínimo en MB.
597        SIZE=$(ntfsresize -fi $PART | awk '/resize at/ {print $8+1000}')
598        ntfsresize -fns "${SIZE}M" $PART >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
599        ntfsresize -fs "${SIZE}M" $PART <<<"y" >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
600            ;;
601    *)  ogRaiseError $OG_ERR_PARTITION "$1,$2"
602            return $? ;;
[3f49cf7]603esac
604#/// Mostrar nuevo tamaño en KB.
605echo $[SIZE*1024]
606}
607
608
[5dbb046]609#/**
[9d96c57]610#         ogUnlock int_ndisk int_npartition
[89403cd]611#@see     ogUnlockPartition
612#*/
613function ogUnlock () {
614ogUnlockPartition "$@"
615}
616
617#/**
618#         ogUnlockPartition int_ndisk int_npartition
[9d96c57]619#@brief   Elimina el fichero de bloqueo para una particion.
[3458879]620#@arg  \c int_ndisk      nº de orden del disco
621#@arg  \c int_npartition nº de orden de la partición
[9d96c57]622#@return  (nada)
623#@exception OG_ERR_FORMAT    Formato incorrecto.
624#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
[73c8417]625#@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]626#@version 0.9 - Primera versión para OpenGNSys.
[9d96c57]627#@author  Ramon Gomez, ETSII Universidad de Sevilla
628#@date    2009-09-03
629#*/
[89403cd]630function ogUnlockPartition () {
[9d96c57]631
[59f9ad2]632# Variables locales
633local PART LOCKFILE
[9d96c57]634
635#/// Si se solicita, mostrar ayuda.
636if [ "$*" == "help" ]; then
637    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
638           "$FUNCNAME 1 1"
639    return
640fi
641#/// Error si no se reciben 2 parámetros.
642[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
643
644#/// Obtener partición.
645PART="$(ogDiskToDev $1 $2)" || return $?
646
647#/// Borrar archivo de bloqueo exclusivo.
[73c8417]648LOCKFILE="/var/lock/lock${PART//\//-}"
649rm -f $LOCKFILE
[9d96c57]650}
651
652
653#/**
[5dbb046]654#         ogUnmount int_ndisk int_npartition
[40488da]655#@see     ogUnmountFs
[89403cd]656#*/
657function ogUnmount () {
[40488da]658ogUnmountFs "$@"
[89403cd]659}
660
661#/**
[40488da]662#         ogUnmountFs int_ndisk int_npartition
[5dbb046]663#@brief   Desmonta un sistema de archivos.
[3458879]664#@arg  \c int_ndisk      nº de orden del disco
665#@arg  \c int_npartition nº de orden de la partición
[5dbb046]666#@return  Nada
667#@exception OG_ERR_FORMAT    Formato incorrecto.
668#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
669#@warning La partición no está previamente montada o no se puede desmontar.
[40488da]670#@version 0.9 - Primera versión para OpenGNSys.
[5dbb046]671#@author  Ramon Gomez, ETSII Universidad de Sevilla
[40488da]672#@date    2009-09-28
[5dbb046]673#*/
[40488da]674function ogUnmountFs () {
[5dbb046]675
[59f9ad2]676# Variables locales
[c56dec5]677local PART MNTDIR
[5dbb046]678
679#/// Si se solicita, mostrar ayuda.
680if [ "$*" == "help" ]; then
681    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" "$FUNCNAME 1 1"
682    return
683fi
684#/// Error si no se reciben 2 parámetros.
685[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
686
687#/// Obtener partición y punto de montaje.
688PART="$(ogDiskToDev $1 $2)" || return $?
[a3348ce]689MNTDIR="$(ogGetMountPoint $1 $2)"
[5dbb046]690
691#/// Si está montada, desmontarla.
[c56dec5]692if [ -n "$MNTDIR" ]; then
[5dbb046]693    # Error si la particion esta bloqueada.
[59f9ad2]694    ogIsLocked $1 $2 && ogRaiseError $OG_ERR_LOCKED "$1 $2" && return $?
[5dbb046]695    #/// Crear punto de montaje.
696    umount $PART 2>/dev/null && rmdir $MNTDIR || ogEcho warning "$FUNCNAME: $MSG_DONTUNMOUNT: \"$1,$2\""
[5ef521e]697        # linea temporal durante desarrollo para testear nuevas herramientas con el cliente completo nfs
[40488da]698    if grep -q nfsroot /proc/cmdline; then
[5ef521e]699                cat /etc/mtab | grep -v $PART > /var/tmp/mtab.temporal && cp /var/tmp/mtab.temporal /var/tmp/mtab && rm /var/tmp/mtab.temporal
700        fi
701        # fin linea temporal.
[5dbb046]702else
703    ogEcho warning "$MSG_DONTMOUNT: \"$1,$2\""
704fi
705}
706
[ee4a96e]707
[be81649]708#/**
709#         ogUnmountAll int_ndisk
710#@brief   Desmonta todos los sistema de archivos de un disco, excepto el caché local.
711#@arg  \c int_ndisk      nº de orden del disco
712#@return  Nada
713#@exception OG_ERR_FORMAT    Formato incorrecto.
714#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
715#@warning No se desmonta la partición marcada como caché local.
716#@version 0.9 - Versión para OpenGNSys.
717#@author  Ramon Gomez, ETSII Universidad de Sevilla
718#@date    2009/10/07
719#*/
[18f4bc2]720function ogUnmountAll () {
[be81649]721
722# Variables locales
[18f4bc2]723local DISK PART
724#/// Si se solicita, mostrar ayuda.
725if [ "$*" == "help" ]; then
726    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "FUNCNAME 1"
727    return
728fi
729#/// Error si no se recibe 1 parámetro.
730[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
731
732#/// Obtener partición y punto de montaje.
733DISK="$(ogDiskToDev $1)" || return $?
734for ((PART=1; PART<=$(ogGetPartitionsNumber $1); PART++)); do
735    case "$(ogGetFsType $1 $PART)" in
736        CACHE|LINUX-SWAP)
737           ;;
738        *)
739           ogUnmount $1 $PART ;;
740    esac
741done
742}
743
744
[b29ee26]745function ogFindCache () {
746#/**  @function ogFindCache: @brief Detecta la particion CACHE EAC seg�n tipo a7 o label CACHE sobre particion ext3.
747#@param  no requiere parametros
748#@return  devuelve el identificador linux de la particion CACHE.
749#@warning  si no hay cache no devuelve nada
750#@attention Requisitos: la salida de fdisk de la cache a7 debe ser NeXTSTEP
751#@note    Notas sin especificar
752#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
753#*/
754#
755if [ $# != 0 ]
756then
757        Msg "FindCache detecta la particion tipo a7 o aquella que tenga el label CACHE" info
758        Msg "devuelve /dev/sda3" info2
759        Msg "sintaxis: FindCache   --- Ejemplo: FindCache -> /dev/sda3/ " example
760        return
761fi
[6a222b2]762end=`ogDiskToDev | wc -w`
[b29ee26]763unset cache
764for (( disk = 1; disk <= $end; disk++))
765do
[6a222b2]766        disco=`ogDiskToDev $disk`
[b29ee26]767        totalpart=`parted $disco print | egrep ^" [0123456789] " -c`
768        #echo Buscando en disco: $disco con $totalpart particiones
769        if [ `fdisk -l $disco | egrep ^/dev | grep NeXTSTEP | cut -f1 -d" "` ]
770        then
771        #       echo comprobando si es particion a7
772                cache=`fdisk -l $disco | egrep ^/dev | grep NeXTSTEP | cut -f1 -d" "`
773        else
774                #echo comprobando si existe la etiqueta cache
[8e9af1c]775                if find /dev/disk | grep CACHE > /dev/null
[b29ee26]776                then
777                        devcache=`ls -ls /dev/disk/by-label/CACHE | awk -F..\/..\/ '{print $2}'`
778                        cache=/dev/$devcache
779                fi
780        fi
781done
782if [ -n "$cache" ]
783then
784        echo $cache
785else
786        return 1
787fi
788}
[5dbb046]789
[ac99761]790function ogMountCache () {
[c717ce3]791#/**  @function ogMountCache: @brief Monta la particion Cache y exporta la variable $OGCAC
[ac99761]792#@param  sin parametros
[c717ce3]793#@return Punto de montaje dentro de mnt, ejemplo con un parametro: ogMountCache => /mnt/sda3
[ac99761]794#@warning  Salidas de errores no determinada
[c717ce3]795#@warning
[ac99761]796#@attention
797#@version 0.1   Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga. Proyecto EAC
798#@note
799#*/
[e95307c]800CACHELINUX=`ogFindCache`
801CACHEOG=`ogDevToDisk $CACHELINUX`
[ee4a96e]802OGCAC=`ogMount $CACHEOG`
[e95307c]803echo $OGCAC
804export OGCAC
[ac99761]805}
[0185f71]806
[e6f3c01]807function ogUnmountCache () {
[f0cc1ab]808#/**  @function UmountCache: @brief Desmonta la particion Cache y elimina la variable $OGCAC
[e6f3c01]809#@param  sin parametros
810#@return nada
811#@warning  Salidas de errores no determinada
812#@warning
813#@attention
814#@version 1.0   Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga. Proyecto EAC
815#@note
816#*/
[f0cc1ab]817CACHELINUX=`ogFindCache`
818CACHEOG=`ogDevToDisk $CACHELINUX`
[e6f3c01]819#echo ogUnmountPartition $cacheeac
[f0cc1ab]820ogUnmountPartition $CACHEOG
821unset OGCAC
[e6f3c01]822}
823
[0185f71]824
825function ogFormatCache () {
826#/**  @function ogFormatCache: @brief Formatea la Cache EAC y le asigna el label CACHE
827#@param  No requiere
828#@return   la propia del mkfs.ext3
829#@warning
830#@attention
831#@note
832#@version 0.1       Date: 27/10/2008                 Author Antonio J. Doblas Viso. Universidad de Malaga
833#*/
834
835if [ $# = 0 ]
836then
837        cd /
[28a2fee]838        ogUnmountCache
[0185f71]839        dev=`ogFindCache`
840        Msg "Iniciando el formateo de la particion CACHE, ubicada en $dev, y asignandole el label CACHE" red
841        mkfs.ext3 $dev -L CACHE
842        ogInfoCache
843fi
844if [ $# = 1 ]
845then
846        mkfs.ext3 $1 -L CACHE
847fi
848}
Note: See TracBrowser for help on using the repository browser.