[PC-BSD Commits] r6538 - in pcbsd/trunk/pc-sysinstall: backend backend-query

svn at pcbsd.org svn at pcbsd.org
Thu Apr 8 12:21:04 PDT 2010


Author: kris
Date: 2010-04-08 12:21:04 -0700 (Thu, 08 Apr 2010)
New Revision: 6538

Modified:
   pcbsd/trunk/pc-sysinstall/backend-query/disk-part.sh
   pcbsd/trunk/pc-sysinstall/backend/functions-disk.sh
   pcbsd/trunk/pc-sysinstall/backend/functions.sh
Log:

Updated query backend, now we can get full listings of gpt partitions as well, with more
detail and reliability



Modified: pcbsd/trunk/pc-sysinstall/backend/functions-disk.sh
===================================================================
--- pcbsd/trunk/pc-sysinstall/backend/functions-disk.sh	2010-04-08 16:05:55 UTC (rev 6537)
+++ pcbsd/trunk/pc-sysinstall/backend/functions-disk.sh	2010-04-08 19:21:04 UTC (rev 6538)
@@ -1,6 +1,139 @@
 #!/bin/sh
 # Functions related to disk operations using gpart
 
+# Get a MBR partitions sysid
+get_partition_sysid_mbr()
+{
+  INPART="0"
+  DISK="$1"
+  PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
+  fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
+  while read i
+  do
+    echo "$i" | grep "The data for partition"  >/dev/null 2>/dev/null
+    if [ "$?" = "0" ] ; then
+       INPART="0"
+       PART="`echo ${i} | cut -d ' ' -f 5`"
+       if [ "$PART" = "$PARTNUM" ] ; then
+          INPART="1"
+       fi
+    fi
+
+    # In the partition section
+    if [ "$INPART" = "1" ] ; then
+       echo "$i" | grep "^sysid" >/dev/null 2>/dev/null
+       if [ "$?" = "0" ] ; then
+         SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`"
+         break
+       fi
+
+    fi
+
+  done < ${TMPDIR}/disk-${DISK}
+  rm ${TMPDIR}/disk-${DISK}
+
+  VAL="${SYSID}"
+  export VAL
+};
+
+# Get the partitions MBR label
+get_partition_label_mbr()
+{
+  INPART="0"
+  DISK="$1"
+  PARTNUM=`echo ${2} | sed "s|${DISK}s||g"`
+  fdisk ${DISK} >${TMPDIR}/disk-${DISK} 2>/dev/null
+  while read i
+  do
+    echo "$i" | grep "The data for partition"  >/dev/null 2>/dev/null
+    if [ "$?" = "0" ] ; then
+       INPART="0"
+       PART="`echo ${i} | cut -d ' ' -f 5`"
+       if [ "$PART" = "$PARTNUM" ] ; then
+          INPART="1"
+       fi
+    fi
+
+    # In the partition section
+    if [ "$INPART" = "1" ] ; then
+       echo "$i" | grep "^sysid" >/dev/null 2>/dev/null
+       if [ "$?" = "0" ] ; then
+         LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`"
+         break
+       fi
+
+    fi
+
+  done < ${TMPDIR}/disk-${DISK}
+  rm ${TMPDIR}/disk-${DISK}
+
+  VAL="${LABEL}"
+  export VAL
+};
+
+# Get a GPT partitions label
+get_partition_label_gpt()
+{
+  DISK="${1}"
+  PARTNUM=`echo ${2} | sed "s|${DISK}p||g"`
+
+  gpart show ${DISK} >${TMPDIR}/disk-${DISK}
+  while read i
+  do
+     SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
+     if [ "${SLICE}" = "${PARTNUM}" ] ; then
+       LABEL="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 4`"
+       break
+     fi
+  done <${TMPDIR}/disk-${DISK}
+  rm ${TMPDIR}/disk-${DISK}
+
+  VAL="${LABEL}"
+  export VAL
+};
+
+# Get a partitions startblock
+get_partition_startblock()
+{
+  DISK="${1}"
+  PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
+
+  gpart show ${DISK} >${TMPDIR}/disk-${DISK}
+  while read i
+  do
+     SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
+     if [ "$SLICE" = "${PARTNUM}" ] ; then
+       SB="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 1`"
+       break
+     fi
+  done <${TMPDIR}/disk-${DISK}
+  rm ${TMPDIR}/disk-${DISK}
+
+  VAL="${SB}"
+  export VAL
+};
+
+# Get a partitions blocksize
+get_partition_blocksize()
+{
+  DISK="${1}"
+  PARTNUM=`echo ${2} | sed "s|${DISK}p||g" | sed "s|${DISK}s||g"`
+
+  gpart show ${DISK} >${TMPDIR}/disk-${DISK}
+  while read i
+  do
+     SLICE="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 3`"
+     if [ "$SLICE" = "${PARTNUM}" ] ; then
+       BS="`echo ${i} | grep -v ${DISK} | grep -v ' free ' |tr -s '\t' ' ' | cut -d ' ' -f 2`"
+       break
+     fi
+  done <${TMPDIR}/disk-${DISK}
+  rm ${TMPDIR}/disk-${DISK}
+
+  VAL="${BS}"
+  export VAL
+};
+
 # Function which returns the partitions on a target disk
 get_disk_partitions()
 {

Modified: pcbsd/trunk/pc-sysinstall/backend/functions.sh
===================================================================
--- pcbsd/trunk/pc-sysinstall/backend/functions.sh	2010-04-08 16:05:55 UTC (rev 6537)
+++ pcbsd/trunk/pc-sysinstall/backend/functions.sh	2010-04-08 19:21:04 UTC (rev 6538)
@@ -46,12 +46,25 @@
   export MB
 };
 
