On 08/06/2010 01:27 PM, Matthew Dillon wrote:
:Hi people,
:
:is there a way to easily list all disks and their associated serno's ?
:Something like 'blkid' utility of Linux, if you happen to know it.
:I could happily hack something like that, if we lack it.
:
:
:Cheers,
:Stathis

    There isn't, and that would be cool.  It is fairly easy to match
    up device numbers from devfs.

    You can use sysctl kern.disks output to get a list of disk devices,
    then you can scan /dev and pick those base names out and stat them,
    and you can scan /dev/serno and stat those babies and match up
    the st_rdev's with the ones from /dev to getting related serial
    numbers.

    If we wanted to get more involved we could add an ioctl() to retrieve
    the serial number (if available), but it can definitely be scripted
    right now without that.

                                        -Matt
                                        Matthew Dillon
                                        <dil...@backplane.com>

I started a utility a while back going down a different path, I have now changed it to use the sysctl call like Matt pointed out. This is my first attempt to contribute a utility to DragonFly (or any project) so I'm looking for feedback.
I have more error checking to add.

I was not sure the best place for the code, so I created a new empty branch [devserno] on my leaf account with the code.
http://gitweb.dragonflybsd.org/~dylan/dragonfly.git/commit/refs/heads/devserno
And a tarball
http://leaf.dragonflybsd.org/~dylan/devserno.tar.gz

The program reads the rdev's from all files in /dev/serno (excluding any with a .) then reads the sysctl kern.disk and prints out the matches.

This is the output from my system :
$ ./devserno
DEVICE          SERNO
/dev/ad2        05008023
/dev/ad4        JPB530HN256PBB
/dev/ad6        WD-WXEZ07T50371

Regards,
Dylan

Reply via email to