1 | #!/bin/bash |
---|
2 | #/** |
---|
3 | #@file Disk.lib |
---|
4 | #@brief Librería o clase Disk |
---|
5 | #@class Disk |
---|
6 | #@brief Funciones para gestión de discos y particiones. |
---|
7 | #@version 1.0.4 |
---|
8 | #@warning License: GNU GPLv3+ |
---|
9 | #*/ |
---|
10 | |
---|
11 | |
---|
12 | #/** |
---|
13 | # ogCreatePartitions int_ndisk str_parttype:int_partsize ... |
---|
14 | #@brief Define el conjunto de particiones de un disco. |
---|
15 | #@param int_ndisk nº de orden del disco |
---|
16 | #@param str_parttype mnemónico del tipo de partición |
---|
17 | #@param int_partsize tamaño de la partición (en KB) |
---|
18 | #@return (nada, por determinar) |
---|
19 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
20 | #@exception OG_ERR_NOTFOUND disco o partición no detectado (no es un dispositivo). |
---|
21 | #@exception OG_ERR_PARTITION error en partición o en tabla de particiones. |
---|
22 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
23 | #@attention Pueden definirse particiones vacías de tipo \c EMPTY |
---|
24 | #@attention No puede definirse partición de cache y no se modifica si existe. |
---|
25 | #@note Requisitos: sfdisk, parted, partprobe, awk |
---|
26 | #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. |
---|
27 | #@version 0.9 - Primera versión para OpenGNSys |
---|
28 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
29 | #@date 2009/09/09 |
---|
30 | #@version 0.9.1 - Corrección del redondeo del tamaño del disco. |
---|
31 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
32 | #@date 2010/03/09 |
---|
33 | #@version 1.0.4 - Llamada a función específica para tablas GPT. |
---|
34 | #@author Universidad de Huelva |
---|
35 | #@date 2012/03/30 |
---|
36 | #*/ ## |
---|
37 | function ogCreatePartitions () |
---|
38 | { |
---|
39 | # Variables locales. |
---|
40 | local ND DISK PTTYPE PART SECTORS START SIZE TYPE CACHEPART CACHESIZE EXTSTART EXTSIZE tmpsfdisk |
---|
41 | # Si se solicita, mostrar ayuda. |
---|
42 | if [ "$*" == "help" ]; then |
---|
43 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \ |
---|
44 | "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
45 | return |
---|
46 | fi |
---|
47 | # Error si no se reciben menos de 2 parámetros. |
---|
48 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
49 | |
---|
50 | # Nº total de sectores, para evitar desbordamiento (evitar redondeo). |
---|
51 | ND="$1" |
---|
52 | DISK=$(ogDiskToDev "$ND") || return $? |
---|
53 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
54 | case "$PTTYPE" in |
---|
55 | GPT) ogCreateGptPartitions "$@" |
---|
56 | return $? ;; |
---|
57 | MSDOS) ;; |
---|
58 | *) ogRaiseError $OG_ERR_PARTITION "$PTTYPE" |
---|
59 | return $? ;; |
---|
60 | esac |
---|
61 | SECTORS=$(ogGetLastSector $1) |
---|
62 | # Se recalcula el nº de sectores del disco 1, si existe partición de caché. |
---|
63 | CACHEPART=$(ogFindCache 2>/dev/null) |
---|
64 | [ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}') |
---|
65 | [ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE] |
---|
66 | # Sector de inicio (la partición 1 empieza en el sector 63). |
---|
67 | START=63 |
---|
68 | PART=1 |
---|
69 | |
---|
70 | # Fichero temporal de entrada para "sfdisk" |
---|
71 | tmpsfdisk=/tmp/sfdisk$$ |
---|
72 | trap "rm -f $tmpsfdisk" 1 2 3 9 15 |
---|
73 | |
---|
74 | echo "unit: sectors" >$tmpsfdisk |
---|
75 | echo >>$tmpsfdisk |
---|
76 | |
---|
77 | # Generar fichero de entrada para "sfdisk" con las particiones. |
---|
78 | shift |
---|
79 | while [ $# -gt 0 ]; do |
---|
80 | # Conservar los datos de la partición de caché. |
---|
81 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
82 | echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk |
---|
83 | PART=$[PART+1] |
---|
84 | fi |
---|
85 | # Leer formato de cada parámetro - Tipo:Tamaño |
---|
86 | TYPE="${1%%:*}" |
---|
87 | SIZE="${1#*:}" |
---|
88 | # Obtener identificador de tipo de partición válido. |
---|
89 | ID=$(ogTypeToId "$TYPE") |
---|
90 | [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
91 | # Comprobar tamaño numérico y convertir en sectores de 512 B. |
---|
92 | [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $? |
---|
93 | SIZE=$[SIZE*2] |
---|
94 | # Comprobar si la partición es extendida. |
---|
95 | if [ $ID = 5 ]; then |
---|
96 | [ $PART -gt 4 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
97 | EXTSTART=$START |
---|
98 | EXTSIZE=$SIZE |
---|
99 | fi |
---|
100 | # Incluir particiones lógicas dentro de la partición extendida. |
---|
101 | if [ $PART = 5 ]; then |
---|
102 | [ -z "$EXTSTART" ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
103 | START=$EXTSTART |
---|
104 | SECTORS=$[EXTSTART+EXTSIZE] |
---|
105 | fi |
---|
106 | # Generar datos para la partición. |
---|
107 | echo "$DISK$PART : start=$START, size=$SIZE, Id=$ID" >>$tmpsfdisk |
---|
108 | # Error si se supera el nº total de sectores. |
---|
109 | START=$[START+SIZE] |
---|
110 | [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $? |
---|
111 | PART=$[PART+1] |
---|
112 | shift |
---|
113 | done |
---|
114 | # Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché. |
---|
115 | while [ $PART -le 4 ]; do |
---|
116 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
117 | echo "$DISK$PART : start=$[SECTORS+1], size=$CACHESIZE, Id=ca" >>$tmpsfdisk |
---|
118 | else |
---|
119 | echo "$DISK$PART : start=0, size=0, Id=0" >>$tmpsfdisk |
---|
120 | fi |
---|
121 | PART=$[PART+1] |
---|
122 | done |
---|
123 | # Si se define partición extendida sin lógicas, crear particion 5 vacía. |
---|
124 | if [ $PART = 5 -a -n "$EXTSTART" ]; then |
---|
125 | echo "${DISK}5 : start=$EXTSTART, size=$EXTSIZE, Id=0" >>$tmpsfdisk |
---|
126 | fi |
---|
127 | |
---|
128 | # Desmontar los sistemas de archivos del disco antes de realizar las operaciones. |
---|
129 | ogUnmountAll $ND 2>/dev/null |
---|
130 | [ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null |
---|
131 | |
---|
132 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
133 | ogCreatePartitionTable $ND |
---|
134 | # Definir particiones y notificar al kernel. |
---|
135 | sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && partprobe $DISK |
---|
136 | rm -f $tmpsfdisk |
---|
137 | [ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | #/** |
---|
142 | # ogCreateGptPartitions int_ndisk str_parttype:int_partsize ... |
---|
143 | #@brief Define el conjunto de particiones de un disco GPT |
---|
144 | #@param int_ndisk nº de orden del disco |
---|
145 | #@param str_parttype mnemónico del tipo de partición |
---|
146 | #@param int_partsize tamaño de la partición (en KB) |
---|
147 | #@return (nada, por determinar) |
---|
148 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
149 | #@exception OG_ERR_NOTFOUND disco o partición no detectado (no es un dispositivo). |
---|
150 | #@exception OG_ERR_PARTITION error en partición o en tabla de particiones. |
---|
151 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
152 | #@attention Pueden definirse particiones vacías de tipo \c EMPTY |
---|
153 | #@attention No puede definirse partición de caché y no se modifica si existe. |
---|
154 | #@note Requisitos: sfdisk, parted, partprobe, awk |
---|
155 | #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. |
---|
156 | #@version 1.0.4 - Primera versión para OpenGnSys |
---|
157 | #@author Universidad de Huelva |
---|
158 | #@date 2012/03/30 |
---|
159 | #*/ ## |
---|
160 | function ogCreateGptPartitions () |
---|
161 | { |
---|
162 | # Variables locales. |
---|
163 | local ND DISK PART SECTORS ALIGN START SIZE TYPE CACHEPART CACHESIZE DELOPTIONS OPTIONS |
---|
164 | # Si se solicita, mostrar ayuda. |
---|
165 | if [ "$*" == "help" ]; then |
---|
166 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \ |
---|
167 | "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
168 | return |
---|
169 | fi |
---|
170 | # Error si no se reciben menos de 2 parámetros. |
---|
171 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
172 | |
---|
173 | # Nº total de sectores, para evitar desbordamiento (evitar redondeo). |
---|
174 | ND="$1" |
---|
175 | DISK=$(ogDiskToDev "$ND") || return $? |
---|
176 | # Se calcula el ultimo sector del disco (total de sectores usables) |
---|
177 | SECTORS=$(ogGetLastSector $1) |
---|
178 | [ "$ND" = "${CACHEPART% *}" ] && CACHESIZE=$(ogGetCacheSize 2>/dev/null | awk '{print $0*2}') |
---|
179 | [ -n "$CACHESIZE" ] && SECTORS=$[SECTORS-CACHESIZE] |
---|
180 | # Si el disco es GPT empieza en el sector 2048 por defecto, pero podria cambiarse |
---|
181 | ALIGN=`sgdisk -D $DISK` |
---|
182 | START=$ALIGN |
---|
183 | PART=1 |
---|
184 | |
---|
185 | # Leer parámetros con definición de particionado. |
---|
186 | shift |
---|
187 | |
---|
188 | while [ $# -gt 0 ]; do |
---|
189 | # Si PART es la cache, nos la saltamos y seguimos con el siguiente numero para conservar los datos de la partición de caché. |
---|
190 | if [ "$ND $PART" == "$CACHEPART" -a -n "$CACHESIZE" ]; then |
---|
191 | PART=$[PART+1] |
---|
192 | fi |
---|
193 | # Leer formato de cada parámetro - Tipo:Tamaño |
---|
194 | TYPE="${1%%:*}" |
---|
195 | SIZE="${1#*:}" |
---|
196 | # Error si la partición es extendida (no válida en discos GPT). |
---|
197 | [ "$TYPE" == "EXTENDED" ] || ogRaiseError $OG_ERR_PARTITION "EXTENDED" || return $? |
---|
198 | # Comprobar si existe la particion actual, capturamos su tamaño para ver si cambio o no |
---|
199 | PARTSIZE=$(ogGetPartitionSize $ND $PART) |
---|
200 | # En sgdisk no se pueden redimensionar las particiones, es necesario borrarlas y volver a crealas |
---|
201 | [ $PARTSIZE ] && DELOPTIONS="$DELOPTIONS -d$PART" |
---|
202 | # Creamos la particion |
---|
203 | # Obtener identificador de tipo de partición válido. |
---|
204 | ID=$(ogTypeToId "$TYPE") |
---|
205 | [ "$TYPE" != "CACHE" -a -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
206 | # Comprobar tamaño numérico y convertir en sectores de 512 B. |
---|
207 | [[ "$SIZE" == *([0-9]) ]] || ogRaiseError $OG_ERR_FORMAT "$SIZE" || return $? |
---|
208 | SIZE=$[SIZE*2] |
---|
209 | # SIZE debe ser múltiplo de ALIGN, si no gdisk lo mueve automáticamente. |
---|
210 | DIV=$[$SIZE/$ALIGN] |
---|
211 | SIZE=$[$DIV*$ALIGN] |
---|
212 | # En el caso de que la partición sea EMPTY no se crea nada |
---|
213 | if [ "$TYPE" != "EMPTY" ]; then |
---|
214 | OPTIONS="$OPTIONS -n$PART:$START:+$SIZE -t$PART:$ID " |
---|
215 | fi |
---|
216 | START=$[START+SIZE] |
---|
217 | # Error si se supera el nº total de sectores. |
---|
218 | [ $START -le $SECTORS ] || ogRaiseError $OG_ERR_FORMAT "$[START/2] > $[SECTORS/2]" || return $? |
---|
219 | PART=$[PART+1] |
---|
220 | shift |
---|
221 | done |
---|
222 | |
---|
223 | # Desmontar los sistemas de archivos del disco antes de realizar las operaciones. |
---|
224 | ogUnmountAll $ND 2>/dev/null |
---|
225 | [ -n "$CACHESIZE" ] && ogUnmountCache 2>/dev/null |
---|
226 | |
---|
227 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
228 | ogCreatePartitionTable $ND |
---|
229 | # Definir particiones y notificar al kernel. |
---|
230 | # Borramos primero las particiones y luego creamos las nuevas |
---|
231 | sgdisk $DELOPTIONS $OPTIONS $DISK && partprobe $DISK |
---|
232 | [ -n "$CACHESIZE" ] && ogMountCache 2>/dev/null |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | #/** |
---|
237 | # ogCreatePartitionTable int_ndisk [str_tabletype] |
---|
238 | #@brief Genera una tabla de particiones en caso de que no sea valida, si es valida no hace nada. |
---|
239 | #@param int_ndisk nº de orden del disco |
---|
240 | #@param str_tabletype tipo de tabla de particiones (opcional) |
---|
241 | #@return (por determinar) |
---|
242 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
243 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
244 | #@note tabletype: { MSDOS, GPT } |
---|
245 | #@note Requisitos: sfdisk, sgdisk |
---|
246 | #@version 1.0.4 - Primera versión compatible con OpenGNSys. |
---|
247 | #@author Universidad de Huelva |
---|
248 | #@date 2012/03/06 |
---|
249 | #*/ ## |
---|
250 | function ogCreatePartitionTable() |
---|
251 | { |
---|
252 | # Variables locales. |
---|
253 | local DISK PTTYPE CREATE CREATEPTT |
---|
254 | |
---|
255 | # Si se solicita, mostrar ayuda. |
---|
256 | if [ "$*" == "help" ]; then |
---|
257 | ogHelp "$FUNCNAME int_ndisk [str_partype]" \ |
---|
258 | "$FUNCNAME 1 GPT" "$FUNCNAME 1" |
---|
259 | return |
---|
260 | fi |
---|
261 | # Error si no se reciben 1 o 2 parámetros. |
---|
262 | case $# in |
---|
263 | 1) CREATEPTT="" ;; |
---|
264 | 2) CREATEPTT="$2" ;; |
---|
265 | *) ogRaiseError $OG_ERR_FORMAT |
---|
266 | return $? ;; |
---|
267 | esac |
---|
268 | |
---|
269 | # Capturamos el tipo de tabla de particiones actual |
---|
270 | DISK=$(ogDiskToDev $1) || return $? |
---|
271 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
272 | CREATEPTT=${CREATEPTT:-"$PTTYPE"} |
---|
273 | |
---|
274 | # Si la tabla actual y la que se indica son iguales, se comprueba por si hay que regenerarla. |
---|
275 | if [ "$CREATEPTT" == "$PTTYPE" ]; then |
---|
276 | case "$PTTYPE" in |
---|
277 | GPT) [ ! $(sgdisk -p $DISK 2>&1 >/dev/null) ] || CREATE="GPT" ;; |
---|
278 | MSDOS) [ $(parted -s $DISK print >/dev/null) ] || CREATE="MSDOS" ;; |
---|
279 | esac |
---|
280 | else |
---|
281 | CREATE="$CREATEPTT" |
---|
282 | fi |
---|
283 | # Dependiendo del valor de CREATE, creamos la tabla de particiones en cada caso. |
---|
284 | case "$CREATE" in |
---|
285 | GPT) |
---|
286 | # Si es necesario crear una tabla GPT pero la actual es MSDOS |
---|
287 | if [ "$PTTYPE" == "MSDOS" ]; then |
---|
288 | sgdisk -g $DISK |
---|
289 | else |
---|
290 | echo -e "2\nw\nY\n" | gdisk $DISK |
---|
291 | fi |
---|
292 | partprobe $DISK 2>/dev/null |
---|
293 | ;; |
---|
294 | MSDOS) |
---|
295 | # Si es necesario crear una tabla MSDOS pero la actual es GPT |
---|
296 | if [ "$PTTYPE" == "GPT" ]; then |
---|
297 | echo -e "r\ng\nw\nY" | gdisk $DISK |
---|
298 | else |
---|
299 | fdisk $DISK <<< "w" |
---|
300 | fi |
---|
301 | partprobe $DISK 2>/dev/null |
---|
302 | ;; |
---|
303 | esac |
---|
304 | } |
---|
305 | |
---|
306 | |
---|
307 | #/** |
---|
308 | # ogDeletePartitionTable ndisk |
---|
309 | #@brief Borra la tabla de particiones del disco. |
---|
310 | #@param int_ndisk nº de orden del disco |
---|
311 | #@return la informacion propia del fdisk |
---|
312 | #@version 0.1 - Integracion para OpenGnSys |
---|
313 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
314 | #@date 2008/10/27 |
---|
315 | #@version 1.0.4 - Adaptado para su uso con discos GPT |
---|
316 | #@author Universidad de Huelva |
---|
317 | #@date 2012/03/13 |
---|
318 | #*/ ## |
---|
319 | function ogDeletePartitionTable () |
---|
320 | { |
---|
321 | # Variables locales. |
---|
322 | local DISK |
---|
323 | |
---|
324 | # Si se solicita, mostrar ayuda. |
---|
325 | if [ "$*" == "help" ]; then |
---|
326 | ogHelp "$FUNCNAME int_ndisk" "$FUNCNAME 1" |
---|
327 | return |
---|
328 | fi |
---|
329 | # Error si no se reciben 1 parámetros. |
---|
330 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
331 | |
---|
332 | # Obteniendo Identificador linux del disco. |
---|
333 | DISK=$(ogDiskToDev $1) || return $? |
---|
334 | # Crear una tabla de particiones vacía. |
---|
335 | case "$(ogGetPartitionTableType $1)" in |
---|
336 | GPT) sgdisk -o $DISK ;; |
---|
337 | MSDOS) echo -ne "o\nw" | fdisk $DISK ;; |
---|
338 | esac |
---|
339 | } |
---|
340 | |
---|
341 | |
---|
342 | #/** |
---|
343 | # ogDevToDisk path_device |
---|
344 | #@brief Devuelve el nº de orden de dicso (y partición) correspondiente al nombre de fichero de dispositivo. |
---|
345 | #@param path_device Camino del fichero de dispositivo. |
---|
346 | #@return int_ndisk (para dispositivo de disco) |
---|
347 | #@return int_ndisk int_npartition (para dispositivo de partición). |
---|
348 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
349 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
350 | #@note Requisitos: awk |
---|
351 | #@version 0.1 - Integracion para Opengnsys - EAC: DiskEAC() en ATA.lib |
---|
352 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
353 | #@date 2008/10/27 |
---|
354 | #@version 0.9 - Primera version para OpenGNSys |
---|
355 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
356 | #@date 2009/07/20 |
---|
357 | #*/ ## |
---|
358 | function ogDevToDisk () |
---|
359 | { |
---|
360 | # Variables locales. |
---|
361 | local d n |
---|
362 | # Si se solicita, mostrar ayuda. |
---|
363 | if [ "$*" == "help" ]; then |
---|
364 | ogHelp "$FUNCNAME" "$FUNCNAME path_device" \ |
---|
365 | "$FUNCNAME /dev/sda => 1 1" |
---|
366 | return |
---|
367 | fi |
---|
368 | |
---|
369 | # Error si no se recibe 1 parámetro. |
---|
370 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
371 | # Error si no es fichero de bloques. |
---|
372 | [ -b "$1" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
373 | |
---|
374 | # Procesa todos los discos para devolver su nº de orden y de partición. |
---|
375 | n=1 |
---|
376 | for d in $(ogDiskToDev); do |
---|
377 | [ -n "$(echo $1 | grep $d)" ] && echo "$n ${1#$d}" && return |
---|
378 | n=$[n+1] |
---|
379 | done |
---|
380 | ogRaiseError $OG_ERR_NOTFOUND "$1" |
---|
381 | return $OG_ERR_NOTFOUND |
---|
382 | } |
---|
383 | |
---|
384 | |
---|
385 | #/** |
---|
386 | # ogDiskToDev [int_ndisk [int_npartition]] |
---|
387 | #@brief Devuelve la equivalencia entre el nº de orden del dispositivo (dicso o partición) y el nombre de fichero de dispositivo correspondiente. |
---|
388 | #@param int_ndisk nº de orden del disco |
---|
389 | #@param int_npartition nº de orden de la partición |
---|
390 | #@return Para 0 parametros: Devuelve los nombres de ficheros de los dispositivos sata/ata/usb linux encontrados. |
---|
391 | #@return Para 1 parametros: Devuelve la ruta del disco duro indicado. |
---|
392 | #@return Para 2 parametros: Devuelve la ruta de la particion indicada. |
---|
393 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
394 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
395 | #@note Requisitos: awk, lvm |
---|
396 | #@version 0.1 - Integracion para Opengnsys - EAC: Disk() en ATA.lib; HIDRA: DetectarDiscos.sh |
---|
397 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
398 | #@Date 2008/06/19 |
---|
399 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
400 | #@date 2008/10/27 |
---|
401 | #@version 0.9 - Primera version para OpenGNSys |
---|
402 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
403 | #@date 2009-07-20 |
---|
404 | #*/ ## |
---|
405 | function ogDiskToDev () |
---|
406 | { |
---|
407 | # Variables locales |
---|
408 | local ALLDISKS VOLGROUPS DISK PART |
---|
409 | |
---|
410 | # Si se solicita, mostrar ayuda. |
---|
411 | if [ "$*" == "help" ]; then |
---|
412 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npartition]" \ |
---|
413 | "$FUNCNAME => /dev/sda /dev/sdb" \ |
---|
414 | "$FUNCNAME 1 => /dev/sda" \ |
---|
415 | "$FUNCNAME 1 1 => /dev/sda1" |
---|
416 | return |
---|
417 | fi |
---|
418 | |
---|
419 | # Listar dispositivo para los discos duros (tipos: 3=hd, 8=sd). |
---|
420 | ALLDISKS=$(awk '($1==3 || $1==8) && $4!~/[0-9]/ {printf "/dev/%s ",$4}' /proc/partitions) |
---|
421 | VOLGROUPS=$(vgs -a --noheadings 2>/dev/null | awk '{printf "/dev/%s ",$1}') |
---|
422 | ALLDISKS="$ALLDISKS $VOLGROUPS" |
---|
423 | |
---|
424 | # Mostrar salidas segun el número de parametros. |
---|
425 | case $# in |
---|
426 | 0) # Muestra todos los discos, separados por espacios. |
---|
427 | echo $ALLDISKS |
---|
428 | ;; |
---|
429 | 1) # Error si el parámetro no es un digito. |
---|
430 | [ -z "${1/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
431 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
432 | # Error si el fichero no existe. |
---|
433 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
434 | echo "$DISK" |
---|
435 | ;; |
---|
436 | 2) # Error si los 2 parámetros no son digitos. |
---|
437 | [ -z "${1/[1-9]/}" -a -z "${2/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT|| return $? |
---|
438 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
439 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
440 | PART="$DISK$2" |
---|
441 | # Comprobar si es partición. |
---|
442 | if [ -b "$PART" ]; then |
---|
443 | echo "$PART" |
---|
444 | elif [ -n "$VOLGROUPS" ]; then |
---|
445 | # Comprobar si volumen lógico. /* (comentario Doxygen) |
---|
446 | PART=$(lvscan -a 2>/dev/null | grep "'$DISK/" | awk -v n=$2 -F\' '{if (NR==n) print $2}') |
---|
447 | [ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
448 | # (comentario Doxygen) */ |
---|
449 | echo "$PART" |
---|
450 | else |
---|
451 | ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
452 | fi |
---|
453 | ;; |
---|
454 | *) # Formato erroneo. |
---|
455 | ogRaiseError $OG_ERR_FORMAT |
---|
456 | return $OG_ERR_FORMAT |
---|
457 | ;; |
---|
458 | esac |
---|
459 | } |
---|
460 | |
---|
461 | |
---|
462 | #/** |
---|
463 | # ogFsToId str_fstype |
---|
464 | #@see ogTypeToId |
---|
465 | #*/ ## |
---|
466 | function ogFsToId () |
---|
467 | { |
---|
468 | ogTypeToId "$@" |
---|
469 | } |
---|
470 | |
---|
471 | |
---|
472 | #/** |
---|
473 | # ogTypeToId str_parttype |
---|
474 | #@brief Devuelve el identificador correspondiente a un tipo de partición. |
---|
475 | #@param str_parttype mnemónico de tipo de partición. |
---|
476 | #@return int_idpart identificador de tipo de partición. |
---|
477 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
478 | #@version 0.1 - Integracion para Opengnsys - EAC: TypeFS () en ATA.lib |
---|
479 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
480 | #@date 2008/10/27 |
---|
481 | #@version 0.9 - Primera version para OpenGNSys |
---|
482 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
483 | #@date 2009-12-14 |
---|
484 | #@version 1.0.4 - Soportar discos GPT (sustituye a ogFsToId). |
---|
485 | #@author Universidad de Huelva |
---|
486 | #@date 2012/03/30 |
---|
487 | #*/ ## |
---|
488 | function ogTypeToId () |
---|
489 | { |
---|
490 | # Variables locales |
---|
491 | local ID |
---|
492 | |
---|
493 | # Si se solicita, mostrar ayuda. |
---|
494 | if [ "$*" == "help" ]; then |
---|
495 | ogHelp "$FUNCNAME" "$FUNCNAME str_fstype" "$FUNCNAME EXT3 => 83" |
---|
496 | return |
---|
497 | fi |
---|
498 | # Error si no se recibe 1 parámetro. |
---|
499 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
500 | |
---|
501 | # Asociar id. de partición para su mnemónico de sistema de archivos. |
---|
502 | case "$(ogGetPartitionTableType $1)" in |
---|
503 | GPT) # Se incluyen mnemónicos compatibles con tablas MSDOS. |
---|
504 | case "$1" in |
---|
505 | EMPTY) ID=0 ;; |
---|
506 | WINDOWS|NTFS|EXFAT|FAT32|FAT16|FAT12|HNTFS|HFAT32|HFAT16|HFAT12) |
---|
507 | ID=0700 ;; |
---|
508 | WIN-RESERV) ID=0C01 ;; |
---|
509 | CHROMEOS-KRN) ID=7F00 ;; |
---|
510 | CHROMEOS) ID=7F01 ;; |
---|
511 | CHROMEOS-RESERV) ID=7F02 ;; |
---|
512 | LINUX-SWAP) ID=8200 ;; |
---|
513 | LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS) |
---|
514 | ID=8300 ;; |
---|
515 | LINUX-RESERV) ID=8301 ;; |
---|
516 | LINUX-LVM) ID=8E00 ;; |
---|
517 | FREEBSD-DISK) ID=A500 ;; |
---|
518 | FREEBSD-BOOT) ID=A501 ;; |
---|
519 | FREEBSD-SWAP) ID=A502 ;; |
---|
520 | FREEBSD) ID=A503 ;; |
---|
521 | HFS|HFS+) ID=AF00 ;; |
---|
522 | HFS-RAID) ID=AF01 ;; |
---|
523 | SOLARIS-BOOT) ID=BE00 ;; |
---|
524 | SOLARIS) ID=BF00 ;; |
---|
525 | SOLARIS-SWAP) ID=BF02 ;; |
---|
526 | SOLARIS-DISK) ID=BF03 ;; |
---|
527 | CACHE) ID=CA00;; |
---|
528 | EFI) ID=EF00 ;; |
---|
529 | LINUX-RAID) ID=FD00 ;; |
---|
530 | *) ID="" ;; |
---|
531 | esac |
---|
532 | ;; |
---|
533 | MSDOS) |
---|
534 | case "$1" in |
---|
535 | EMPTY) ID=0 ;; |
---|
536 | FAT12) ID=1 ;; |
---|
537 | EXTENDED) ID=5 ;; |
---|
538 | FAT16) ID=6 ;; |
---|
539 | WINDOWS|NTFS|EXFAT) |
---|
540 | ID=7 ;; |
---|
541 | FAT32) ID=b ;; |
---|
542 | HFAT12) ID=11 ;; |
---|
543 | HFAT16) ID=16 ;; |
---|
544 | HNTFS) ID=17 ;; |
---|
545 | HFAT32) ID=1b ;; |
---|
546 | LINUX-SWAP) ID=82 ;; |
---|
547 | LINUX|EXT[234]|REISERFS|REISER4|XFS|JFS) |
---|
548 | ID=83 ;; |
---|
549 | LINUX-LVM) ID=8e ;; |
---|
550 | FREEBSD) ID=a5 ;; |
---|
551 | OPENBSD) ID=a6 ;; |
---|
552 | HFS|HFS+) ID=af ;; |
---|
553 | SOLARIS-BOOT) ID=be ;; |
---|
554 | SOLARIS) ID=bf ;; |
---|
555 | CACHE) ID=ca ;; |
---|
556 | DATA) ID=da ;; |
---|
557 | GPT) ID=ee ;; |
---|
558 | EFI) ID=ef ;; |
---|
559 | VMFS) ID=fb ;; |
---|
560 | LINUX-RAID) ID=fd ;; |
---|
561 | *) ID="" ;; |
---|
562 | esac |
---|
563 | ;; |
---|
564 | esac |
---|
565 | echo $ID |
---|
566 | } |
---|
567 | |
---|
568 | |
---|
569 | #/** |
---|
570 | # ogGetDiskSize int_ndisk |
---|
571 | #@brief Muestra el tamaño en KB de un disco. |
---|
572 | #@param int_ndisk nº de orden del disco |
---|
573 | #@return int_size - Tamaño en KB del disco. |
---|
574 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
575 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
576 | #@note Requisitos: sfdisk, awk |
---|
577 | #@version 0.9.2 - Primera version para OpenGnSys |
---|
578 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
579 | #@date 2010/09/15 |
---|
580 | #*/ ## |
---|
581 | function ogGetDiskSize () |
---|
582 | { |
---|
583 | # Variables locales. |
---|
584 | local DISK |
---|
585 | |
---|
586 | # Si se solicita, mostrar ayuda. |
---|
587 | if [ "$*" == "help" ]; then |
---|
588 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 244198584" |
---|
589 | return |
---|
590 | fi |
---|
591 | # Error si no se recibe 1 parámetro. |
---|
592 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
593 | |
---|
594 | # Obtener el tamaño del disco. |
---|
595 | DISK="$(ogDiskToDev $1)" || return $? |
---|
596 | awk -v D=${DISK#/dev/} '{if ($4==D) {print $3}}' /proc/partitions |
---|
597 | } |
---|
598 | |
---|
599 | |
---|
600 | #/** |
---|
601 | # ogGetDiskType path_device |
---|
602 | #@brief Muestra el tipo de disco (real, RAID, meta-disco, etc.). |
---|
603 | #@warning Función en pruebas |
---|
604 | #*/ ## |
---|
605 | function ogGetDiskType () |
---|
606 | { |
---|
607 | local DEV MAJOR TYPE |
---|
608 | |
---|
609 | # Obtener el driver del dispositivo de bloques. |
---|
610 | [ -b "$1" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
611 | DEV=${1#/dev/} |
---|
612 | MAJOR=$(awk -v D="$DEV" '{if ($4==D) print $1;}' /proc/partitions) |
---|
613 | TYPE=$(awk -v D=$MAJOR '/Block/ {bl=1} {if ($1==D&&bl) print toupper($2)}' /proc/devices) |
---|
614 | # Devolver mnemónico del driver de dispositivo. |
---|
615 | case "$TYPE" in |
---|
616 | SD) TYPE="DISK" ;; |
---|
617 | SR|IDE*) TYPE="CDROM" ;; # FIXME Comprobar discos IDE. |
---|
618 | MD|CCISS*) TYPE="RAID" ;; |
---|
619 | DEVICE-MAPPER) TYPE="MAPPER" ;; # FIXME Comprobar LVM y RAID. |
---|
620 | esac |
---|
621 | echo $TYPE |
---|
622 | } |
---|
623 | |
---|
624 | |
---|
625 | #/** |
---|
626 | # ogGetLastSector int_ndisk [int_npart] |
---|
627 | #@brief Devuelve el último sector usable del disco o una partición. |
---|
628 | #@param int_ndisk nº de orden del disco |
---|
629 | #@param int_npart nº de orden de la partición (opcional) |
---|
630 | #@return Último sector usable. |
---|
631 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
632 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo. |
---|
633 | #@note Requisitos: sfdisk, sgdisk |
---|
634 | #@version 1.0.4 - Primera versión compatible con OpenGnSys. |
---|
635 | #@author Universidad de Huelva |
---|
636 | #@date 2012/06/03 |
---|
637 | #*/ ## |
---|
638 | |
---|
639 | function ogGetLastSector () |
---|
640 | { |
---|
641 | # Variables locales |
---|
642 | local DISK PART PTTYPE LASTSECTOR SECTORS CYLS |
---|
643 | # Si se solicita, mostrar ayuda. |
---|
644 | if [ "$*" == "help" ]; then |
---|
645 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npart]" \ |
---|
646 | "$FUNCNAME 1 => 488392064" \ |
---|
647 | "$FUNCNAME 1 1 => 102400062" |
---|
648 | return |
---|
649 | fi |
---|
650 | # Error si no se reciben 1 o 2 parámetros. |
---|
651 | case $# in |
---|
652 | 1) DISK=$(ogDiskToDev $1) || return $? |
---|
653 | ;; |
---|
654 | 2) DISK=$(ogDiskToDev $1) || return $? |
---|
655 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
656 | ;; |
---|
657 | *) ogRaiseError $OG_ERR_FORMAT |
---|
658 | return $? ;; |
---|
659 | esac |
---|
660 | |
---|
661 | # Hay que comprobar si el disco es GPT |
---|
662 | PTTYPE=$(ogGetPartitionTableType $1) |
---|
663 | case "$PTTYPE" in |
---|
664 | GPT) |
---|
665 | if [ $# == 1 ]; then |
---|
666 | LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk '/last usable sector/ {print($(NF))}') |
---|
667 | else |
---|
668 | LASTSECTOR=$(LANG=C sgdisk -p $DISK | awk -v P="$2" '{if ($1==P) print $3}') |
---|
669 | fi |
---|
670 | ;; |
---|
671 | MSDOS) |
---|
672 | if [ $# == 1 ]; then |
---|
673 | SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions) |
---|
674 | CYLS=$(sfdisk -g $DISK | cut -f2 -d" ") |
---|
675 | LASTSECTOR=$[SECTORS/CYLS*CYLS-1] |
---|
676 | else |
---|
677 | LASTSECTOR=$(sfdisk -uS -l $DISK | \ |
---|
678 | awk -v P="$PART" '{if ($1==P) {if ($2=="*") print $4; else print $3} }') |
---|
679 | fi |
---|
680 | ;; |
---|
681 | esac |
---|
682 | echo $LASTSECTOR |
---|
683 | } |
---|
684 | |
---|
685 | |
---|
686 | #/** |
---|
687 | # ogGetPartitionActive int_ndisk |
---|
688 | #@brief Muestra que particion de un disco esta marcada como de activa. |
---|
689 | #@param int_ndisk nº de orden del disco |
---|
690 | #@return int_npart Nº de partición activa |
---|
691 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
692 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
693 | #@note Requisitos: parted |
---|
694 | #@todo Queda definir formato para atributos (arranque, oculta, ...). |
---|
695 | #@version 0.9 - Primera version compatible con OpenGNSys. |
---|
696 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
697 | #@date 2009/09/17 |
---|
698 | #*/ ## |
---|
699 | function ogGetPartitionActive () |
---|
700 | { |
---|
701 | # Variables locales |
---|
702 | local DISK |
---|
703 | |
---|
704 | # Si se solicita, mostrar ayuda. |
---|
705 | if [ "$*" == "help" ]; then |
---|
706 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 1" |
---|
707 | return |
---|
708 | fi |
---|
709 | # Error si no se recibe 1 parámetro. |
---|
710 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
711 | |
---|
712 | # Comprobar que el disco existe y listar su partición activa. |
---|
713 | DISK="$(ogDiskToDev $1)" || return $? |
---|
714 | parted $DISK print 2>/dev/null | awk '/boot/ {print $1}' |
---|
715 | } |
---|
716 | |
---|
717 | |
---|
718 | #/** |
---|
719 | # ogGetPartitionId int_ndisk int_npartition |
---|
720 | #@brief Devuelve el mnemónico con el tipo de partición. |
---|
721 | #@param int_ndisk nº de orden del disco |
---|
722 | #@param int_npartition nº de orden de la partición |
---|
723 | #@return Identificador de tipo de partición. |
---|
724 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
725 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponde con un dispositivo. |
---|
726 | #@note Requisitos: sfdisk |
---|
727 | #@version 0.9 - Primera versión compatible con OpenGnSys. |
---|
728 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
729 | #@date 2009/03/25 |
---|
730 | #@version 1.0.2 - Detectar partición vacía. |
---|
731 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
732 | #@date 2011/12/23 |
---|
733 | #*/ ## |
---|
734 | function ogGetPartitionId () |
---|
735 | { |
---|
736 | # Variables locales. |
---|
737 | local DISK PART ID |
---|
738 | |
---|
739 | # Si se solicita, mostrar ayuda. |
---|
740 | if [ "$*" == "help" ]; then |
---|
741 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
742 | "$FUNCNAME 1 1 => 7" |
---|
743 | return |
---|
744 | fi |
---|
745 | # Error si no se reciben 2 parámetros. |
---|
746 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
747 | |
---|
748 | # Detectar id. de tipo de partición y codificar al mnemónico. |
---|
749 | DISK=$(ogDiskToDev $1) || return $? |
---|
750 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
751 | case "$(ogGetPartitionTableType $1)" in |
---|
752 | GPT) ID=$(sgdisk -p $DISK 2>/dev/null | awk -v p="$2" '{if ($1==p) print $6;}') || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $? |
---|
753 | [ "$ID" == "8300" -a "$1 $2" == "$(ogFindCache)" ] && ID=CA00 |
---|
754 | ;; |
---|
755 | MSDOS) ID=$(sfdisk --id $DISK $2 2>/dev/null) || ogRaiseError $OG_ERR_NOTFOUND "$1,$2" || return $? ;; |
---|
756 | esac |
---|
757 | echo $ID |
---|
758 | } |
---|
759 | |
---|
760 | |
---|
761 | #/** |
---|
762 | # ogGetPartitionSize int_ndisk int_npartition |
---|
763 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
764 | #@param int_ndisk nº de orden del disco |
---|
765 | #@param int_npartition nº de orden de la partición |
---|
766 | #@return int_partsize - Tamaño en KB de la partición. |
---|
767 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
768 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
769 | #@note Requisitos: sfdisk, awk |
---|
770 | #@version 0.1 - Integracion para Opengnsys - EAC: SizePartition () en ATA.lib |
---|
771 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
772 | #@date 2008/10/27 |
---|
773 | #@version 0.9 - Primera version para OpenGNSys |
---|
774 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
775 | #@date 2009/07/24 |
---|
776 | #*/ ## |
---|
777 | function ogGetPartitionSize () |
---|
778 | { |
---|
779 | # Variables locales. |
---|
780 | local DISK PART |
---|
781 | |
---|
782 | # Si se solicita, mostrar ayuda. |
---|
783 | if [ "$*" == "help" ]; then |
---|
784 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
785 | "$FUNCNAME 1 1 => 10000000" |
---|
786 | return |
---|
787 | fi |
---|
788 | # Error si no se reciben 2 parámetros. |
---|
789 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
790 | |
---|
791 | # Obtener el tamaño de la partición. |
---|
792 | DISK="$(ogDiskToDev $1)" || return $? |
---|
793 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
794 | case "$(ogGetPartitionId $1 $2)" in |
---|
795 | 5|f) # Procesar detección de tamaño de partición Extendida. |
---|
796 | sfdisk -l $DISK 2>/dev/null | \ |
---|
797 | awk -v p=$PART '{if ($1==p) {sub (/[^0-9]+/,"",$5); print $5} }' |
---|
798 | ;; |
---|
799 | *) sfdisk -s $PART |
---|
800 | ;; |
---|
801 | esac |
---|
802 | } |
---|
803 | |
---|
804 | |
---|
805 | #/** |
---|
806 | # ogGetPartitionsNumber int_ndisk |
---|
807 | #@brief Detecta el numero de particiones del disco duro indicado. |
---|
808 | #@param int_ndisk nº de orden del disco |
---|
809 | #@return Devuelve el numero paritiones del disco duro indicado |
---|
810 | #@warning Salidas de errores no determinada |
---|
811 | #@attention Requisitos: parted |
---|
812 | #@note Notas sin especificar |
---|
813 | #@version 0.1 - Integracion para Opengnsys - EAC: DetectNumberPartition () en ATA.lib |
---|
814 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
815 | #@date Date: 27/10/2008 |
---|
816 | #@version 1.0 - Uso de sfdisk Primera version para OpenGnSys |
---|
817 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
818 | #@date 2009/07/24 |
---|
819 | #@version 1.0.4 - Uso de /proc/partitions para detectar el numero de particiones |
---|
820 | #@author Universidad de Huelva |
---|
821 | #@date 2012/03/28 |
---|
822 | #*/ ## |
---|
823 | function ogGetPartitionsNumber () |
---|
824 | { |
---|
825 | # Variables locales. |
---|
826 | local DISK |
---|
827 | # Si se solicita, mostrar ayuda. |
---|
828 | if [ "$*" == "help" ]; then |
---|
829 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
830 | "$FUNCNAME 1 => 3" |
---|
831 | return |
---|
832 | fi |
---|
833 | # Error si no se recibe 1 parámetro. |
---|
834 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
835 | |
---|
836 | # Contar el nº de veces que aparece el disco en su lista de particiones. |
---|
837 | DISK=$(ogDiskToDev $1) 2>/dev/null |
---|
838 | #sfdisk -l $DISK 2>/dev/null | grep -c "^$DISK" |
---|
839 | grep -c "${DISK#/dev/}." /proc/partitions |
---|
840 | } |
---|
841 | |
---|
842 | |
---|
843 | #/** |
---|
844 | # ogGetPartitionTableType int_ndisk |
---|
845 | #@brief Devuelve el tipo de tabla de particiones del disco (GPT o MSDOS) |
---|
846 | #@param int_ndisk nº de orden del disco |
---|
847 | #@return str_tabletype - Tipo de tabla de paritiones |
---|
848 | #@warning Salidas de errores no determinada |
---|
849 | #@note tabletype: { MSDOS, GPT } |
---|
850 | #@note Requisitos: parted |
---|
851 | #@version 1.0.4 - Primera versión para OpenGnSys |
---|
852 | #@author Universidad de Huelva |
---|
853 | #@date 2012/03/01 |
---|
854 | #*/ |
---|
855 | function ogGetPartitionTableType () |
---|
856 | { |
---|
857 | # Variables locales. |
---|
858 | local DISK |
---|
859 | |
---|
860 | # Si se solicita, mostrar ayuda. |
---|
861 | if [ "$*" == "help" ]; then |
---|
862 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
863 | "$FUNCNAME 1" |
---|
864 | return |
---|
865 | fi |
---|
866 | # Error si no se recibe 1 parámetro. |
---|
867 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
868 | |
---|
869 | # Sustituye n de disco por su dispositivo. |
---|
870 | DISK=`ogDiskToDev $1` || return $? |
---|
871 | parted -sm $DISK print | awk -F: -v D=$DISK '{ if($1 == D) print toupper($6)}' |
---|
872 | } |
---|
873 | |
---|
874 | |
---|
875 | #/** |
---|
876 | # ogGetPartitionType int_ndisk int_npartition |
---|
877 | #@brief Devuelve el mnemonico con el tipo de partición. |
---|
878 | #@param int_ndisk nº de orden del disco |
---|
879 | #@param int_npartition nº de orden de la partición |
---|
880 | #@return Mnemonico |
---|
881 | #@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 } |
---|
882 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
883 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
884 | #@version 0.1 - Integracion para Opengnsys - EAC: TypeFS() en ATA.lib |
---|
885 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
886 | #@date 2008-10-27 |
---|
887 | #@version 0.9 - Primera adaptacion para OpenGnSys. |
---|
888 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
889 | #@date 2009-07-21 |
---|
890 | #@version 1.0.3 - Código trasladado de antigua función ogGetFsType. |
---|
891 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
892 | #@date 2011-12-01 |
---|
893 | #*/ ## |
---|
894 | function ogGetPartitionType () |
---|
895 | { |
---|
896 | # Variables locales. |
---|
897 | local ID TYPE |
---|
898 | |
---|
899 | # Si se solicita, mostrar ayuda. |
---|
900 | if [ "$*" == "help" ]; then |
---|
901 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
902 | "$FUNCNAME 1 1 => NTFS" |
---|
903 | return |
---|
904 | fi |
---|
905 | # Error si no se reciben 2 parámetros. |
---|
906 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
907 | |
---|
908 | # Detectar id. de tipo de partición y codificar al mnemonico. |
---|
909 | ID=$(ogGetPartitionId "$1" "$2") || return $? |
---|
910 | case "$ID" in |
---|
911 | 0) TYPE="EMPTY" ;; |
---|
912 | 1) TYPE="FAT12" ;; |
---|
913 | 5|f) TYPE="EXTENDED" ;; |
---|
914 | 6|e) TYPE="FAT16" ;; |
---|
915 | 7) TYPE="NTFS" ;; |
---|
916 | 700|0700) TYPE="WINDOWS" ;; |
---|
917 | b|c) TYPE="FAT32" ;; |
---|
918 | C01|0C01) TYPE="WIN-RESERV" ;; |
---|
919 | 11) TYPE="HFAT12" ;; |
---|
920 | 12) TYPE="COMPAQDIAG" ;; |
---|
921 | 16|1e) TYPE="HFAT16" ;; |
---|
922 | 17) TYPE="HNTFS" ;; |
---|
923 | 1b|1c) TYPE="HFAT32" ;; |
---|
924 | 42) TYPE="WIN-DYNAMIC" ;; |
---|
925 | 7F00) TYPE="CHROMEOS-KRN" ;; |
---|
926 | 7F01) TYPE="CHROMEOS" ;; |
---|
927 | 7F02) TYPE="CHROMEOS-RESERV" ;; |
---|
928 | 82|8200) TYPE="LINUX-SWAP" ;; |
---|
929 | 83|8300) TYPE="LINUX" ;; |
---|
930 | 8301) TYPE="LINUX-RESERV" ;; |
---|
931 | 8e|8E00) TYPE="LINUX-LVM" ;; |
---|
932 | a5|A503) TYPE="FREEBSD" ;; |
---|
933 | A500) TYPE="FREEBSD-DISK" ;; |
---|
934 | A501) TYPE="FREEBSD-BOOT" ;; |
---|
935 | A502) TYPE="FREEBSD-SWAP" ;; |
---|
936 | a6) TYPE="OPENBSD" ;; |
---|
937 | a7) TYPE="CACHE" ;; # (compatibilidad con Brutalix) |
---|
938 | af|AF00) TYPE="HFS" ;; |
---|
939 | Af01) TYPE="HFS-RAID" ;; |
---|
940 | be|BE00) TYPE="SOLARIS-BOOT" ;; |
---|
941 | bf|BF0[0145]) TYPE="SOLARIS" ;; |
---|
942 | BF02) TYPE="SOLARIS-SWAP" ;; |
---|
943 | BF03) TYPE="SOLARIS-DISK" ;; |
---|
944 | ca|CA00) TYPE="CACHE" ;; |
---|
945 | da) TYPE="DATA" ;; |
---|
946 | ee) TYPE="GPT" ;; |
---|
947 | ef|EF00) TYPE="EFI" ;; |
---|
948 | EF01) TYPE="MBR" ;; |
---|
949 | EF02) TYPE="BIOS-BOOT" ;; |
---|
950 | fb) TYPE="VMFS" ;; |
---|
951 | fd|FD00) TYPE="LINUX-RAID" ;; |
---|
952 | *) TYPE="UNKNOWN" ;; |
---|
953 | esac |
---|
954 | echo "$TYPE" |
---|
955 | } |
---|
956 | |
---|
957 | |
---|
958 | #/** |
---|
959 | # ogHidePartition int_ndisk int_npartition |
---|
960 | #@brief Oculta un apartición visible. |
---|
961 | #@param int_ndisk nº de orden del disco |
---|
962 | #@param int_npartition nº de orden de la partición |
---|
963 | #@return (nada) |
---|
964 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
965 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
966 | #@exception OG_ERR_PARTITION tipo de partición no reconocido. |
---|
967 | #@version 1.0 - Versión en pruebas. |
---|
968 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
969 | #@date 2010/01/12 |
---|
970 | #*/ ## |
---|
971 | function ogHidePartition () |
---|
972 | { |
---|
973 | # Variables locales. |
---|
974 | local PART TYPE NEWTYPE |
---|
975 | # Si se solicita, mostrar ayuda. |
---|
976 | if [ "$*" == "help" ]; then |
---|
977 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
978 | "$FUNCNAME 1 1" |
---|
979 | return |
---|
980 | fi |
---|
981 | # Error si no se reciben 2 parámetros. |
---|
982 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
983 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
984 | |
---|
985 | # Obtener tipo de partición. |
---|
986 | TYPE=$(ogGetPartitionType "$1" "$2") |
---|
987 | case "$TYPE" in |
---|
988 | NTFS) NEWTYPE="HNTFS" ;; |
---|
989 | FAT32) NEWTYPE="HFAT32" ;; |
---|
990 | FAT16) NEWTYPE="HFAT16" ;; |
---|
991 | FAT12) NEWTYPE="HFAT12" ;; |
---|
992 | *) ogRaiseError $OG_ERR_PARTITION "$TYPE" |
---|
993 | return $? ;; |
---|
994 | esac |
---|
995 | # Cambiar tipo de partición. |
---|
996 | ogSetPartitionId $1 $2 $NEWTYPE |
---|
997 | } |
---|
998 | |
---|
999 | |
---|
1000 | #/** |
---|
1001 | # ogListPartitions int_ndisk |
---|
1002 | #@brief Lista las particiones definidas en un disco. |
---|
1003 | #@param int_ndisk nº de orden del disco |
---|
1004 | #@return str_parttype:int_partsize ... |
---|
1005 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1006 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
1007 | #@note Requisitos: \c parted \c awk |
---|
1008 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
1009 | #@attention Las tuplas de valores están separadas por espacios. |
---|
1010 | #@version 0.9 - Primera versión para OpenGNSys |
---|
1011 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
1012 | #@date 2009/07/24 |
---|
1013 | #*/ ## |
---|
1014 | function ogListPartitions () |
---|
1015 | { |
---|
1016 | # Variables locales. |
---|
1017 | local DISK PART NPARTS TYPE SIZE |
---|
1018 | |
---|
1019 | # Si se solicita, mostrar ayuda. |
---|
1020 | if [ "$*" == "help" ]; then |
---|
1021 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
1022 | "$FUNCNAME 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
1023 | return |
---|
1024 | fi |
---|
1025 | # Error si no se recibe 1 parámetro. |
---|
1026 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $? |
---|
1027 | |
---|
1028 | # Procesar la salida de \c parted . |
---|
1029 | DISK="$(ogDiskToDev $1)" || return $? |
---|
1030 | NPARTS=$(ogGetPartitionsNumber $1) |
---|
1031 | for (( PART = 1; PART <= NPARTS; PART++ )); do |
---|
1032 | TYPE=$(ogGetPartitionType $1 $PART 2>/dev/null) |
---|
1033 | if [ $? -eq 0 ]; then |
---|
1034 | SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null) |
---|
1035 | echo -n "$TYPE:$SIZE " |
---|
1036 | else |
---|
1037 | echo -n "EMPTY:0 " |
---|
1038 | fi |
---|
1039 | done |
---|
1040 | echo |
---|
1041 | } |
---|
1042 | |
---|
1043 | |
---|
1044 | #/** |
---|
1045 | # ogListPrimaryPartitions int_ndisk |
---|
1046 | #@brief Metafunción que lista las particiones primarias no vacías de un disco. |
---|
1047 | #@param int_ndisk nº de orden del disco |
---|
1048 | #@see ogListPartitions |
---|
1049 | #*/ ## |
---|
1050 | function ogListPrimaryPartitions () |
---|
1051 | { |
---|
1052 | # Variables locales. |
---|
1053 | local PTTYPE PARTS |
---|
1054 | |
---|
1055 | PTTYPE=$(ogGetPartitionTableType $1) || return $? |
---|
1056 | PARTS=$(ogListPartitions "$@") || return $? |
---|
1057 | case "$PTTYPE" in |
---|
1058 | GPT) echo $PARTS | sed 's/\( EMPTY:0\)*$//' ;; |
---|
1059 | MSDOS) echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//' ;; |
---|
1060 | esac |
---|
1061 | } |
---|
1062 | |
---|
1063 | |
---|
1064 | #/** |
---|
1065 | # ogListLogicalPartitions int_ndisk |
---|
1066 | #@brief Metafunción que lista las particiones lógicas de una tabla tipo MSDOS. |
---|
1067 | #@param int_ndisk nº de orden del disco |
---|
1068 | #@see ogListPartitions |
---|
1069 | #*/ ## |
---|
1070 | function ogListLogicalPartitions () |
---|
1071 | { |
---|
1072 | # Variables locales. |
---|
1073 | local PTTYPE PARTS |
---|
1074 | |
---|
1075 | PTTYPE=$(ogGetPartitionTableType $1) || return $? |
---|
1076 | [ "$PTTYPE" == "MSDOS" ] || ogRaiseError $OG_ERR_PARTITION "" || return $? |
---|
1077 | PARTS=$(ogListPartitions "$@") || return $? |
---|
1078 | echo $PARTS | cut -sf5- -d" " |
---|
1079 | } |
---|
1080 | |
---|
1081 | |
---|
1082 | #/** |
---|
1083 | # ogSetPartitionActive int_ndisk int_npartition |
---|
1084 | #@brief Establece cual es la partición activa de un disco. |
---|
1085 | #@param int_ndisk nº de orden del disco |
---|
1086 | #@param int_npartition nº de orden de la partición |
---|
1087 | #@return (nada). |
---|
1088 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
1089 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
1090 | #@note Requisitos: parted |
---|
1091 | #@version 0.1 - Integracion para Opengnsys - EAC: SetPartitionActive() en ATA.lib |
---|
1092 | #@author Antonio J. Doblas Viso, Universidad de Malaga |
---|
1093 | #@date 2008/10/27 |
---|
1094 | #@version 0.9 - Primera version compatible con OpenGNSys. |
---|
1095 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
1096 | #@date 2009/09/17 |
---|
1097 | #*/ ## |
---|
1098 | function ogSetPartitionActive () |
---|
1099 | { |
---|
1100 | # Variables locales |
---|
1101 | local DISK PART |
---|
1102 | |
---|
1103 | # Si se solicita, mostrar ayuda. |
---|
1104 | if [ "$*" == "help" ]; then |
---|
1105 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
1106 | "$FUNCNAME 1 1" |
---|
1107 | return |
---|
1108 | fi |
---|
1109 | # Error si no se reciben 2 parámetros. |
---|
1110 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1111 | |
---|
1112 | # Comprobar que el disco existe y activar la partición indicada. |
---|
1113 | DISK="$(ogDiskToDev $1)" || return $? |
---|
1114 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
1115 | parted -s $DISK set $2 boot on 2>/dev/null |
---|
1116 | } |
---|
1117 | |
---|
1118 | |
---|
1119 | #/** |
---|
1120 | # ogSetPartitionSize int_ndisk int_npartition int_size |
---|
1121 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
1122 | #@param int_ndisk nº de orden del disco |
---|
1123 | #@param int_npartition nº de orden de la partición |
---|
1124 | #@param int_size tamaño de la partición (en KB) |
---|
1125 | #@return (nada) |
---|
1126 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1127 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
1128 | #@note Requisitos: sfdisk, awk |
---|
1129 | #@todo Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición. |
---|
1130 | #@version 0.9 - Primera versión para OpenGNSys |
---|
1131 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
1132 | #@date 2009/07/24 |
---|
1133 | #*/ ## |
---|
1134 | function ogSetPartitionSize () |
---|
1135 | { |
---|
1136 | # Variables locales. |
---|
1137 | local DISK PART SIZE |
---|
1138 | |
---|
1139 | # Si se solicita, mostrar ayuda. |
---|
1140 | if [ "$*" == "help" ]; then |
---|
1141 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition int_size" \ |
---|
1142 | "$FUNCNAME 1 1 10000000" |
---|
1143 | return |
---|
1144 | fi |
---|
1145 | # Error si no se reciben 3 parámetros. |
---|
1146 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1147 | |
---|
1148 | # Obtener el tamaño de la partición. |
---|
1149 | DISK="$(ogDiskToDev $1)" || return $? |
---|
1150 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
1151 | # Convertir tamaño en KB a sectores de 512 B. |
---|
1152 | SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1153 | # Redefinir el tamaño de la partición. |
---|
1154 | sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $? |
---|
1155 | partprobe $DISK 2>/dev/null |
---|
1156 | } |
---|
1157 | |
---|
1158 | #/** |
---|
1159 | # ogUnhidePartition int_ndisk int_npartition |
---|
1160 | #@brief Hace visible una partición oculta. |
---|
1161 | #@param int_ndisk nº de orden del disco |
---|
1162 | #@param int_npartition nº de orden de la partición |
---|
1163 | #@return (nada) |
---|
1164 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
1165 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
1166 | #@exception OG_ERR_PARTITION tipo de partición no reconocido. |
---|
1167 | #@version 1.0 - Versión en pruebas. |
---|
1168 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
1169 | #@date 2010/01/12 |
---|
1170 | #*/ ## |
---|
1171 | function ogUnhidePartition () |
---|
1172 | { |
---|
1173 | # Variables locales. |
---|
1174 | local PART TYPE NEWTYPE |
---|
1175 | # Si se solicita, mostrar ayuda. |
---|
1176 | if [ "$*" == "help" ]; then |
---|
1177 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
1178 | "$FUNCNAME 1 1" |
---|
1179 | return |
---|
1180 | fi |
---|
1181 | # Error si no se reciben 2 parámetros. |
---|
1182 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1183 | PART=$(ogDiskToDev "$1" "$2") || return $? |
---|
1184 | |
---|
1185 | # Obtener tipo de partición. |
---|
1186 | TYPE=$(ogGetPartitionType "$1" "$2") |
---|
1187 | case "$TYPE" in |
---|
1188 | HNTFS) NEWTYPE="NTFS" ;; |
---|
1189 | HFAT32) NEWTYPE="FAT32" ;; |
---|
1190 | HFAT16) NEWTYPE="FAT16" ;; |
---|
1191 | HFAT12) NEWTYPE="FAT12" ;; |
---|
1192 | *) ogRaiseError $OG_ERR_PARTITION "$TYPE" |
---|
1193 | return $? ;; |
---|
1194 | esac |
---|
1195 | # Cambiar tipo de partición. |
---|
1196 | ogSetPartitionId $1 $2 $NEWTYPE |
---|
1197 | } |
---|
1198 | |
---|
1199 | |
---|
1200 | #/** |
---|
1201 | # ogUpdatePartitionTable |
---|
1202 | #@brief Fuerza al kernel releer la tabla de particiones de los discos duros |
---|
1203 | #@param no requiere |
---|
1204 | #@return informacion propia de la herramienta |
---|
1205 | #@note Requisitos: \c partprobe |
---|
1206 | #@warning pendiente estructurar la funcion a opengnsys |
---|
1207 | #@version 0.1 - Integracion para Opengnsys - EAC: UpdatePartitionTable() en ATA.lib |
---|
1208 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
1209 | #@date 27/10/2008 |
---|
1210 | #*/ ## |
---|
1211 | function ogUpdatePartitionTable () |
---|
1212 | { |
---|
1213 | local i |
---|
1214 | for i in `ogDiskToDev` |
---|
1215 | do |
---|
1216 | partprobe $i |
---|
1217 | done |
---|
1218 | } |
---|
1219 | |
---|
1220 | |
---|
1221 | #/** @function ogDiskToRelativeDev: @brief Traduce los ID de discos o particiones EAC a ID Linux relativos, es decir 1 1 => sda1 |
---|
1222 | #@param Admite 1 parametro: $1 int_numdisk |
---|
1223 | #@param Admite 2 parametro: $1 int_numdisk $2 int_partition |
---|
1224 | #@return Para 1 parametros traduce Discos Duros: Devuelve la ruta relativa linux del disco duro indicado con nomenclatura EAC.........ejemplo: IdPartition 1 => sda |
---|
1225 | #@return Para 2 parametros traduce Particiones: Devuelve la ruta relativa linux de la particion indicado con nomenclatura EAC........... ejemplo: IdPartition 2 1 => sdb1 |
---|
1226 | #@warning No definidas |
---|
1227 | #@attention |
---|
1228 | #@note Notas sin especificar |
---|
1229 | #@version 0.1 - Integracion para Opengnsys - EAC: IdPartition en ATA.lib |
---|
1230 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
1231 | #@date 27/10/2008 |
---|
1232 | #*/ |
---|
1233 | function ogDiskToRelativeDev () { |
---|
1234 | if [ $# = 0 ] |
---|
1235 | then |
---|
1236 | Msg "Info: Traduce el identificador del dispositivo EAC a dispositivo linux \n" info |
---|
1237 | Msg "Sintaxis1: IdPartition int_disk -----------------Ejemplo1: IdPartition 1 -> sda " example |
---|
1238 | Msg "Sintaxis2: IdPartition int_disk int_partition --Ejemplo2: IdPartition 1 2 -> sda2 " example |
---|
1239 | |
---|
1240 | return |
---|
1241 | fi |
---|
1242 | #PART="$(Disk|cut -f$1 -d' ')$2" # se comenta esta linea porque doxygen no reconoce la funcion disk y no crea los enlaces y referencias correctas. |
---|
1243 | PART=$(ogDiskToDev|cut -f$1 -d' ')$2 |
---|
1244 | echo $PART | cut -f3 -d \/ |
---|
1245 | } |
---|
1246 | |
---|
1247 | |
---|
1248 | #/** @function ogSetPartitionId: @brief Cambia el identificador de la particion, pero no su sistema de archivos. |
---|
1249 | #@param $1 int_numdiskEAC |
---|
1250 | #@param $2 int_numpartitionEAC |
---|
1251 | #@param $3 str_tipoPartition admite EXT2 EXT3 NTFS FAT32 SWAP CACHE |
---|
1252 | #@return la propia del fdisk |
---|
1253 | #@warning no controla los parametros, si se introducen mal o simplemente no se introducen no muestra mensaje |
---|
1254 | #@warning Identifica por nombre del sistema de archivos no por número |
---|
1255 | #@attention Requisitos: fdisk |
---|
1256 | #@note |
---|
1257 | #@version 0.1 - Integracion para Opengnsys - SetPartitionType() en ATA.lib |
---|
1258 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
1259 | #@date 27/10/2008 |
---|
1260 | #*/ |
---|
1261 | function ogSetPartitionId() { |
---|
1262 | # Variables locales |
---|
1263 | local DISK PART ID |
---|
1264 | |
---|
1265 | # Si se solicita, mostrar ayuda. |
---|
1266 | if [ "$*" == "help" ]; then |
---|
1267 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition str_type" \ |
---|
1268 | "$FUNCNAME 1 1 NTFS" |
---|
1269 | return |
---|
1270 | fi |
---|
1271 | # Error si no se reciben 3 parámetros. |
---|
1272 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
1273 | |
---|
1274 | # Sustituye nº de disco por su dispositivo. |
---|
1275 | DISK=`ogDiskToDev $1` || return $? |
---|
1276 | PART=`ogDiskToDev $1 $2` || return $? |
---|
1277 | |
---|
1278 | # Elección del tipo de partición. |
---|
1279 | ID=$(ogFsToId "$3") |
---|
1280 | [ -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$3" || return $? |
---|
1281 | |
---|
1282 | echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK 1>/dev/null 2>&1 |
---|
1283 | } |
---|
1284 | |
---|
1285 | |
---|
1286 | #/** @function ogDeletePartitionsLabels: @brief Elimina la informacion que tiene el kernel del cliente og sobre los labels de los sistemas de archivos |
---|
1287 | #@param No requiere |
---|
1288 | #@return Nada |
---|
1289 | #@warning |
---|
1290 | #@attention Requisitos: comando interno linux rm |
---|
1291 | #@note |
---|
1292 | #@version 0.1 - Integracion para Opengnsys - EAC: DeletePartitionTable() en ATA.lib |
---|
1293 | #@author Antonio J. Doblas Viso. Universidad de Malaga |
---|
1294 | #@date 27/10/2008 |
---|
1295 | #*/ |
---|
1296 | function ogDeletePartitionsLabels () { |
---|
1297 | # Si se solicita, mostrar ayuda. |
---|
1298 | if [ "$*" == "help" ]; then |
---|
1299 | ogHelp "$FUNCNAME" "$FUNCNAME " \ |
---|
1300 | "$FUNCNAME " |
---|
1301 | return |
---|
1302 | fi |
---|
1303 | |
---|
1304 | rm /dev/disk/by-label/* # */ COMENTARIO OBLIGATORIO PARA DOXYGEN |
---|
1305 | } |
---|
1306 | |
---|