Page 1 of 1

List Computer Drives and Volume Informations

Posted: Thu Apr 21, 2011 7:20 pm
by DarkRookie
I saw code to do this On purearea but it all is windows specific.
Is there a way to do it in linux and be demo friendly?

Re: List Computer Drives and Volume Informations

Posted: Thu Apr 21, 2011 9:39 pm
by idle
look under /proc directory for the files partitions and mounts

Code: Select all

fn = ReadFile(#PB_Any,"/proc/partitions")
If fn 
  While Not Eof(fn)
   Debug ReadString(fn)
  Wend   
EndIf 
If fn 
  CloseFile(fn)
EndIf 

Re: List Computer Drives and Volume Informations

Posted: Wed Apr 27, 2011 12:08 pm
by Shardik
An alternative is to utilize the console command "df" and display volume
name, file system type, total space, free space, percentage used and
mount point (the space is displayed in "human readable" format using
the switch "-h", i.e. KB, MB, GB - whatever seems appropriate; if you
prefer to get all space values in the same notation, change "-h" against
"-B K" for KB, "-B M" for MB or "-B G" for GB):

Code: Select all

ProgramID = RunProgram("df", "-h -T", "", #PB_Program_Open | #PB_Program_Read)

If ProgramID
  While ProgramRunning(ProgramID)
    If AvailableProgramOutput(ProgramID)
      Output$ + ReadProgramString(ProgramID) + #CR$
    EndIf
  Wend
 
  CloseProgram(ProgramID)

  Debug Output$
EndIf

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 4:10 pm
by charvista
List Computer Drives and Volume Informations
DarkRookie wrote: I saw code to do this On purearea but it all is windows specific.
This is exactly what I need, the Windows specific code. I have not found it on purearea. Please, can you tell me where it is? Somewhere on http://www.purearea.net .....
Thanks.

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 4:24 pm
by ts-soft
charvista wrote:
List Computer Drives and Volume Informations
DarkRookie wrote: I saw code to do this On purearea but it all is windows specific.
This is exactly what I need, the Windows specific code. I have not found it on purearea. Please, can you tell me where it is? Somewhere on http://www.purearea.net .....
Thanks.
Here some routines from my old project:

Code: Select all

EnableExplicit

Structure DriveInfos
   DriveLetter.s
   DriveType.l
   NameOfVolume.s
EndStructure

Global NewList Drives.DriveInfos()

Procedure CountDrives()
  Protected AllDriveNames.s, Size, i, *pAllDriveNames
  
  Size = GetLogicalDriveStrings_(0, @AllDriveNames)
  AllDriveNames = Space(Size)
  Size = GetLogicalDriveStrings_(Size, @AllDriveNames)

  ProcedureReturn Size / 4
EndProcedure

Procedure SearchDrives()
  Protected AllDriveNames.s, Size, Count, i, *pAllDriveNames
  ClearList(Drives())
  Size = GetLogicalDriveStrings_(0, @AllDriveNames)
  AllDriveNames = Space(Size)
  Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
  *pAllDriveNames = @AllDriveNames
  Count = Size / 4
  For i = 1 To Count
    AddElement(Drives())
    Drives()\DriveLetter = LCase(PeekS(*pAllDriveNames, 3))
    *pAllDriveNames + (4 * SizeOf(Character))
    Drives()\NameOfVolume = Space(#MAX_PATH)
    Drives()\DriveType = GetDriveType_(@Drives()\DriveLetter)
    If Drives()\DriveType = #DRIVE_FIXED
      GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, 0, 0, 0, 0, 0)
    EndIf
  Next
EndProcedure

Debug CountDrives()
Debug "....."
SearchDrives()
ForEach Drives()
  Debug Drives()\DriveLetter
  Debug Drives()\DriveType
  Debug Drives()\NameOfVolume
  Debug "......."
Next

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 4:51 pm
by charvista
Thanks Thomas, it gets local hard disks and USB external disks with its label name.
But, it does not take CD's in consideration???

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 4:58 pm
by ts-soft
The read from CD is to slow for my program but you can change this:
line 35:

Code: Select all

    If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
      GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, 0, 0, 0, 0, 0)
    EndIf

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 5:07 pm
by charvista
Works like a charm! :D
Now I have the Drive Letter, the Label Name, and the Drive Type. Is there also a variable for the Serial Number?
After that it will be complete I think :) Or is there more to get? :mrgreen:

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 5:29 pm
by ts-soft
charvista wrote:Works like a charm! :D
thx
charvista wrote:Or is there more to get? :mrgreen:
I don't now

