Get list of mounted drives?

Linux specific forum
garretthylltun
Enthusiast
Enthusiast
Posts: 346
Joined: Wed Oct 26, 2005 2:46 am
Contact:

Get list of mounted drives?

Post by garretthylltun »

Anybody know how to get a list of mounted drives via PureBasic, or
by polling another app and redirecting the output to a PureBasic app?

Thanks,
-Garrett
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
· Necroprogramming FTW! - "Wait.. Is necroprogramming legal?"
· http://www.freewarehome.com/ <-- Freeware listings since 1996
Beach
Enthusiast
Enthusiast
Posts: 677
Joined: Mon Feb 02, 2004 3:16 am
Location: Beyond the sun...

Post by Beach »

You could pipe the output of 'mount'. Here is an example:

Code: Select all

Procedure.s ConsoleCommand(Command$)

    Output$ = ""
    Pipe = popen_(Command$, "r")
    If Pipe
    
      *Buffer = AllocateMemory(2000)
      If *Buffer
    
        Repeat
          result = fgets_(*Buffer, 2000, Pipe)
          If result         
            Output$ + PeekS(*Buffer)         
          EndIf
        Until result = 0
    
      EndIf
    
      pclose_(Pipe)
    EndIf
    
    ProcedureReturn Output$

EndProcedure

mount$ = ConsoleCommand("mount")
Got this from Freak and I use it all the time... Thanks again Freak!

:)
Ramihyn_
Enthusiast
Enthusiast
Posts: 314
Joined: Fri Feb 24, 2006 9:40 am

Post by Ramihyn_ »

Parse /etc/mtab - for a list including unmounted devices parse /etc/fstab

(/etc/fstab completeness depends on the installation)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

i recently downloaded the linux beta, and started to play with this.....
and since i'm new to linux programming, it surprised me when i actually got it to work!

Code: Select all

Structure mntent
mnt_fsname.s
mnt_dir.s
mnt_type.s
mnt_opts.s
mnt_freq.l ; may not be right data type
mnt_passno.l ; may not be right data type
EndStructure

mtab = setmntent_("/etc/mtab", "r")
If mtab
  *info.mntent
  pointer = getmntent_(mtab)
  While pointer
    *info = pointer
    Debug *info\mnt_fsname
    Debug *info\mnt_dir
    Debug *info\mnt_type
    Debug *info\mnt_opts
    Debug "---------"
    pointer = getmntent_(mtab)
  Wend
  endmntent_(mtab)
EndIf
but it only works in ASCII mode (or is that the same with all 'linux api' commands?)
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply