LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Please fix this mess ! (https://www.linuxquestions.org/questions/slackware-14/please-fix-this-mess-4175559146/)

ivandi 11-17-2015 07:33 PM

Please fix this mess !
 
I took a quick look at the installer and it seems that this script is responsible for displaying the wrong partition sizes, but I might be wrong.

/sbin/probe:
Code:

#!/bin/sh
# This is 'probe', a wrapper for using fdisk to gather drive info for
# the Slackware setup scripts.  I hate to bounce this much garbage through
# a tmpdir, but it looks like large variables can make ash crash...

# Many thanks to Vincent Rivellino for contributing the patches to support
# Mylex and Compaq RAID controllers.

# Regularize output that will be parsed:
unset LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \
  LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \
  LC_IDENTIFICATION LC_ALL
LANG=C
export LANG

TMP=/var/log/setup/tmp
rm -f $TMP/SeTfdisk

# listide major minor hd1 hd2 (2 base devs for major)
list_ide() {
  if [ "$2" = "0" ]; then
    fdisk -l /dev/$3 >> $TMP/SeTfdisk
  elif [ "$2" = "64" ]; then
    fdisk -l /dev/$4 >> $TMP/SeTfdisk
  fi
}

list_scsi() {
  # find drive # 0 - 15
  DRV=`expr $1 / 16`
  NUM=`expr $1 % 16`
  if [ ! "$NUM" = "0" ]; then
    return
  fi
  if [ "$DRV" = "0" ]; then
    fdisk -l /dev/sda >> $TMP/SeTfdisk
  elif [ "$DRV" = "1" ]; then
    fdisk -l /dev/sdb >> $TMP/SeTfdisk
  elif [ "$DRV" = "2" ]; then
    fdisk -l /dev/sdc >> $TMP/SeTfdisk
  elif [ "$DRV" = "3" ]; then
    fdisk -l /dev/sdd >> $TMP/SeTfdisk
  elif [ "$DRV" = "4" ]; then
    fdisk -l /dev/sde >> $TMP/SeTfdisk
  elif [ "$DRV" = "5" ]; then
    fdisk -l /dev/sdf >> $TMP/SeTfdisk
  elif [ "$DRV" = "6" ]; then
    fdisk -l /dev/sdg >> $TMP/SeTfdisk
  elif [ "$DRV" = "7" ]; then
    fdisk -l /dev/sdh >> $TMP/SeTfdisk
  elif [ "$DRV" = "8" ]; then
    fdisk -l /dev/sdi >> $TMP/SeTfdisk
  elif [ "$DRV" = "9" ]; then
    fdisk -l /dev/sdj >> $TMP/SeTfdisk
  elif [ "$DRV" = "10" ]; then
    fdisk -l /dev/sdk >> $TMP/SeTfdisk
  elif [ "$DRV" = "11" ]; then
    fdisk -l /dev/sdl >> $TMP/SeTfdisk
  elif [ "$DRV" = "12" ]; then
    fdisk -l /dev/sdm >> $TMP/SeTfdisk
  elif [ "$DRV" = "13" ]; then
    fdisk -l /dev/sdn >> $TMP/SeTfdisk
  elif [ "$DRV" = "14" ]; then
    fdisk -l /dev/sdo >> $TMP/SeTfdisk
  elif [ "$DRV" = "15" ]; then
    fdisk -l /dev/sdp >> $TMP/SeTfdisk
  fi
}

# List Mylex RAID device
list_rd() {
  # find drive
  DRV=`expr $2 / 8`
  NUM=`expr $2 % 8`
  if [ ! "$NUM" = "0" ]; then
    return
  fi
  fdisk -l /dev/rd/c$1d$DRV >> $TMP/SeTfdisk
  #output_gpt_partitions /dev/rd/c$1d$DRV >> $TMP/SeTfdisk
}

# List Cpq SMART/2 RAID device
list_ida() {
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ ! "$NUM" = "0" ]; then
    return
  fi
  fdisk -l /dev/ida/c$1d$DRV >> $TMP/SeTfdisk
  #output_gpt_partitions /dev/ida/c$1d$DRV >> $TMP/SeTfdisk
}

list_cciss() {
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ ! "$NUM" = "0" ]; then
    return
  fi
  fdisk -l /dev/cciss/c$1d$DRV >> $TMP/SeTfdisk
  #output_gpt_partitions /dev/cciss/c$1d$DRV >> $TMP/SeTfdisk
}

list_ataraid() {
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ "$NUM" = "0" ]; then
    fdisk -l /dev/ataraid/d$DRV >> $TMP/SeTfdisk
    #output_gpt_partitions /dev/ataraid/d$DRV >> $TMP/SeTfdisk
  else
    return
  fi
}

list_amiraid() {
  # find drive
  DRV=`expr $2 / 16`
  NUM=`expr $2 % 16`
  if [ "$NUM" = "0" ]; then
    fdisk -l /dev/amiraid/ar$DRV >> $TMP/SeTfdisk
    #output_gpt_partitions /dev/amiraid/ar$DRV >> $TMP/SeTfdisk
  else
    return
  fi
}

list_mmc() {
  # find drive
  DRV=`expr $2 / 8`
  NUM=`expr $2 % 8`
  if [ "$NUM" = "0" ]; then
    fdisk -l /dev/mmcblk$DRV >> $TMP/SeTfdisk
    #output_gpt_partitions /dev/mmcblk$DRV >> $TMP/SeTfdisk
  else
    return
  fi
}

is_swap() {
  HEADER=`dd if="$1" bs=1 skip=4086 count=10 2>/dev/null`
  if [ "$HEADER" = "SWAPSPACE2" -o "$HEADER" = "SWAP_SPACE" ]; then
    return 0
  else
    return 1
  fi
}

list_md() {
  if ( is_swap "/dev/$2" ); then TYPE="Linux swap"; else TYPE="Linux"; fi
  echo "/dev/$2  1 2 $1 kk $TYPE" >> $TMP/SeTfdisk
}

list_lvm() {
  lvscan 2>/dev/null | grep "ACTIVE" | while read line ; do
    SMASHED_LINE=$line
    if [ "$SMASHED_LINE" = "" ]; then
      break;
    fi
    DEV=`echo $SMASHED_LINE | cut -f2 -d"'"`
    SIZE=`lvdisplay $DEV -C --units k --noheadings --separator : | cut -f4 -d':'  | sed -e 's/^\([0-9]*\)[^0-9].*/\1/'`
    TYPE="Linux"
    if ( is_swap "$DEV" ); then TYPE="Linux swap"; fi
    echo "$DEV  0  0  $SIZE  lv  $TYPE" >> $TMP/SeTfdisk
  done
}

# List any volumes created by cryptsetup
list_crypt() {
  for i in $(ls /dev/mapper/); do
    if cryptsetup status $i 2>/dev/null | grep "is active" 1>/dev/null ; then
      DEV=$(cryptsetup status $i 2>/dev/null | grep "is active" | cut -f1 -d' ')
      SIZE=$(fdisk -s $(cryptsetup status $i 2>/dev/null | grep "device:" | cut -f2 -d: | tr -d ' '))
      echo "$DEV  0  0  $SIZE  lc  Linux" >> $TMP/SeTfdisk
    fi
  done
}

# List virtual partitions
list_virt() {
  fdisk -l /dev/$1 >> $TMP/SeTfdisk
  #output_gpt_partitions /dev/$1 >> $TMP/SeTfdisk
}

