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