source: client/engine/XFileSystem.lib @ 8850d1b

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 8850d1b was 9948203, checked in by adv <adv@…>, 14 years ago

integracion version 1.0 - engine -- ticket:305

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

  • Property mode set to 100755
File size: 7.6 KB
RevLine 
[9948203]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
14#/**
15#         ogReduceFs int_ndisk int_npartition
16#@brief   Reduce el tamaño del sistema de archivos, sin tener en cuenta el espacio libre.
17#@param   int_ndisk      nº de orden del disco
18#@param   int_npartition nº de orden de la partición
19#@return  tamañoKB
20#@exception OG_ERR_FORMAT    Formato incorrecto.
21#@exception OG_ERR_NOTFOUND  Disco o particion no corresponden con un dispositivo.
22#@exception OG_ERR_PARTITION Partición desconocida o no accesible.
23#@warning En Windows, se borran los ficheros pagefile.sys e hiberfile.sys
24#@warning El sistema de archivos se amplía al mínimo + 1 KB.
25#@note    Requisitos:   *resize*
26#@version 0.9 - Primera versión para OpenGNSys.
27#@author  Ramon Gomez, ETSII Universidad de Sevilla
28#@date    2009-09-23
29#*/ ##
30function ogReduceFs ()
31{
32# Variables locales
33local PART BLKS SIZE
34echo "xfile"
35# Si se solicita, mostrar ayuda.
36if [ "$*" == "help" ]; then
37    ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \
38           "$FUNCNAME 1 1"
39    return
40fi
41# Error si no se reciben 2 parámetros.
42[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
43
44# Obtener partición.
45PART="$(ogDiskToDev $1 $2)" || return $?
46
47# Redimensionar según el tipo de particion.
48case "$(ogGetFsType $1 $2)" in
49    EXT[234])
50        ogUnmount $1 $2 2>/dev/null
51        # Ext2/3/4: Tamaño de los bloques del sistema de archivos
52        BLKS=$(tune2fs -l $PART | awk '/Block size/ {print int($3/512)}')
53        # Traduce el num. en sectores de 512B a tamano en MB.
54        SIZE=$(resize2fs -P $PART 2>/dev/null | \
55                       awk -v B=$BLKS '/minimum size/ {print int($7*B/2048+1000)}')
56        resize2fs -fp $PART "${SIZE}M" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
57            ;;
58#    REISERFS)          # Usar "resize_reiserfs"
59#           ;;
60    NTFS|HNTFS)
61        ogDeleteFile $1 $2 pagefile.sys &>/dev/null
62        ogDeleteFile $1 $2 hiberfile.sys &>/dev/null
63        ogUnmount $1 $2 2>/dev/null
64### Modificaciones del trunk
65        # NTFS: Obtiene tamaño mínimo en MB. 1.16
66        #SIZEDATA=$(ntfsresize -fi $PART | awk '/resize at/ {printf "%d", $8*1.16}')
67        #SIZEDATA=$(ntfsresize -fi $PART | awk '/resize at/ {print $8+500}')
68        echo "iniciando calculo reduccion FS"
69        SIZE=$(ReduceFsNT2 $1 $2)
70### fin modificaciones
71        echo "iniciando proceso de reduccion con $SIZE"
72        [ "$SIZE" == 0 ] && return 1   
73        ntfsresize -fs "${SIZE}M" $PART <<<"y"  || ogRaiseError $OG_ERR_PARTITION "error reduciendo $1,$2" || return $?
74        #ntfsresize -fs "${SIZE}M" $PART <<<"y" >/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $?
75            ;;
76    *) 
77                echo "sin tipo de sistema archivos"
78                ogRaiseError $OG_ERR_PARTITION "$1,$2"
79            return $? ;;
80esac
81#/// Mostrar nuevo tamaño en KB.
82echo $[SIZE*1024]
83#echo $SIZE
84}
85
86
87
88
89function ReduceFsNT2 ()
90{
91#IMPORTANTE: retorna el valor en MB que podrá reducir el FS de una particion ntfs
92#valor devulto 0, y codigo error 1. No se puede reducir, probar a reiniciar windows.
93
94
95local  PART RC MODE SIZE SIZEDATA
96[ $# == 2 ] && MODE=STAGE1
97[ $# == 3 ] && MODE=STAGE2
98[ -z $MODE ] && return
99
100PART="$(ogDiskToDev $1 $2)" || return $?
101ogUnmount $1 $2 &>/dev/null
102
103
104case $MODE in
105        STAGE1)
106        #       echo "primera etapa $*"
107                ntfsresize -fi $PART &>/dev/null
108                RC=`echo $?`
109        #       echo "RC es" $RC
110                if [ "$RC" -eq "1" ]
111                then
112                        echo "0"
113                        return 1       
114                fi 
115                SIZEDATA=$(ntfsresize -fi $PART | awk '/resize at/ {print $8+1000}')
116        #       echo "salida" $?
117        #       echo $SIZEDATA
118                ReduceFsNT2 $1 $2 $SIZEDATA
119                return 0
120       ;;
121        STAGE2)
122        #       echo "segunda etapa $*"
123                SIZEDATA=$3
124                ntfsresize -fns "${SIZEDATA}M" $PART &>/tmp/ntfsresize.txt
125                RC=$?
126                if [ "$RC" == "0" ]
127                then 
128                        SIZE=$SIZEDATA 
129                        echo $SIZE     
130                else
131                        SIZEEXTRA=$(cat /tmp/ntfsresize.txt | awk '/Needed relocations :/ {print $0}' | awk -F"(" '{print $2}' | awk '{print $1+500}')
132                        SIZE=$(expr $SIZEDATA + $SIZEEXTRA)
133                        ReduceFsNT2 $1 $2 $SIZE
134                        return 0
135                fi
136        ;;
137        *)
138        return
139        ;;
140esac
141
142}
143
144
145function ogGetFreeSize () {
146if [ $# = 0 ]
147then
148        echo "sintaxis: ogGetFreeSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
149        echo "devuelve int_size : int_data : int_free" red
150return
151fi
152if [ $# -ge 2 ]
153then
154        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
155        if [ -z $3 ]
156                then
157                        unit=kB  # s B kB MB GB TB %
158                else
159                        unit=$3
160        fi
161        case $unit in
162                kB)
163                        factor="1.024";
164                        #valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d:%d:%d", size,used,free}'`
165                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", free}'`
166                        ;;
167                MB)
168                        factor="1.024/1000";
169                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024/1000; used=$3*1.024/1000; free=$4*1.024/1000; printf "%d:%d:%d", size,used,free}'`
170                ;;
171                GB)
172                        factor="1.024/1000000";
173                        valor=`df | grep $particion | awk -F" " '{size=$2*1.024/1000000; used=$3*1.024/1000000; free=$4*1.024/1000000; printf "%f:%f:%f", size,used,free}'`
174                ;;
175        esac
176        #echo $valor
177        #NumberRound $valor
178        #valor=`NumberRound $valor`;
179        ogUnmount $1 $2 1>/dev/null 2>&1
180        echo $valor
181
182fi
183}
184
185
186
187
188
189
190
191
192
193
194#/**  @function ogGetFsSize: @brief Muestra el tamanio del sistema de archivos indicado, permite definir la unidad de medida, por defecto GB
195#@param  $1 int_disk
196#@param $2 int_Partition
197#@param $3 str_UnidadMediada            parametro opcional, admite [ kB MB GB -default kB]
198#@return  cadena con int_TotalSize                 no=>:int_DataSize:int_DataFree
199#@warning  Salidas de errores no determinada
200#@warning
201#@attention
202#@version 0.1 -  Integracion para Opengnsys  -  EAC:  SizeFileSystem() en FileSystem.lib
203#@author  Antonio J. Doblas Viso. Universidad de Malaga
204#@date    2008-10-27
205#*/
206function ogGetFsSize () {
207if [ $# = 0 ]
208then
209        echo "sintaxis: ogGetFsSize int_disco int_partition str_SizeOutput [ kB MB GB -default GB]-]" red
210        echo "devuelve int_size : int_data : int_free" red
211return
212fi
213if [ $# -ge 2 ]
214then
215        particion=`ogMount $1 $2 ` #1>/dev/null 2>&1
216        if [ -z $3 ]
217                then
218                        unit=kB  # s B kB MB GB TB %
219                else
220                        unit=$3
221        fi
222        case $unit in
223                kB)
224                        factor="1.024";
225                        #valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d:%d:%d", size,used,free}'`
226                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024; used=$3*1.024; free=$4*1.024; printf "%d", size}'`
227                        ;;
228                MB)
229                        factor="1.024/1000";
230                        valor=`df | grep  $particion | awk -F" " '{size=$2*1.024/1000; used=$3*1.024/1000; free=$4*1.024/1000; printf "%d:%d:%d", size,used,free}'`
231                ;;
232                GB)
233                        factor="1.024/1000000";
234                        valor=`df | grep $particion | awk -F" " '{size=$2*1.024/1000000; used=$3*1.024/1000000; free=$4*1.024/1000000; printf "%f:%f:%f", size,used,free}'`
235                ;;
236        esac
237        #echo $valor
238        #NumberRound $valor
239        #valor=`NumberRound $valor`;
240        ogUnmount $1 $2 1>/dev/null 2>&1
241        echo $valor
242
243fi
244}
245
246#/** copia literal del engine 1.0
247function ogDeletePartitionsLabels ()
248{
249# Si se solicita, mostrar ayuda.
250if [ "$*" == "help" ]; then
251    ogHelp "$FUNCNAME" "$FUNCNAME " \
252           "$FUNCNAME "
253    return
254fi
255rm /dev/disk/by-label/* 2>/dev/null   # */ COMENTARIO OBLIGATORIO PARA DOXYGEN
256}
257
258
259
260
261
262
263
264
265
266
267
268
269
270#/** copia literal del engine 1.0
271function ogDeletePartitionTable ()
272{
273
274# Variables locales.
275local DISK
276
277# Si se solicita, mostrar ayuda.
278if [ "$*" == "help" ]; then
279    ogHelp "$FUNCNAME int_disk"  \
280           "$FUNCNAME 1"
281    return
282fi
283# Error si no se reciben 1 parámetros.
284[ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $?
285
286# Obteniendo Identificador linux de la particion.
287DISK=$(ogDiskToDev $1) || return $?
288
289# Elimando las particiones con fdisk
290echo -ne "o\nw" | fdisk $DISK
291}
292
293
Note: See TracBrowser for help on using the repository browser.