It is currently Sat Oct 31, 2020 8:09 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How can I get disk Infos?
PostPosted: Wed Sep 09, 2020 3:36 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 523
At the moment I use diskutil info to get the media name and size of all disks.
Also disk which are not formatted or in a unknown format.

Is there a way to do it with the FileManager or something similar?


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Wed Sep 09, 2020 4:49 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3683
Location: Netherlands
Did you see this post from Shardik ?
https://www.purebasic.fr/english/viewto ... 35#p415435

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Wed Sep 09, 2020 5:35 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 523
[quote="wilbert"]Did you see this post from Shardik ?

No, I didn't see it, but I tried similar code yesterday and could find a way to list disks that are not in a read able format.

Code:
 CocoaMessage(0, FileManager, "mountedVolumeURLsIncludingResourceValuesForKeys:", KeyArray, "options:", 0)

lists disk which are already read able only, but not unformatted or unknown formats.


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Thu Sep 10, 2020 12:09 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3683
Location: Netherlands
Maybe you can use the DiskArbitration framework.

This uses DADiskCreateFromBSDName
https://www.purebasic.fr/german/viewtop ... 43#p328843

It might be possible you need the IOKit framework as well and use DADiskCreateFromIOMedia instead of DADiskCreateFromBSDName but I'm not sure.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Thu Sep 10, 2020 2:58 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 523
This works, but I wasn't able to get other objects for key.

How can I get the size of the device or partitions?


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Thu Sep 10, 2020 7:29 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1772
Location: Germany
Wolfram wrote:
This works, but I wasn't able to get other objects for key.

How can I get the size of the device or partitions?

I have just posted this example in the German forum.


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Thu Sep 10, 2020 8:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3683
Location: Netherlands
Nice example Shardik.

This is what I came up with (not as extended as your code).
Code:
ImportC "-framework DiskArbitration"
  DADiskCopyDescription(disk)
  DADiskCreateFromBSDName(allocator, session, name.p-ascii)
  DASessionCreate(allocator)
EndImport

Procedure.s GetStringForKey(Dictionary, Key.s)
  Protected.i Object, UTF8String
  Object = CocoaMessage(0, Dictionary, "objectForKey:$", @Key)
  If Object
    UTF8String = CocoaMessage(0, Object, "UTF8String")
    If UTF8String
      ProcedureReturn PeekS(UTF8String, -1, #PB_UTF8)
    EndIf
  EndIf
  ProcedureReturn #Null$
EndProcedure

Procedure.q GetQuadValueForKey(Dictionary, Key.s)
  Protected.i Value, ValueQ.q
  Value = CocoaMessage(0, Dictionary, "valueForKey:$", @Key)
  If Value
    CocoaMessage(@ValueQ, Value, "longLongValue")
    ProcedureReturn ValueQ
  EndIf
  ProcedureReturn #Null
EndProcedure



Session = DASessionCreate(#Null)
If Session
  DiskNumber = 0
  Repeat
    PartitionNumber = 1
    Repeat
      DiskName.s = "/dev/disk"+DiskNumber+"s"+PartitionNumber
      Disk = DADiskCreateFromBSDName(#Null, Session, DiskName)
      If Disk
        Dictionary = DADiskCopyDescription(Disk)
        If Dictionary
          Debug "BSDName: " + DiskName
          Debug "Device model: " + GetStringForKey(Dictionary, "DADeviceModel")
          Debug "Media name: " + GetStringForKey(Dictionary, "DAMediaName")
          Debug "Media size: " + GetQuadValueForKey(Dictionary, "DAMediaSize")
          Debug "Volume name: " + GetStringForKey(Dictionary, "DAVolumeName")
          Debug "Volume type: " + GetStringForKey(Dictionary, "DAVolumeType")
          Debug LSet("", 50, "-")
          CFRelease_(Dictionary)
          PartitionNumber + 1
        EndIf
        CFRelease_(Disk)
      EndIf
    Until Dictionary = #Null
    Disknumber + 1
  Until PartitionNumber = 1
  CFRelease_(Session)
EndIf


Some partitions return the same very large number for DAMediaSize.
I have no idea why. :?

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get disk Infos?
PostPosted: Thu Sep 10, 2020 8:45 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 523
Thank you both :D


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


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