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 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)
15 * Revision 1.2.40.2 2002/06/15 03:50:38 dieter
16 * - corrected com.apple.AppleDiskImageController.load string
18 * Revision 1.2.40.1 2002/06/15 03:01:08 dieter
20 * - add call to force IOHDIXController to get loaded/matched
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)
26 * Revision 1.1.2.1 2002/04/24 22:29:12 dieter
28 * - added IOHDIXController netboot stubs
30 * Revision 1.3 2002/04/16 00:41:37 han
31 * migrated code out of here to IOHDIXController's setProperty method
33 * Revision 1.2 2002/04/14 23:53:53 han
34 * eliminate qDEBUG=1, use emums instead of hard coded string constants
36 * Revision 1.1 2002/04/14 22:54:42 han
37 * Renamed from DINetBookHook.c.
38 * First stab at implementing this code.
40 * Revision 1.1 2002/04/13 19:22:28 han
41 * added stub file DINetBookHook.c
53 #include <sys/types.h>
54 #include <IOKit/IOService.h>
55 #include <IOKit/IOLib.h>
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"
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
72 int di_root_image(const char *path
, char devname
[], dev_t
*dev_p
)
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;
83 // sanity check arguments please
84 if (devname
) *devname
= 0;
85 if (dev_p
) *dev_p
= 0;
87 if (!path
) return kIOReturnBadArgument
;
88 if (!devname
) return kIOReturnBadArgument
;
89 if (!dev_p
) return kIOReturnBadArgument
;
91 (void)IOService::getResourceService()->publishResource("com.apple.AppleDiskImageController.load", kOSBooleanTrue
);
92 IOService::getResourceService()->waitQuiet();
94 // first find IOHDIXController
95 matchDictionary
= IOService::serviceMatching(kIOHDIXControllerClassName
);
96 if (!matchDictionary
) {
97 res
= kIOReturnNoMemory
;
98 goto serviceMatching_FAILED
;
101 controllerIterator
= IOService::getMatchingServices(matchDictionary
);
102 if (!controllerIterator
) {
103 res
= kIOReturnNoMemory
;
104 goto getMatchingServices_FAILED
;
107 // use the "setProperty" method of IOHDIXController to trigger the desired behaviour
108 controller
= OSDynamicCast(IOService
, controllerIterator
->getNextObject());
110 res
= kIOReturnNotFound
;
111 goto NoIOHDIXController
;
114 // okay create path object
115 pathString
= OSString::withCString(path
);
117 res
= kIOReturnNoMemory
;
118 goto CannotCreatePathOSString
;
122 if (!controller
->setProperty(kDIRootImageKey
, pathString
))
123 IOLog("IOHDIXController::setProperty(%s, %s) failed.\n", kDIRootImageKey
, pathString
->getCStringNoCopy());
125 myResult
= OSDynamicCast(OSNumber
, controller
->getProperty(kDIRootImageResultKey
));
126 res
= kIOReturnError
;
128 res
= myResult
->unsigned32BitValue();
131 IOLog("%s is 0x%08X/%d\n", kDIRootImageResultKey
, res
, res
);
132 goto di_root_image_FAILED
;
136 myDevT
= OSDynamicCast(OSNumber
, controller
->getProperty(kDIRootImageDevTKey
));
138 *dev_p
= myDevT
->unsigned32BitValue();
140 IOLog("could not get %s\n", kDIRootImageDevTKey
);
141 res
= kIOReturnError
;
142 goto di_root_image_FAILED
;
145 myDevName
= OSDynamicCast(OSString
, controller
->getProperty(kDIRootImageDevNameKey
));
147 strcpy(devname
, myDevName
->getCStringNoCopy());
149 IOLog("could not get %s\n", kDIRootImageDevNameKey
);
150 res
= kIOReturnError
;
151 goto di_root_image_FAILED
;
155 di_root_image_FAILED
:
156 CannotCreatePathOSString
:
157 serviceMatching_FAILED
:
159 getMatchingServices_FAILED
:
161 // clean up memory allocations
162 if (pathString
) pathString
->release();
163 if (matchDictionary
) matchDictionary
->release();
164 if (controllerIterator
) controllerIterator
->release();