pkg/pillar/vendor/github.com/shirou/gopsutil/disk/disk_darwin.h
int ReadDiskInfo(DiskInfo *info)
{
    // Parent props. Allocated by us.
    CFDictionaryRef parentProps = NULL;

    // Disk props. Allocated by us.
    CFDictionaryRef diskProps = NULL;

    // Disk stats, fetched by us, but not allocated by us.
    CFDictionaryRef stats = NULL;

    if (IORegistryEntryCreateCFProperties(diskEntry, (CFMutableDictionaryRef *)&parentProps,
                                          kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
    {
        // can't get parent props, give up
        CFRelease(parentProps);
        IOObjectRelease(diskEntry);
        IOObjectRelease(parentEntry);
        return -1;
    }

    if (IORegistryEntryCreateCFProperties(parentEntry, (CFMutableDictionaryRef *)&diskProps,
                                          kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
    {
        // can't get disk props, give up
        CFRelease(parentProps);
        CFRelease(diskProps);
        IOObjectRelease(diskEntry);
        IOObjectRelease(parentEntry);
        return -1;
    }

    // Start fetching
    CFStringRef cfDiskName = (CFStringRef)CFDictionaryGetValue(parentProps, CFSTR(kIOBSDNameKey));
    CFStringGetCString(cfDiskName, info->DiskName, MAX_DISK_NAME, CFStringGetSystemEncoding());
    stats = (CFDictionaryRef)CFDictionaryGetValue( diskProps, CFSTR(kIOBlockStorageDriverStatisticsKey));

    if (stats == NULL) {
        // stat fetch failed...
        CFRelease(parentProps);
        CFRelease(diskProps);
        IOObjectRelease(parentEntry);
        IOObjectRelease(diskEntry);
        return -1;
    }

    CFNumberRef cfnum;

    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsReadsKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->Reads);
    } else {
        info->Reads = 0;
    }

    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsWritesKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->Writes);
    } else {
        info->Writes = 0;
    }

    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->ReadBytes);
    } else {
        info->ReadBytes = 0;
    }

    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->WriteBytes);
    } else {
        info->WriteBytes = 0;
    }

    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsTotalReadTimeKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->ReadTime);
    } else {
        info->ReadTime = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsTotalWriteTimeKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->WriteTime);
    } else {
        info->WriteTime = 0;
    }

    // note: read/write time are in ns, but we want ms.
    info->ReadTime = info->ReadTime / 1000 / 1000;
    info->WriteTime = info->WriteTime / 1000 / 1000;

    CFRelease(parentProps);
    CFRelease(diskProps);
    IOObjectRelease(parentEntry);
    IOObjectRelease(diskEntry);
    return 0;
}
// Reads the current disk (from iteration) info into DiskInfo struct.
// Once done, all resources from the current iteration of reading are freed,
// ready for FetchNextDisk() to be called again.
Reads the current disk (from iteration) info into DiskInfo struct.
Once done, all resources from the current iteration of reading are freed,
ready for FetchNextDisk() to be called again.
Reads the current disk ( from iteration ) info into DiskInfo struct . Once done all resources from the current iteration of reading are freed ready for FetchNextDisk () to be called again .
int ReadDiskInfo(DiskInfo *info)
{
    CFDictionaryRef parentProps = NULL;
    CFDictionaryRef diskProps = NULL;
    CFDictionaryRef stats = NULL;
    if (IORegistryEntryCreateCFProperties(diskEntry, (CFMutableDictionaryRef *)&parentProps,
                                          kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
    {
        CFRelease(parentProps);
        IOObjectRelease(diskEntry);
        IOObjectRelease(parentEntry);
        return -1;
    }
    if (IORegistryEntryCreateCFProperties(parentEntry, (CFMutableDictionaryRef *)&diskProps,
                                          kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
    {
        CFRelease(parentProps);
        CFRelease(diskProps);
        IOObjectRelease(diskEntry);
        IOObjectRelease(parentEntry);
        return -1;
    }
    CFStringRef cfDiskName = (CFStringRef)CFDictionaryGetValue(parentProps, CFSTR(kIOBSDNameKey));
    CFStringGetCString(cfDiskName, info->DiskName, MAX_DISK_NAME, CFStringGetSystemEncoding());
    stats = (CFDictionaryRef)CFDictionaryGetValue( diskProps, CFSTR(kIOBlockStorageDriverStatisticsKey));
    if (stats == NULL) {
        CFRelease(parentProps);
        CFRelease(diskProps);
        IOObjectRelease(parentEntry);
        IOObjectRelease(diskEntry);
        return -1;
    }
    CFNumberRef cfnum;
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsReadsKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->Reads);
    } else {
        info->Reads = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsWritesKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->Writes);
    } else {
        info->Writes = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->ReadBytes);
    } else {
        info->ReadBytes = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->WriteBytes);
    } else {
        info->WriteBytes = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsTotalReadTimeKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->ReadTime);
    } else {
        info->ReadTime = 0;
    }
    if ((cfnum = (CFNumberRef)CFDictionaryGetValue(stats, CFSTR(kIOBlockStorageDriverStatisticsTotalWriteTimeKey)))) {
        CFNumberGetValue(cfnum, kCFNumberSInt64Type, &info->WriteTime);
    } else {
        info->WriteTime = 0;
    }
    info->ReadTime = info->ReadTime / 1000 / 1000;
    info->WriteTime = info->WriteTime / 1000 / 1000;
    CFRelease(parentProps);
    CFRelease(diskProps);
    IOObjectRelease(parentEntry);
    IOObjectRelease(diskEntry);
    return 0;
}
int ReadDiskInfo ( DiskInfo * info ) { CFDictionaryRef parentProps = NULL ; CFDictionaryRef diskProps = NULL ; CFDictionaryRef stats = NULL ; if ( IORegistryEntryCreateCFProperties ( diskEntry , ( CFMutableDictionaryRef * ) & parentProps , kCFAllocatorDefault , kNilOptions ) != kIOReturnSuccess ) { CFRelease ( parentProps ) ; IOObjectRelease ( diskEntry ) ; IOObjectRelease ( parentEntry ) ; return -1 ; } if ( IORegistryEntryCreateCFProperties ( parentEntry , ( CFMutableDictionaryRef * ) & diskProps , kCFAllocatorDefault , kNilOptions ) != kIOReturnSuccess ) { CFRelease ( parentProps ) ; CFRelease ( diskProps ) ; IOObjectRelease ( diskEntry ) ; IOObjectRelease ( parentEntry ) ; return -1 ; } CFStringRef cfDiskName = ( CFStringRef ) CFDictionaryGetValue ( parentProps , CFSTR ( kIOBSDNameKey ) ) ; CFStringGetCString ( cfDiskName , info -> DiskName , MAX_DISK_NAME , CFStringGetSystemEncoding ( ) ) ; stats = ( CFDictionaryRef ) CFDictionaryGetValue ( diskProps , CFSTR ( kIOBlockStorageDriverStatisticsKey ) ) ; if ( stats == NULL ) { CFRelease ( parentProps ) ; CFRelease ( diskProps ) ; IOObjectRelease ( parentEntry ) ; IOObjectRelease ( diskEntry ) ; return -1 ; } CFNumberRef cfnum ; if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsReadsKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> Reads ) ; } else { info -> Reads = 0 ; } if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsWritesKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> Writes ) ; } else { info -> Writes = 0 ; } if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsBytesReadKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> ReadBytes ) ; } else { info -> ReadBytes = 0 ; } if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsBytesWrittenKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> WriteBytes ) ; } else { info -> WriteBytes = 0 ; } if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsTotalReadTimeKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> ReadTime ) ; } else { info -> ReadTime = 0 ; } if ( ( cfnum = ( CFNumberRef ) CFDictionaryGetValue ( stats , CFSTR ( kIOBlockStorageDriverStatisticsTotalWriteTimeKey ) ) ) ) { CFNumberGetValue ( cfnum , kCFNumberSInt64Type , & info -> WriteTime ) ; } else { info -> WriteTime = 0 ; } info -> ReadTime = info -> ReadTime / 1000 / 1000 ; info -> WriteTime = info -> WriteTime / 1000 / 1000 ; CFRelease ( parentProps ) ; CFRelease ( diskProps ) ; IOObjectRelease ( parentEntry ) ; IOObjectRelease ( diskEntry ) ; return 0 ; }
Reads the current disk (from iteration) info into DiskInfo struct.
Reads the current disk ( from iteration ) info into DiskInfo struct .
// Parent props. Allocated by us. // Disk props. Allocated by us. // Disk stats, fetched by us, but not allocated by us. // can't get parent props, give up // can't get disk props, give up // Start fetching // stat fetch failed... // note: read/write time are in ns, but we want ms.