bool IORangeAllocator::serialize(OSSerialize *s) const { OSArray * array = OSArray::withCapacity( numElements * 2 ); OSNumber * num; UInt32 index; bool ret; if( !array) return( false ); LOCK(); for( index = 0; index < numElements; index++) { if( (num = OSNumber::withNumber( elements[index].start, 8 * sizeof(IORangeScalar) ))) { array->setObject(num); num->release(); } if( (num = OSNumber::withNumber( elements[index].end, 8 * sizeof(IORangeScalar) ))) { array->setObject(num); num->release(); } } UNLOCK(); ret = array->serialize(s); array->release(); return( ret ); }
OSDictionary * AppleIntelPIIXATARoot::createChannelInfo( UInt32 ataChannel, UInt32 channelMode, UInt16 commandPort, UInt16 controlPort, UInt8 interruptVector ) { OSDictionary * dict = OSDictionary::withCapacity( 4 ); OSNumber * num; if ( dict == 0 || commandPort == 0 || controlPort == 0 || interruptVector == 0 || interruptVector == 0xFF ) { if ( dict ) dict->release(); return 0; } num = OSNumber::withNumber( ataChannel, 32 ); if (num) { dict->setObject( kChannelNumberKey, num ); num->release(); } num = OSNumber::withNumber( commandPort, 16 ); if (num) { dict->setObject( kCommandBlockAddressKey, num ); num->release(); } num = OSNumber::withNumber( controlPort, 16 ); if (num) { dict->setObject( kControlBlockAddressKey, num ); num->release(); } num = OSNumber::withNumber( interruptVector, 8 ); if (num) { dict->setObject( kInterruptVectorKey, num ); num->release(); } num = OSNumber::withNumber( channelMode, 32 ); if (num) { dict->setObject( kChannelModeKey, num ); num->release(); } return dict; }
void AppleUSBDiagnostics::serializePort(OSDictionary *dictionary, int port, UIMPortDiagnostics *counts, IOService *controller) const { #pragma unused(controller, port) UpdateNumberEntry( dictionary, counts->errorCount, "Port errors"); if( (gUSBStackDebugFlags & kUSBEnableErrorLogMask) != 0) { UpdateNumberEntry( dictionary, counts->totalBytes, "Bytes"); UpdateNumberEntry( dictionary, counts->totalBytes-counts->prevBytes, "Bytes (New)"); counts->prevBytes = counts->totalBytes; UpdateNumberEntry( dictionary, counts->timeouts, "Timeouts"); UpdateNumberEntry( dictionary, counts->timeouts-counts->prevTimeouts, "Timeouts (New)"); counts->prevTimeouts = counts->timeouts; } UpdateNumberEntry( dictionary, counts->resets, "Resets"); UpdateNumberEntry( dictionary, counts->resets-counts->prevResets, "Resets (New)"); counts->prevResets = counts->resets; UpdateNumberEntry( dictionary, counts->enable, "enable"); UpdateNumberEntry( dictionary, counts->suspend, "suspend"); UpdateNumberEntry( dictionary, counts->resume, "resume"); UpdateNumberEntry( dictionary, counts->warmReset, "warmReset"); UpdateNumberEntry( dictionary, counts->power, "power"); UpdateNumberEntry( dictionary, counts->u1Timeout, "u1Timeout"); UpdateNumberEntry( dictionary, counts->u2Timeout, "u2Timeout"); UpdateNumberEntry( dictionary, counts->remoteWakeMask, "remoteWakeMask"); OSArray * errorArray = OSArray::withCapacity(kXHCIMaxCompletionCodes); for(int i=0; i<kXHCIMaxCompletionCodes; i++) { OSNumber * number = OSNumber::withNumber( counts->xhciErrorCode[i], 32 ); errorArray->setObject( i, number ); number->release(); } dictionary->setObject( "XHCI Completion Codes", errorArray ); errorArray->release(); OSArray * linkStateArray = OSArray::withCapacity(kXHCILinkStates); for(int i=0; i<kXHCILinkStates; i++) { OSNumber * number = OSNumber::withNumber( counts->linkState[i], 32 ); linkStateArray->setObject( i, number ); number->release(); } dictionary->setObject( "LinkStates", linkStateArray ); linkStateArray->release(); }
int VoodooI2CHIDDevice::i2c_hid_acpi_pdata(i2c_hid *ihid) { UInt32 guid_1 = 0x3CDFF6F7; UInt32 guid_2 = 0x45554267; UInt32 guid_3 = 0x0AB305AD; UInt32 guid_4 = 0xDE38893D; OSObject *result = NULL; OSObject *params[3]; char buffer[16]; memcpy(buffer, &guid_1, 4); memcpy(buffer + 4, &guid_2, 4); memcpy(buffer + 8, &guid_3, 4); memcpy(buffer + 12, &guid_4, 4); params[0] = OSData::withBytes(buffer, 16); params[1] = OSNumber::withNumber(0x1, 8); params[2] = OSNumber::withNumber(0x1, 8); ihid->client->provider->evaluateObject("_DSM", &result, params, 3); OSNumber* number = OSDynamicCast(OSNumber, result); ihid->pdata.hid_descriptor_address = number->unsigned32BitValue(); number->release(); params[0]->release(); params[1]->release(); params[2]->release(); return 0; }
/*--------------------------------------------------------------------------- * Update all the registry properties associated with an interface ---------------------------------------------------------------------------*/ void EInterfaces::update_interface_property(void) { int n; debug("update_interface_property - m_nInterfacesInUse=%d\n", m_nInterfacesInUse); if ( m_pProvider ) { m_pProvider->removeProperty(ENABLED_INTERFACES_PROPERTY); if ( m_nInterfacesInUse ) { OSArray* pInterfaces = OSArray::withCapacity(m_nInterfacesInUse); if ( pInterfaces ) { for(n=0; n<numberof(m_aInterfaces); n++) if ( m_aInterfaces[n].m_fEnabled ) { OSNumber* pNumber = OSNumber::withNumber(n, 32); if ( pNumber ) { pInterfaces->setObject(pNumber); pNumber->release(); } } m_pProvider->setProperty(ENABLED_INTERFACES_PROPERTY, (OSObject* )pInterfaces); pInterfaces->release(); } } } }
bool IOAudioSelectorControl::init(SInt32 initialValue, UInt32 channelID, const char *channelName, UInt32 cntrlID, UInt32 subType, UInt32 usage, OSDictionary *properties) { bool result = false; OSNumber *number; number = OSNumber::withNumber(initialValue, sizeof(SInt32)*8); if (number) { result = super::init(kIOAudioControlTypeSelector, number, channelID, channelName, cntrlID, subType, usage, properties); number->release(); } if (result) { availableSelections = OSArray::withCapacity(2); setProperty(kIOAudioSelectorControlAvailableSelectionsKey, availableSelections); } return result; }
bool IOEthernetInterface::setFilters( OSDictionary * dict, const OSSymbol * group, UInt32 filters ) { OSNumber * num; bool ret = false; assert( dict && group ); num = (OSNumber *) dict->getObject(group); if ( num == 0 ) { if (( num = OSNumber::withNumber(filters, 32) )) { ret = dict->setObject(group, num); num->release(); } } else { num->setValue(filters); ret = true; } return ret; }
bool IOAudioLevelControl::init(SInt32 initialValue, SInt32 minValue, SInt32 maxValue, IOFixed minDB, IOFixed maxDB, UInt32 channelID, const char *channelName, UInt32 cntrlID, UInt32 subType, UInt32 usage, OSDictionary *properties) { bool result = true; OSNumber *number; number = OSNumber::withNumber(initialValue, sizeof(SInt32)*8); if ((number == NULL) || !super::init(kIOAudioControlTypeLevel, number, channelID, channelName, cntrlID, subType, usage, properties)) { result = false; goto Done; } setMinValue(minValue); setMaxValue(maxValue); setMinDB(minDB); setMaxDB(maxDB); Done: if (number) { number->release(); } return result; }
void AppleACPIBatteryDevice::setSerialNumber(int sernum) { OSNumber *n = OSNumber::withNumber(sernum, NUM_BITS); if (n) { properties->setObject(_SerialNumberSym, n); n->release(); } }
void AppleACPIBatteryDevice::setAverageTimeToFull(int seconds) { OSNumber *n = OSNumber::withNumber(seconds, NUM_BITS); if (n) { properties->setObject(_AvgTimeToFullSym, n); n->release(); } }
void AppleACPIBatteryDevice::setInstantAmperage(int mA) { OSNumber *n = OSNumber::withNumber(mA, NUM_BITS); if (n) { properties->setObject(_InstantAmperageSym, n); n->release(); } }
void AppleACPIBatteryDevice::setInstantaneousTimeToEmpty(int seconds) { OSNumber *n = OSNumber::withNumber(seconds, NUM_BITS); if (n) { properties->setObject(_InstantTimeToEmptySym, n); n->release(); } }
bool ACPIBacklightPanel::doUpdate( void ) { DbgLog("enter %s::%s()\n", this->getName(),__FUNCTION__); bool result = false; OSDictionary* newDict = 0; OSDictionary* allParams = OSDynamicCast(OSDictionary, _display->copyProperty(gIODisplayParametersKey)); if (allParams) { newDict = OSDictionary::withDictionary(allParams); allParams->release(); } OSDictionary* backlightParams = OSDictionary::withCapacity(2); ////OSDictionary* linearParams = OSDictionary::withCapacity(2); //REVIEW_REHABMAN: myParams is not used... OSDictionary* myParams = OSDynamicCast(OSDictionary, copyProperty(gIODisplayParametersKey)); if (/*linearParams && */backlightParams && myParams) { //DbgLog("%s: ACPILevel min %d, max %d, value %d\n", this->getName(), min, max, _value); IODisplay::addParameter(backlightParams, gIODisplayBrightnessKey, kBacklightLevelMin, kBacklightLevelMax); IODisplay::setParameter(backlightParams, gIODisplayBrightnessKey, _committed_value); ////IODisplay::addParameter(linearParams, gIODisplayLinearBrightnessKey, 0, 0x710); ////IODisplay::setParameter(linearParams, gIODisplayLinearBrightnessKey, ((_index-min) * 0x710 + (max-min)/2) / (max-min)); OSNumber * num = OSNumber::withNumber(0ULL, 32); OSDictionary * commitParams = OSDictionary::withCapacity(1); commitParams->setObject("reg", num); backlightParams->setObject(gIODisplayParametersCommitKey, commitParams); num->release(); commitParams->release(); if (newDict) { newDict->merge(backlightParams); ////newDict->merge(linearParams); _display->setProperty(gIODisplayParametersKey, newDict); newDict->release(); } else _display->setProperty(gIODisplayParametersKey, backlightParams); //refresh properties here too setProperty(gIODisplayParametersKey, backlightParams); backlightParams->release(); myParams->release(); ////linearParams->release(); result = true; } DbgLog("exit %s::%s()\n", this->getName(),__FUNCTION__); return result; }
// <rdar://8202424> IOReturn IOAudioSelectorControl::addAvailableSelection(SInt32 selectionValue, OSString *selectionDescription, const char* tagName, OSObject* tag) { OSArray *newSelections; OSArray *oldAvailableSelections; IOReturn result = kIOReturnSuccess; oldAvailableSelections = availableSelections; newSelections = OSArray::withArray(availableSelections); if (!newSelections) return kIOReturnNoMemory; if (selectionDescription == NULL) { result = kIOReturnBadArgument; } else { if (valueExists(selectionValue)) { result = kIOReturnError; } else { OSDictionary *newSelection; newSelection = OSDictionary::withCapacity(2); if (newSelection) { OSNumber *number; number = OSNumber::withNumber(selectionValue, sizeof(SInt32)*8); if (number) { newSelection->setObject(kIOAudioSelectorControlSelectionValueKey, number); newSelection->setObject(kIOAudioSelectorControlSelectionDescriptionKey, selectionDescription); newSelections->setObject(newSelection); number->release(); } else { result = kIOReturnError; } if ( tagName && tag ) { newSelection->setObject(tagName, tag); } availableSelections = newSelections; setProperty(kIOAudioSelectorControlAvailableSelectionsKey, availableSelections); oldAvailableSelections->release(); newSelection->release(); } else { result = kIOReturnError; } } } if (kIOReturnSuccess == result) { sendChangeNotification(kIOAudioControlRangeChangeNotification); } return result; }
static void setNumberInDict(OSDictionary* dict, const char* key, UInt16 value) { OSNumber* num = OSNumber::withNumber(value, 16); if (num) { dict->setObject(key, num); num->release(); } }
bool IOFWController::publishProperties() { bool ret = false; IOFWAddress addr; OSDictionary *dict; do { // Let the superclass publish properties first. if (super::publishProperties() == false) break; // Publish the controller's FireWire address. if ( (getHardwareAddress(&addr) != kIOReturnSuccess) || (setProperty(kIOMACAddress, (void *) &addr, kIOFWAddressSize) == false) ) { break; } // Publish FireWire defined packet filters. dict = OSDynamicCast(OSDictionary, getProperty(kIOPacketFilters)); if ( dict ) { UInt32 filters; OSNumber *num; OSDictionary *newdict; if ( getPacketFilters(gIOEthernetWakeOnLANFilterGroup, &filters) != kIOReturnSuccess ) { break; } num = OSNumber::withNumber(filters, sizeof(filters) * 8); if (num == 0) break; //to avoid race condition with external threads we'll modify a copy of dictionary newdict = OSDictionary::withDictionary(dict); //copy the dictionary if(newdict) { ret = newdict->setObject(gIOEthernetWakeOnLANFilterGroup, num); //and add the WOL group to it setProperty(kIOPacketFilters, newdict); //then replace the property with the new dictionary newdict->release(); } num->release(); } } while (false); return ret; }
void AppleUSBDiagnostics::UpdateNumberEntry( OSDictionary * dictionary, UInt32 value, const char * name ) const { OSNumber * number; number = OSNumber::withNumber( value, 32 ); if( !number ) return; dictionary->setObject( name, number ); number->release(); }
void IOKitDiagnostics::updateOffset( OSDictionary * dict, UInt32 value, const char * name ) { OSNumber * off; off = OSNumber::withNumber( value, 32 ); if( !off) return; dict->setObject( name, off ); off->release(); }
static IOService * IOCopyMediaForDev(dev_t device) { OSDictionary * matching; OSNumber * num; OSIterator * iter; IOService * result = 0; matching = IOService::serviceMatching("IOMedia"); if (!matching) return (0); do { num = OSNumber::withNumber(major(device), 32); if (!num) break; matching->setObject(kIOBSDMajorKey, num); num->release(); num = OSNumber::withNumber(minor(device), 32); if (!num) break; matching->setObject(kIOBSDMinorKey, num); num->release(); if (!num) break; iter = IOService::getMatchingServices(matching); if (iter) { result = (IOService *) iter->getNextObject(); result->retain(); iter->release(); } } while (false); matching->release(); return (result); }
/* read the <partition#> sector on the root address for label and size */ void net_habitue_device_SC101::partitionCompletion(void *parameter, IOReturn status, UInt64 actualByteCount) { if (status != kIOReturnSuccess || actualByteCount != sizeof(psan_get_response_partition_t)) { KINFO("partition lookup on %s failed", getID()->getCStringNoCopy()); return; } IOBufferMemoryDescriptor *buffer = (IOBufferMemoryDescriptor *)parameter; psan_get_response_partition_t *part = (psan_get_response_partition_t *)buffer->getBytesNoCopy(); OSString *id = getID(); for (UInt32 i = 0; i < actualByteCount / sizeof(psan_get_response_partition_t); i++, part++) { KDEBUG("cmp %s", part->id); if (strncmp(part->id, id->getCStringNoCopy(), id->getLength() + 1) != 0) continue; KDEBUG("Matched!"); OSString *label = OSString::withCString(part->label); if (label) { setProperty(gSC101DeviceLabelKey, label); label->release(); } OSNumber *size = OSNumber::withNumber(getUInt48(part->sector_size) << 9, 64); if (size) { setProperty(gSC101DeviceSizeKey, size); size->release(); } if (1) // TODO(iwade) determine minimum fields needed { _mediaStateAttached = true; _mediaStateChanged = true; } break; } }
// Gets the location ID for this device OSNumber* WirelessDevice::newLocationIDNumber() const { OSNumber *owner; UInt32 location = 0; if (index == -1) return NULL; WirelessGamingReceiver *receiver = OSDynamicCast(WirelessGamingReceiver, getProvider()); if (receiver == NULL) return NULL; owner = receiver->newLocationIDNumber(); if (owner != NULL) { location = owner->unsigned32BitValue() + 1 + index; owner->release(); } return OSNumber::withNumber(location, 32); }
/* static */ void OSMetaClass::serializeClassDictionary(OSDictionary * serializeDictionary) { OSDictionary * classDict = NULL; IOLockLock(sAllClassesLock); classDict = OSDictionary::withCapacity(sAllClassesDict->getCount()); if (!classDict) { goto finish; } do { OSCollectionIterator * classes; const OSSymbol * className; classes = OSCollectionIterator::withCollection(sAllClassesDict); if (!classes) { break; } while ((className = (const OSSymbol *)classes->getNextObject())) { const OSMetaClass * meta; OSNumber * count; meta = (OSMetaClass *)sAllClassesDict->getObject(className); count = OSNumber::withNumber(meta->getInstanceCount(), 32); if (count) { classDict->setObject(className, count); count->release(); } } classes->release(); serializeDictionary->setObject("Classes", classDict); } while (0); finish: OSSafeRelease(classDict); IOLockUnlock(sAllClassesLock); return; }
bool IOAudioToggleControl::init(bool initialValue, UInt32 channelID, const char *channelName, UInt32 cntrlID, UInt32 subType, UInt32 usage, OSDictionary *properties) { bool result = false; OSNumber *number; number = OSNumber::withNumber((initialValue == 0) ? 0 : 1, 8); if (number) { result = super::init(kIOAudioControlTypeToggle, number, channelID, channelName, cntrlID, subType, usage, properties); number->release(); } return result; }
void OSMetaClass::serializeClassDictionary(OSDictionary *serializeDictionary) { OSDictionary *classDict; classDict = OSDictionary::withCapacity(sAllClassesDict->getCount()); if (!classDict) return; mutex_lock(loadLock); do { OSCollectionIterator *classes; const OSSymbol *className; classes = OSCollectionIterator::withCollection(sAllClassesDict); if (!classes) break; while ((className = (const OSSymbol *) classes->getNextObject())) { const OSMetaClass *meta; OSNumber *count; meta = (OSMetaClass *) sAllClassesDict->getObject(className); count = OSNumber::withNumber(meta->getInstanceCount(), 32); if (count) { classDict->setObject(className, count); count->release(); } } classes->release(); serializeDictionary->setObject("Classes", classDict); } while (0); mutex_unlock(loadLock); classDict->release(); }
bool net_habitue_device_SC101::init(OSDictionary *properties) { KINFO("init"); gSC101DeviceIDKey = OSSymbol::withCString(kSC101DeviceIDKey); gSC101DeviceIOMaxReadSizeKey = OSSymbol::withCString(kSC101DeviceIOMaxReadSizeKey); gSC101DeviceIOMaxWriteSizeKey = OSSymbol::withCString(kSC101DeviceIOMaxWriteSizeKey); gSC101DevicePartitionAddressKey = OSSymbol::withCString(kSC101DevicePartitionAddressKey); gSC101DeviceRootAddressKey = OSSymbol::withCString(kSC101DeviceRootAddressKey); gSC101DevicePartNumberKey = OSSymbol::withCString(kSC101DevicePartNumberKey); gSC101DeviceVersionKey = OSSymbol::withCString(kSC101DeviceVersionKey); gSC101DeviceLabelKey = OSSymbol::withCString(kSC101DeviceLabelKey); gSC101DeviceSizeKey = OSSymbol::withCString(kSC101DeviceSizeKey); OSString *id = OSDynamicCast(OSString, properties->getObject(gSC101DeviceIDKey)); if (!id) return false; if (!super::init(properties)) return false; OSNumber *ioMaxReadSize = OSDynamicCast(OSNumber, properties->getObject(gSC101DeviceIOMaxReadSizeKey)); if (!ioMaxReadSize || ioMaxReadSize->unsigned64BitValue() < SECTOR_SIZE || ioMaxReadSize->unsigned64BitValue() > MAX_IO_READ_SIZE || ioMaxReadSize->unsigned64BitValue() & (ioMaxReadSize->unsigned64BitValue() - 1)) { ioMaxReadSize = OSNumber::withNumber(DEFAULT_IO_READ_SIZE, 64); if (ioMaxReadSize) { setProperty(gSC101DeviceIOMaxReadSizeKey, ioMaxReadSize); ioMaxReadSize->release(); } } OSNumber *ioMaxWriteSize = OSDynamicCast(OSNumber, properties->getObject(gSC101DeviceIOMaxWriteSizeKey)); if (!ioMaxWriteSize || ioMaxWriteSize->unsigned64BitValue() < SECTOR_SIZE || ioMaxWriteSize->unsigned64BitValue() > MAX_IO_WRITE_SIZE || ioMaxWriteSize->unsigned64BitValue() & (ioMaxWriteSize->unsigned64BitValue() - 1)) { ioMaxWriteSize = OSNumber::withNumber(DEFAULT_IO_WRITE_SIZE, 64); if (ioMaxWriteSize) { setProperty(gSC101DeviceIOMaxWriteSizeKey, ioMaxWriteSize); ioMaxWriteSize->release(); } } nanoseconds_to_absolutetime(1000000000ULL * 60, &_resolveInterval); _mediaStateAttached = false; _mediaStateChanged = true; STAILQ_INIT(&_pendingHead); _pendingCount = 0; STAILQ_INIT(&_outstandingHead); _outstandingCount = 0; return true; }
void AppleACPIBatteryDevice::setDesignCapacity(unsigned int val) { OSNumber *n = OSNumber::withNumber(val, NUM_BITS); properties->setObject(_DesignCapacitySym, n); n->release(); }
VNodeDiskDeviceClass * VNodeDiskDeviceClass::withFilePathAndBlockSizeAndBlockNum( const char * filePath, const UInt64 blockSize, const UInt64 blockNum) { OSDictionary * vnodeParams = NULL; OSString * filePathObject = NULL; OSNumber * blockSizeObject = NULL; OSNumber * blockNumberObject = NULL; VNodeDiskDeviceClass * instance = NULL; vnodeParams = OSDictionary::withCapacity(4); if (!vnodeParams) goto error; filePathObject = OSString::withCString(filePath); if (!filePathObject) goto error; blockSizeObject = OSNumber::withNumber(blockSize, 64); if (!blockSizeObject) goto error; blockNumberObject = OSNumber::withNumber(blockNum, 64); if (!blockNumberObject) goto error; if (!vnodeParams->setObject(OSString::withCString("VNode File Path"), filePathObject)) goto error; if (!vnodeParams->setObject(OSString::withCString("Block Size"), blockSizeObject)) goto error; if (!vnodeParams->setObject(OSString::withCString("Block num"), blockNumberObject)) goto error; instance = new VNodeDiskDeviceClass; if (!instance) goto error; if (!instance->init(vnodeParams)) goto error; return instance; error: if (!instance) instance->release(); if (!blockNumberObject) blockNumberObject->release(); if (!blockSizeObject) blockSizeObject->release(); if (!filePathObject) filePathObject->release(); if (!vnodeParams) vnodeParams->release(); return NULL; }
bool net_lundman_zfs_zvol_device::attach(IOService* provider) { OSDictionary *protocolCharacteristics = 0; OSDictionary *deviceCharacteristics = 0; OSDictionary *storageFeatures = 0; OSBoolean *unmapFeature = 0; OSString *dataString = 0; OSNumber *dataNumber = 0; if (super::attach(provider) == false) return (false); m_provider = OSDynamicCast(net_lundman_zfs_zvol, provider); if (m_provider == NULL) return (false); /* * We want to set some additional properties for ZVOLs, in * particular, "Virtual Device", and type "File" * (or is Internal better?) * * Finally "Generic" type. * * These properties are defined in *protocol* characteristics */ protocolCharacteristics = OSDictionary::withCapacity(3); if (!protocolCharacteristics) { IOLog("failed to create dict for protocolCharacteristics.\n"); return (true); } dataString = OSString::withCString( kIOPropertyPhysicalInterconnectTypeVirtual); if (!dataString) { IOLog("could not create interconnect type string\n"); return (true); } protocolCharacteristics->setObject( kIOPropertyPhysicalInterconnectTypeKey, dataString); dataString->release(); dataString = 0; dataString = OSString::withCString(kIOPropertyInterconnectFileKey); if (!dataString) { IOLog("could not create interconnect location string\n"); return (true); } protocolCharacteristics->setObject( kIOPropertyPhysicalInterconnectLocationKey, dataString); dataString->release(); dataString = 0; setProperty(kIOPropertyProtocolCharacteristicsKey, protocolCharacteristics); protocolCharacteristics->release(); protocolCharacteristics = 0; /* * We want to set some additional properties for ZVOLs, in * particular, physical block size (volblocksize) of the * underlying ZVOL, and 'logical' block size presented by * the virtual disk. Also set physical bytes per sector. * * These properties are defined in *device* characteristics */ deviceCharacteristics = OSDictionary::withCapacity(3); if (!deviceCharacteristics) { IOLog("failed to create dict for deviceCharacteristics.\n"); return (true); } /* Set logical block size to ZVOL_BSIZE (512b) */ dataNumber = OSNumber::withNumber(ZVOL_BSIZE, 8 * sizeof (ZVOL_BSIZE)); deviceCharacteristics->setObject(kIOPropertyLogicalBlockSizeKey, dataNumber); dprintf("logicalBlockSize %llu\n", dataNumber->unsigned64BitValue()); dataNumber->release(); dataNumber = 0; /* Set physical block size to match volblocksize property */ dataNumber = OSNumber::withNumber(zv->zv_volblocksize, 8 * sizeof (zv->zv_volblocksize)); deviceCharacteristics->setObject(kIOPropertyPhysicalBlockSizeKey, dataNumber); dprintf("physicalBlockSize %llu\n", dataNumber->unsigned64BitValue()); dataNumber->release(); dataNumber = 0; /* Set physical bytes per sector to match volblocksize property */ dataNumber = OSNumber::withNumber((uint64_t)(zv->zv_volblocksize), 8 * sizeof (uint64_t)); deviceCharacteristics->setObject(kIOPropertyBytesPerPhysicalSectorKey, dataNumber); dprintf("physicalBytesPerSector %llu\n", dataNumber->unsigned64BitValue()); dataNumber->release(); dataNumber = 0; /* Apply these characteristics */ setProperty(kIOPropertyDeviceCharacteristicsKey, deviceCharacteristics); deviceCharacteristics->release(); deviceCharacteristics = 0; /* * ZVOL unmap support * * These properties are defined in IOStorageFeatures */ storageFeatures = OSDictionary::withCapacity(1); if (!storageFeatures) { IOLog("failed to create dictionary for storageFeatures.\n"); return (true); } /* Set unmap feature */ unmapFeature = OSBoolean::withBoolean(true); storageFeatures->setObject(kIOStorageFeatureUnmap, unmapFeature); unmapFeature->release(); unmapFeature = 0; /* Apply these storage features */ setProperty(kIOStorageFeaturesKey, storageFeatures); storageFeatures->release(); storageFeatures = 0; /* * Set transfer limits: * * Maximum transfer size (bytes) * Maximum transfer block count * Maximum transfer block size (bytes) * Maximum transfer segment count * Maximum transfer segment size (bytes) * Minimum transfer segment size (bytes) * * We will need to establish safe defaults for all / per volblocksize * * Example: setProperty(kIOMinimumSegmentAlignmentByteCountKey, 1, 1); */ /* * Finally "Generic" type, set as a device property. Tried setting this * to the string "ZVOL" however the OS does not recognize it as a block * storage device. This would probably be possible by extending the * IOBlockStorage Device / Driver relationship. */ setProperty(kIOBlockStorageDeviceTypeKey, kIOBlockStorageDeviceTypeGeneric); return (true); }
// Should only be done during init time - this is not thread safe IOReturn IOAudioLevelControl::addRange(SInt32 minRangeValue, SInt32 maxRangeValue, IOFixed minRangeDB, IOFixed maxRangeDB) { IOReturn result = kIOReturnSuccess; // We should verify the new range doesn't overlap any others here if (ranges == NULL) { ranges = OSArray::withCapacity(1); if (ranges) { setProperty(kIOAudioLevelControlRangesKey, ranges); } } if (ranges) { OSDictionary *newRange; OSArray *newRanges; OSArray *oldRanges; oldRanges = ranges; newRanges = OSArray::withArray(ranges); if (!newRanges) return kIOReturnNoMemory; newRange = OSDictionary::withCapacity(4); if (newRange) { OSNumber *number; number = OSNumber::withNumber(minRangeValue, sizeof(SInt32)*8); newRange->setObject(kIOAudioLevelControlMinValueKey, number); number->release(); number = OSNumber::withNumber(maxRangeValue, sizeof(SInt32)*8); newRange->setObject(kIOAudioLevelControlMaxValueKey, number); number->release(); number = OSNumber::withNumber(minRangeDB, sizeof(IOFixed)*8); newRange->setObject(kIOAudioLevelControlMinDBKey, number); number->release(); number = OSNumber::withNumber(maxRangeDB, sizeof(IOFixed)*8); newRange->setObject(kIOAudioLevelControlMaxDBKey, number); number->release(); newRanges->setObject(newRange); setProperty(kIOAudioLevelControlRangesKey, newRanges); ranges = newRanges; oldRanges->release(); newRange->release(); } else { result = kIOReturnError; } } else { result = kIOReturnError; } return result; }