Recent

Author Topic: [SOLVED] Parsing physical disk attributes similar to Gnome Disk Manager  (Read 7693 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Hi

I want to create some functionality that requires my program to list physical disk drives and their attributes to the user when my program is run in Linux Mint, Ubuntu environments etc in a similar way to how Gnome Disk Manager does it in Linux Mint (https://git.gnome.org/browse/gnome-disk-utility/) - see attached screenshot. i.e. Model number of the disk, manufacturer, serial number, as well as size, partitions, and so on.

So although I realise I could parse /etc/mtab and\or /etc/fstab as mentioned in http://forum.lazarus.freepascal.org/index.php/topic,15943.0.html for some info, most likely much of that would be "/dev/sda1..." etc; my needs are bit more specific about the attached disks.

I've looked through the C code of the GDM project, but regret that I can't actually work out what parts of Linux or what calls it is making to obtain this information. Is it querying SMART or something? If so, how?

Any ideas? Anyone had to do this before? Linux specifically.
« Last Edit: May 28, 2015, 10:43:47 pm by Gizmo »

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #1 on: May 27, 2015, 04:00:23 pm »
SMART isn't used to display that information. You probably need to use some external library or query the kernel/related daemons directly.

This link may help : http://stackoverflow.com/questions/200960/find-all-storage-devices-attached-to-a-linux-machine

garlar27

  • Hero Member
  • *****
  • Posts: 652

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #3 on: May 27, 2015, 05:06:29 pm »
(...) Gnome Disk Manager does it in Linux Mint (https://git.gnome.org/browse/gnome-disk-utility/) - see attached screenshot. i.e. Model number of the disk, manufacturer, serial number, as well as size, partitions, and so on.

I may be wrong but I think you can find that interrogating the disks structures in "/proc" or "/dev".
I'll try to check later at home where exactly is all that down there.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Signal

  • New Member
  • *
  • Posts: 41
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #4 on: May 27, 2015, 10:05:33 pm »

I may be wrong but I think you can find that interrogating the disks structures in "/proc" or "/dev".
I'll try to check later at home where exactly is all that down there.

You're not wrong.

Code: [Select]
$ cat /proc/diskstats
   8       0 sda 17226 3682 800219 89936 5380 7473 167088 57793 0 66950 148300
   8       1 sda1 102 0 1712 1280 0 0 0 0 0 1280 1280
   8       2 sda2 96 0 1648 1166 0 0 0 0 0 1156 1166
   8       3 sda3 2221 122 52114 8353 1955 2611 77632 25633 0 23216 33976
   8       4 sda4 191 15 3042 1250 266 199 3744 2540 0 3156 3790
   8       5 sda5 13331 3509 714266 68370 851 1504 19032 13386 0 34690 81746
   8       6 sda6 754 36 18730 6436 2165 3159 53904 15623 0 18083 22643
   8       7 sda7 135 0 2249 1023 32 0 4360 183 0 1156 1206
   8       8 sda8 133 0 2233 790 16 0 4208 106 0 890 896
   8       9 sda9 135 0 2249 930 16 0 4208 106 0 1030 1036

There is also /proc/mounts and /proc/partitions.

The man page is procfs.



Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #5 on: May 28, 2015, 04:55:30 pm »
Thanks for the suggestions, as always. But none of them show me anything I didn't already mention that I knew at the start. I want to be able to scan and then list details such as :

Manufacturer : Western Digital
Model Number : WD250-XXXX
Serial Number : 123456

just as Gnome-Disk-Utility does. I e-mailed the developer but no reply as yet.

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #6 on: May 28, 2015, 05:48:18 pm »
Some Ideas:

- Download SWAG and searh for somethin about disks... by example int 13h (int 13h interrupt)
- Filter output lshw.
- Filter output hwinfo.
- Filter output dmidecode (see DMI Specification).
- See SATA / PATA specifications (¿direct access to regitry ports?)
- hdparm http://www.cyberciti.biz/faq/linux-getting-scsi-ide-harddisk-information/

The last command show interesting information.
Be careful with direct calls to hardware. Under linux root rights may be required.

Best Regards.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

balazsszekely

  • Guest
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #7 on: May 28, 2015, 06:14:37 pm »
1. Download then install lsscsi utility(http://sg.danny.cz/scsi/lsscsi.html)
2. Run lsscsi with TProcess(http://wiki.freepascal.org/Executing_External_Programs
You can scan/display all the details you want, by passing different parameters(see documentation).

PS: I think this is the easiest solution, without going low level.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #8 on: May 28, 2015, 06:21:52 pm »
Easier, to get the drive model: read /proc/scsi/scsi
This is what it says in my laptop:
Code: [Select]
# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: ATA      Model: WDC WD1600BEVE-0 Rev: 01.0
  Type:   Direct-Access                    ANSI  SCSI revision: 05
Host: scsi1 Channel: 00 Id: 00 Lun: 00
  Vendor: MATSHITA Model: DVD-RAM UJ-820S  Rev: 1.50
  Type:   CD-ROM                           ANSI  SCSI revision: 05
Incidentally, to "make X like Y program does" ... just read the source! ;-)
« Last Edit: May 28, 2015, 06:24:47 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: Parsing physical disk attributes similar to Gnome Disk Manager
« Reply #9 on: May 28, 2015, 10:43:32 pm »
I've had a reply from one of the assistant developers of GDU which is a helpful pointer:

Quote
GNOME Disks gets all that information from udisks.
You should consider having your application use udisks to get
that information, though, since it probably does everything you want. I
think udisks_drive_get_model(), udisks_drive_get_serial(), and
udisks_drive_get_vendor() look interesting for you.
http://udisks.freedesktop.org/docs/latest/
http://cgit.freedesktop.org/udisks

Quote
to get the drive model: read /proc/scsi/scsi
Good find. That certainly gets some of the info needed that I can piece with the rest

Quote
... just read the source! ;-)
Always so irritating when people say that. See my first entry : "I've looked through the C code of the GDM project, but regret that I can't actually work out what parts of Linux or what calls it is making to obtain this information. "

Getmem - thanks for the suggestion but I need my program to be deployable standalone without the user being expected to get additional programs.

Given all the suggestions and replies I will mark the thread as solved. Thanks all.
« Last Edit: May 28, 2015, 10:45:30 pm by Gizmo »

paweld

  • Hero Member
  • *****
  • Posts: 1003
output from udevadm. sample inattachement.

EDIT: modify version in new post
« Last Edit: May 29, 2015, 12:19:16 am by paweld »
Best regards / Pozdrawiam
paweld

Gizmo

  • Hero Member
  • *****
  • Posts: 831
paweld : you're awesome!! Thanks man. That's superb. Good of you to take so much time to help....thanks again

paweld

  • Hero Member
  • *****
  • Posts: 1003
delete bug: not show pendrive
Best regards / Pozdrawiam
paweld

Gizmo

  • Hero Member
  • *****
  • Posts: 831
The following shows all the data we need and more - useful for a technical record of the disk :

udisks --show-info /dev/sdX (where X is a, b, c etc)

So I've added the following portion:
Code: [Select]
// Get all technical specifications about a user selected disk and save it
  DiskInfoProcessUDISKS := TProcess.Create(nil);
  DiskInfoProcessUDISKS.Options := [poWaitOnExit, poUsePipes];
  DiskInfoProcessUDISKS.CommandLine := 'udisks --show-info /dev/' + cbdisks.Text;
  DiskInfoProcessUDISKS.Execute;
  diskinfoUDISKS := TStringList.Create;
  diskinfoUDISKS.LoadFromStream(diskinfoProcessUDISKS.Output);
  diskinfoUDISKS.SaveToFile('TechnicalDiskDetails.txt');
« Last Edit: May 29, 2015, 12:46:33 am by Gizmo »

 

TinyPortal © 2005-2018