/sbin/probepart2

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

/sbin/probepart2

#1 Post by Karl Godt »

Have completely rewritten now using /proc/diskstats instead of /proc/partitions.
This added the -A --all option to show everything like ram and unused loop disks.

Code: Select all

#!/bin/bash

###INTRO
# Karl Reimer Godt, March 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/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 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.0'

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

example usage : DEBUG=1 probepart -d/dev/sdc1 /dev/sdd1 -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 .

##edit2: added the forgotten -d parameter to check only given partitions
-d/dev/sdaX [/dev/sdaY ..] : output only for given partitions

$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!'  ##+++edit4 sanity check
##
SIZE_FACTOR=1
SIZE_PARAM=`echo "$@" | grep -o -m1 -w -i -E '\-k|\-m|\-b|\-[kmg]b|\-[kmg]ib' | head -n1`  ##-+edit2
  [ "$SIZE_PARAM" = '-b' ] && SIZE_FACTOR=1
  [ "$SIZE_PARAM" = '-B' ] && SIZE_FACTOR=8
 [ "$SIZE_PARAM" = '-kb' ] && SIZE_FACTOR=$((1*1000))
 [ "$SIZE_PARAM" = '-mb' ] && SIZE_FACTOR=$((1*1000*1000))
 [ "$SIZE_PARAM" = '-gb' ] && SIZE_FACTOR=$((1*1000*1000*1000))
 [ "$SIZE_PARAM" = '-KB' ] && SIZE_FACTOR=$((8*1000))
 [ "$SIZE_PARAM" = '-MB' ] && SIZE_FACTOR=$((8*1000*1000))
 [ "$SIZE_PARAM" = '-GB' ] && SIZE_FACTOR=$((8*1000*1000*1000))
[ "$SIZE_PARAM" = '-kib' ] && SIZE_FACTOR=$((1*1024))
[ "$SIZE_PARAM" = '-mib' ] && SIZE_FACTOR=$((1*1024*1024))
[ "$SIZE_PARAM" = '-gib' ] && SIZE_FACTOR=$((1*1024*1024*1024))
[ "$SIZE_PARAM" = '-KIB' ] && SIZE_FACTOR=$((8*1024))
  [ "$SIZE_PARAM" = '-k' ] && SIZE_FACTOR=$((8*1024))  ##compat.
[ "$SIZE_PARAM" = '-MIB' ] && SIZE_FACTOR=$((8*1024*1024))
  [ "$SIZE_PARAM" = '-m' ] && SIZE_FACTOR=$((8*1024*1024))  ##compat.
[ "$SIZE_PARAM" = '-GIB' ] && SIZE_FACTOR=$((8*1024*1024*1024))

DEVICES=`echo "$@" | grep -o '\-d.*' |sed 's%-[[:alnum:]]*%%g;s%/dev/%%g'`  ##+++edit2
SHOWALL=`echo "$@" | grep -oE '\-A|\-\-all' |tr -d '-'` ##+++edit3
##ENDHEAD

disktype_func(){
     disktype /dev/"$1" |grep -iE -o '.* file system|swap|squashfs' |tail -n1 |awk '{print $1}' |tr '[A-Z]' '[a-z]'  ##+edit2 support detection of squashfs
}

filesystem_func(){  ##+++edit1
    [ "$FSTYPE" ] || FSTYPE=`guess_fstype /dev/"$1" 2>$ERR`
    [ "$FSTYPE" = 'unknown' ] && FSTYPE=`disktype_func "$1"`   ##-+edit2
    [ "$FSTYPE" ] || FSTYPE='none or unknown'  ##-+edit2 added none to please pmount thanks to Keef
}

cddetect_func(){  ##+++edit1
    cddetect_quick -d/dev/"$1" >$OUT && FSTYPE=`disktype_func "$1"` || FSTYPE='none or not inserted'   ##+edit3 none to please pmount thanks to Keef
}

present_removable(){
   cddetect_func "$drive"
   filesystem_func "$drive"
   echo "/dev/$drive|$FSTYPE|$SIZE"
}

FDISK=`fdisk -l | grep '^/dev' |tr -s ' ' |sed 's%\(/dev/[[:alpha:]]*[0-9]*\) \([[:digit:]]*\) \(.*\)%\1 N \2 \3%'`  ##=+-edit2 : sed + bash and the # sign ..

##MAIN
while read maj min drive rest; do
[ "$maj" -a " $min" -a "$drive" -a "$rest" ] || continue  ##+++edit4
#[ "`echo "$line" | grep '^[[:digit:]]'`" ] || continue   ##---edit4
#drive=`echo $line |awk '{print $3}'`  ##---edit4 out again, thanks to wjaguar
[ "$drive" ] || continue   ##+++edit3
[ "$SHOWALL" ] || { [ "`echo $drive | grep -vE 'ram|loop|mtd|md'`" ] || continue; }  ##+++edit3 added --all option
[ -b /dev/$drive ] || { 
   #maj="${line%% *}" ; min=`echo $line |awk '{print $2}'`;  ##---edit4 thanks to wjaguar, no need for this anymore
   [ "$DEBUG" ] && echo "'$maj' '$min' '$drive'" >&2;
   [ "$maj" -a "$min" -a "$drive" ] && mknod /dev/$drive b $maj $min 2>$ERR || continue; }  ##+++edit2 : create nodes if not exists, older Puppy's static /dev/ directory supported only up to 15 partitions for each drive, newer only for sda up to 23.  ##+edit3 check for maj min not NULL
[ "$DEVICES" ] && { [ "`echo "$DEVICES" | grep -w "$drive"`" ] || continue; }  ##+++edit2 forgot to implement it
SIZE='';FSTYPE='';
[ -f /sys/class/block/$drive/size ] || continue
SIZE=$((`cat /sys/class/block/$drive/size`*512*8))  ##want bits
[ "$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}" =~ [0-9] ]]; then  ## was '[0-9]' : bash-3.00 accepts it, bash-3.2 not
 if [ -d /sys/class/block/$drive/device ]; then
 REMOVEABLE=`cat /sys/class/block/$drive/removable`
 fi
 [ "$REMOVEABLE" = 0 ] || cddetect_func "$drive"
  filesystem_func "$drive"
  echo "/dev/$drive|$FSTYPE|$SIZE"  ##edit1 wrong order for pmount
else  #whole drive
 if [ -d /sys/class/block/$drive/device ]; then
 REMOVEABLE=`cat /sys/class/block/$drive/removable`
 if [ "$REMOVEABLE" = 1 ]; then
 if [ -f /sys/class/block/$drive/device/type ]; then  ##+++edit3
  if [ "`cat /sys/class/block/$drive/device/type`" = 5 ]; then
   present_removable
  fi
 else  ##+++edit3
   present_removable
 fi
 fi;fi
fi
#done</proc/partitions
done</proc/diskstats  ##-+edit3

Reports on IDE kernels welcome.

*TODO : Look into the kernel source about which drives get which hex ( usb, cd, ..)

EDIT1 :
* Changed output order from DEVICE|SIZE|FSTYPE to DEVICE|FSTYPE|SIZE thanks to Keef.
* If no CDDRIVE attached, ls output had been empty and the code tried to find files for /sys/class/block//dev/ which don't exist.
* Put repeatedly used code into functions.
* Added more code to give more size formatting output possibilities, ie: -MB and -MIB .

EDIT2 :
* added note that the #110919 implemented /usr/sbin/shutdownconfig uses probepart too.
* sed on bash-3.2 failed using #numbersign as delimiter, treated it as comment, resulting in screwing the script. I used to use # because it is easy to type, and it is seldom that sed should edit a commented line.
* added the forgotten -d option to present only given partitions.
* added support to detect squashfs.
* fixed an error in edit1, which passed a too long argument from cddetect_func to disktype_func .
* force the creation of device nodes, if their number exceeds the supported by the static /dev directory (important for attached drives with more than 15/23 partitions).
* added to append the term 'none' to extended partitions so they don't show up in pmount.
* some minor changes to use shell builtins than external commands.
* minor security fix in case of aliases in /etc/profile or .bashrc : had ls -F alias on one partition, making mknod choke.

EDIT3 :
* Complete rewrite to use /proc/diskstats for handling hdb IDE-Kernel CD -drives.
* Added --all option to show everything in /proc/diskstats .
* Better handling of the mknod part.
* Add a second time none to cd-drives to please pmount.
* Obsoleted the second drives loop now using diskstats file.

EDIT4 :
* Use read val1 val2 val3 rest instead of read line to avoid usage of awk. This seems to fix crashes at first usages.
* extra check if /proc and /sys are mounted
* extra check for /sys/class/block/drive/size is there
Last edited by Karl Godt on Thu 28 Mar 2013, 01:40, edited 4 times in total.

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#2 Post by Keef »

I tried this on Wary 5.5.
Pmount only showed a floppy drive (which I don't have anyway).
Did not show internal IDE HDD, DVD/CDrw combo drive, or CF card in a PCMCIA adapter.
Running it from a terminal showed no output.

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

#3 Post by Karl Godt »

Keef, I am shocked. Sorry for any inconveniences. Am downloading wary-5.5.iso right now .
Am on 7-8Kbytes for the rest of the month and wget is telling me ETA 7hours.
Will install it onto USB Pendrive and take a look. Many thanks for reporting this.

The main file is /proc/partitions that I use to complicate things a bit to get a partition order that shows 10 below 9 and not underneath 1 as all my sort utilities do.

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#4 Post by Ted Dog »

Karl Godt wrote:Keef, I am shocked. Sorry for any inconveniences. Am downloading wary-5.5.iso right now .
Am on 7-8Kbytes for the rest of the month and wget is telling me ETA 7hours.
Will install it onto USB Pendrive and take a look. Many thanks for reporting this.

The main file is /proc/partitions that I use to complicate things a bit to get a partition order that shows 10 below 9 and not underneath 1 as all my sort utilities do.
I hate when they limit my speed like that and you still have a week to go until reset.

However, I take this time to download the big stuff using wget so to not eat into my FAST speed at the start of the next cycle. I set up a shell file full of wgets and just let it go morning/noon/overnight as they finish I remove that line from my 'download que' My way of getting my 'UNLIMITED' plan after the speed limits kick-in.

Also make 4 different wget script files with unique downloads and run them from from 4 different command shells. They usually only place limits per 'connection channel' I have 4 channels each running at the 7-8K rate. So I stll get around 28K when used at the sametime.

so open a new command line and start downloading the dev.sfs file in parallel.

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

#5 Post by Karl Godt »

Ted Dog : My Provider unfortunately seems to handle it correctly (t-mobile germany) .

Tried to wget -c also the devx from
http://ftp.nluug.nl/ibiblio/distributio ... ry_5.5.sfs
and from
http://distro.ibiblio.org/quirky/wary-5 ... ry_5.5.sfs
and it doesn't matter to which site i run wget on.

and now these two files ( wary-5.5.iso and devx_wary_5.5.sfs ) vessel along at 3.5KBytes per second. Firefox dl many times incorrectly when on low speed so i use wget -c on large files too.

*

Have fired up my wary-5.1.99 on my old P4 single core machine and the script should output anything, at least some errors , also pmount , from terminal, since i have set the size and filesystemtype fields in the wrong order. Have edited the script.
Attachments
wget_on_low_speed.jpg
(45.61 KiB) Downloaded 616 times

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#6 Post by Ted Dog »

Dang Germans closing those loop holes - :twisted:

They need to be like my brits plan -sloppy but mostly works ok.

Hope my British owned running on American leased cell towers does not get wind of this, or the 12am reup coding bug that gets you an extra day..... :wink:

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

#7 Post by Karl Godt »

Ted Dog wrote:Dang Germans closing those loop holes - :twisted:
They need to be like my brits plan -sloppy but mostly works ok.
Hope my British owned running on American leased cell towers does not get wind of this, or the 12am reup coding bug that gets you an extra day..... :wink:
Vodafone I had one contract too, even 10 bukkuletties cheaper by a sub-provider The Phone House ( ebay 1euro Lappy that broke already ),
but somehow they gave the money responsibility back to whoisthastsaphone and they decided to fetch the money after t-mobby ,
while PhonyMelony did it before them and my account went dry one month ..
So I am left with one contract only , and I remember in the beginning , that Vodafone had some holes and I was able to surf using Puppy even above the 5GB limit with acceptable speed.
Nowerdays these contracts allow only 3GB .. Old times are sometimes better times ..
And I was not able to connect after exceeding these 5GB , but I figured out an AT command to set the Speed of the modem ( which is the Vodafone by the way) to GPRS only , that may have worked this month. Will have to see what next month will bring.

User avatar
headfound
Posts: 371
Joined: Sun 25 Jun 2006, 00:58
Location: England
Contact:

#8 Post by headfound »

do you guys have something like sambamobile in your countries?
http://www.sambamobile.com
You watch adverts and build up download credit. If you used your normal internet connection when you are unlimited, then you could save the credits for the end of the month when you are limited.
Download a better Computer :)
[url=http://uk.youtube.com/watch?v=rDTLJYDHX3g]Puppy Linux Song[/url]
[url=http://www.letterbyletter.co.uk]www.letterbyletter.co.uk[/url]

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#9 Post by Ted Dog »

headfound wrote:do you guys have something like sambamobile in your countries?
http://www.sambamobile.com
You watch adverts and build up download credit. If you used your normal internet connection when you are unlimited, then you could save the credits for the end of the month when you are limited.
Interesting... but I've spend months fine-tuning my hosts file to remove all those extra bandwidth wasting ads. All but that crazy red penguin ad at top of this forum is blocked, but if it does not change soon to the host file it goes :evil:

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

#10 Post by Karl Godt »

Keef wrote:I tried this on Wary 5.5.
Pmount only showed a floppy drive (which I don't have anyway).
Did not show internal IDE HDD, DVD/CDrw combo drive, or CF card in a PCMCIA adapter.
Running it from a terminal showed no output.
Running Wary-5.5 right now.

The original code displays the following ( have dropped it as /sbin/probepart2.0, made executable, renamed /sbin/probepart to /sbin/probepart-orig , made a symbolic link ln -s probepart2.0 /sbin/probepart :

output of probepart2.0 in the console :

Code: Select all

# time /sbin/probepart2.0
/dev/loop0|274712|unknown
/dev/loop1|1441792|ext2
/dev/sda1|20755917|ext2
/dev/sda2|20627460|ext3
/dev/sda3|29929095|ntfs
/dev/sda4|905455530|W95 Ext'd (LBA)
/dev/sda5|2040129|swap
/dev/sda6|30780477|ext3
/dev/sda7|30732282|ext3
/dev/sda8|31117842|ext4
/dev/sda9|30892932|ext3
/dev/sda10|31760442|ext3
/dev/sda11|16996707|ext2
/dev/sda12|2056257|swap
/dev/sda13|495765837|ext3
/dev/sda14|2104452|swap
/dev/sda15|229102902|ext3
/dev/sda16|2104452|swap
/dev/sdb1|3897213|vfat
/dev/sr0|282944|iso9660
/dev/sr1|153344|iso9660

real	0m8.300s
user	0m1.536s
sys	0m0.632s
and from probepart-orig :

Code: Select all

# time /sbin/probepart-orig
/dev/sda1|ext2|20755916
/dev/sda2|ext3|20627460
/dev/sda3|ntfs|29929094
/dev/sda4|none|2
/dev/sda5|swap|2040128
/dev/sda6|ext3|30780476
/dev/sda7|ext3|30732282
/dev/sda8|ext4|31117842
/dev/sda9|ext3|30892932
/dev/sda10|ext3|31760442
/dev/sda11|ext2|16996706
/dev/sda12|swap|2056256
/dev/sda13|ext3|495765836
/dev/sda14|swap|2104452
/dev/sda15|ext3|229102902
/dev/sda16|none|2104452
/dev/sdb1|vfat|3897212
/dev/sr0|iso9660|282944
/dev/sr1|iso9660|153344

real	0m9.697s
user	0m2.524s
sys	0m0.836s
( Seamonkey flashplayer is currently pretty heavy on the load, should think about Ted Dog's advise with the host file ; therefore the time values should be 5 seconds lesser )

Pmount was erroring a lot in the console for the filesystemtype has no integer value, but that did not crash pmount, just displayed the GIB values in KIB.

Am working on the better handling for squashfs loop devices plus some code cleanups. Please expect some new edits tomorrow, probably a final .pet in two or three days, which should include a postinstall script to make the necessary backup of the original file and the symlink.

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#11 Post by Keef »

Karl,

Lack of console output partly my fauly, just ran probepart, not /sbin/probepart, although I would have thought it would work any way.
I had symlinked also. In the following, probepart1 is the original, and probepart2 is your version obviously.

Code: Select all

# /sbin/probepart1
/dev/sda1|ext2|24579386
/dev/sda2|ext2|22521856
/dev/sda3|ext3|28065554
/dev/sda4|swap|2972024
/dev/sdb1|ext3|7919982
# /sbin/probepart2
/dev/loop0|unknown|1125220352
/dev/loop1|ext2|2147483648
/dev/loop4|unknown|922779648
/dev/sda1|ext2|100677169152
/dev/sda2|ext2|92249522176
/dev/sda3|ext3|114956513280
/dev/sda4|swap|12173414400
/dev/sdb1|ext3|32440246272
/dev/sr0|not inserted|8589930496
After running it, pmount now shows other drives, but the CF card is first labelled as the 'optical' drive.
Once it is mounted, it becomes a 'usbdrive', but will revert to 'optical' when unmounted.

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

#12 Post by Karl Godt »

Keef, pmount is a little beast sometimes. Probably has changed a little since at least udf filesystem support had been added as far as I can see "#130128 support udf f.s." in /etc/rc.d/rc.shutdown .
pmount uses two scripts :
/sbin/probepart for the VALIDPARTS variable
and
/sbin/probedisk2 for the TABLIST variable .

At least for the Floppy drive tab :
I think, if you enable one or both floppy drives in the bios
and disconnect one or both of them
and do not change the entries in the bios,
then the bios tells the kernel that there are floppies enabled
and therefore the kernel floppy driver creates device entries in /sys/class/block and /sys/block,
and pmount script has "if [ -e /sys/block/fd0 ];then [..]" code block and therefore will create the floppy tab.

I have no CF card but I think, they are not too expensive and will get me one.

* Have edited the script 2nd time.

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#13 Post by Keef »

Here is the output from current version:

Code: Select all

# /sbin/probepart
/dev/loop0|squashfs|1125220352
/dev/loop1|ext2|2147483648
/dev/loop4|squashfs|922779648
/dev/sda1|ext2|100677169152
/dev/sda2|ext2|92249522176
/dev/sda3|ext3|114956513280
/dev/sda4|swap|12173414400
/dev/sdb1|ext3|32440246272
/dev/sr0|not inserted|8589930496
BusyBox v1.21.0 (2013-02-18 15:57:06 WST) multi-call binary.

Usage: mknod [-m MODE] NAME TYPE MAJOR MINOR

Create a special file (block, character, or pipe)

	-m MODE	Creation mode (default a=rw)
TYPE:
	b	Block device
	c or u	Character device
	p	Named pipe (MAJOR and MINOR are ignored)

BusyBox v1.21.0 (2013-02-18 15:57:06 WST) multi-call binary.

Usage: mknod [-m MODE] NAME TYPE MAJOR MINOR

Create a special file (block, character, or pipe)

	-m MODE	Creation mode (default a=rw)
TYPE:
	b	Block device
	c or u	Character device
	p	Named pipe (MAJOR and MINOR are ignored)
Running Pmount is as before, but the usbdrive (CF card in PCMCIA adapter), retains its status after unmounting. Previously it reverted to being listed as an optical drive.
No other ill-effects. Rox desktop drive icons all work as usual.

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

#14 Post by Karl Godt »

Keef, Thanks for reporting. Now found the same when a CD was not inserted, that the usbdrive aka SDcard reader showed as optical drive.

That is due to changing none to not inserted for cd drives. Will edit later to 'none or not inserted' .

And for the mknod it will be some tests for variables being only one row of major/minor , having no NULL value and greping only one time sr0 out of /proc/diskstats .

Keef, could you post the output of

Code: Select all

grep 'sr0' /proc/diskstats 
Attachments
pmount-hassle.jpg
OOPS that was not in my mind - funny, but more confusing
(29.27 KiB) Downloaded 573 times

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

#15 Post by Karl Godt »

Rewrote the code .
Running Barry's 2.6.31.14 IDE kernel right now,
have not yet tested on usual SATA kernels today.

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#16 Post by Keef »

As requested:

Code: Select all

# grep 'sr0' /proc/diskstats
  11       0 sr0 0 0 0 0 0 0 0 0 0 0 0
[/code]

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

#17 Post by Karl Godt »

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: Select all

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: Select all

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.

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#18 Post by Keef »

Current version:

Code: Select all

# 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.

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

probepart2.07

#19 Post by Karl Godt »

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: Select all

#!/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

Post Reply