output_gpt_partitions() {
# First, make sure the device is GPT:
if fdisk -l $1 2> /dev/null | grep -wq -e "GPT" -e "Disklabel type: gpt" ; then
  unset output
  # In the case of some RAID device like Mylex we will need to delimit the
  # partition number.  We will set a partition delimiter variable P set
  # either to an empty string (default) or the needed delimiter.
  TESTRAID="$(echo $1 | cut -f 2 -d /)"
  case "$TESTRAID" in
  'amiraid' )
    P="p"
    ;;
  'ataraid' )
    P="p"
    ;;
  'cciss' )
    P="p"
    ;;
  'ida' )
    P="p"
    ;;
  'rd' )
    P="p"
    ;;
  *)
    P=""
    ;;
  esac
  gdisk -l $1 | tr -d '*' | while read parse ; do
    if [ ! -z $output ]; then
      line=$parse
      if [ ! "$(echo $line | cut -b1)" = "" ]; then
        gptpartition=${1}${P}$(echo $line | cut -f 1 -d ' ')
        gpttype="$(echo $line | cut -f 6 -d ' ')"
        if [ "$gpttype" = "8200" ]; then
          fdisktype="Linux swap"
        elif [ "$gpttype" = "0700" ]; then
          if dd if=$gptpartition bs=1K count=1 2> /dev/null | grep -wq NTFS ; then
            fdisktype="HPFS/NTFS"
          elif dd if=$gptpartition bs=1K count=1 2> /dev/null | grep -wq EXFAT ; then
            fdisktype="exFAT"
          else
            fdisktype="W95 FAT32"
          fi
        elif [ "$gpttype" = "AF00" ]; then
          fdisktype="HFS+"
        elif [ "$gpttype" = "EF00" ]; then
          fdisktype="EFI System Partition"
        elif [ "$gpttype" = "8300" ]; then
          fdisktype=Linux
        else
          fdisktype="Unknown hex code $gpttype"
        fi
        sectorsize="$(gdisk -l $1 | tr -d '*' | grep "Logical sector size" | cut -f 2 -d : | cut -f 2 -d ' ')"
        gptstart="$(expr $(echo $line | cut -f 2 -d ' ') \* $sectorsize / 1024)"
        gptend="$(expr $(echo $line | cut -f 3 -d ' ') \* $sectorsize / 1024)"
        gptsize="$(expr $gptend - $gptstart)"
        echo $gptpartition $gptstart $gptend $gptsize $gpttype $fdisktype
      fi
    fi
    if echo $parse | grep -q "^Number" ; then
      output=true
    fi
  done
fi
}

list_scsi_gpt() {
  # find drive # 0 - 15
  DRV=`expr $1 / 16`
  NUM=`expr $1 % 16`
  if [ ! "$NUM" = "0" ]; then
    return
  fi
  if [ "$DRV" = "0" ]; then
    output_gpt_partitions /dev/sda
  elif [ "$DRV" = "1" ]; then
    output_gpt_partitions /dev/sdb
  elif [ "$DRV" = "2" ]; then
    output_gpt_partitions /dev/sdc
  elif [ "$DRV" = "3" ]; then
    output_gpt_partitions /dev/sdd
  elif [ "$DRV" = "4" ]; then
    output_gpt_partitions /dev/sde
  elif [ "$DRV" = "5" ]; then
    output_gpt_partitions /dev/sdf
  elif [ "$DRV" = "6" ]; then
    output_gpt_partitions /dev/sdg
  elif [ "$DRV" = "7" ]; then
    output_gpt_partitions /dev/sdh
  elif [ "$DRV" = "8" ]; then
    output_gpt_partitions /dev/sdi
  elif [ "$DRV" = "9" ]; then
    output_gpt_partitions /dev/sdj
  elif [ "$DRV" = "10" ]; then
    output_gpt_partitions /dev/sdk
  elif [ "$DRV" = "11" ]; then
    output_gpt_partitions /dev/sdl
  elif [ "$DRV" = "12" ]; then
    output_gpt_partitions /dev/sdm
  elif [ "$DRV" = "13" ]; then
    output_gpt_partitions /dev/sdn
  elif [ "$DRV" = "14" ]; then
    output_gpt_partitions /dev/sdo
  elif [ "$DRV" = "15" ]; then
    output_gpt_partitions /dev/sdp
  fi
}

# List the LVM volumes:
list_lvm

# List CRYPT volumes:
list_crypt

## This is obsolete, since fdisk handles GPT now.
## List GPT partitions:
#cat /proc/partitions | while read line ; do
#  SMASHED_LINE=$line
#  MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
#  MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
#  if [ "$MAJOR" = "8" ]; then
#    list_scsi_gpt $MINOR
#  fi
#done

# Other partitions:
if cat /proc/partitions | grep -E '/|[0-9]' 1>/dev/null 2>/dev/null ; then # new
  cat /proc/partitions | grep -E '/|[0-9]' | while read line ; do
    SMASHED_LINE=$line
    MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
    MINOR=`echo $SMASHED_LINE | cut -f 2 -d ' '`
    DEVNAME=`echo $SMASHED_LINE | cut -f 4 -d ' '`
    if [ "$MAJOR" = "3" ]; then
      list_ide $MAJOR $MINOR hda hdb
    elif [ "$MAJOR" = "8" ]; then
      list_scsi $MINOR
    elif [ "$MAJOR" = "9" ]; then
      list_md `echo $SMASHED_LINE | cut -f 3 -d ' ' | tr -d '/'` \
              `echo $SMASHED_LINE | cut -f 4 -d ' '`
    elif [ "$MAJOR" = "22" ]; then
      list_ide $MAJOR $MINOR hdc hdd
    elif [ "$MAJOR" = "33" ]; then
      list_ide $MAJOR $MINOR hde hdf
    elif [ "$MAJOR" = "34" ]; then
      list_ide $MAJOR $MINOR hdg hdh
    elif [ "$MAJOR" = "48" ]; then
      list_rd 0 $MINOR
    elif [ "$MAJOR" = "49" ]; then
      list_rd 1 $MINOR
    elif [ "$MAJOR" = "50" ]; then
      list_rd 2 $MINOR
    elif [ "$MAJOR" = "51" ]; then
      list_rd 3 $MINOR
    elif [ "$MAJOR" = "52" ]; then
      list_rd 4 $MINOR
    elif [ "$MAJOR" = "53" ]; then
      list_rd 5 $MINOR
    elif [ "$MAJOR" = "54" ]; then
      list_rd 6 $MINOR
    elif [ "$MAJOR" = "55" ]; then
      list_rd 7 $MINOR
    elif [ "$MAJOR" = "56" ]; then
      list_ide $MAJOR $MINOR hdi hdj
    elif [ "$MAJOR" = "57" ]; then
      list_ide $MAJOR $MINOR hdk hdl
    elif [ "$MAJOR" = "72" ]; then
      list_ida 0 $MINOR
    elif [ "$MAJOR" = "73" ]; then
      list_ida 1 $MINOR
    elif [ "$MAJOR" = "74" ]; then
      list_ida 2 $MINOR
    elif [ "$MAJOR" = "75" ]; then
      list_ida 3 $MINOR
    elif [ "$MAJOR" = "76" ]; then
      list_ida 4 $MINOR
    elif [ "$MAJOR" = "77" ]; then
      list_ida 5 $MINOR
    elif [ "$MAJOR" = "78" ]; then
      list_ida 6 $MINOR
    elif [ "$MAJOR" = "79" ]; then
      list_ida 7 $MINOR
    elif [ "$MAJOR" = "80" ]; then
      list_ide $MAJOR $MINOR hdm hdn
    elif [ "$MAJOR" = "89" ]; then
      list_ide $MAJOR $MINOR hdo hdp
    elif [ "$MAJOR" = "90" ]; then
      list_ide $MAJOR $MINOR hdq hdr
    elif [ "$MAJOR" = "91" ]; then
      list_ide $MAJOR $MINOR hds hdt
    elif [ "$MAJOR" = "101" ]; then
      list_amiraid $MAJOR $MINOR
    elif [ "$MAJOR" = "104" \
      -o "$MAJOR" = "105" \
      -o "$MAJOR" = "106" \
      -o "$MAJOR" = "107" \
      -o "$MAJOR" = "108" \
      -o "$MAJOR" = "109" \
      -o "$MAJOR" = "110" \
      -o "$MAJOR" = "111" ]; then
      list_cciss $(( $MAJOR - 104 )) $MINOR
    elif [ "$MAJOR" = "114" ]; then
      list_ataraid $MAJOR $MINOR
    elif [ "$MAJOR" = "179" ]; then
      list_mmc $MAJOR $MINOR
    elif [ $(expr $DEVNAME : 'x\?vd[^0-9]*$') -ne 0 ]; then
      # The virtio devices have no set major dev number, so we have to search
      # by name.  Matches full drive names for KVM/lguest (vda) and Xen (xvda).
      list_virt $DEVNAME
    fi
  done
else # old format and no RAID:
  if cat /proc/partitions | grep md 1> /dev/null 2> /dev/null ; then
    cat /proc/partitions | grep md | while read line ; do
      SMASHED_LINE=$line
      MAJOR=`echo $SMASHED_LINE | cut -f 1 -d ' '`
      if [ "$MAJOR" = "9" ]; then
        list_md `echo $SMASHED_LINE | cut -f 3 -d ' ' | tr -d '/'` \
                `echo $SMASHED_LINE | cut -f 4 -d ' '`
      fi
    done
  fi
  fdisk -l 2> /dev/null >> $TMP/SeTfdisk
fi

# Change the names to be the same as what the old fdisk used:
sed -i -e "s/Linux filesystem/Linux/g" $TMP/SeTfdisk
sed -i -e "s/EFI System/EFI System Partition/g" $TMP/SeTfdisk

cat $TMP/SeTfdisk


Cheers

Didier Spaier 11-17-2015 09:43 PM

If that's what you mean, IIRC the unit in sizes displayed by fdisk has changed at some point in time. Should be easy to check and fix. I will investigate further in a few hours if nobody did since then

ponce 11-18-2015 12:12 AM

you already did!

https://www.linuxquestions.org/quest...1/#post5362773

Didier Spaier 11-18-2015 02:20 AM

Thanks for the heads-up, Matteo. I will propose a patch later today, in this thread as I think it's better to put all suggestions in the same place.

PS Done.

ivandi 11-19-2015 09:13 PM

Quote:

Originally Posted by Didier Spaier (Post 5451322)
I will propose a patch later today, in this thread as I think it's better to put all suggestions in the same place.

PS Done.

Well, this hasn't been fixed for six months now. I only hope it wont take two years, like another simply stupid bug in pkgtools.

Usually it is much easier. One just has to leach an ARCH or Gentoo patch and stick a copyright on top of the slackbuild :D


Cheers

Didier Spaier 11-19-2015 10:35 PM

Quote:

Originally Posted by ivandi (Post 5452430)
Well, this hasn't been fixed for six months now. I only hope it wont take two years, like another simply stupid bug in pkgtools.

This is an issue with Slackware-current. Nobody is expected to run that in production, so there is no need to hurry. Unless it be not fixed in Slackware-14.2 no one is entitled to complain.

Quote:

Usually it is much easier. One just has to leach an ARCH or Gentoo patch and stick a copyright on top of the slackbuild :D
Being sarcastic does not help in any way, furthermore this remark is irrelevant as there is nothing in ARCH or Gentoo that can be reused in this case.

Then, fixing this issue is not simple as you seem to think[1]. Trying to fix it then reading Pat's answer made me realize that a real fix would need to be verified in all situations considered in /sbin/probe, and that needs hardware that I personally do not own.

[1]But if it is that simple, why didn't you propose a fix yourself?

kikinovak 11-20-2015 01:31 AM

Looks like the problem is fixed. Here's today's ChangeLog.

Code:

usb-and-pxe-installers/usbboot.img:  Rebuilt.
  Removed udev, added eudev and libgudev.
  Fixed partition size output.

Cheers,

Niki

ReaperX7 11-20-2015 05:42 AM

Patches get shared around lots of distributions. Add Red Hat, Fedora, LFS, and others to the vast resource of patchworks out there.

The sarcasm wasn't needed on any level and is a bit rude towards the Slackware team.

55020 11-20-2015 07:18 AM

Where does Ivandi think that Arch and Gentoo get their patches? Many of them are just cherry-picked commits from upstream.

One side of Ivandi's brain thinks copyright is a ridiculous barrier to this sharing (he's right, so we'll call that the "right" side of his brain), but the other side of his brain seems to think... well, forgive me if I'm wrong, but the implication seems to be that snarfing patches is somehow demeaning? Larry Wall disagrees. "The three chief virtues of a programmer are: Laziness, Impatience and Hubris."

Sharing patches is normal and expected. One of the things Lucas Nussbaum said he wanted to work on after his Debian Project Leader stint was improving patch-sharing between distros. Also, acknowledging where patches originated is not merely polite, it is also an audit trail against the introduction of backdoors, and a lazy/impatient/hubristic way of referring other people to further information.

I'd love to know where Ivandi thinks I found this, this and this. There is no copyright notice on those patches... I'd love to know what Ivandi thinks that means, under the Bern conventions.

Tonus 11-20-2015 07:32 AM

Hi,

While trying to compile Nixnote2, got a problem :

With

Code:

pkg-config --libs hunspell
I have

Code:

-lhunspell-1.3
And expected

Code:

-lhunspell
Might be on purpose, might not...

Regards

Didier Spaier 11-20-2015 09:40 AM

1 Attachment(s)
Quote:

Originally Posted by Didier Spaier (Post 5452443)
Then, fixing this issue is not simple as you seem to think[1]. Trying to fix it then reading Pat's answer made me realize that a real fix would need to be verified in all situations considered in /sbin/probe, and that needs hardware that I personally do not own.

Well, eventually Pat found a more clever (and less lazy) solution, see attached patch.

ivandi 11-22-2015 06:28 PM

Quote:

Originally Posted by Didier Spaier (Post 5452688)
Well, eventually Pat found a more clever (and less lazy) solution, see attached patch.

Hm, it works sort of. I often install VMs on 8G virtual disks, 1G swap 7G root. With this patch the root partition size is displayed as 6G.

This function:
Code:

# get_part_size( dev ) - Return the size in K, M, G, or T of the named partition.
get_part_size() {
  BYTES=$(blockdev --getsize64 $1)
  K=$(expr $BYTES / 1024)
  if [ $K -lt 1024 ]; then
    SIZE="${K}K"
  elif [ $K -lt 1048576 ]; then
    SIZE="$(expr $K / 1024)M"
  elif [ $K -lt 1073741824 ]; then
    SIZE="$(expr $K / 1048576)G"
  elif [ $K -lt 10737418240 ]; then # 1.0T - 9.9T
    SIZE="$(expr $K \* 1000 / 1073741824 | cut -b1).$(expr $K \* 1000 / 1073741824 | cut -b2)T"
  else
    SIZE="$(expr $K / 1073741824)T"
  fi
  echo $SIZE
}

shows a byte size of 2147483648 (2G) as 2G, but a byte size of 2147483647 (2G -1byte) as 1G.

Is there any special reason for using expr instead of awk to do the math. For example this:
Code:

get_part_size() {
  BYTES=$(blockdev --getsize64 $1)
  K=$(expr $BYTES / 1024)
  if [ $K -lt 1024 ]; then
    SIZE="$(echo $BYTES | awk '{s = $1 / 1024 ; printf("%.2f",s)}')K"
  elif [ $K -lt 1048576 ]; then
    SIZE="$(echo $K | awk '{s = $1 / 1024 ; printf("%.2f",s)}')M"
  elif [ $K -lt 1073741824 ]; then
    SIZE="$(echo $K | awk '{s = $1 / 1048576 ; printf("%.2f",s)}')G"
  else
    SIZE="$(echo $K | awk '{s = $1 / 1073741824 ; printf("%.2f",s)}')T"
  fi
  echo $SIZE
}

