5 * Created by Byron Han on Sat Apr 13 2002.
6 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
10 * $Log: DINetBootHook.cpp,v $
11 * Revision 1.3.1558.1 2005/06/24 01:47:25 lindak
12 * Bringing over all of the Karma changes into chardonnay.
14 * Revision 1.1.1.1 2005/02/24 21:48:06 akosut
15 * Import xnu-764 from Tiger8A395
17 * Revision 1.3 2002/06/16 20:36:02 lindak
18 * Merged PR-2957314 into Jaguar (siegmund: netboot kernel code needs to set
19 * com.apple.AppleDiskImageController.load to boolean Yes)
21 * Revision 1.2.40.2 2002/06/15 03:50:38 dieter
22 * - corrected com.apple.AppleDiskImageController.load string
24 * Revision 1.2.40.1 2002/06/15 03:01:08 dieter
26 * - add call to force IOHDIXController to get loaded/matched
28 * Revision 1.2 2002/05/03 18:08:39 lindak
29 * Merged PR-2909558 into Jaguar (siegmund POST WWDC: add support for NetBoot
30 * over IOHDIXController)
32 * Revision 1.1.2.1 2002/04/24 22:29:12 dieter
34 * - added IOHDIXController netboot stubs
36 * Revision 1.3 2002/04/16 00:41:37 han
37 * migrated code out of here to IOHDIXController's setProperty method
39 * Revision 1.2 2002/04/14 23:53:53 han
40 * eliminate qDEBUG=1, use emums instead of hard coded string constants
42 * Revision 1.1 2002/04/14 22:54:42 han
43 * Renamed from DINetBookHook.c.
44 * First stab at implementing this code.
46 * Revision 1.1 2002/04/13 19:22:28 han
47 * added stub file DINetBookHook.c
59 #include <sys/types.h>
60 #include <IOKit/IOService.h>
61 #include <IOKit/IOLib.h>
63 #define kIOHDIXControllerClassName "IOHDIXController"
64 #define kDIRootImageKey "di-root-image"
65 #define kDIRootImageResultKey "di-root-image-result"
66 #define kDIRootImageDevNameKey "di-root-image-devname"
67 #define kDIRootImageDevTKey "di-root-image-devt"
72 Function: mount the disk image returning the dev node
73 Parameters: path -> path/url to disk image
74 devname <- dev node used to set the rootdevice global variable
75 dev_p <- device number generated from major/minor numbers
78 int di_root_image(const char *path
, char devname
[], dev_t
*dev_p
)
81 OSIterator
* controllerIterator
= 0;
82 OSDictionary
* matchDictionary
= 0;
83 IOService
* controller
= 0;
84 OSString
* pathString
= 0;
85 OSNumber
* myResult
= 0;
86 OSString
* myDevName
= 0;
87 OSNumber
* myDevT
= 0;
89 // sanity check arguments please
90 if (devname
) *devname
= 0;
91 if (dev_p
) *dev_p
= 0;
93 if (!path
) return kIOReturnBadArgument
;
94 if (!devname
) return kIOReturnBadArgument
;
95 if (!dev_p
) return kIOReturnBadArgument
;
97 (void)IOService::getResourceService()->publishResource("com.apple.AppleDiskImageController.load", kOSBooleanTrue
);
98 IOService::getResourceService()->waitQuiet();
100 // first find IOHDIXController
101 matchDictionary
= IOService::serviceMatching(kIOHDIXControllerClassName
);
102 if (!matchDictionary
) {
103 res
= kIOReturnNoMemory
;
104 goto serviceMatching_FAILED
;
107 controllerIterator
= IOService::getMatchingServices(matchDictionary
);
108 if (!controllerIterator
) {
109 res
= kIOReturnNoMemory
;
110 goto getMatchingServices_FAILED
;
113 // use the "setProperty" method of IOHDIXController to trigger the desired behaviour
114 controller
= OSDynamicCast(IOService
, controllerIterator
->getNextObject());
116 res
= kIOReturnNotFound
;
117 goto NoIOHDIXController
;
120 // okay create path object
121 pathString
= OSString::withCString(path
);
123 res
= kIOReturnNoMemory
;
124 goto CannotCreatePathOSString
;
128 if (!controller
->setProperty(kDIRootImageKey
, pathString
))
129 IOLog("IOHDIXController::setProperty(%s, %s) failed.\n", kDIRootImageKey
, pathString
->getCStringNoCopy());
131 myResult
= OSDynamicCast(OSNumber
, controller
->getProperty(kDIRootImageResultKey
));
132 res
= kIOReturnError
;
134 res
= myResult
->unsigned32BitValue();
137 IOLog("%s is 0x%08X/%d\n", kDIRootImageResultKey
, res
, res
);
138 goto di_root_image_FAILED
;
142 myDevT
= OSDynamicCast(OSNumber
, controller
->getProperty(kDIRootImageDevTKey
));
144 *dev_p
= myDevT
->unsigned32BitValue();
146 IOLog("could not get %s\n", kDIRootImageDevTKey
);
147 res
= kIOReturnError
;
148 goto di_root_image_FAILED
;
151 myDevName
= OSDynamicCast(OSString
, controller
->getProperty(kDIRootImageDevNameKey
));
153 strcpy(devname
, myDevName
->getCStringNoCopy());
155 IOLog("could not get %s\n", kDIRootImageDevNameKey
);
156 res
= kIOReturnError
;
157 goto di_root_image_FAILED
;
161 di_root_image_FAILED
:
162 CannotCreatePathOSString
:
163 serviceMatching_FAILED
:
165 getMatchingServices_FAILED
:
167 // clean up memory allocations
168 if (pathString
) pathString
->release();
169 if (matchDictionary
) matchDictionary
->release();
170 if (controllerIterator
) controllerIterator
->release();