Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem retrieving version from driver bundle on Mac OS X Intel



If you'll excuse some Cocoa, here is the code we use for detecting the
version number of our driver. It works fine on both PPC and intel

-(NSString*) getKEXTVersionStringFromIdentifier:(NSString*)pBundleIdentifier
{
	NSString* pStr = @"vx.xx";
	CFBundleRef MyBundle = NULL;
	
	// Make a CFURLRef from the CFString representation of the
	// bundles path.
	CFURLRef BundleURL =
KextManagerCreateURLForBundleIdentifier(kCFAllocatorDefault,
(CFStringRef)pBundleIdentifier);
	
	// Make a bundle instance using the URLRef.
	if ( BundleURL )
	{
		MyBundle = CFBundleCreate( kCFAllocatorDefault, BundleURL );
		if ( MyBundle )
		{
			pStr = (NSString*) CFBundleGetValueForInfoDictionaryKey(MyBundle,
kCFBundleVersionKey);
			pStr = [NSString stringWithFormat:@"v%@", pStr];
		}
	}
	// Any CF objects returned from functions with "create" or
	// "copy" in their names must be released by us!
	if ( BundleURL )
		CFRelease( BundleURL );
	if ( MyBundle )
		CFRelease( MyBundle );
	
	return pStr;
}


Hope that helps,
Brett




Peter Young wrote:
> Hi,
> 
>  
> 
> I am in the process of porting our OS X driver and support code to Mac
> OS X Intel.
> 
> I have hit a minor snag in that the code I used for the retrieving the
> driver version for the PPC version no longer works on the Intel version.
> 
> This is the code fragment I used for the PPC version:
> 
>  
> 
> #define       kHWPlotLocation      "/System/Library/Extensions/HWPlot.kext"
> 
>  
> 
> void GetDriverVersion ( char *RefNum, char *VersionString )
> 
> {
> 
>        CFURLRef      bundleURL = NULL;
> 
>        CFBundleRef   myBundle = NULL;
> 
> CFString      cs = CFSTR ( kHWPlotLocation );
> 
>  
> 
>        // Make a CFURLRef from the CFString representation of the
> bundle's path.
> 
>        strcpy ( VersionString, "Unknown" );
> 
>        bundleURL = CFURLCreateWithFileSystemPath ( kCFAllocatorDefault,
> cs, kCFURLPOSIXPathStyle, true );
> 
>        CFRelease ( cs );
> 
>        if ( (CFURLRef)NULL != bundleURL )
> 
>        {
> 
>               myBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
> 
>               if ( (CFBundleRef)NULL != myBundle )
> 
>               {
> 
>               // Try to get the version number from the bundle
> 
>               UInt32 ver = CFBundleGetVersionNumber ( bundle );
> 
>               UInt32 mode = ( ( ver >> 13 ) & 0x07 ) - 1;
> 
>               ShortString modes = kVersionStates;
> 
>  
> 
>               HWDBprintf ( 5, DBG_T, "ver = 0x%08lx, mode = 0x%08lx%s",
> ver, mode, NEWLINE );
> 
>               _stprintf ( VersionString, _T("v%d.%d.%d"), ( ( ver >> 24
> ) & 0xff ),
> 
>                            ( ( ver >> 20 ) & 0x0f ), ( ( ver >> 16 ) &
> 0x0f ) );
> 
>               if ( kReleaseVersion != mode )
> 
>               {
> 
>                      _stprintf ( buff, _T("%c%d"), modes [ mode ], ver &
> 0xff );
> 
>                      _tcscat ( VersionString, buff );
> 
>               }
> 
> CFRelease( myBundle );
> 
>               }
> 
>               CFRelease( bundleURL );
> 
>        }
> 
> }
> 
>  
> 
> This works perfectly well on PPC but on Intel the
> CFBundleGetVersionNumber() call always returns 0.
> 
>  
> 
> I have tried KextManagerCreateURLForBundleIdentifier(), and also
> CFBundleGetValueForInfoDictionaryKey() with various key entries but with
> no success.
> 
> I either get back a version number of ZERO, or the call returns NULL.
> 
>  
> 
> Here is the info.plist file for my Intel driver which, except for the
> IOPCIPrimaryMatch field, is identical to the PPC driver info.plist:
> 
>  
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
> 
> <plist version="1.0">
> 
> <dict>
> 
>        <key>CFBundleDevelopmentRegion</key>
> 
>        <string>English</string>
> 
>        <key>CFBundleExecutable</key>
> 
>        <string>HWPlot</string>
> 
>        <key>CFBundleGetInfoString</key>
> 
>        <string>HWPlot v5.0.2, Copyright 1996 - 2007 HighWater Designs
> Ltd.</string>
> 
>        <key>CFBundleIconFile</key>
> 
>        <string>hwplot.icns</string>
> 
>        <key>CFBundleIdentifier</key>
> 
>        <string>uk.co.highwater.iokit.HWPlot</string>
> 
>        <key>CFBundleInfoDictionaryVersion</key>
> 
>        <string>6.0</string>
> 
>        <key>CFBundleName</key>
> 
>        <string>HWPlot</string>
> 
>        <key>CFBundlePackageType</key>
> 
>        <string>KEXT</string>
> 
>        <key>CFBundleShortVersionString</key>
> 
>        <string>HWPlot v5.0.2</string>
> 
>        <key>CFBundleSignature</key>
> 
>        <string>HGWT</string>
> 
>        <key>CFBundleVersion</key>
> 
>        <string>5.0.2</string>
> 
>        <key>CFBundleVersionString</key>
> 
>        <string>5.0.2</string>
> 
>        <key>IOKitPersonalities</key>
> 
>        <dict>
> 
>               <key>HWPlot</key>
> 
>               <dict>
> 
>                      <key>CFBundleIdentifier</key>
> 
>                      <string>uk.co.highwater.iokit.HWPlot</string>
> 
>                      <key>IOClass</key>
> 
>                      <string>uk_co_highwater_iokit_HWPlot</string>
> 
>                      <key>IOKitDebug</key>
> 
>                      <integer>65535</integer>
> 
>                      <key>IOMatchCategory</key>
> 
>                      <string>HWPlot</string>
> 
>                      <key>IOPCIPrimaryMatch</key>
> 
>                      <string>0x099011e9&amp;0x09f0ffff</string>
> 
>                      <key>IOProviderClass</key>
> 
>                      <string>IOPCIDevice</string>
> 
>               </dict>
> 
>        </dict>
> 
>        <key>OSBundleLibraries</key>
> 
>        <dict>
> 
>               <key>com.apple.iokit.IOFireWireFamily</key>
> 
>               <string>1.0</string>
> 
>               <key>com.apple.iokit.IOPCIFamily</key>
> 
>               <string>1.1</string>
> 
>               <key>com.apple.kernel.iokit</key>
> 
>               <string>1.1</string>
> 
>               <key>com.apple.kernel.libkern</key>
> 
>               <string>1.1</string>
> 
>               <key>com.apple.kernel.mach</key>
> 
>               <string>1.1</string>
> 
>        </dict>
> 
> </dict>
> 
> </plist>
> 
>  
> 
> The driver's version information appears correctly in its Finder Get
> Info window, and is also correctly listed in the kextstat output.
> 
>  
> 
> While not vitally important, I would like to understand why I can no
> longer retrieve this information from within my code.
> 
> Any ideas?
> 
>  
> 
>  
> 
> Peter Young
> 
>  
> 
> 	
> 
> " Build a man a fire - he's warm for a day. Set a man on fire - he's
> warm for the rest of his life!"
> 
> 	
> 
>  
> 
> *Peter Young*
> Senior Software Engineer
> /Remove *.nospam* from address/
> /email@hidden <mailto:email@hidden>/
> 
> 	
> 
> *HighWater Designs Ltd*
> 1-6 St. George's Business Park,
> Alstone Lane, Cheltenham,
> Gloucestershire, GL51 8HF UK
> 
> Registered in England and Wales No 2111605. VAT No GB 448 485117
> 
> 	
> 
>  
> 
> 	
> 
>  
> 
>  
> 
>  
> 
> 
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.467 / Virus Database: 269.6.2/787 - Release Date:
> 03/05/2007 14:11
> 
> 
> ------------------------------------------------------------------------
> 
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-drivers mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/darwin-drivers/email@hidden
> 
> This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-drivers mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-drivers/email@hidden

This email sent to email@hidden

References: 
 >Problem retrieving version from driver bundle on Mac OS X Intel (From: "Peter Young" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.