IOMedia * IOGUIDPartitionScheme::instantiateMediaObject( gpt_ent * partition, UInt32 partitionID ) { // // Instantiate a new media object to represent the given partition. // IOMedia * media = getProvider(); UInt64 mediaBlockSize = media->getPreferredBlockSize(); UInt64 partitionBase = 0; uuid_string_t partitionHint; char partitionName[36 * 3 + 1]; UInt64 partitionSize = 0; ucs2_to_utf8( partition->ent_name, sizeof(partition->ent_name), partitionName, sizeof(partitionName), UCS_LITTLE_ENDIAN ); uuid_unparse( partition->ent_type, partitionHint ); // Compute the relative byte position and size of the new partition. partitionBase = OSSwapLittleToHostInt64(partition->ent_lba_start); partitionSize = OSSwapLittleToHostInt64(partition->ent_lba_end); partitionBase *= mediaBlockSize; partitionSize *= mediaBlockSize; partitionSize -= partitionBase - mediaBlockSize; // Create the new media object. IOMedia * newMedia = instantiateDesiredMediaObject( /* partition */ partition, /* partitionID */ partitionID ); if ( newMedia ) { if ( newMedia->init( /* base */ partitionBase, /* size */ partitionSize, /* preferredBlockSize */ mediaBlockSize, /* attributes */ media->getAttributes(), /* isWhole */ false, /* isWritable */ media->isWritable(), /* contentHint */ partitionHint ) ) { // Set a name for this partition. char name[24]; snprintf(name, sizeof(name), "Untitled %d", (int) partitionID); newMedia->setName(partitionName[0] ? partitionName : name); // Set a location value (the partition number) for this partition. char location[12]; snprintf(location, sizeof(location), "%d", (int) partitionID); newMedia->setLocation(location); // Set the "Base" key for this partition. newMedia->setProperty(kIOMediaBaseKey, partitionBase, 64); // Set the "Partition ID" key for this partition. newMedia->setProperty(kIOMediaPartitionIDKey, partitionID, 32); // Set the "Universal Unique ID" key for this partition. uuid_string_t uuid; uuid_unparse(partition->ent_uuid, uuid); newMedia->setProperty(kIOMediaUUIDKey, uuid); } else { newMedia->release(); newMedia = 0; } } return newMedia; }
IOMedia * IODVDBlockStorageDriver::instantiateMediaObject(UInt64 base,UInt64 byteSize, UInt32 blockSize,char *mediaName) { IOMedia *media = NULL; if (getMediaType() < kDVDMediaTypeMin || getMediaType() > kDVDMediaTypeMax) { return super::instantiateMediaObject(base,byteSize,blockSize,mediaName); } media = IOBlockStorageDriver::instantiateMediaObject( base,byteSize,blockSize,mediaName); if (media) { const char *description = NULL; const char *picture = NULL; switch (getMediaType()) { case kDVDMediaTypeROM: description = kIODVDMediaTypeROM; picture = "DVD.icns"; break; case kDVDMediaTypeRAM: description = kIODVDMediaTypeRAM; picture = "DVD-RAM.icns"; break; case kDVDMediaTypeR: description = kIODVDMediaTypeR; picture = "DVD-R.icns"; break; case kDVDMediaTypeRW: description = kIODVDMediaTypeRW; picture = "DVD-RW.icns"; break; case kDVDMediaTypePlusR: description = kIODVDMediaTypePlusR; picture = "DVD+R.icns"; break; case kDVDMediaTypePlusRW: description = kIODVDMediaTypePlusRW; picture = "DVD+RW.icns"; break; case kDVDMediaTypeHDROM: description = kIODVDMediaTypeHDROM; picture = "DVD.icns"; break; case kDVDMediaTypeHDRAM: description = kIODVDMediaTypeHDRAM; picture = "DVD-RAM.icns"; break; case kDVDMediaTypeHDR: description = kIODVDMediaTypeHDR; picture = "DVD-R.icns"; break; case kDVDMediaTypeHDRW: description = kIODVDMediaTypeHDRW; picture = "DVD-RW.icns"; break; } if (description) { media->setProperty(kIODVDMediaTypeKey, description); } if (picture) { OSDictionary *dictionary = OSDictionary::withCapacity(2); OSString *identifier = OSString::withCString("com.apple.iokit.IODVDStorageFamily"); OSString *resourceFile = OSString::withCString(picture); if (dictionary && identifier && resourceFile) { dictionary->setObject("CFBundleIdentifier", identifier); dictionary->setObject("IOBundleResourceFile", resourceFile); } media->setProperty(kIOMediaIconKey, dictionary); if (resourceFile) { resourceFile->release(); } if (identifier) { identifier->release(); } if (dictionary) { dictionary->release(); } } } return media; }
IOMedia * IOFDiskPartitionScheme::instantiateMediaObject( fdisk_part * partition, UInt32 partitionID, UInt32 fdiskBlock ) { // // Instantiate a new media object to represent the given partition. // IOMedia * media = getProvider(); UInt64 mediaBlockSize = media->getPreferredBlockSize(); UInt64 partitionBase = 0; char * partitionHint = 0; UInt64 partitionSize = 0; // Compute the relative byte position and size of the new partition. partitionBase = OSSwapLittleToHostInt32(partition->relsect) + fdiskBlock; partitionSize = OSSwapLittleToHostInt32(partition->numsect); partitionBase *= mediaBlockSize; partitionSize *= mediaBlockSize; // Clip the size of the new partition if it extends past the end-of-media. if ( partitionBase + partitionSize > media->getSize() ) { partitionSize = media->getSize() - partitionBase; } // Look up a type for the new partition. char hintIndex[5]; snprintf(hintIndex, sizeof(hintIndex), "0x%02X", partition->systid & 0xFF); partitionHint = hintIndex; OSDictionary * hintTable = OSDynamicCast( /* type */ OSDictionary, /* instance */ getProperty(kIOFDiskPartitionSchemeContentTable) ); if ( hintTable ) { OSString * hintValue; hintValue = OSDynamicCast(OSString, hintTable->getObject(hintIndex)); if ( hintValue ) partitionHint = (char *) hintValue->getCStringNoCopy(); } // Create the new media object. IOMedia * newMedia = instantiateDesiredMediaObject( /* partition */ partition, /* partitionID */ partitionID, /* fdiskBlock */ fdiskBlock ); if ( newMedia ) { if ( newMedia->init( /* base */ partitionBase, /* size */ partitionSize, /* preferredBlockSize */ mediaBlockSize, /* attributes */ media->getAttributes(), /* isWhole */ false, /* isWritable */ media->isWritable(), /* contentHint */ partitionHint ) ) { // Set a name for this partition. char name[24]; snprintf(name, sizeof(name), "Untitled %d", (int) partitionID); newMedia->setName(name); // Set a location value (the partition number) for this partition. char location[12]; snprintf(location, sizeof(location), "%d", (int) partitionID); newMedia->setLocation(location); // Set the "Partition ID" key for this partition. newMedia->setProperty(kIOMediaPartitionIDKey, partitionID, 32); } else { newMedia->release(); newMedia = 0; } } return newMedia; }