List Computer Drives and Volume Informations

Linux specific forum
User avatar
DarkRookie
User
User
Posts: 20
Joined: Wed Nov 24, 2010 5:47 pm

List Computer Drives and Volume Informations

Post 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?
It is better to have a dumb question than a wrong answer!
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: List Computer Drives and Volume Informations

Post 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 
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: List Computer Drives and Volume Informations

Post 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
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: List Computer Drives and Volume Informations

Post 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.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: List Computer Drives and Volume Informations

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: List Computer Drives and Volume Informations

Post 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???
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: List Computer Drives and Volume Informations

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: List Computer Drives and Volume Informations

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: List Computer Drives and Volume Informations

Post 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 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: List Computer Drives and Volume Informations

Post 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  
Last edited by charvista on Sun Apr 22, 2012 12:31 am, edited 1 time in total.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: List Computer Drives and Volume Informations

Post 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:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply