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?
How can I get disk Infos?
How can I get disk Infos?
macOS Catalina 10.15.7
Re: How can I get disk Infos?
Did you see this post from Shardik ?
viewtopic.php?p=415435#p415435
viewtopic.php?p=415435#p415435
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: How can I get disk Infos?
[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.
lists disk which are already read able only, but not unformatted or unknown formats.
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: Select all
CocoaMessage(0, FileManager, "mountedVolumeURLsIncludingResourceValuesForKeys:", KeyArray, "options:", 0)
macOS Catalina 10.15.7
Re: How can I get disk Infos?
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.
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.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: How can I get disk Infos?
This works, but I wasn't able to get other objects for key.
How can I get the size of the device or partitions?
How can I get the size of the device or partitions?
macOS Catalina 10.15.7
Re: How can I get disk Infos?
I have just posted this example in the German forum.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?
Re: How can I get disk Infos?
Nice example Shardik.
This is what I came up with (not as extended as your code).
Some partitions return the same very large number for DAMediaSize.
I have no idea why.
This is what I came up with (not as extended as your code).
Code: Select all
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
I have no idea why.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)