Code: Select all

EnableExplicit

Structure DriveInfos
   DriveLetter.s
   DriveType.l
   NameOfVolume.s
   DriveSerial.s
EndStructure

Global NewList Drives.DriveInfos()

Procedure CountDrives()
  Protected AllDriveNames.s, Size, i, *pAllDriveNames
 
  Size = GetLogicalDriveStrings_(0, @AllDriveNames)
  AllDriveNames = Space(Size)
  Size = GetLogicalDriveStrings_(Size, @AllDriveNames)

  ProcedureReturn Size / 4
EndProcedure

Procedure SearchDrives()
  Protected AllDriveNames.s, Size, Count, i, *pAllDriveNames, lpVolumeSerialNumber
  ClearList(Drives())
  Size = GetLogicalDriveStrings_(0, @AllDriveNames)
  AllDriveNames = Space(Size)
  Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
  *pAllDriveNames = @AllDriveNames
  Count = Size / 4
  For i = 1 To Count
    AddElement(Drives())
    Drives()\DriveLetter = LCase(PeekS(*pAllDriveNames, 3))
    *pAllDriveNames + (4 * SizeOf(Character))
    Drives()\NameOfVolume = Space(#MAX_PATH)
    Drives()\DriveType = GetDriveType_(@Drives()\DriveLetter)
    If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
      GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, @lpVolumeSerialNumber, 0, 0, 0, 0)
    EndIf
    If Drives()\DriveType = #DRIVE_FIXED
      Drives()\DriveSerial = Hex(PeekW(@lpVolumeSerialNumber + 2) & $FFFF) + "-" + Hex(PeekW(@lpVolumeSerialNumber) & $FFFF)
    EndIf    
  Next
EndProcedure

Debug CountDrives()
Debug "....."
SearchDrives()
ForEach Drives()
  Debug Drives()\DriveLetter
  Debug Drives()\DriveType
  Debug Drives()\NameOfVolume
  Debug Drives()\DriveSerial
  Debug "......."
Next 

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 5:55 pm
by charvista
:arrow: Serial Number is also working like a charm! :D
It also works on CDs, but there, some attention should be paid. I have a CD put in drive D: and it returns its SSN. OK. But there is also a CDROM found in H:, which is not connected, but H: returns the SSN of D:.
If I remove the CD from D:, D: and H: both return the SSN of C:
I conclude that it is best to use the SSN only if a label is found on the CD, when the type is #DRIVE_CDROM.
Many thanks for your help, Thomas!


EDIT
I know why the Serial Number is incorrectly given.
The variable lpVolumeSerialNumber has to be set to 0 before calling the API GetVolumeInformation_()

Code: Select all

        If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
            lpVolumeSerialNumber=0
            GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, @lpVolumeSerialNumber, 0, 0, 0, 0)
            Drives()\DriveSerial = Hex(PeekW(@lpVolumeSerialNumber + 2) & $FFFF) + "-" + Hex(PeekW(@lpVolumeSerialNumber) & $FFFF)
        EndIf  

Re: List Computer Drives and Volume Informations

Posted: Sat Apr 21, 2012 6:23 pm
by ts-soft
CD-ROMs to i couldn't say much, since I have a few years ago exploded a CD in the drives, I use a CD only once, in order to transfer it to the hard drive. Is a slow and loud medium.

Enough offtopic, back to linux :wink: