* * *

Author Topic: Get list of drives  (Read 1673 times)

T-bear

  • Full Member
  • ***
  • Posts: 158
Get list of drives
« on: February 03, 2012, 01:09:52 pm »
How can i in lazarus get a list of all drives connected to a computer. I saw on some delphi pages a procedure "GetDriveType" does this exist in lazarus too, or is there something similar?
TY!

BigChimp

  • Hero Member
  • *****
  • Posts: 1012
    • CheckRide remote control and other open source projects
Re: Get list of drives
« Reply #1 on: February 03, 2012, 02:08:45 pm »
CheckRide remote control and other open source projects:
https://bitbucket.org/reiniero/

TurboRascal

  • Sr. Member
  • ****
  • Posts: 457
  • "Good sysadmin. Bad programmer."™
Re: Get list of drives
« Reply #2 on: February 10, 2012, 12:20:11 am »
Interesting. Is there some example how to enumerate filesystems in unixes? Like 'mount' (or 'df)'command does...
Regards, Arny the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

timppl

  • New member
  • *
  • Posts: 26
Re: Get list of drives
« Reply #3 on: February 10, 2012, 08:59:04 am »
Simply read /etc/mtab; it shows all mounted drives ( strictly it shows all mounts ) .

Regards

Tim

BigChimp

  • Hero Member
  • *****
  • Posts: 1012
    • CheckRide remote control and other open source projects
Re: Get list of drives
« Reply #4 on: February 10, 2012, 09:58:18 am »
Tim, do you know whether that will that work on Solaris, FreeBSD, OSX as well?
CheckRide remote control and other open source projects:
https://bitbucket.org/reiniero/

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3162
Re: Get list of drives
« Reply #5 on: February 10, 2012, 11:33:58 am »
Simply read /etc/mtab; it shows all mounted drives ( strictly it shows all mounts ) .

Nice, I have put it in the wiki in a new page for linux tips: http://wiki.lazarus.freepascal.org/Linux_Programming_Tips#Get_the_list_of_mounted_partitions

TurboRascal

  • Sr. Member
  • ****
  • Posts: 457
  • "Good sysadmin. Bad programmer."™
Re: Get list of drives
« Reply #6 on: February 10, 2012, 04:39:55 pm »
Simply read /etc/mtab; it shows all mounted drives ( strictly it shows all mounts ) .

Thanks, I cannot believe I forgot about it!  :-[ Simple and effective...
Tim, do you know whether that will that work on Solaris, FreeBSD, OSX as well?

AFAIK it should work with all unix-like systems, IIRC it's a Unix SysV thing...

Nice, I have put it in the wiki in a new page for linux tips:
...

Great idea to finally have one for linux too  :)
Regards, Arny the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

ludob

  • Hero Member
  • *****
  • Posts: 623
Re: Get list of drives
« Reply #7 on: February 10, 2012, 05:07:46 pm »
Tim, do you know whether that will that work on Solaris, FreeBSD, OSX as well?

AFAIK it should work with all unix-like systems, IIRC it's a Unix SysV thing...

On Solaris 10 it is in /etc/mnttab. Also note that on Solaris a lot of stuff is mounted, including /lib/libc.so.1 and  /etc/mnttab itself  :)

benohb

  • New member
  • *
  • Posts: 31
Re: Get list of drives
« Reply #8 on: February 11, 2012, 07:04:01 am »
Code: [Select]
Simply read /etc/mtab; it shows all mounted drives ( strictly it shows all mounts ) .

This is a mistake
Mtab contains information for * how to mount FS*


For a list of devices on Linux ... Explore

Quote
/proc
You will find all the details
Example :

for All parts

Code: [Select]
/proc/partitions

mounted
Code: [Select]
/proc/mounts

Information Processor
Code: [Select]
/proc/cpuinfo

Memory information
Code: [Select]
/proc/meminfo

Network
Code: [Select]
/proc/self/net/arp
Input devices
Code: [Select]
/proc/bus/input/devices

More
Quote
/proc/sys


largely (/proc) Contains all the information system and logistics and drivers ...And many... 8)
http://www.thegeekstuff.com/2010/11/linux-proc-file-system/
« Last Edit: February 11, 2012, 07:17:53 am by benohb »

ludob

  • Hero Member
  • *****
  • Posts: 623
Re: Get list of drives
« Reply #9 on: February 11, 2012, 08:26:26 am »
This is a mistake
Mtab contains information for * how to mount FS*
Hmm.
* how to mount FS* = fstab
* what is mounted* = mtab

From 'man mount':
Quote
The programs mount and umount maintain a list of currently mounted filesystems in the file /etc/mtab. If no arguments are given to mount, this list is printed.
Quote
When the proc filesystem is mounted (say at /proc), the files /etc/mtab and /proc/mounts have very similar contents.

TurboRascal

  • Sr. Member
  • ****
  • Posts: 457
  • "Good sysadmin. Bad programmer."™
Re: Get list of drives
« Reply #10 on: February 11, 2012, 08:15:32 pm »
Also mtab can be used on many different unix OS-es, while linux procfs is, well, linux specific...
Regards, Arny the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

BigChimp

  • Hero Member
  • *****
  • Posts: 1012
    • CheckRide remote control and other open source projects
Re: Get list of drives
« Reply #11 on: February 11, 2012, 08:39:11 pm »
Also mtab can be used on many different unix OS-es, while linux procfs is, well, linux specific...
Though apparently not in Solaris (see above) or FreeBSD (if this http://onlamp.com/pub/a/bsd/2005/01/13/FreeBSD_Basics.html is still correct) or AIX (found some old forum post asking for that; may have been fixed meanwhile, and FPC doesn't have an AIX port anyway ;)

Would parsing the output of mount be any better? I suspect various *nix flavours will have various output formats as well...
CheckRide remote control and other open source projects:
https://bitbucket.org/reiniero/

TurboRascal

  • Sr. Member
  • ****
  • Posts: 457
  • "Good sysadmin. Bad programmer."™
Re: Get list of drives
« Reply #12 on: February 11, 2012, 08:45:59 pm »
Well, it is true that various unixes have traditionally done the same things differently :)

I would avoid calling external programs if possible, however. I'd still prefer to parse different files configured with ifdefs because their formats are different as well, like you said (at the very least the disk device names are different).

Now I wonder if there exists a POSIX standard for this...
Regards, Arny the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

benohb

  • New member
  • *
  • Posts: 31
Re: Get list of drives
« Reply #13 on: February 11, 2012, 09:42:23 pm »
Quote
Hmm.
* how to mount FS* = fstab
* what is mounted* = mtab

That's right , I did not  attention to the letters  :-X



But sometimes .. There are no partition  in  fstab
This means manually  mount 


Code: [Select]
Now I wonder if there exists a POSIX standard for this...

May be different places .. but these systems easy access to information services

ludob

  • Hero Member
  • *****
  • Posts: 623
Re: Get list of drives
« Reply #14 on: February 12, 2012, 08:36:50 am »
A quick look in the source code of df shows that the list of mounted drives is retrieved with the getmntent family of functions. Docs for getmntent specify the use of /etc/mtab or /etc/mnttab as the source of info.
The use of getmntent et.al. doesn't make life easier. A lot of function name and parameter variations exist. The file mountlist.c (http://siarzhuk.dyndns.org/haiku/doxygen/coreutils_2lib_2mountlist_8c_source.html) shows how the mount list is retrieved on all systems supported by gnu df. Basically a different method for every unix flavor ...

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads