enhanced /sbin/probedisk2

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

enhanced /sbin/probedisk2

#1 Post by Karl Godt »

This is cutting edge - likely has bugs .

Features added :
Support for /dev/fd* floppy drives .
usage message if called with -h parameter
shell builtin getopts
Supported Parameters :
  • -V : Shows version information.
    -H|-h : Shows this usage.

    -E : Use dc external binary if option -S applies.
    -M : Shorter machine readable output for to be used in scripts.
    -P : Show partition numbers.
    -p : Pretty and long output for terminal usage.
    -S : Show drive sizes in 1000/1024 format.
    -s : Shorter output.
I am mainly interested in the -M option to reduce code in parent scripts eg /sbin/pup_event_frontend_d
Example output :
bash-3.00# probedisk2E -M
  • fd0|floppy|Generic 1440kb FD|4/4 K
    sda|drive|ATA ST500DM002-1BD14|500/465 G
    sdb|drive|ATA ST1000DM003-9YN1|1000/931 G
    sdc|usbdrv|HUAWEI MMC Storage|1/1 G
    sdd|usbdrv|HitachiG ST|500/465 G
    sr0|optical|PLDS DVD-ROM DH-16D3S|1073/1023 M
    sr1|optical|HL-DT-ST DVD-RAM GH10L|1073/1023 M
    sr2|optical|HUAWEI Mass Storage|78/74 M

Code: Select all

#!/bin/sh
#LGPL 2007 Puppy Linux www.puppyos.com
#based on probedisk3 written by Dougal.
#small mods by BK 16 june 2007
# 21 Jun 2007 BK: force /proc update for usb drives.
#v3.93 10 dec 2007 BK: updated for 2.6.24 kernel, no /dev/hd*.
#v3.97 31jan2008 BK: refinement for detecting kernels with /dev/hd* drives.
#v4.01 10may2008 BK: bugfix for detecting if usb drive.
#v4.01 10may2008 BK: new 2nd-param categories. named 'probedisk2'.
#v4.01 21may2008 BK: zip and ls120 now categorized as 'floppy'.
#v4.02 9jun08 BK: correct detection of usb floppy.
#v403 fixed excessive spaces in description field.
#v406 support for old kernel, /proc/ide, /dev/hd*.


###KRG Fr 31. Aug 23:34:58 GMT+1 2012

trap "exit 1" HUP INT QUIT KILL TERM

OUT=/dev/null;ERR=$OUT
[ "$DEBUG" ] && { OUT=/dev/stdout;ERR=/dev/stderr; }
[ "$DEBUG" = "2" ] && set -x


Version='1.1'  ##added partitions
Version='1.2E' ##added function_size, moved code

usage(){
USAGE_MSG="
$0 [ PARAMETERS ]

-V : Shows version information.
-H|-h : Shows this usage.

-E : Use dc external binary if option -S applies.
-M : Shorter machine readable output for to be used in scripts.
-P : Show partition numbers.
-p : Pretty and long output for terminal usage.
-S : Show drive sizes in 1000/1024 format.
-s : Shorter output.

*******  *******  *******  *******  *******  *******  *******  *******  *******
$2"

echo "$USAGE_MSG"
exit $1
}

###KRG Fr 31. Aug 23:34:58 GMT+1 2012


###KRG Mon Jul  8 22:35:19 GMT+1 2013

function_format_size(){
if [ "$USE_DC" ] ; then
   SIZE_I=`dc $blocks_1024 $F1024 \/ p`
   SIZE_K=`dc $blocks_1000 $F1000 \/ p`
else
   SIZE_I=$(($blocks_1024 / $F1024))
   SIZE_K=$(($blocks_1000 / $F1000))
fi
SIZES="|${SIZE_K}/${SIZE_I} $USE_C"
}

function_size(){
  if [ -f /sys/block/$ONEDRV/size ] ; then
  read blocks_512 </sys/block/$ONEDRV/size
  blocks_1024=$(($blocks_512/2))
  blocks_1000=$((($blocks_512 * 512) / 1000 ))
   if [ "$blocks_1024" -gt $((1024*1024)) ] ; then
   F1024=$((1024*1024)) F1000=$((1000*1000)) USE_C=G function_format_size
   elif [ "$blocks_1024" -gt 1024 ] ; then
   F1024=1024 F1000=1000 USE_C=M function_format_size
   else
   F1024=1 F1000=1 USE_C=K function_format_size
   fi
  else
  SIZES='|not available'
  fi
}

function_partitions(){
  PARTITIONS='|'`ls -1 /sys/class/block/$ONEDRV |grep -o -e '[[:digit:]]*' |sort -n |tr '\n' ' '`
}

PRETTY=YES;DICE=/dev/
while getopts hEMsSpPV option ; do
case $option in
E) USE_DC=YES ;;  ## Exact count
h|H) usage 0 ;;
M) MACHINE=YES;PRETTY='';NO_CATEG='';USE_SIZES=YES;USE_PARTS='' ;; # pup_event OUPUT style
s) NO_CATEG=YES ;;  ## omit $CATEGORY
S) USE_SIZES=YES ;;  ## show sizes of drives
p) PRETTY=YES;MACHINE='';USE_DC=YES;USE_SIZES=YES;USE_PARTS=yes ;; # Pretty OUTPUT style
P) USE_PARTS=YES ;; ## show partitions
V) echo "$0 -version $Version";exit 0 ;;
esac
done
[ "$PRETTY" ] || DICE='';

function_output(){
[ "$NO_CATEG" ] && INFO="$MODEL" || INFO="$VENDOR $MODEL"
   INFO=`echo $INFO | sed '/^$/d'`
[ "$INFO" ] && INFO="|$INFO" || INFO='|?'
[ "$NO_CATEG" ] && MEDIA=''
[ "$USE_SIZES" ] && function_size
[ "$USE_PARTS" ] && function_partitions
echo ${DICE}${ONEDRV}${MEDIA}${INFO}${SIZES}${PARTITIONS}
}

###KRGMon Jul  8 22:35:19 GMT+1 2013

. /etc/rc.d/PUPSTATE
#ATADRIVES is all ide/sata drives (not usb) (which all have /dev/sd notation).
#if old kernel supporting /dev/hd* then using SATADRIVES variable...
INTERNAL_SD_DRIVES="$SATADRIVES"
[ "$ATADRIVES" != "" ] && INTERNAL_SD_DRIVES="$ATADRIVES"

if [ -f /root/.usb-drive-log-probedisk ];then #force /proc upate mechanism
 for ONEUSBDRV in `cat /root/.usb-drive-log-probedisk`;
 do
  #disktype /dev/$ONEUSBDRV > /dev/null 2>&1
  [ -b /dev/$ONEUSBDRV ] && dd if=/dev/$ONEUSBDRV of=/dev/null bs=512 count=1 1>$OUT 2>$ERR #v4.01 faster.
 done
fi

if [ ! "$MACHINE" ] ; then
#mounted drives/partitions...
MNTDDEVS=`awk '{print $1}' /proc/mounts | grep -o -E '[fhs]d.*|sr.*|scd.*|mmc.*'`
fi

#crap, right now, /sys/block does not show my hdb cd/dvd drive, but it is in
#/proc/ide. pathetic kernel! oh well...
if [ ! -e /proc/ide ];then #v3.97
 ALLDRVS=`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr|^fd'`
else
 ALLDRVS=`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr|^fd' | tr '\n' ' '``ls -1 /proc/ide | grep '^hd'`
fi
#note: after further testing, the 2.6.21.5 kernel exhibits inconsistent behaviour for hd devices, best to avoid old CONFIG_IDE kernel driver.

for ONEDRV in $ALLDRVS
do
  case $ONEDRV in
   hd*) # ide device, look in /proc/ide for info
     read MEDIA </proc/ide/$ONEDRV/media
     [ "$MEDIA" = "disk" ] && MEDIA="drive"
     [ "$MEDIA" = "cdrom" ] && MEDIA="optical"
     read INFO </proc/ide/$ONEDRV/model
   ;;
   sd*) # scsi devices, look in /sys/block (all appear as Direct-Access)
     MEDIA="|drive"
     read VENDOR </sys/block/$ONEDRV/device/vendor
     read MODEL </sys/block/$ONEDRV/device/model
     DRVNAMES="$DRVNAMES `echo -n "$ONEDRV" | cut -b 1-3` "

     #log if usb drive (not a sata drive)... v4.01...
     #if [ "`echo "$INTERNAL_SD_DRIVES" | grep "$ONEDRV"`" = "" ];then
     if [ "`find /sys -name $ONEDRV | grep 'usb' | grep 'block'`" ] ; then
      MEDIA="|usbdrv" #v4.01
      echo "$ONEDRV" >> /root/.usb-drive-log-probedisk
      sort -u /root/.usb-drive-log-probedisk > /tmp/usb-drive-log-probedisk-tmp
      mv -f /tmp/usb-drive-log-probedisk-tmp /root/.usb-drive-log-probedisk
      #find out if a usb floppy drive...

       if [ -e /sys/block/${ONEDRV}/size ];then
       [ "`cat /sys/block/${ONEDRV}/size`" = "2880" ] && MEDIA="|floppy"
       fi

       if [ -e /sys/block/${ONEDRV}/device/model ];then
       [ "`grep -E ' FDD| UF000x|Floppy|USB\-FDU|^FD\-|FLOPPY' /sys/block/${ONEDRV}/device/model`" ] && MEDIA="|floppy"
       fi
     #find out if it is a removable internal drive (zip, ls120, etc)...
     elif [ -e /sys/block/${ONEDRV}/removable ];then
       [ "`cat /sys/block/${ONEDRV}/removable`" = "1" ] && MEDIA="|floppy"
     fi

   ;;
   scd*|sr*) #  scsi cdroms
     MEDIA="|optical"
     read VENDOR </sys/block/$ONEDRV/device/vendor
     read MODEL </sys/block/$ONEDRV/device/model
   ;;
   mmc*) #/dev/mmcblk0
     MEDIA="|card"
     VENDOR='MMC/SD:'
     read MODEL </sys/block/$ONEDRV/device/name
   ;;
    fd*)
     MEDIA='|floppy'
     VENDOR='Generic'
     MODEL='1440kb FD'
   ;;
   *)
     MEDIA='|unknown'
     VENDOR='?'
   ;;
  esac

  function_output

done

if [ ! "$MACHINE" ] ; then
#find out if a mounted device has been unplugged...
#for hotplug drives, remove it and it will disappear from /sys/block, however
#still shows up in 'mount' if hasn't been unmounted.
for ONEMNTD in $MNTDDEVS
do
 case $ONEMNTD in
  hd*|sd*|sr*|fd*)
   MNTDDRV="`echo -n "$ONEMNTD" | cut -b 1-3` "
   ;;
  scd*)
   MNTDDRV="`echo -n "$ONEMNTD" | cut -b 1-4` "
   ;;
  mmc*)
   MNTDDRV="`echo -n "$ONEMNTD" | cut -b 1-7` "
   ;;
 esac
 #prints to system log and to stderr...
 [ "`echo "$ALLDRVS" | grep "$MNTDDRV"`" ] || logger -s "PROBEDISK WARNING: $ONEMNTD UNPLUGGED WITHOUT UNMOUNTING it FOREHAND !"
done
fi

###END###
exit 0  #force exitcode for klibc K.Almquist dash/sh
REMARKS :
There might be some code changes due to my main installations are pre - #110126 no longer using SATADRIVES variable in PUPSTATE.
Dropping the hidden /root/.usb*log file , thought dd is really fast .
Dropping the logger part , because nothing uses it, and nothing would inform a user about that, if not run from CLI .
Probably merging probedisk with probepart - so scripts like pmount or *_frontend_d will only need to call one script and not two .
User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

enhanced /sbin/probedisk2

#2 Post by L18L »

Code: Select all

# ./probedisk2 -M
mmcblk0|card|MMC/SD: 00000|7/7 G
sda|usbdrv|Multiple Card Reader|7/7 G
#
Hdh :)
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

Hey Lutz ! :)

Of course it helps . Hope that everything is detected that was attached .

I must recon that I live by every response - be it positive or negative .

BTW : Where to get mmcblock devices in Germany ? Until now I thought that they were some rare devices distributed in the US only .
User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

