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