]> git.saurik.com Git - apple/xnu.git/blob - iokit/bsddev/DINetBootHook.cpp
xnu-792.18.15.tar.gz
[apple/xnu.git] / iokit / bsddev / DINetBootHook.cpp
1 /*
2 * DINetBootHook.c
3 * DiskImages
4 *
5 * Created by Byron Han on Sat Apr 13 2002.
6 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
7 *
8 * Revision History
9 *
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.
13 *
14 * Revision 1.1.1.1 2005/02/24 21:48:06 akosut
15 * Import xnu-764 from Tiger8A395
16 *
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)
20 *
21 * Revision 1.2.40.2 2002/06/15 03:50:38 dieter
22 * - corrected com.apple.AppleDiskImageController.load string
23 *
24 * Revision 1.2.40.1 2002/06/15 03:01:08 dieter
25 * Bug #: 2957314
26 * - add call to force IOHDIXController to get loaded/matched
27 *
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)
31 *
32 * Revision 1.1.2.1 2002/04/24 22:29:12 dieter
33 * Bug #: 2909558
34 * - added IOHDIXController netboot stubs
35 *
36 * Revision 1.3 2002/04/16 00:41:37 han
37 * migrated code out of here to IOHDIXController's setProperty method
38 *
39 * Revision 1.2 2002/04/14 23:53:53 han
40 * eliminate qDEBUG=1, use emums instead of hard coded string constants
41 *
42 * Revision 1.1 2002/04/14 22:54:42 han
43 * Renamed from DINetBookHook.c.
44 * First stab at implementing this code.
45 *
46 * Revision 1.1 2002/04/13 19:22:28 han
47 * added stub file DINetBookHook.c
48 *
49 *
50 */
51 #ifndef qDEBUG
52 #define qDEBUG 0
53 #endif
54
55 #if qDEBUG
56 #warning qDEBUG is 1!
57 #endif
58
59 #include <sys/types.h>
60 #include <IOKit/IOService.h>
61 #include <IOKit/IOLib.h>
62
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"
68
69 extern "C" {
70 /*
71 Name: di_root_image
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
76 Comments:
77 */
78 int di_root_image(const char *path, char devname[], dev_t *dev_p)
79 {
80 IOReturn res = 0;
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;
88
89 // sanity check arguments please
90 if (devname) *devname = 0;
91 if (dev_p) *dev_p = 0;
92
93 if (!path) return kIOReturnBadArgument;
94 if (!devname) return kIOReturnBadArgument;
95 if (!dev_p) return kIOReturnBadArgument;
96
97 (void)IOService::getResourceService()->publishResource("com.apple.AppleDiskImageController.load", kOSBooleanTrue);
98 IOService::getResourceService()->waitQuiet();
99
100 // first find IOHDIXController
101 matchDictionary = IOService::serviceMatching(kIOHDIXControllerClassName);
102 if (!matchDictionary) {
103 res = kIOReturnNoMemory;
104 goto serviceMatching_FAILED;
105 }
106
107 controllerIterator = IOService::getMatchingServices(matchDictionary);
108 if (!controllerIterator) {
109 res = kIOReturnNoMemory;
110 goto getMatchingServices_FAILED;
111 }
112
113 // use the "setProperty" method of IOHDIXController to trigger the desired behaviour
114 controller = OSDynamicCast(IOService, controllerIterator->getNextObject());
115 if (!controller) {
116 res = kIOReturnNotFound;
117 goto NoIOHDIXController;
118 }
119
120 // okay create path object
121 pathString = OSString::withCString(path);
122 if (!pathString) {
123 res = kIOReturnNoMemory;
124 goto CannotCreatePathOSString;
125 }
126
127 // do it
128 if (!controller->setProperty(kDIRootImageKey, pathString))
129 IOLog("IOHDIXController::setProperty(%s, %s) failed.\n", kDIRootImageKey, pathString->getCStringNoCopy());
130
131 myResult = OSDynamicCast(OSNumber, controller->getProperty(kDIRootImageResultKey));
132 res = kIOReturnError;
133 if (myResult)
134 res = myResult->unsigned32BitValue();
135
136 if (res) {
137 IOLog("%s is 0x%08X/%d\n", kDIRootImageResultKey, res, res);
138 goto di_root_image_FAILED;
139 }
140
141 // success - grab
142 myDevT = OSDynamicCast(OSNumber, controller->getProperty(kDIRootImageDevTKey));
143 if (myDevT)
144 *dev_p = myDevT->unsigned32BitValue();
145 else {
146 IOLog("could not get %s\n", kDIRootImageDevTKey);
147 res = kIOReturnError;
148 goto di_root_image_FAILED;
149 }
150
151 myDevName = OSDynamicCast(OSString, controller->getProperty(kDIRootImageDevNameKey));
152 if (myDevName)
153 strcpy(devname, myDevName->getCStringNoCopy());
154 else {
155 IOLog("could not get %s\n", kDIRootImageDevNameKey);
156 res = kIOReturnError;
157 goto di_root_image_FAILED;
158 }
159
160
161 di_root_image_FAILED:
162 CannotCreatePathOSString:
163 serviceMatching_FAILED:
164 NoIOHDIXController:
165 getMatchingServices_FAILED:
166
167 // clean up memory allocations
168 if (pathString) pathString->release();
169 if (matchDictionary) matchDictionary->release();
170 if (controllerIterator) controllerIterator->release();
171
172 return res;
173 }
174
175 };