It is currently Sun May 19, 2013 6:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: List Computer Drives and Volume Informations
PostPosted: Thu Apr 21, 2011 7:20 pm 
Offline
User
User

Joined: Wed Nov 24, 2010 5:47 pm
Posts: 12
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!


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Thu Apr 21, 2011 9:39 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 2484
Location: New Zealand
look under /proc directory for the files partitions and mounts

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


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Wed Apr 27, 2011 12:08 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 813
Location: Germany
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:
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


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 4:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 702
Location: Belgium (& Luxembourg)
Quote:
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.

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 4:24 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4714
Location: Berlin - Germany
charvista wrote:
Quote:
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:
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.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 4:51 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 702
Location: Belgium (& Luxembourg)
Thanks Thomas, it gets local hard disks and USB external disks with its label name.
But, it does not take CD's in consideration???

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 4:58 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4714
Location: Berlin - Germany
The read from CD is to slow for my program but you can change this:
line 35:
Code:
    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.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 5:07 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 702
Location: Belgium (& Luxembourg)
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:

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 5:29 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4714
Location: Berlin - Germany
charvista wrote:
Works like a charm! :D
thx
charvista wrote:
Or is there more to get? :mrgreen:

I don't now
Code:
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.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 5:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Tue Sep 23, 2008 11:38 pm
Posts: 702
Location: Belgium (& Luxembourg)
: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:
        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 

_________________
- Future conversation forecasting not yet implemented.
- If the future had copied a program from now, they would have called it version -1.


Last edited by charvista on Sun Apr 22, 2012 12:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: List Computer Drives and Volume Informations
PostPosted: Sat Apr 21, 2012 6:23 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 4714
Location: Berlin - Germany
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.11 | Windows 7 SP1 (x64) | Linux Mint 14 (x64) | RealSource

The use of EnableExplicit is free of charge and avoids errors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye