Page 1 of 1

Get list of mounted drives?

Posted: Mon Sep 18, 2006 6:34 am
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

Posted: Mon Sep 18, 2006 6:52 am
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!

:)

Posted: Mon Oct 02, 2006 11:50 am
by Ramihyn_
Parse /etc/mtab - for a list including unmounted devices parse /etc/fstab

(/etc/fstab completeness depends on the installation)

Posted: Sun Oct 29, 2006 6:17 am
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?)