I need to get from C or from a script info for hard drives and usb sticks.
I get installed disks with:
Then for a hard drive is simple:
I would get:
Here I have all info I need.
The problem arise when I use usb sticks or hot swapable hard drives.
If I connect for example a 2G USB stick and then I remove it and I connect a 8G USB stick I will have two entries with da0 name, and knowing that my devices is da0 does not help because I don't know in /var/run/dmesg.boot which of them (the 2G one or the 8G one) is installed.
Also I am using head -n 1 for hard drives but for usb sticks the sizeinfo is on third line:
Also da0 could be a SCSI drive in which case rules from hard drives applies (info on first line, not third).
So is there a way to know drive manufacturer/USB String-manufacturer by using only drive name that will apply to: IDE/SATA drives, SCSI/SAS drives and usb flashes?
I get installed disks with:
Code:
sysctl kern.disks
Then for a hard drive is simple:
Code:
egrep ad6: /var/run/dmesg.boot | head -n1
I would get:
Code:
ad6: 152627MB <WDC WD1600JS-22NCB1 10.02E02> at ata3-master UDMA100 SATA 3Gb/s
Here I have all info I need.
The problem arise when I use usb sticks or hot swapable hard drives.
If I connect for example a 2G USB stick and then I remove it and I connect a 8G USB stick I will have two entries with da0 name, and knowing that my devices is da0 does not help because I don't know in /var/run/dmesg.boot which of them (the 2G one or the 8G one) is installed.
Also I am using head -n 1 for hard drives but for usb sticks the sizeinfo is on third line:
Code:
da0: <Generic USB Flash Disk 0.00> Removable Direct Access SCSI-2 device
da0: 1.000MB/s transfers
da0: 1927MB (3948543 512 byte sectors: 255H 63S/T 245C)
Also da0 could be a SCSI drive in which case rules from hard drives applies (info on first line, not third).
So is there a way to know drive manufacturer/USB String-manufacturer by using only drive name that will apply to: IDE/SATA drives, SCSI/SAS drives and usb flashes?