The time now is Tue 24 Apr 2018, 05:09
All times are UTC - 4 |
Page 2 of 2 [19 Posts] |
Goto page: Previous 1, 2 |
Author |
Message |
Keef

Joined: 20 Dec 2007 Posts: 891 Location: Staffordshire
|
Posted: Tue 26 Mar 2013, 15:48 Post subject:
|
|
As requested:
Code: |
# grep 'sr0' /proc/diskstats
11 0 sr0 0 0 0 0 0 0 0 0 0 0 0
| [/code]
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 4208 Location: Kiel,Germany
|
Posted: Wed 27 Mar 2013, 21:34 Post subject:
|
|
Keef, that output is as expected.
Dunno for now the real reason, have such output, too, often after the fd0 drive.
I thought that the kernel might have refreshed the /proc/diskstats file.
It happened always only the first time it had run, the second and later runs had no problems.
But wjaguar showed me a better use of the read buildin, and that seems to be robust:
Instead of
Code: | while read line; do
echo $line
#do a lot of awk here to get third and second value
done</proc/diskstats |
the use of
Code: | while read maj min drive rest; do
echo $maj $min $drive
#no need for awk anymore
done</proc/diskstats |
has not failed anytime for me now.
This is also faster without the need for awk.
Will change the script in post 1 now.
|
Back to top
|
|
 |
Keef

