[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. |
---|
[9f29ba6] | 7 | #@version 0.9 |
---|
| 8 | #@warning License: GNU GPLv3+ |
---|
| 9 | #*/ |
---|
| 10 | |
---|
[5dbb046] | 11 | |
---|
| 12 | #/** |
---|
[4b45aff] | 13 | # ogCreateCache int_partsize |
---|
| 14 | #@brief Define la caché local en la partición 4 del disco 1 |
---|
| 15 | #@param int_partsize tamaño de la partición (en KB) |
---|
| 16 | #@return (nada, por determinar) |
---|
| 17 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 18 | #@note Requisitos: sfdisk, parted, awk, sed |
---|
[b9e1a8c] | 19 | #@version 0.91 - Definición de caché local. |
---|
[4b45aff] | 20 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 21 | #@date 2010/03/09 |
---|
| 22 | #*/ ## |
---|
| 23 | function ogCreateCache () |
---|
| 24 | { |
---|
| 25 | # Variables locales. |
---|
[b9e1a8c] | 26 | local DISK SECTORS CYLS START END SIZE ENDPART3 |
---|
| 27 | # Si se solicita, mostrar ayuda. |
---|
| 28 | if [ "$*" == "help" ]; then |
---|
| 29 | ogHelp "$FUNCNAME" "$FUNCNAME 10000000" |
---|
| 30 | return |
---|
| 31 | fi |
---|
[4b45aff] | 32 | # Error si no se recibe 1 parámetro. |
---|
[b9e1a8c] | 33 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[4b45aff] | 34 | |
---|
| 35 | DISK=$(ogDiskToDev 1) || return $? |
---|
| 36 | PART="${DISK}4" |
---|
| 37 | SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions) |
---|
| 38 | CYLS=$(sfdisk -g $DISK | cut -f2 -d" ") |
---|
| 39 | END=$[SECTORS/CYLS*CYLS-1] |
---|
| 40 | SIZE=$(echo $1|awk '{print $0*2}') # En sectores de 512 B. |
---|
| 41 | START=$[END-SIZE+1] |
---|
[b9e1a8c] | 42 | ENDPART3=$(sfdisk -uS -l $DISK | awk -v P="${DISK}3" '{if ($1==P) print $3}') |
---|
[4b45aff] | 43 | # Error si tamaño 0 o si mayor que la mitad del disco o si pisa la partición 3. |
---|
| 44 | if [ $SIZE -eq 0 -o $SIZE -ge $[END/2] -o $START -le $ENDPART3 ]; then |
---|
| 45 | ogRaiseError $OG_ERR_FORMAT "$1" || return $? |
---|
| 46 | fi |
---|
| 47 | |
---|
| 48 | # Crear plantilla de particionado, modificando partición 4 para caché local. |
---|
| 49 | tmpsfdisk=/tmp/sfdiskout$$ |
---|
| 50 | trap "rm -f $tmpsfdisk" 1 2 3 9 15 |
---|
| 51 | sfdisk -d $DISK | sed "s;$PART.*$;$PART : start=$START, size=$SIZE, Id=ca;" >$tmpsfdisk |
---|
| 52 | |
---|
| 53 | # Desmontar todos los sistemas de archivos del disco. |
---|
| 54 | ogUnmountAll 1 2>/dev/null |
---|
| 55 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
| 56 | [ $(parted -s $DISK print >/dev/null) ] || fdisk $DISK <<< "w" |
---|
| 57 | # Definir particiones y notificar al kernel. |
---|
| 58 | sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && sfdisk -R $DISK |
---|
| 59 | rm -f $tmpsfdisk |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | #/** |
---|
[42669ebf] | 64 | # ogCreatePartitions int_ndisk str_parttype:int_partsize ... |
---|
[b094c59] | 65 | #@brief Define el conjunto de particiones de un disco. |
---|
[42669ebf] | 66 | #@param int_ndisk nº de orden del disco |
---|
| 67 | #@param str_parttype mnemónico del tipo de partición |
---|
| 68 | #@param int_partsize tamaño de la partición (en KB) |
---|
[73c8417] | 69 | #@return (nada, por determinar) |
---|
| 70 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 71 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 72 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
| 73 | #@attention Pueden definirse particiones vacías de tipo \c EMPTY |
---|
| 74 | #@note Requisitos: sfdisk, parted, partprobe, awk |
---|
| 75 | #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. |
---|
| 76 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 77 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 78 | #@date 2009/09/09 |
---|
[4b45aff] | 79 | #@version 0.91 - Corrección del redondeo del tamaño del disco. |
---|
| 80 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 81 | #@date 2010/03/09 |
---|
[1e7eaab] | 82 | #*/ ## |
---|
[42669ebf] | 83 | function ogCreatePartitions () |
---|
| 84 | { |
---|
[73c8417] | 85 | # Variables locales. |
---|
[4b45aff] | 86 | local DISK PART SECTORS CYLS START SIZE TYPE EXTSTART EXTSIZE tmpsfdisk |
---|
[1e7eaab] | 87 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 88 | if [ "$*" == "help" ]; then |
---|
[73c8417] | 89 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk str_parttype:int_partsize ..." \ |
---|
| 90 | "$FUNCNAME 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
| 91 | return |
---|
| 92 | fi |
---|
[1e7eaab] | 93 | # Error si no se reciben menos de 2 parámetros. |
---|
[55ad138c] | 94 | [ $# -ge 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[73c8417] | 95 | |
---|
| 96 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[1a7130a] | 97 | shift |
---|
[73c8417] | 98 | |
---|
[4b45aff] | 99 | # Nº total de sectores, para evitar desbordamiento (evitar redondeo). |
---|
[73c8417] | 100 | SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions) |
---|
[4b45aff] | 101 | CYLS=$(sfdisk -g $DISK | cut -f2 -d" ") |
---|
| 102 | SECTORS=$[SECTORS/CYLS*CYLS-1] |
---|
[73c8417] | 103 | # Sector de inicio de la particon (la 1ª empieza en el sector 63). |
---|
| 104 | START=63 |
---|
| 105 | PART=1 |
---|
| 106 | |
---|
[b094c59] | 107 | # Fichero temporal de entrada para "sfdisk" |
---|
[73c8417] | 108 | tmpsfdisk=/tmp/sfdisk$$ |
---|
| 109 | trap "rm -f $tmpsfdisk" 1 2 3 9 15 |
---|
| 110 | |
---|
| 111 | echo "unit: sectors" >$tmpsfdisk |
---|
| 112 | echo >>$tmpsfdisk |
---|
| 113 | |
---|
[42669ebf] | 114 | # Generar fichero de entrada para "sfdisk" con las particiones. |
---|
[73c8417] | 115 | while [ $# -gt 0 ]; do |
---|
[42669ebf] | 116 | # Leer formato de cada parámetro - Tipo:Tamaño |
---|
[73c8417] | 117 | TYPE="${1%%:*}" |
---|
| 118 | SIZE="${1#*:}" |
---|
| 119 | [ -z "$SIZE" ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[42669ebf] | 120 | # Convertir en sectores de 512 B. |
---|
[73c8417] | 121 | SIZE=$[SIZE*2] |
---|
| 122 | [ $SIZE -eq 0 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
[42669ebf] | 123 | # Obtener identificador de tipo de partición. |
---|
| 124 | ID=$(ogFsToId "$TYPE") |
---|
| 125 | [ -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
| 126 | # Comprobar si la partición es extendida. |
---|
| 127 | if [ $ID = 5 ]; then |
---|
| 128 | [ $PART -gt 4 ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 129 | EXTSTART=$START |
---|
| 130 | EXTSIZE=$SIZE |
---|
| 131 | fi |
---|
[1e7eaab] | 132 | # Incluir particiones lógicas dentro de la partición extendida. |
---|
[73c8417] | 133 | if [ $PART = 5 ]; then |
---|
| 134 | [ -z "$EXTSTART" ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 135 | START=$EXTSTART |
---|
| 136 | SECTORS=$[EXTSTART+EXTSIZE] |
---|
| 137 | fi |
---|
[1e7eaab] | 138 | # Generar datos para la partición. |
---|
[73c8417] | 139 | echo "$DISK$PART : start=$START, size=$SIZE, Id=$ID" >>$tmpsfdisk |
---|
[42669ebf] | 140 | # Error si se supera el nº total de sectores. |
---|
[73c8417] | 141 | START=$[START+SIZE] |
---|
| 142 | [ $START -gt $SECTORS ] && ogRaiseError $OG_ERR_FORMAT && return $? |
---|
| 143 | PART=$[PART+1] |
---|
| 144 | shift |
---|
| 145 | done |
---|
[b094c59] | 146 | # Si no se indican las 4 particiones primarias, definirlas como vacías. |
---|
[73c8417] | 147 | while [ $PART -le 4 ]; do |
---|
| 148 | echo "$DISK$PART : start=0, size=0, Id=0" >>$tmpsfdisk |
---|
| 149 | PART=$[PART+1] |
---|
| 150 | done |
---|
[b094c59] | 151 | # Si se define partición extendida sin lógicas, crear particion 5 vacía. |
---|
[73c8417] | 152 | if [ $PART = 5 -a -n "$EXTSTART" ]; then |
---|
| 153 | echo "${DISK}5 : start=$EXTSTART, size=$EXTSIZE, Id=0" >>$tmpsfdisk |
---|
| 154 | fi |
---|
| 155 | |
---|
[4b45aff] | 156 | # Desmontar todos los sistemas de archivos del disco. |
---|
| 157 | ogUnmountAll $1 |
---|
[73c8417] | 158 | # Si la tabla de particiones no es valida, volver a generarla. |
---|
| 159 | [ $(parted -s $DISK print >/dev/null) ] || fdisk $DISK <<< "w" |
---|
[1e7eaab] | 160 | # Definir particiones y notificar al kernel. |
---|
[3458879] | 161 | sfdisk -f $DISK < $tmpsfdisk 2>/dev/null && sfdisk -R $DISK |
---|
[73c8417] | 162 | rm -f $tmpsfdisk |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | #/** |
---|
[42669ebf] | 167 | # ogDevToDisk path_device |
---|
[5dbb046] | 168 | #@brief Devuelve el nº de orden de dicso (y partición) correspondiente al nombre de fichero de dispositivo. |
---|
[42669ebf] | 169 | #@param path_device Camino del fichero de dispositivo. |
---|
| 170 | #@return int_ndisk (para dispositivo de disco) |
---|
| 171 | #@return int_ndisk int_npartition (para dispositivo de partición). |
---|
[5dbb046] | 172 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 173 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
| 174 | #@note Requisitos: awk |
---|
| 175 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 176 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 177 | #@date 2009-07-20 |
---|
[1e7eaab] | 178 | #*/ ## |
---|
[42669ebf] | 179 | function ogDevToDisk () |
---|
| 180 | { |
---|
[73c8417] | 181 | # Variables locales. |
---|
[5dbb046] | 182 | local d n |
---|
[1e7eaab] | 183 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 184 | if [ "$*" == "help" ]; then |
---|
[5dbb046] | 185 | ogHelp "$FUNCNAME" "$FUNCNAME path_device" \ |
---|
| 186 | "$FUNCNAME /dev/sda => 1 1" |
---|
| 187 | return |
---|
| 188 | fi |
---|
| 189 | |
---|
[1e7eaab] | 190 | # Error si no se recibe 1 parámetro. |
---|
[5dbb046] | 191 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[42669ebf] | 192 | # Error si no es fichero de bloques. |
---|
[5dbb046] | 193 | [ -b "$1" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 194 | |
---|
[1e7eaab] | 195 | # Procesa todos los discos para devolver su nº de orden y de partición. |
---|
[5dbb046] | 196 | n=1 |
---|
| 197 | for d in $(ogDiskToDev); do |
---|
| 198 | [ -n "$(echo $1 | grep $d)" ] && echo "$n ${1#$d}" && return |
---|
| 199 | n=$[n+1] |
---|
| 200 | done |
---|
| 201 | ogRaiseError $OG_ERR_NOTFOUND "$1" |
---|
| 202 | return $OG_ERR_NOTFOUND |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
[9f29ba6] | 206 | #/** |
---|
[42669ebf] | 207 | # ogDiskToDev [int_ndisk [int_npartition]] |
---|
[9f57de01] | 208 | #@brief Devuelve la equivalencia entre el nº de orden del dispositivo (dicso o partición) y el nombre de fichero de dispositivo correspondiente. |
---|
[42669ebf] | 209 | #@param int_ndisk nº de orden del disco |
---|
| 210 | #@param int_npartition nº de orden de la partición |
---|
[9f57de01] | 211 | #@return Para 0 parametros: Devuelve los nombres de ficheros de los dispositivos sata/ata/usb linux encontrados. |
---|
| 212 | #@return Para 1 parametros: Devuelve la ruta del disco duro indicado. |
---|
| 213 | #@return Para 2 parametros: Devuelve la ruta de la particion indicada. |
---|
| 214 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 215 | #@exception OG_ERR_NOTFOUND Dispositivo no detectado. |
---|
[2717297] | 216 | #@note Requisitos: awk, lvm |
---|
[a5df9b9] | 217 | #@version 0.9 - Primera versión para OpenGNSys |
---|
[9f57de01] | 218 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 219 | #@date 2009-07-20 |
---|
[1e7eaab] | 220 | #*/ ## |
---|
[42669ebf] | 221 | function ogDiskToDev () |
---|
| 222 | { |
---|
[59f9ad2] | 223 | # Variables locales |
---|
[2717297] | 224 | local ALLDISKS VOLGROUPS DISK PART |
---|
[9f29ba6] | 225 | |
---|
[1e7eaab] | 226 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 227 | if [ "$*" == "help" ]; then |
---|
[aae34f6] | 228 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk [int_npartition]" \ |
---|
| 229 | "$FUNCNAME => /dev/sda /dev/sdb" \ |
---|
| 230 | "$FUNCNAME 1 => /dev/sda" \ |
---|
| 231 | "$FUNCNAME 1 1 => /dev/sda1" |
---|
| 232 | return |
---|
| 233 | fi |
---|
| 234 | |
---|
[1e7eaab] | 235 | # Listar dispositivo para los discos duros (tipos: 3=hd, 8=sd). |
---|
[a5df9b9] | 236 | ALLDISKS=$(awk '($1==3 || $1==8) && $4!~/[0-9]/ {printf "/dev/%s ",$4}' /proc/partitions) |
---|
[13ccdf5] | 237 | VOLGROUPS=$(vgs -a --noheadings 2>/dev/null | awk '{printf "/dev/%s ",$1}') |
---|
[2717297] | 238 | ALLDISKS="$ALLDISKS $VOLGROUPS" |
---|
[9f29ba6] | 239 | |
---|
[1e7eaab] | 240 | # Mostrar salidas segun el número de parametros. |
---|
[9f29ba6] | 241 | case $# in |
---|
[2717297] | 242 | 0) # Muestra todos los discos, separados por espacios. |
---|
| 243 | echo $ALLDISKS |
---|
| 244 | ;; |
---|
| 245 | 1) # Error si el parámetro no es un digito. |
---|
| 246 | [ -z "${1/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 247 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
| 248 | # Error si el fichero no existe. |
---|
| 249 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 250 | echo "$DISK" |
---|
| 251 | ;; |
---|
| 252 | 2) # Error si los 2 parámetros no son digitos. |
---|
| 253 | [ -z "${1/[1-9]/}" -a -z "${2/[1-9]/}" ] || ogRaiseError $OG_ERR_FORMAT|| return $? |
---|
| 254 | DISK=$(echo "$ALLDISKS" | awk -v n=$1 '{print $n}') |
---|
| 255 | [ -e "$DISK" ] || ogRaiseError $OG_ERR_NOTFOUND "$1" || return $? |
---|
| 256 | PART="$DISK$2" |
---|
[1e7eaab] | 257 | # Comprobar si es partición. |
---|
[2717297] | 258 | if [ -b "$PART" ]; then |
---|
| 259 | echo "$PART" |
---|
| 260 | elif [ -n "$VOLGROUPS" ]; then |
---|
[0bfbbe1] | 261 | # Comprobar si volumen lógico. /* (comentario Doxygen) |
---|
[2717297] | 262 | PART=$(lvscan -a 2>/dev/null | grep "'$DISK/" | awk -v n=$2 -F\' '{if (NR==n) print $2}') |
---|
| 263 | [ -e "$PART" ] || ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
[0bfbbe1] | 264 | # (comentario Doxygen) */ |
---|
[2717297] | 265 | echo "$PART" |
---|
| 266 | else |
---|
| 267 | ogRaiseError $OG_ERR_NOTFOUND "$1 $2" || return $? |
---|
| 268 | fi |
---|
| 269 | ;; |
---|
| 270 | *) # Formato erroneo. |
---|
| 271 | ogRaiseError $OG_ERR_FORMAT |
---|
[aae34f6] | 272 | return $OG_ERR_FORMAT |
---|
| 273 | ;; |
---|
[9f29ba6] | 274 | esac |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | #/** |
---|
[42669ebf] | 279 | # ogFsToId str_fstype |
---|
| 280 | #@brief Devuelve el identificador de partición correspondiente a un tipo de sistema de archivos. |
---|
| 281 | #@param str_fstype mnemónico de tipo de sistema de archivos |
---|
| 282 | #@return int_idpart nº identificador de tipo de partición. |
---|
| 283 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 284 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 285 | #@author Ramon Gomez, ETSII Universidad Sevilla |
---|
| 286 | #@date 2009-12-14 |
---|
| 287 | #*/ ## |
---|
| 288 | function ogFsToId () |
---|
| 289 | { |
---|
| 290 | # Variables locales |
---|
| 291 | local ID |
---|
| 292 | |
---|
| 293 | # Si se solicita, mostrar ayuda. |
---|
| 294 | if [ "$*" == "help" ]; then |
---|
| 295 | ogHelp "$FUNCNAME" "$FUNCNAME str_fstype" "$FUNCNAME EXT3 => 83" |
---|
| 296 | return |
---|
| 297 | fi |
---|
| 298 | # Error si no se recibe 1 parámetro. |
---|
| 299 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 300 | |
---|
| 301 | # Asociar id. de partición para su mnemónico de sistema de archivos. |
---|
| 302 | case "$1" in |
---|
| 303 | EMPTY) ID=0 ;; |
---|
| 304 | FAT12) ID=1 ;; |
---|
| 305 | EXTENDED) ID=5 ;; |
---|
| 306 | FAT16) ID=6 ;; |
---|
| 307 | NTFS|EXFAT) ID=7 ;; |
---|
| 308 | FAT32) ID=b ;; |
---|
| 309 | HFAT12) ID=11 ;; |
---|
| 310 | HFAT16) ID=16 ;; |
---|
| 311 | HNTFS) ID=17 ;; |
---|
| 312 | HFAT32) ID=1b ;; |
---|
| 313 | LINUX-SWAP) ID=82 ;; |
---|
| 314 | EXT[234]|REISERFS|REISER4|XFS|JFS) |
---|
| 315 | ID=83 ;; |
---|
| 316 | LINUX-LVM) ID=8e ;; |
---|
| 317 | SOLARIS) ID=bf ;; |
---|
| 318 | CACHE) ID=ca ;; |
---|
| 319 | LINUX-RAID) ID=fd ;; |
---|
| 320 | *) ID="" ;; |
---|
| 321 | esac |
---|
| 322 | echo $ID |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | #/** |
---|
[b9e1a8c] | 327 | # ogGetCacheSize |
---|
| 328 | #@brief Devuelve el tamaño definido para la partición de caché. |
---|
| 329 | #@return int_partsize tamaño de la partición (en KB) |
---|
| 330 | #@exception OG_ERR_PARTITION No existe partición de caché. |
---|
| 331 | #@version 0.91 - Definición de caché local. |
---|
| 332 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 333 | #@date 2010/03/09 |
---|
| 334 | #*/ ## |
---|
| 335 | function ogGetCacheSize () |
---|
| 336 | { |
---|
| 337 | # Variables locales |
---|
| 338 | local PART |
---|
| 339 | |
---|
| 340 | # Si se solicita, mostrar ayuda. |
---|
| 341 | if [ "$*" == "help" ]; then |
---|
| 342 | ogHelp "$FUNCNAME" "$FUNCNAME => 10000000" |
---|
| 343 | return |
---|
| 344 | fi |
---|
| 345 | # Error si no se encuentra partición de caché. |
---|
| 346 | PART=$(ogDevToDisk $(ogFindCache) 2>/dev/null) || ogRaiseError $OG_ERR_PARTITION "CACHE" || return $OG_ERR_PARTITION |
---|
| 347 | |
---|
| 348 | # Devuelve tamaño de la partición de caché. |
---|
| 349 | ogGetPartitionSize $PART |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | |
---|
| 353 | #/** |
---|
| 354 | # ogGetCacheSpace |
---|
| 355 | #@brief Devuelve el espacio de disco disponible para la partición de caché. |
---|
| 356 | #@return int_size tamaño disponible (en KB) |
---|
| 357 | #@note El espacio disponible es el que hay entre el límite superior de la partición 3 del disco 1 y el final de dicho disco, y no puede ser superior a la mitad de dicho disco. |
---|
| 358 | #@version 0.91 - Definición de caché local. |
---|
| 359 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 360 | #@date 2010/03/09 |
---|
| 361 | #*/ ## |
---|
| 362 | function ogGetCacheSpace () |
---|
| 363 | { |
---|
| 364 | |
---|
| 365 | # Variables locales. |
---|
| 366 | local DISK SECTORS CYLS ENDPART3 |
---|
| 367 | # Si se solicita, mostrar ayuda. |
---|
| 368 | if [ "$*" == "help" ]; then |
---|
| 369 | ogHelp "$FUNCNAME" "$FUNCNAME => 23165386" |
---|
| 370 | return |
---|
| 371 | fi |
---|
| 372 | |
---|
| 373 | DISK=$(ogDiskToDev 1) || return $? |
---|
| 374 | SECTORS=$(awk -v D=${DISK#/dev/} '{if ($4==D) {print $3*2}}' /proc/partitions) |
---|
| 375 | CYLS=$(sfdisk -g $DISK | cut -f2 -d" ") |
---|
| 376 | SECTORS=$[SECTORS/CYLS*CYLS-1] |
---|
| 377 | ENDPART3=$(sfdisk -uS -l $DISK | awk -v P="${DISK}3" '{if ($1==P) print $3}') |
---|
| 378 | # Mostrar espacio libre en KB (1 KB = 2 sectores) |
---|
| 379 | if [ $ENDPART3 -gt $[SECTORS/2] ]; then |
---|
| 380 | echo $[(SECTORS-ENDPART3)/2] |
---|
| 381 | else |
---|
| 382 | echo $[SECTORS/4] |
---|
| 383 | fi |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | |
---|
[42669ebf] | 387 | # ogGetPartitionActive int_ndisk |
---|
[a5df9b9] | 388 | #@brief Muestra que particion de un disco esta marcada como de activa. |
---|
[b9e1a8c] | 389 | #@param int_ndisk nº de orden del disco |
---|
| 390 | #@return int_npart Nº de partición activa |
---|
[a5df9b9] | 391 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 392 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
| 393 | #@note Requisitos: parted |
---|
[59f9ad2] | 394 | #@todo Queda definir formato para atributos (arranque, oculta, ...). |
---|
[a5df9b9] | 395 | #@version 0.9 - Primera versión compatible con OpenGNSys. |
---|
| 396 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 397 | #@date 2009/07/24 |
---|
[1e7eaab] | 398 | #*/ ## |
---|
[42669ebf] | 399 | function ogGetPartitionActive () |
---|
| 400 | { |
---|
[59f9ad2] | 401 | # Variables locales |
---|
[a5df9b9] | 402 | local DISK |
---|
| 403 | |
---|
[1e7eaab] | 404 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 405 | if [ "$*" == "help" ]; then |
---|
| 406 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" "$FUNCNAME 1 => 1" |
---|
| 407 | return |
---|
| 408 | fi |
---|
[1e7eaab] | 409 | # Error si no se recibe 1 parámetro. |
---|
[aae34f6] | 410 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 411 | |
---|
[1e7eaab] | 412 | # Comprobar que el disco existe y listar su partición activa. |
---|
[a5df9b9] | 413 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 414 | parted $DISK print 2>/dev/null | awk '/boot/ {print $1}' |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | #/** |
---|
[42669ebf] | 419 | # ogGetPartitionId int_ndisk int_npartition |
---|
[9f57de01] | 420 | #@brief Devuelve el mnemonico con el tipo de sistema de archivos. |
---|
[42669ebf] | 421 | #@param int_ndisk nº de orden del disco |
---|
| 422 | #@param int_npartition nº de orden de la partición |
---|
[9f57de01] | 423 | #@return Identificador de tipo de partición. |
---|
[326cec3] | 424 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
[9f57de01] | 425 | #@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo. |
---|
[a5df9b9] | 426 | #@note Requisitos: sfdisk |
---|
[9f57de01] | 427 | #@version 0.9 - Primera versión compatible con OpenGNSys. |
---|
| 428 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 429 | #@date 25/03/2009 |
---|
[1e7eaab] | 430 | #*/ ## |
---|
[42669ebf] | 431 | function ogGetPartitionId () |
---|
| 432 | { |
---|
[59f9ad2] | 433 | # Variables locales. |
---|
[a5df9b9] | 434 | local DISK PART |
---|
[2e15649] | 435 | |
---|
[1e7eaab] | 436 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 437 | if [ "$*" == "help" ]; then |
---|
| 438 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 439 | "$FUNCNAME 1 1 => 7" |
---|
| 440 | return |
---|
| 441 | fi |
---|
[1e7eaab] | 442 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 443 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[2e15649] | 444 | |
---|
[1e7eaab] | 445 | # Detectar id. de tipo de particion y codificar al mnemonico. |
---|
[2e15649] | 446 | DISK=$(ogDiskToDev $1) || return $? |
---|
| 447 | PART=$(ogDiskToDev $1 $2) || return $? |
---|
| 448 | echo $(sfdisk --id $DISK $2 2>/dev/null) |
---|
[9f29ba6] | 449 | } |
---|
| 450 | |
---|
[a5df9b9] | 451 | |
---|
| 452 | #/** |
---|
[42669ebf] | 453 | # ogGetPartitionSize int_ndisk int_npartition |
---|
[a5df9b9] | 454 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[42669ebf] | 455 | #@param int_ndisk nº de orden del disco |
---|
| 456 | #@param int_npartition nº de orden de la partición |
---|
| 457 | #@return int_partsize - Tamaño en KB de la partición. |
---|
[a5df9b9] | 458 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 459 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 460 | #@note Requisitos: sfdisk, awk |
---|
| 461 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 462 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 463 | #@date 2009/07/24 |
---|
[1e7eaab] | 464 | #*/ ## |
---|
[42669ebf] | 465 | function ogGetPartitionSize () |
---|
| 466 | { |
---|
[59f9ad2] | 467 | # Variables locales. |
---|
| 468 | local PART |
---|
[a5df9b9] | 469 | |
---|
[1e7eaab] | 470 | # Si se solicita, mostrar ayuda. |
---|
[aae34f6] | 471 | if [ "$*" == "help" ]; then |
---|
| 472 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 473 | "$FUNCNAME 1 1 => 10000000" |
---|
| 474 | return |
---|
| 475 | fi |
---|
[1e7eaab] | 476 | # Error si no se reciben 2 parámetros. |
---|
[aae34f6] | 477 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[a5df9b9] | 478 | |
---|
[1e7eaab] | 479 | # Obtener el tamaño de la partición. |
---|
[3543b3e] | 480 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[a5df9b9] | 481 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
[3543b3e] | 482 | case "$(ogGetPartitionId $1 $2)" in |
---|
| 483 | 5|f) # Procesar detección de tamaño de partición Extendida. |
---|
[55ad138c] | 484 | sfdisk -l $DISK 2>/dev/null | \ |
---|
[3543b3e] | 485 | awk -v p=$PART '{if ($1==p) {sub (/\*/,""); print $5} }' |
---|
| 486 | ;; |
---|
| 487 | *) sfdisk -s $PART |
---|
| 488 | ;; |
---|
| 489 | esac |
---|
[a5df9b9] | 490 | } |
---|
| 491 | |
---|
| 492 | |
---|
[b094c59] | 493 | #/** |
---|
[73c8417] | 494 | # ogListPartitions int_ndisk |
---|
[a5df9b9] | 495 | #@brief Lista las particiones definidas en un disco. |
---|
[42669ebf] | 496 | #@param int_ndisk nº de orden del disco |
---|
| 497 | #@return str_parttype:int_partsize ... |
---|
[a5df9b9] | 498 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 499 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 500 | #@note Requisitos: \c parted \c awk |
---|
[73c8417] | 501 | #@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize |
---|
[59f9ad2] | 502 | #@attention Las tuplas de valores están separadas por espacios. |
---|
[a5df9b9] | 503 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 504 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 505 | #@date 2009/07/24 |
---|
[1e7eaab] | 506 | #*/ ## |
---|
[42669ebf] | 507 | function ogListPartitions () |
---|
| 508 | { |
---|
[59f9ad2] | 509 | # Variables locales. |
---|
[55ad138c] | 510 | local DISK PART NPARTS TYPE SIZE |
---|
[aae34f6] | 511 | |
---|
[42669ebf] | 512 | # Si se solicita, mostrar ayuda. |
---|
[1a7130a] | 513 | if [ "$*" == "help" ]; then |
---|
[aae34f6] | 514 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk" \ |
---|
[73c8417] | 515 | "$FUNCNAME 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000" |
---|
[aae34f6] | 516 | return |
---|
| 517 | fi |
---|
[42669ebf] | 518 | # Error si no se recibe 1 parámetro. |
---|
[5dbb046] | 519 | [ $# == 1 ] || ogRaiseError $OG_ERR_FORMAT "$FORMAT" || return $? |
---|
[a5df9b9] | 520 | |
---|
[42669ebf] | 521 | # Procesar la salida de \c parted . |
---|
[b094c59] | 522 | DISK="$(ogDiskToDev $1)" || return $? |
---|
[3543b3e] | 523 | NPARTS=$(ogGetPartitionsNumber $1) |
---|
| 524 | for (( PART = 1; PART <= NPARTS; PART++ )); do |
---|
[55ad138c] | 525 | TYPE=$(ogGetFsType $1 $PART 2>/dev/null) |
---|
[3543b3e] | 526 | if [ $? -eq 0 ]; then |
---|
[55ad138c] | 527 | SIZE=$(ogGetPartitionSize $1 $PART 2>/dev/null) |
---|
| 528 | echo -n "$TYPE:$SIZE " |
---|
[3543b3e] | 529 | else |
---|
| 530 | echo -n "EMPTY:0 " |
---|
| 531 | fi |
---|
[a5df9b9] | 532 | done |
---|
| 533 | echo |
---|
| 534 | } |
---|
| 535 | |
---|
[326cec3] | 536 | |
---|
| 537 | #/** |
---|
[55ad138c] | 538 | # ogListPrimaryPartitions int_ndisk |
---|
| 539 | #@brief Metafunción que lista las particiones primarias no vacías definidas en un disco. |
---|
[42669ebf] | 540 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 541 | #@see ogListPartitions |
---|
[1e7eaab] | 542 | #*/ ## |
---|
[42669ebf] | 543 | function ogListPrimaryPartitions () |
---|
| 544 | { |
---|
[55ad138c] | 545 | # Variables locales. |
---|
| 546 | local PARTS |
---|
| 547 | |
---|
| 548 | PARTS=$(ogListPartitions "$@") || return $? |
---|
| 549 | echo $PARTS | cut -sf1-4 -d" " | sed 's/\( EMPTY:0\)*$//' |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | |
---|
| 553 | #/** |
---|
| 554 | # ogListLogicalPartitions int_ndisk |
---|
| 555 | #@brief Metafunción que lista las particiones lógicas definidas en un disco. |
---|
[42669ebf] | 556 | #@param int_ndisk nº de orden del disco |
---|
[55ad138c] | 557 | #@see ogListPartitions |
---|
[1e7eaab] | 558 | #*/ ## |
---|
[b061ad0] | 559 | function ogListLogicalPartitions () |
---|
| 560 | { |
---|
[55ad138c] | 561 | # Variables locales. |
---|
| 562 | local PARTS |
---|
| 563 | |
---|
| 564 | PARTS=$(ogListPartitions "$@") || return $? |
---|
| 565 | echo $PARTS | cut -sf5- -d" " |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | |
---|
| 569 | #/** |
---|
[42669ebf] | 570 | # ogSetPartitionActive int_ndisk int_npartition |
---|
[89403cd] | 571 | #@brief Establece cual es la partición activa de un disco. |
---|
[42669ebf] | 572 | #@param int_ndisk nº de orden del disco |
---|
| 573 | #@param int_npartition nº de orden de la partición |
---|
| 574 | #@return (nada). |
---|
[326cec3] | 575 | #@exception OG_ERR_FORMAT Formato incorrecto. |
---|
| 576 | #@exception OG_ERR_NOTFOUND Disco o partición no corresponden con un dispositivo. |
---|
| 577 | #@note Requisitos: parted |
---|
| 578 | #@version 0.9 - Primera versión compatible con OpenGNSys. |
---|
| 579 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 580 | #@date 2009/09/17 |
---|
[1e7eaab] | 581 | #*/ ## |
---|
[42669ebf] | 582 | function ogSetPartitionActive () |
---|
| 583 | { |
---|
[326cec3] | 584 | # Variables locales |
---|
| 585 | local DISK PART |
---|
| 586 | |
---|
[1e7eaab] | 587 | # Si se solicita, mostrar ayuda. |
---|
[326cec3] | 588 | if [ "$*" == "help" ]; then |
---|
| 589 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 590 | "$FUNCNAME 1 1" |
---|
| 591 | return |
---|
| 592 | fi |
---|
[1e7eaab] | 593 | # Error si no se reciben 2 parámetros. |
---|
[326cec3] | 594 | [ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 595 | |
---|
[1e7eaab] | 596 | # Comprobar que el disco existe y activar la partición indicada. |
---|
[326cec3] | 597 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 598 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 599 | parted -s $DISK set $2 boot on 2>/dev/null |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | |
---|
[1553fc7] | 603 | #/** |
---|
[42669ebf] | 604 | # ogSetPartitionSize int_ndisk int_npartition int_size |
---|
[2ecd096] | 605 | #@brief Muestra el tamano en KB de una particion determinada. |
---|
[42669ebf] | 606 | #@param int_ndisk nº de orden del disco |
---|
| 607 | #@param int_npartition nº de orden de la partición |
---|
| 608 | #@param int_size tamaño de la partición (en KB) |
---|
[2ecd096] | 609 | #@return (nada) |
---|
| 610 | #@exception OG_ERR_FORMAT formato incorrecto. |
---|
| 611 | #@exception OG_ERR_NOTFOUND disco o particion no detectado (no es un dispositivo). |
---|
| 612 | #@note Requisitos: sfdisk, awk |
---|
| 613 | #@todo Compruebar que el tamaño sea numérico positivo y evitar que pueda solaparse con la siguiente partición. |
---|
| 614 | #@version 0.9 - Primera versión para OpenGNSys |
---|
| 615 | #@author Ramon Gomez, ETSII Universidad de Sevilla |
---|
| 616 | #@date 2009/07/24 |
---|
[1e7eaab] | 617 | #*/ ## |
---|
[42669ebf] | 618 | function ogSetPartitionSize () |
---|
| 619 | { |
---|
[2ecd096] | 620 | # Variables locales. |
---|
| 621 | local DISK PART SIZE |
---|
| 622 | |
---|
[1e7eaab] | 623 | # Si se solicita, mostrar ayuda. |
---|
[2ecd096] | 624 | if [ "$*" == "help" ]; then |
---|
| 625 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 626 | "$FUNCNAME 1 1 10000000" |
---|
| 627 | return |
---|
| 628 | fi |
---|
[1e7eaab] | 629 | # Error si no se reciben 3 parámetros. |
---|
[2ecd096] | 630 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 631 | |
---|
[1e7eaab] | 632 | # Obtener el tamaño de la partición. |
---|
[2ecd096] | 633 | DISK="$(ogDiskToDev $1)" || return $? |
---|
| 634 | PART="$(ogDiskToDev $1 $2)" || return $? |
---|
| 635 | # Convertir tamaño en KB a sectores de 512 B. |
---|
| 636 | SIZE=$[$3*2] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
[1e7eaab] | 637 | # Usar \c sfdisk para redefinir el tamaño. |
---|
[1c04494] | 638 | sfdisk -f -uS -N$2 $DISK <<< ",$SIZE" &>/dev/null || ogRaiseError $OG_ERR_PARTITION "$1,$2" || return $? |
---|
[2ecd096] | 639 | } |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | #/** |
---|
[6cdca0c] | 643 | # ogUpdatePartitionTable |
---|
[1553fc7] | 644 | #@brief Fuerza al kernel releer la tabla de particiones de los discos duros |
---|
[42669ebf] | 645 | #@param no requiere |
---|
[1553fc7] | 646 | #@return informacion propia de la herramienta |
---|
| 647 | #@note Requisitos: \c partprobe |
---|
| 648 | #@warning pendiente estructurar la funcion a opengnsys |
---|
| 649 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 650 | #@note funcion importada de EAC |
---|
| 651 | #*/ |
---|
| 652 | |
---|
[42669ebf] | 653 | function ogUpdatePartitionTable () |
---|
| 654 | { |
---|
[1553fc7] | 655 | echo "Forzando al kernel la lectura de la tabla de particiones" |
---|
| 656 | list=`partprobe -s | cut -f1 -d: ` 2>/dev/null |
---|
| 657 | echo $list > /tmp/disk |
---|
| 658 | } |
---|
[1a7130a] | 659 | |
---|
| 660 | |
---|
| 661 | |
---|
| 662 | |
---|
| 663 | function ogGetPartitionsNumber () { |
---|
[24f2399] | 664 | #/** @function ogGetPartitionsNumber: @brief detecta el numero de particiones del disco duro indicado. |
---|
[42669ebf] | 665 | #@param int_numdisk (indentificado EAC del disco) |
---|
[1a7130a] | 666 | #@return devuelve el numero paritiones del disco duro indicado |
---|
| 667 | #@warning Salidas de errores no determinada |
---|
| 668 | #@attention Requisitos: parted |
---|
| 669 | #@note Notas sin especificar |
---|
| 670 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 671 | #*/ |
---|
[55ad138c] | 672 | #local disco totalpart |
---|
| 673 | #disco=`ogDiskToDev $1` |
---|
| 674 | #totalpart=`parted $disco print | egrep ^" [0123456789] " -c` |
---|
| 675 | #echo $totalpart |
---|
| 676 | local DISK |
---|
| 677 | #/// Contar el nº de veces que aparece el disco en su lista de particiones. |
---|
| 678 | DISK=$(ogDiskToDev $1) 2>/dev/null |
---|
| 679 | sfdisk -l $DISK 2>/dev/null | grep -c "^$DISK" |
---|
[1a7130a] | 680 | } |
---|
[6cdca0c] | 681 | |
---|
| 682 | |
---|
| 683 | function ogDiskToRelativeDev () { |
---|
| 684 | #/** @function ogDiskToRelativeDev: @brief Traduce los ID de discos o particiones EAC a ID Linux relativos, es decir 1 1 => sda1 |
---|
| 685 | #@param Admite 1 parametro: $1 int_numdisk |
---|
| 686 | #@param Admite 2 parametro: $1 int_numdisk $2 int_partition |
---|
| 687 | #@return Para 1 parametros traduce Discos Duros: Devuelve la ruta relativa linux del disco duro indicado con nomenclatura EAC.........ejemplo: IdPartition 1 => sda |
---|
| 688 | #@return Para 2 parametros traduce Particiones: Devuelve la ruta relativa linux de la particion indicado con nomenclatura EAC........... ejemplo: IdPartition 2 1 => sdb1 |
---|
| 689 | #@warning No definidas |
---|
| 690 | #@attention |
---|
| 691 | #@note Notas sin especificar |
---|
| 692 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 693 | #*/ |
---|
| 694 | |
---|
| 695 | if [ $# = 0 ] |
---|
| 696 | then |
---|
| 697 | Msg "Info: Traduce el identificador del dispositivo EAC a dispositivo linux \n" info |
---|
| 698 | Msg "Sintaxis1: IdPartition int_disk -----------------Ejemplo1: IdPartition 1 -> sda " example |
---|
| 699 | Msg "Sintaxis2: IdPartition int_disk int_partition --Ejemplo2: IdPartition 1 2 -> sda2 " example |
---|
| 700 | |
---|
| 701 | return |
---|
| 702 | fi |
---|
| 703 | #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. |
---|
| 704 | PART=$(ogDiskToDev|cut -f$1 -d' ')$2 |
---|
| 705 | echo $PART | cut -f3 -d \/ |
---|
| 706 | } |
---|
[26c729b] | 707 | |
---|
| 708 | |
---|
| 709 | function ogDeletePartitionTable () { |
---|
| 710 | #/** @function ogDeletePartitionTable: @brief Borra la tabla de particiones del disco. |
---|
| 711 | #@param $1 opcion A (identificador LINUX) str_ID_linux (/dev/sda) |
---|
| 712 | #@param $1 opcion B (Identifiador EAC) int_numdiskEAC(1) |
---|
| 713 | #@return la informacion propia del fdisk |
---|
| 714 | #@warning no definidos |
---|
| 715 | #@attention |
---|
| 716 | #@note |
---|
| 717 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 718 | #*/ |
---|
| 719 | if [ $# = 0 ] |
---|
| 720 | then |
---|
| 721 | Msg "sintaxis1: ogDeletePartitionTable int_disk" red |
---|
| 722 | Msg "sintaxis2: ogDeletePartitionTable str_/dev/sdX" red |
---|
| 723 | return |
---|
| 724 | fi |
---|
| 725 | if [ -n "${1%/dev/*}" ] |
---|
| 726 | then |
---|
| 727 | dev=`DiskToDev $1` |
---|
| 728 | else |
---|
| 729 | dev=$1 |
---|
| 730 | fi |
---|
| 731 | echo -ne "o\nw" | fdisk $dev |
---|
| 732 | } |
---|
[0df4b9f7] | 733 | |
---|
| 734 | |
---|
| 735 | |
---|
| 736 | function ogSetPartitionId() { |
---|
| 737 | #/** @function ogSetPartitionId: @brief Cambia el identificador de la particion, pero no su sistema de archivos. |
---|
| 738 | #@param $1 int_numdiskEAC |
---|
| 739 | #@param $2 int_numpartitionEAC |
---|
| 740 | #@param $3 str_tipoPartition admite EXT2 EXT3 NTFS FAT32 SWAP CACHE |
---|
| 741 | #@return la propia del fdisk |
---|
| 742 | #@warning no controla los parametros, si se introducen mal o simplemente no se introducen no muestra mensaje |
---|
| 743 | #@warning Identifica por nombre del sistema de archivos no por número |
---|
| 744 | #@attention Requisitos: fdisk |
---|
| 745 | #@note |
---|
| 746 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 747 | #*/ |
---|
[be81649] | 748 | |
---|
| 749 | # Variables locales |
---|
| 750 | local DISK PART ID |
---|
| 751 | |
---|
[42669ebf] | 752 | # Si se solicita, mostrar ayuda. |
---|
[be81649] | 753 | if [ "$*" == "help" ]; then |
---|
| 754 | ogHelp "$FUNCNAME" "$FUNCNAME int_ndisk int_npartition" \ |
---|
| 755 | "$FUNCNAME 1 1 10000000" |
---|
| 756 | return |
---|
[0df4b9f7] | 757 | fi |
---|
[42669ebf] | 758 | # Error si no se reciben 3 parámetros. |
---|
[be81649] | 759 | [ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $? |
---|
| 760 | |
---|
[42669ebf] | 761 | # Sustituye nº de disco por su dispositivo. |
---|
[be81649] | 762 | DISK=`ogDiskToDev $1` || return $? |
---|
| 763 | PART=`ogDiskToDev $1 $2` || return $? |
---|
| 764 | |
---|
[42669ebf] | 765 | # Elección del tipo de partición. |
---|
| 766 | ID=$(ogFsToId "$3") |
---|
| 767 | [ -n "$ID" ] || ogRaiseError $OG_ERR_PARTITION "$TYPE" || return $? |
---|
| 768 | |
---|
[be81649] | 769 | echo -ne "t\n$2\n${ID}\nw\n" | fdisk $DISK 1>/dev/null 2>&1 |
---|
[0df4b9f7] | 770 | } |
---|
[cc6ad14] | 771 | |
---|
[be81649] | 772 | |
---|
[cc6ad14] | 773 | function ogDeletePartitionsLabels () { |
---|
[97da528] | 774 | #/** @function ogDeletePartitionsLabels: @brief Elimina la informacion que tiene el kernel del cliente og sobre los labels de los sistemas de archivos |
---|
[cc6ad14] | 775 | #@param No requiere |
---|
| 776 | #@return Nada |
---|
| 777 | #@warning |
---|
| 778 | #@attention Requisitos: comando interno linux rm |
---|
| 779 | #@note |
---|
| 780 | #@version 0.1 Date: 27/10/2008 Author Antonio J. Doblas Viso. Universidad de Malaga |
---|
| 781 | #*/ |
---|
| 782 | rm /dev/disk/by-label/* # */ COMENTARIO OBLIGATORIO PARA DOXYGEN |
---|
| 783 | } |
---|
| 784 | |
---|