enhanced /sbin/probedisk

#4 Post by L18L »

Yes, everything has been detected.

There are only mmc at this box which is a RaspberryPi from UK.
sda is inside a USB adapter; that is why it does not appear as mm1 I think.

Something like
http://www.amazon.de/Integral-Single-Co ... B000TD50ZS
Attachments
my_mmcblock_devices.png
running Puppy on RaspberryPi
(60.85 KiB) Downloaded 2482 times
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#5 Post by sunburnt »

Hi Karl; I`ve written a probepart also... Suggestion:

Wouldn`t it be best if probepart worked without any Puppy specific code.?

So it will then stand-alone and be far more widely useful.
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#6 Post by Karl Godt »

Yo, Thierry, there is some PUPPY special code in there :
The INTERNAL_SD_DRIVES variable but that's been dropped since 2011-01-26 and the
/root/.usb*log* file, that I think should be kept in /tmp/[*/] and not in /root .

I also feel not so well if scripts touch the MBR/Superblock of drives all the time .
For a FUN-Distro it is OK,
I think, but probably not if you want serious deployment as you stated somewhere .

Thierry, you may loadup your probedisk to google docs or code or pastebin or skydrive or whatever and give links to them .
I should do so too for the many old but crazy/buggy script experiments of mine :oops:

*
Lutz , Thanks for the pointer towards CF cards . Was using SD/MMC cards until now besides USB-Pen-Flash drives . Had a look at conrad.de and will probably purchase a USB-Multicard reader for about 15€ and a
Transcend-CF-Karte-4GB-170
for 22 € . Have to have a look for Bauhaus and Max Bahr that day too .
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#7 Post by sunburnt »

Your script uses at least these Puppy specific items:
/root/.usb-drive-log-probedisk
/etc/rc.d/PUPSTATE
and Dougal`s /sbin/probedisk > /sbin/probedisk2

I also don`t like using /sys, I found it to be a rats nest.
But it does give more info than /proc does.

I`d like to make a partition-report exec. written in BaCon.
But Bash does all the work, so it may as well be written in Bash.

I`ll take a look at my old code, it`s been years since I wrote it.
If it looks useful I`ll post it... Keep coding good buddy!

# Here`s old Bash library scripts ( I have many of them ), they should be working...

This is: lib_partinfo

Code: Select all

#!/bin/sh
#########	This script gets info about partitions.	Terry Becker	2010

#########	Check for partitions on: hda-hdd & sda-sdd

if [ "$1" = '?' -o "$1" = '-h' -o "$1" = '-help' ];then
 echo ''
 echo 'Usage:   partinfo (-s = include swap partitions)'
 echo ''
 exit
fi

rm -f /tmp/partinfo.txt
Parts=`cat /proc/partitions`				# get info on drive partitions

for Dev in hda hdb hdc hdd sda sdb sdc sdd sde sdf sdg sdh	# Loop: 4-hd & 8-sd
do
 for N in 1 2 3 4 5 6 7 8					# Loop: 8 parts. for each dev.
 do
  Line=`echo "$Parts" |grep "$Dev$N"`
  if [ -n "$Line" ];then
   Info=`disktype /dev/$Dev$N`					# relies on "disktype"
   Size=`echo "$Info" |grep 'Block' |sed 's/^.*(//' |sed 's/ .*$//'`

   FS=`echo "$Info" |grep 'system' |sed 's/ .*$//'`		# get info for normal part.
   if [ -n "$FS" ];then
    echo "$Dev$N $FS $Size"
    echo "$Dev$N $FS $Size" >> /tmp/partinfo.txt
    continue 
   fi

   if [ "$1" = '-s' ];then			# if -s option: get info for swap part.
    FS=`echo "$Info" |grep 'Swap'`
    if [ -n "$FS" ];then
     FS='swap'
     echo "$Dev$N $FS $Size"
     echo "$Dev$N $FS $Size" >> /tmp/partinfo.txt
     continue 
    fi
   fi
  fi
 done
done
And this is: lib_sysinfo

Code: Select all

#!/bin/sh
#######	System info.		by: Terry Becker		aka: SunBurnt		Nov. 1	2011

#####	No warranty of any kind...	Use at your own risk!		

###	This file can be sourced, or run with function as argument, or run by link ( like BusyBox ).


infoApp='sysinfo'		### set this app`s. name
																				############	Start of Library Functions.
convsize() { [ ! "$1" ]&& exit 11
if [ '' ];then
	echo $1 |sed 's/,//g' |awk '{ sum=$Size ;hum[1024**8]="YB";hum[1024**7]="ZB";hum[1024**6]="EB";
		hum[1024**5]="PB";hum[1024**4]="TB";hum[1024**3]="GB";hum[1024**2]="MB";hum[1024]="KB";
		for (x=1024**3 ;x>=1024 ;x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}' 
fi	
	
	echo $1 |sed 's/,//g' |awk '{ split( "B KB MB GB TB PB EB ZB YB" , v );
	 s=1; while( $1>1024 ){ $1/=1024; s++ } print int($1), v[s] }'
return 0
##############	NEED to SIZE OUTPUT to 3 NUMBERS and NO TRAILING 0s.

#	if [ ! "$2" ];then Size=$1 ; i=0 ;else Size=$2
#		case $1 in -b) i=0;; -k) i=1;; -m) i=2;; -g) i=3;; -t) i=4;; -p) i=5;; -e) i=6;; -z) i=7;; esac
	if [ ! "$2" ];then i=0 ;else B=`echo $2 |tr '[:lower:]' '[:upper:]'`
		case $B in B) i=0;; KB) i=1;; MB) i=2;; GB) i=3;; TB) i=4;; PB) i=5;; EB) i=6;; ZB) i=7;;
		YB) echo $1 $2 ;exit;; esac ;fi
	Bytes=(B KB MB GB TB PB EB ZB YB)
	while [ ${Size/.*} -ge 1024 ]
	do Size=`echo "scale=2; $Size/1024" | bc` ; ((i++)) ;done
	echo `echo $Size |sed 's/0.*$//;s/\.$//'` ${Bytes[$i]}
}
error() {
	case $1 in
		p1) echo "###  Error:  No partition input." ; exit 1 ;;
		p3) echo "###  Error:  No partition: $2" ; exit 3 ;;
		o1) echo "###  Error:  No optical drive input." ; exit 1 ;;
		o3) echo "###  Error:  No optical drive: $2" ; exit 3 ;;
	esac
}

partinfo() { echo -e "\n Part.	Type	Size\n ====================="
	for P in /sys/block/[hs]d?/[hs]d*
	do read S < $P/size
		[ $S -lt 3 ]&& continue
		T=`guess_fstype /dev/${P##*/}`
		S=`$infoApp convsize $S`
		L=$((7-`echo $S |wc -c`))
		case $L in 1) sp=' ';; 2) sp='  ';; esac &&
		echo " ${P##*/}	$T	$sp$S" ; sp=''
	done ; echo ''
}
partlist() { awk '/[0-9] [hsm][dm][a-z][0-9]/ {if ($3>1) print $4}' /proc/partitions
}
parttype() { [ ! "$1" ]&& error p1
	[ ! "/dev/`$infoApp partlist |grep $1`" ]&& error p3 $1
	guess_fstype /dev/$1
}
partsize() { [ ! "$1" ]&& error p1
	[ ! "/dev/`$infoApp partlist |grep $1`" ]&& error p3 $1
#	awk -v a=$1 "/$a/ {print $3}" /proc/partitions ;exit
#	awk -v a=$1 "/$a/"'{print $3}' /proc/partitions ;exit

#	awk -v s=$1 "/$s/" /proc/partitions |awk '{print $3}'
#	awk -v s=$1 "/$s/" /proc/partitions

#	grep $1 /proc/partitions |awk '{print $3}'
}
partfree() { [ ! "$1" ]&& error p1
	if [ ! "`df |grep $1`" ];then M=1
		[ ! -d /mnt/$1 ]&& mkdir /mnt/$1
		mount /dev/$1 /mnt/$1
	fi
	DF=`df |grep $1`
	echo $((`echo "$DF" |awk '{print $2}'` - `echo "$DF" |awk '{print $3}'`))
	[ "$M" = 1 ]&& umount /mnt/$P
}

optiinfo() {
	echo -e "\nDrive	Speed	Type\n======================"
	for D in `$infoApp optilist`
	do echo -e " $D	 `$infoApp optispeed $D`	`$infoApp optitype $D`\n" ;done
}
optilist() { for D in `awk '/[sr][0-9]/ {print $6,$5,$4,$3}' /proc/sys/dev/cdrom/info`
	do echo $D ;done
}
optispeed() { [ ! "$1" ]&& error o1
	[ ! "/dev/`$infoApp optilist |grep $D`" ]&& error o3 $1
	Info=`sed '1,2d;s/^Can //;s/	/ /g' /proc/sys/dev/cdrom/info |tr -s ' '`
	H=`echo "$Info" |head -n1`
	S=${H//[^ ]/} ; col=$((${#S}+1-${1:$((${#1}-1)):1}))		# get drive`s col.
	echo "$Info" |grep 'drive speed:' |cut -d' ' -f $col
}
optitype() { [ ! "$1" ]&& error o1
	[ ! "/dev/`$infoApp optilist |grep $D`" ]&& error o3 $1
	Info=`sed '1,2d;s/^Can //;s/	/ /g' /proc/sys/dev/cdrom/info |tr -s ' '`
	H=`echo "$Info" |head -n1`
	S=${H//[^ ]/} ; col=$((${#S}+1-${1:$((${#1}-1)):1}))		# get drive`s col.

	for D in DVD-RAM: DVD-R: DVD: CD-RW: CD-R: CD:
	do
		if [ `echo "$Info" |grep $D |cut -d' ' -f $col` -eq 1 ];then
			[ "$D" = DVD-RAM: ]&& D=DVD-RW: ; echo ${D//:/} ; break
		fi
	done
}

memsize() { free |grep 'Mem:' |tr -s ' ' |cut -d' ' -f3
#awk '/MemTotal:/ {print $2}' /proc/meminfo
}
memused() { free |grep 'Mem:' |tr -s ' ' |cut -d' ' -f4
#awk '/MemTotal:/ {print $3}' /proc/meminfo
}
memfree() { free |grep 'Mem:' |tr -s ' ' |cut -d' ' -f5
}
swapinfo() { cat /proc/swaps
exit
	Info=$(</proc/swaps)
	echo "$Info" |sed '1,1d;s/	/ /g' |tr -s ' ' |cut -d' ' -f 3 > /tmp/sysinfo.size
	echo "$Info" |sed '1,1d;s/	/ /g' |tr -s ' ' |cut -d' ' -f 2 > /tmp/sysinfo.type
	echo "$Info" |sed '1,1d;s/	/ /g' |tr -s ' ' |cut -d' ' -f 1 > /tmp/sysinfo.dev
	paste /tmp/sysinfo.type /tmp/sysinfo.dev > /tmp/sysinfo.info
	paste /tmp/sysinfo.size /tmp/sysinfo.info
	rm -f /tmp/$infoApp.*
}
macadd() { grep ":" /proc/net/arp |awk '{print $4}'
}
ipadd() {	grep ":" /proc/net/arp |awk '{print $1}'
}																				############	End of Library Functions.

############################################	START:	Called

List='partinfo partlist parttype partsize optiinfo optilist optispeed optitype memsize memused memfree swapinfo'
FN=`basename $0`
for Name in $infoApp $List
do [ "$FN" = "$Name" ]&& Sourced='False' && break ;done	###	Test if this file is sourced.

if [ "$Sourced" = 'False' ];then
	help() {
		echo -e '\n#####   '$infoApp'         System Information\n'
		echo '###   CLI normal usage:   '$infoApp' ( function name ) [ arg(s). ]'
		echo '###   CLI linked usage:   ( function name ) [ arg(s). ]'
		echo '###   Sourced usage:      ( function name ) [ arg(s). ]'
		echo -e '\n  ########   Functions.'
		echo '# partinfo [-s] = Drive partitions info list.	# -s = Show swap partitions.'
		echo '# partlist [-s] = Drive partitions list.	# -s = Show swap partitions.'
		echo '# parttype = Drive partition type.	# [sysinfo] parttype ( part. (sda1))'
		echo '# partsize = Drive part. size in bytes.	# [sysinfo] partsize ( part. (sda1))'
		echo '# optiinfo = Optical drives info list.'
		echo '# optilist = Optical drives list.'
		echo '# optispeed = Optical drive speed.	# [sysinfo] opticalsize ( part. (sr0))'
		echo '# optitype = Optical drive type.	# [sysinfo] opticaltype ( part. (sr1))'
		echo -e '\n# memsize = Memory size KB.   # memused = Mem. used.   # memfree = Mem. free.'
		echo '# swapinfo = Swap partitions and/or files info list, sizes in KB.'
		echo -e '\n ### mklinks = Make links to "sysinfo`s" functions.	# sysinfo mklinks\n'
	}
	mklinks() { P=`dirname $0` ; for Link in $List ;do ln -s $0 $P/$Link ;done
	}

	if [ -L $0 -a "`echo $FN |egrep "($List)"`" ];then				# called by link to function
		$FN $([ $1 ]&& basename $1)
	else																					# called with function as arg.
		if [ "$1" = '' -o "$1" = '?' -o "$1" = '-h' -o "$1" = '--help' ];then
			help
		else
			$1 $([ $2 ]&& basename $2)
		fi
	fi
fi	##########################################	END:	Called
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

Nice, Terry .

The first one is fixed to 8 partitions a drive, where I have up to 22 partitions on a 1TB drive .

The second one is a kind of jesse's mut(2) .

Have problems with the output :

Code: Select all

bash-3.00# time ./sys_info.sh partinfo

 Part.   Type   Size
 =====================
 sda1   ext4    93 MB
 sda2   ext4    93 MB
 sda3   ext3    46 MB
 sda5   swap     7 MB
 sda6   ext3    46 MB
 sda7   ext4    93 MB
 sda8   ext4    93 MB
 sda9   ext4   458 MB
 sdb1   ntfs    96 MB
 sdb10   ext4    63 MB
 sdb11   swap     9 MB
 sdb12   swap     9 MB
 sdb13   ext4    61 MB
 sdb14   ext4    63 MB
 sdb15   ext4    65 MB
 sdb16   ext4    61 MB
 sdb17   ext4    61 MB
 sdb18   ext4    61 MB
 sdb19   ext4   614 MB
 sdb2   ext3    96 MB
 sdb20   ext4    72 MB
 sdb21   swap     9 MB
 sdb22   swap     9 MB
 sdb3   ext4   192 MB
 sdb5   ext4    63 MB
 sdb6   ext4    63 MB
 sdb7   ext4    63 MB
 sdb8   ext4    63 MB
 sdb9   ext4    63 MB
 sdc1   vfat     3 MB


real	0m0.985s
user	0m0.142s
sys	0m0.316s
it uses 512 bytes blocks thus making the value 2x as it should - and gives me MB instead of GB .

Comparison :

Code: Select all

bash-3.00# time probepart2.07 -GIB
/dev/fd0|none or not inserted|0
/dev/sda1|ext4|46
/dev/sda2|ext4|46
/dev/sda3|ext3|23
/dev/sda4|Extended(none)|349
/dev/sda5|swap|3
/dev/sda6|ext3|23
/dev/sda7|ext4|46
/dev/sda8|ext4|46
/dev/sda9|ext4|229
/dev/sr0|none or not inserted|0
/dev/sdb1|ntfs|48
/dev/sdb2|ext3|48
/dev/sdb3|ext4|96
/dev/sdb4|Extended(none)|738
/dev/sdb5|ext4|31
/dev/sdb6|ext4|31
/dev/sdb7|ext4|31
/dev/sdb8|ext4|31
/dev/sdb9|ext4|31
/dev/sdb10|ext4|31
/dev/sdb11|swap|4
/dev/sdb12|swap|4
/dev/sdb13|ext4|30
/dev/sdb14|ext4|31
/dev/sdb15|ext4|32
/dev/sdb16|ext4|30
/dev/sdb17|ext4|30
/dev/sdb18|ext4|30
/dev/sdb19|ext4|307
/dev/sdb20|ext4|36
/dev/sdb21|swap|4
/dev/sdb22|swap|4
/dev/sr1|none or not inserted|0
/dev/sr2|iso9660|0
/dev/sdc1|vfat|1

real	0m0.498s
user	0m0.007s
sys	0m0.048s
probepart2.07 from here : http://murga-linux.com/puppy/viewtopic. ... 339#702339

time is unfair because i use a busybox ash configured with preferring applets and NOFORK option enabled .
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#9 Post by sunburnt »

Yep, it`s been awhile since I`ve looked at them.
Barry`s probepart gives twice the real size also, should be easy to fix.
The MB instead of GB is due to the conversion function, an easy fix too.

parttype() uses guess_fstype , which I intend to do away with.
I`ve rewritten so many things and I don`t upgrade older stuff.
That`s why separate function libraries are critical, everything`s always up to date.
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#10 Post by Karl Godt »

Can't confirm that Barry's code did not recognize the difference between block size of 512 and 1024 :
/sbin/probepart-orig wrote:SIZE=`cat /sys/block/${DEVICE}/size`
SIZE=$(($SIZE/2)) #get KB.

[ .. snip .. ]

[ "$SUNITS" = "" ] && SIZE=$(($SIZE*2)) #want 512 byte blocks.
[ "$SUNITS" = '-m' ] && SIZE=$(($SIZE/1024)) #want MB
Of course original probepart always need to be called with the -k or -m option
- otherwise you're right - would show double sizes of 512er blocks .

That code (was) inefficient in a lower CPU area though .
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#11 Post by sunburnt »

guess_fstype doesn`t recognize the newer squash files ( at least it didn`t...).

I think I settled on disktype for partition types and file for file types.
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#12 Post by Karl Godt »

sunburnt wrote:guess_fstype doesn`t recognize the newer squash files ( at least it didn`t...).

I think I settled on disktype for partition types and file for file types.
There had been posted squashfs patch for guess_fstype by jamesbond here :
guess_fstype reports unknown for Puppy SFS files. [ No Fix ] http://murga-linux.com/puppy/viewtopic.php?t=85046
But that does not dl for me anymore .
Apparently John Murga has an odd virus scanner or filesystem problems of some kind ..
Should have it on my 55-65°C Atom machine, but that's heatwave here paralizes me to set it up .

I was preferring disktype too but lately found that blkid did better . Will have to see if busybox blkid is good as regular blkid - depends on the version and libs each time am guessing .

A fourth way to add would be fstype from the klibc package :

Code: Select all

 /root/COMPILE/KLIBC/klibc-2.0.1/_install/lib/klibc/bin/fstype /dev/loop0
FSTYPE=squashfs
FSSIZE=38254374911
Attachments
fstype.bz2
statically linked (uses shared libs), stripped -- strace showed no library look up ..
(2.53 KiB) Downloaded 652 times
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#13 Post by sunburnt »

I`ll take a look at fstype, I`m always looking for a better way to do everything. 8)

And I seem to recall trying blkid but can`t remember what I decided about it.
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#14 Post by technosaurus »

blkid and fstype are now in toybox too.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#15 Post by sunburnt »

Not sure what`s wrong, but my copies of file and fstype just give errors.

Code: Select all

# file /bin/cp
file: symbol lookup error: file: undefined symbol: magic_version

# fstype /dev/sda1
bash: /root/my-applications/bin/fstype: No such file or directory

# NOTE: The file fstype IS in the stated dir.!
But it`s 4096 in size. Corrupt I think...
User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#16 Post by mikeb »

I revisited mut recently and added ext4 , cut out the debugging stuff and it its a rather neat binary for detecting drive info which can be used for one off scans or as a backend daemon including detecting usb insertions.
Its a bit like busybox for hardware.... perhaps could be built on if scripting proves too scripty....

I used a cut down uClib version in the initrd of lucid sucessfully too.

It was an ongoing promising project until jesse left the fold, though the guess_fstype part of it has had some further attention.

mike
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#17 Post by Karl Godt »

Mike -> Please open a Thread as

"EXT4 FS support ported to Mut" .

Thanks .
User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#18 Post by mikeb »

okay dokay

mike
Post Reply