]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/bsddev/DINetBootHook.cpp
xnu-792.6.61.tar.gz
[apple/xnu.git] / iokit / bsddev / DINetBootHook.cpp
... / ...
CommitLineData
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 2002/06/16 20:36:02 lindak
12 * Merged PR-2957314 into Jaguar (siegmund: netboot kernel code needs to set
13 * com.apple.AppleDiskImageController.load to boolean Yes)
14 *
15 * Revision 1.2.40.2 2002/06/15 03:50:38 dieter
16 * - corrected com.apple.AppleDiskImageController.load string
17 *
18 * Revision 1.2.40.1 2002/06/15 03:01:08 dieter
19 * Bug #: 2957314
20 * - add call to force IOHDIXController to get loaded/matched
21 *
22 * Revision 1.2 2002/05/03 18:08:39 lindak
23 * Merged PR-2909558 into Jaguar (siegmund POST WWDC: add support for NetBoot
24 * over IOHDIXController)
25 *
26 * Revision 1.1.2.1 2002/04/24 22:29:12 dieter
27 * Bug #: 2909558
28 * - added IOHDIXController netboot stubs
29 *
30 * Revision 1.3 2002/04/16 00:41:37 han
31 * migrated code out of here to IOHDIXController's setProperty method
32 *
33 * Revision 1.2 2002/04/14 23:53:53 han
34 * eliminate qDEBUG=1, use emums instead of hard coded string constants
35 *
36 * Revision 1.1 2002/04/14 22:54:42 han
37 * Renamed from DINetBookHook.c.
38 * First stab at implementing this code.
39 *
40 * Revision 1.1 2002/04/13 19:22:28 han
41 * added stub file DINetBookHook.c
42 *
43 *
44 */
45#ifndef qDEBUG
46#define qDEBUG 0
47#endif
48
49#if qDEBUG
50#warning qDEBUG is 1!
51#endif
52
53#include <sys/types.h>
54#include <IOKit/IOService.h>
55#include <IOKit/IOLib.h>
56
57#define kIOHDIXControllerClassName "IOHDIXController"
58#define kDIRootImageKey "di-root-image"
59#define kDIRootImageResultKey "di-root-image-result"
60#define kDIRootImageDevNameKey "di-root-image-devname"
61#define kDIRootImageDevTKey "di-root-image-devt"
62
63extern "C" {
64/*
65 Name: di_root_image
66 Function: mount the disk image returning the dev node
67 Parameters: path -> path/url to disk image
68 devname <- dev node used to set the rootdevice global variable
69 dev_p <- device number generated from major/minor numbers
70 Comments:
71*/
72int di_root_image(const char *path, char devname[], dev_t *dev_p)
73{
74 IOReturn res = 0;
75 OSIterator * controllerIterator = 0;
76 OSDictionary * matchDictionary = 0;
77 IOService * controller = 0;
78 OSString * pathString = 0;
79 OSNumber * myResult = 0;
80 OSString * myDevName = 0;
81 OSNumber * myDevT = 0;
82
83 // sanity check arguments please
84 if (devname) *devname = 0;
85 if (dev_p) *dev_p = 0;
86
87 if (!path) return kIOReturnBadArgument;
88 if (!devname) return kIOReturnBadArgument;
89 if (!dev_p) return kIOReturnBadArgument;
90
91 (void)IOService::getResourceService()->publishResource("com.apple.AppleDiskImageController.load", kOSBooleanTrue);
92 IOService::getResourceService()->waitQuiet();
93
94 // first find IOHDIXController
95 matchDictionary = IOService::serviceMatching(kIOHDIXControllerClassName);
96 if (!matchDictionary) {
97 res = kIOReturnNoMemory;
98 goto serviceMatching_FAILED;
99 }
100
101 controllerIterator = IOService::getMatchingServices(matchDictionary);
102 if (!controllerIterator) {
103 res = kIOReturnNoMemory;
104 goto getMatchingServices_FAILED;
105 }
106
107 // use the "setProperty" method of IOHDIXController to trigger the desired behaviour
108 controller = OSDynamicCast(IOService, controllerIterator->getNextObject());
109 if (!controller) {
110 res = kIOReturnNotFound;
111 goto NoIOHDIXController;
112 }
113
114 // okay create path object
115 pathString = OSString::withCString(path);
116 if (!pathString) {
117 res = kIOReturnNoMemory;
118 goto CannotCreatePathOSString;
119 }
120
121 // do it
122 if (!controller->setProperty(kDIRootImageKey, pathString))
123 IOLog("IOHDIXController::setProperty(%s, %s) failed.\n", kDIRootImageKey, pathString->getCStringNoCopy());
124
125 myResult = OSDynamicCast(OSNumber, controller->getProperty(kDIRootImageResultKey));
126 res = kIOReturnError;
127 if (myResult)
128 res = myResult->unsigned32BitValue();
129
130 if (res) {
131 IOLog("%s is 0x%08X/%d\n", kDIRootImageResultKey, res, res);
132 goto di_root_image_FAILED;
133 }
134
135 // success - grab
136 myDevT = OSDynamicCast(OSNumber, controller->getProperty(kDIRootImageDevTKey));
137 if (myDevT)
138 *dev_p = myDevT->unsigned32BitValue();
139 else {
140 IOLog("could not get %s\n", kDIRootImageDevTKey);
141 res = kIOReturnError;
142 goto di_root_image_FAILED;
143 }
144
145 myDevName = OSDynamicCast(OSString, controller->getProperty(kDIRootImageDevNameKey));
146 if (myDevName)
147 strcpy(devname, myDevName->getCStringNoCopy());
148 else {
149 IOLog("could not get %s\n", kDIRootImageDevNameKey);
150 res = kIOReturnError;
151 goto di_root_image_FAILED;
152 }
153
154
155di_root_image_FAILED:
156CannotCreatePathOSString:
157serviceMatching_FAILED:
158NoIOHDIXController:
159getMatchingServices_FAILED:
160
161 // clean up memory allocations
162 if (pathString) pathString->release();
163 if (matchDictionary) matchDictionary->release();
164 if (controllerIterator) controllerIterator->release();
165
166 return res;
167}
168
169};