shows a 7515144192 bytes partition (6.999 G) as 7G and not 6G. And a 2000000000 bytes as 1.86G and not 1G.


Cheers

bassmadrigal 11-22-2015 09:14 PM

I am using numfmt in a script to get human readable sizes from a download speed provided by curl (allows me to test the speed of many mirrors and then find the fastest one available). From my limited scripting experience, it looks like what both awk and expr are doing, but with a much simpler command... although I'm not sure if it is included (or would be hard to include) with the Slackware installer (it's part of coreutils on a full Slackware install). This would require no changes to support larger drives (although, PB drives are still pretty far away) and would require no if/then/elif statements. Although, to be fair, I haven't looked through the script at all, and I haven't plugged in any numbers except for the four ivandi provided. It does only do one decimal place and a with quick look through the man page I didn't see anything to change it. Sorry if this is a stupid suggestion, I am still pretty noobish when it comes to the types of scripting that occurs in the installer.

Code:

get_part_size() {
  BYTES=$(blockdev --getsize64 $1)
  SIZE=$(numfmt --to=iec $BYTES)
  echo $SIZE
}

Code:

jbhansen@craven-moorhead:~$ numfmt --to=iec 2147483648 2147483647 7515144192 2000000000
2.0G
2.0G
7.0G
1.9G


Philip Lacroix 11-22-2015 09:52 PM

Greetings. What about using bc as in the draft below? It won't truncate the decimal part and "scale" allows to set the needed number of decimal digits. I assumed from the original function that for sizes less than 1G decimals are not that important (1-1023K, 1-1023M, 1.0-1023.9G, 1.00T-etc.). Please don't take this post as if I'm trying to teach something to anybody: on the contrary, I'm just curious and interested in learning from you guys.

Code:

get_part_size() {
  BYTES=$(blockdev --getsize64 $1)
  K=$(expr $BYTES / 1024)
  if [ $K -lt 1024 ]; then
    SIZE="${K}K"
  elif [ $K -lt 1048576 ]; then
    SIZE="$(expr $K / 1024)M"
  elif [ $K -lt 1073741824 ]; then
    SIZE="$(echo "scale=1; $K / 1048576" | bc)G"
  else
    SIZE="$(echo "scale=2; $K / 1073741824" | bc)T"
  fi
  echo $SIZE
}

Regards
Philip

ReaperX7 11-22-2015 10:12 PM

Quote:

Originally Posted by 55020 (Post 5452620)
Where does Ivandi think that Arch and Gentoo get their patches? Many of them are just cherry-picked commits from upstream.

One side of Ivandi's brain thinks copyright is a ridiculous barrier to this sharing (he's right, so we'll call that the "right" side of his brain), but the other side of his brain seems to think... well, forgive me if I'm wrong, but the implication seems to be that snarfing patches is somehow demeaning? Larry Wall disagrees. "The three chief virtues of a programmer are: Laziness, Impatience and Hubris."

Sharing patches is normal and expected. One of the things Lucas Nussbaum said he wanted to work on after his Debian Project Leader stint was improving patch-sharing between distros. Also, acknowledging where patches originated is not merely polite, it is also an audit trail against the introduction of backdoors, and a lazy/impatient/hubristic way of referring other people to further information.

I'd love to know where Ivandi thinks I found this, this and this. There is no copyright notice on those patches... I'd love to know what Ivandi thinks that means, under the Bern conventions.

I don't ever recall any instance where a patch had any copyright that wasn't re-share, re-use, re-distribute friendly not in favor of ISC, BSD, MIT, GPL, GNU, or any open source license. Much less, I barely recall any patches having any licenses period. Most are just diff extracted commits.


All times are GMT -5. The time now is 03:25 PM.