source: client/engine/FileSystem.lib @ 9a2cda1e

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

Corregir errata en ogMountFs; solución ticket:75 (arrancar Linux en otra partición).

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

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