which flag of DiskArbitration is to indicate the external drive

Hi Experts,


I know kDADiskDescriptionDeviceInternalKey of DiskArbitration is to identify the internal drive, right?

I wonder which flag is for external drive? kDADiskDescriptionMediaEjectableKey or kDADiskDescriptionMediaRemovableKey?

Thanks!

Replies

I wonder which flag is for external drive?

If it’s not internal, it’s external, right?

kDADiskDescriptionMediaEjectableKey
or
kDADiskDescriptionMediaRemovableKey
?

No, these mean what they say, and neither of those words has anything to do with the notion of ‘internal’ versus ‘external’.

Using the ‘not internal’ approach is a fine starting place but it’s just that. The critical next step here is to clarify your goals. What exactly do you mean by an “external drive”? For example:

  • If I mount a disk image, is that external or internal? Does it matter where the disk image is mounted from?

  • If I have a RAID set where some of the members are internal drives and some are external, what’s that?

If you can explain more about what decisions you’re planning to make based on this query, I may be able to offer more specific guidance.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks very much, Eskimo!

I am developing an application that uses disk arbitration to find out which devices are connected to a machine and react to connect/disconnect events.


/dev/disk0 (internal):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                         1.0 TB     disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         1.0 TB     disk0s2


/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +1.0 TB     disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            509.7 GB   disk1s1
   2:                APFS Volume Preboot                 44.5 MB    disk1s2
   3:                APFS Volume Recovery                513.5 MB   disk1s3
   4:                APFS Volume VM                      2.1 GB     disk1s4


/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *1.0 TB     disk2
   1:               Windows_NTFS TOSHIBA EXT             1.0 TB     disk2s1


/dev/disk3 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +10.1 MB    disk3
   1:                  Apple_HFS File Transfer   10.0 MB    disk3s1


As the output of Disktutil above, I assume all ejectable drivers are the external drives(such as .dmg, CD/DVD drives, external hard drive...), so I can use kDADiskDescriptionMediaEjectableKey to identify them as below? or any other way?

ASessionRef session = DASessionCreate(NULL);
if (session) {
    disk = DADiskCreateFromBSDName(NULL, session, "/dev/disk2s1");
    if (disk) {
        descDict = DADiskCopyDescription(disk);
        if (descDict) {
            object = CFDictionaryGetValue(description, kDADiskDescriptionMediaEjectableKey);
            if (object) {
                if (object == kCFBooleanTrue) {
                    return true;
                }
            }
        }
    }
}


As you mentioned, I can use kDADiskDescriptionDeviceInternalKey to identify the local driver, so I can also use ‘not internal’ to replace the above approach?

If a drive isn't internal and it isn't network and it isn't simulated (dmg) it must be external, correct?