Joined: 20 Dec 2007 Posts: 891 Location: Staffordshire
|
Posted: Thu 28 Mar 2013, 15:37 Post subject:
|
|
Current version:
Code: | # probepart
/dev/sr0|none or not inserted|8589930496
/dev/sda1|ext2|100677169152
/dev/sda2|ext2|92249522176
/dev/sda3|ext3|114956513280
/dev/sda4|swap|12173414400
/dev/fd0|none or not inserted|32768
/dev/sdb1|ext3|32440246272
|
Pmount is showing the CF card correctly, and the optical drive is now being detected once a disc is inserted.
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 4208 Location: Kiel,Germany
|
Posted: Tue 07 May 2013, 15:48 Post subject:
probepart2.07 |
|
Update :
* Made it work in ash .
* Use of case instead of the many [ ] tests for the options.
* read shell builtin function instead of external cat.
* Changed logic to enable output also for -d/dev/sda ( whole single drive - was for -d/dev/sda1 partitions ) .
Code: |
#!/bin/ash
###INTRO
# Karl Reimer Godt, March-May 2013
# /sbin/probepart originally written by
#
# Barry Kauler www.puppylinux.com
# LGPL 2007 Puppy Linux www.puppylinux.com
#
# Different code for /sbin/probepart
# that is used by
# /sbin/pup_event_frontend_d
# ,
# /usr/sbin/pmount
# ,
# /usr/sbin/partview
# ,
# /usr/local/bin/drive_all
# and
# /usr/sbin/shutdownconfig
# and probably some more .
#
# May output fat as Fat[16|32] by disktype, not as vfat
# so take this into account if these scripts don't
# show your fat partitions.
# Also omitting the /root/.usb-drive-log-probepart file
# , the forcing of USB by
# dd if=/dev/$ONEUSBDRV of=/dev/null bs=512 count=1 >/dev/null 2>&1 #v3.97 faster.
# and unfortunately
# /usr/lib/mut/bin/guess_fstype
# since the developer jesse had not ported it to support ext4.
#
# Thanks very much to Keef for patience while testing and
# helping me detecting some wrong formatted code, confirmations
# and to keep pmount happier.
# Thanks muchly to wjaguar to remind/teach me to use the read command more effectively,
# which solved problems posted by Keef and also encountered by me, and did
# increase the speed reasonably.
# Also thanks to Ted Dog for reporting about network-block-devices (nbd.ko)
# and headfound for company.
###ENDINTRO
##HEAD
trap "exit 1" HUP INT QUIT KILL TERM
OUT=/dev/null;ERR=$OUT
[ "$DEBUG" ] || DEBUG=`sed 's% %\n%g' /proc/cmdline | grep -w -i '^debug'`
[ "$DEBUG" ] && { OUT=/dev/stdout;ERR=/dev/stderr; }
Version='2.07'
usage(){
USAGE_MSG="
$0 [ PARAMETERS ]
example usage : DEBUG=1 probepart -d/dev/sdc1 /dev/sdd -m
PARAMETERS:
-V|--version : showing version information
-H|--help : show this usage information
-A|--all : show all disks noted in /proc/diskstats like ram|loop|mtd|md
##edit1: added following size formats:
-b : show size in bits (default)
-B : Bytes
-kb : 1000-kilo bits
-mb : 1000-mega bits
-gb : 1000-giga bits
-kib : 1024-kilo bits
-mib : 1024-mega bits
-gib : 1024-giga bits
-KB : 1000-kilo Bytes
-MB : 1000-mega Bytes
-GB : 1000-giga Bytes
-KIB : 1024-kilo Bytes
-MIB : 1024-mega Bytes
-GIB : 1024-giga Bytes
-k : show sizes in kilobytes (KiB) #compat.
-m : show sizes in megabytes (MiB) #compat.
Without one of the above parameters it is the value found in
/sys/class/block/drive/size
; usually as blocksize=512 formatted to bits .
-d/dev/sdaX [/dev/sdb ..] : output only for given partitions/drives
$2
"
echo "$USAGE_MSG"
exit $1
}
[ "`echo "$1" | grep -wiE "help|\-H"`" ] && usage 0
[ "`echo "$1" | grep -wiE "version|\-V"`" ] && { echo "$0 -version $Version";exit 0; }
(mount |grep -o "/proc " >$OUT 2>$ERR && mount |grep -o "/sys " >$OUT 2>$ERR) || usage 1 '/proc or /sys not mounted!'
##
SIZE_FACTOR=1
for p in $* ; do
P="${p//-/}"
case $P in
b) SIZE_FACTOR=1;;
B) SIZE_FACTOR=8;;
kb) SIZE_FACTOR=$((1*1000));;
mb) SIZE_FACTOR=$((1*1000*1000));;
gb) SIZE_FACTOR=$((1*1000*1000*1000));;
kib) SIZE_FACTOR=$((1*1024));;
mib) SIZE_FACTOR=$((1*1024*1024));;
gib) SIZE_FACTOR=$((1*1024*1024*1024));;
KB) SIZE_FACTOR=$((8*1000));;
MB) SIZE_FACTOR=$((8*1000*1000));;
GB) SIZE_FACTOR=$((8*1000*1000*1000));;
KIB|k) SIZE_FACTOR=$((8*1024));;
MIB|m) SIZE_FACTOR=$((8*1024*1024));;
GIB) SIZE_FACTOR=$((8*1024*1024*1024));;
A|all) SHOWALL=YES;;
d/dev/*|/dev/*)
[ "${P//[[:punct:][:alpha:]]/}" ] && P="${P}\|"
DEVICES="${DEVICES}|${P##*/}" ;;
esac
done
[ "$DEVICES" ] && DEVICES=`echo "${DEVICES}" | sed 's%^|*%%'`
[ "$DEBUG" ] && echo "DEVICES='$DEVICES'"
##ENDHEAD
disktype_func(){
disktype /dev/"$1" 2>$ERR |grep -iE -o '.* file system|swap|squashfs' |tail -n1 |awk '{print $1}' |tr '[A-Z]' '[a-z]'
}
filesystem_func(){
[ "$FSTYPE" ] || FSTYPE=`guess_fstype /dev/"$1" 2>$ERR`
[ "$FSTYPE" = 'unknown' ] && FSTYPE=`disktype_func "$1"`
[ "$FSTYPE" ] || FSTYPE='none or unknown'
}
cddetect_func(){
cddetect_quick -d/dev/"$1" >$OUT 2>$ERR && FSTYPE=`disktype_func "$1"` || FSTYPE='none or not inserted'
}
present_removable(){
cddetect_func "$drive"
filesystem_func "$drive"
echo "/dev/$drive|$FSTYPE|$SIZE"
}
LANG=$LNG FDISK=`fdisk -l | grep '^/dev' 2>$ERR |tr -s ' ' |sed 's%\(/dev/[[:alpha:]]*[0-9]*\) \([[:digit:]]*\) \(.*\)%\1 N \2 \3%'`
##MAIN
while read maj min drive rest; do
[ "$maj" -a " $min" -a "$drive" -a "$rest" ] || continue
[ "$drive" ] || continue
[ "$SHOWALL" ] || { [ "`echo "$drive" | grep -vE 'ram|loop|mtd|md|nbd'`" ] || continue; }
[ -b /dev/$drive ] || {
[ "$DEBUG" ] && echo "'$maj' '$min' '$drive'" >&2;
[ "$maj" -a "$min" -a "$drive" ] && mknod /dev/$drive b $maj $min 2>$ERR || continue; }
[ "$DEVICES" ] && { [ "`echo "${drive}|" | grep -E "$DEVICES"`" ] || continue; }
SIZE='';FSTYPE='';
[ -f /sys/class/block/$drive/size ] || continue
read SIZE </sys/class/block/$drive/size && SIZE=$((SIZE*512*8)) || continue
[ "$SIZE" = $((2*8*512)) ] && { SIZE=$((`echo "$FDISK" |grep -w "^/dev/$drive" | awk '{print $5}' |sed 's%[^[:digit:]]%%g'`*2*512*8));FSTYPE=`echo "$FDISK" |grep -w "^/dev/$drive" |cut -f7- -d ' '`'(none)'; } ##+ edit2 added (none) to please pmount
SIZE=$((SIZE/SIZE_FACTOR))
REMOVEABLE=0
if [ "${drive//[[:alpha:]]/}" ]; then
if [ -d /sys/class/block/$drive/device ]; then
read REMOVEABLE </sys/class/block/$drive/removable
fi
[ "$REMOVEABLE" = 0 ] || cddetect_func "$drive"
filesystem_func "$drive"
echo "/dev/$drive|$FSTYPE|$SIZE"
else #whole drive
if [ -d /sys/class/block/$drive/device ]; then
read REMOVEABLE </sys/class/block/$drive/removable
if [ "$REMOVEABLE" = 1 ]; then
if [ -f /sys/class/block/$drive/device/type ]; then
if [ "`cat /sys/class/block/$drive/device/type`" = 5 ]; then
present_removable
fi
else
present_removable
fi
fi;fi
fi
done</proc/diskstats
|
|
Back to top
|
|
 |
|
Page 2 of 2 [19 Posts] |
Goto page: Previous 1, 2 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|