+# Function to convert blocks to megabytes
+convert_blocks_to_megabyte()
+{
+  if [ -z "${1}" ] ; then
+    echo "Error: No blocks specified!"
+    exit 1
+  fi
+
+  MB="`expr -e ${1} \/ 2048`"
+  export MB
+};
+
 # Takes $1 and strips the whitespace out of it, returns VAL
 strip_white_space()
 {
   if [ -z "${1}" ]
   then
     echo "Error: No value setup to strip whitespace from!"
+
     exit 1
   fi
 

Modified: pcbsd/trunk/pc-sysinstall/backend-query/disk-part.sh
===================================================================
--- pcbsd/trunk/pc-sysinstall/backend-query/disk-part.sh	2010-04-08 16:05:55 UTC (rev 6537)
+++ pcbsd/trunk/pc-sysinstall/backend-query/disk-part.sh	2010-04-08 19:21:04 UTC (rev 6538)
@@ -3,6 +3,7 @@
 #############################
 
 . ${PROGDIR}/backend/functions.sh
+. ${PROGDIR}/backend/functions-disk.sh
 
 if [ -z "${1}" ]
 then
@@ -16,6 +17,8 @@
   exit 1
 fi
 
+DISK="${1}"
+
 # Now get the disks size in MB
 KB="`diskinfo -v ${1} | grep 'bytes' | cut -d '#' -f 1 | tr -s '\t' ' ' | tr -d ' '`"
 convert_byte_to_megabyte ${KB}
@@ -23,6 +26,7 @@
 TOTALB="`diskinfo -v ${1} | grep 'in sectors' | tr -s '\t' ' ' | cut -d ' ' -f 2`"
 
 
+
 gpart show ${1} >/dev/null 2>/dev/null
 if [ "$?" != "0" ] ; then
   # No partitions on this disk, display entire disk size and exit
@@ -31,12 +35,14 @@
   exit
 fi
 
-fdisk ${1} >${TMPDIR}/disk-${1} 2>/dev/null
-# Don't display partitions on EFI GPT disks, need to re-format entire disk on them
-cat ${TMPDIR}/disk-${1} | grep "GPT" >/dev/null 2>/dev/null
+# Display if this is GPT or MBR formatted
+gpart show ${1} | grep "GPT" >/dev/null 2>/dev/null
 if [ "$?" = "0" ] ; then
-  rm ${TMPDIR}/disk-${1}
-  exit
+  echo "${1}-format: GPT"
+  TYPE="GPT"
+else
+  echo "${1}-format: MBR"
+  TYPE="MBR"
 fi
 
 # Set some search flags
@@ -45,56 +51,44 @@
 START="0"
 SIZEB="0"
 
-while read i
+# Get a listing of partitions on this disk
+get_disk_partitions "${DISK}"
+PARTS="${VAL}"
+for curpart in $PARTS
 do
-  # Check if we have any extended partitions
-  echo "$i" | grep "Extended"  >/dev/null 2>/dev/null
-  if [ "$?" = "0" ]
-  then
-     EXTENDED="1"
-  fi
-  
 
-  echo "$i" | grep "The data for partition"  >/dev/null 2>/dev/null
-  if [ "$?" = "0" ]
-  then
-     PART="`echo ${i} | cut -d ' ' -f 5`"
+  # First get the sysid / label for this partition
+  if [ "$TYPE" = "MBR" ] ; then
+     get_partition_sysid_mbr "${DISK}" "${curpart}"
+     echo "${curpart}-sysid: ${VAL}"
+     get_partition_label_mbr "${DISK}" "${curpart}"
+     echo "${curpart}-label: ${VAL}"
+  else
+     get_partition_label_gpt "${DISK}" "${curpart}"
+     echo "${curpart}-sysid: ${VAL}"
+     echo "${curpart}-label: ${VAL}"
   fi
 
-  echo "$i" | grep "^sysid" >/dev/null 2>/dev/null
-  if [ "$?" = "0" ]
-  then
-     SYSID="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2`"
-     echo "${1}s${PART}-sysid: ${SYSID}"
-     LABEL="`echo ${i} | tr -s '\t' ' ' | cut -d ',' -f 2-10`"
-     echo "${1}s${PART}-label: ${LABEL}"
-  fi
-  
-  echo "$i" | tr -s '\t' ' ' | grep 'start ' >/dev/null 2>/dev/null
-  if [ "$?" = "0" ]
-  then
-     START="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 2 | cut -d ',' -f 1`"
-     echo "${1}s${PART}-blockstart: ${START}"
-     SIZEB="`echo ${i} | tr -s '\t' ' ' | cut -d ' ' -f 4`"
-     echo "${1}s${PART}-blocksize: ${SIZEB}"
-     SIZEMB="`echo ${i} | tr -s '\t' ' ' | cut -d '(' -f 2 | cut -d ' ' -f 1`"
-     echo "${1}s${PART}-sizemb: ${SIZEMB}"
-  fi
+  # Now get the startblock, blocksize and MB size of this partition
 
-done < ${TMPDIR}/disk-${1}
+  get_partition_startblock "${DISK}" "${curpart}"
+  START="${VAL}"
+  echo "${curpart}-blockstart: ${START}"
 
+  get_partition_blocksize "${DISK}" "${curpart}"
+  SIZEB="${VAL}"
+  echo "${curpart}-blocksize: ${SIZEB}"
 
-# Check if we found any extended partitions
-if [ "$EXTENDED" = "1" ]
-then
-  echo "${i}-extended: YES"
-fi
+  convert_blocks_to_megabyte "${SIZEB}" 
+  SIZEMB="${MB}"
+  echo "${curpart}-sizemb: ${SIZEMB}"
 
+done
+
+
 # Now calculate any free space
 LASTB="`expr $SIZEB + $START`"
 FREEB="`expr $TOTALB - $LASTB`"
 FREEMB="`expr ${FREEB} / 2048`"
 echo "${1}-freemb: $FREEMB"
 echo "${1}-freeblocks: $FREEB"
-
-rm ${TMPDIR}/disk-${1}



More information about the Commits mailing list