]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOStorage/IOStorage.cpp
535c8878cab514e460ea52229ff79025793c1c73
[apple/xnu.git] / iokit / Families / IOStorage / IOStorage.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <IOKit/assert.h>
24 #include <IOKit/IOLib.h>
25 #include <IOKit/IOSyncer.h>
26 #include <IOKit/storage/IOStorage.h>
27
28 #define super IOService
29 OSDefineMetaClass(IOStorage, IOService)
30 OSDefineAbstractStructors(IOStorage, IOService)
31
32 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33 // Local Functions
34
35 static void storageCompletion(void * target,
36 void * parameter,
37 IOReturn status,
38 UInt64 actualByteCount)
39 {
40 //
41 // Internal completion routine for synchronous versions of read and write.
42 //
43
44 if (parameter) *((UInt64 *)parameter) = actualByteCount;
45 ((IOSyncer *)target)->signal(status);
46 }
47
48 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49
50 bool IOStorage::open(IOService * client,
51 IOOptionBits options,
52 IOStorageAccess access)
53 {
54 //
55 // Ask the storage object for permission to access its contents; the method
56 // is equivalent to IOService::open(), but with the correct parameter types.
57 //
58
59 return super::open(client, options, (void *) access);
60 }
61
62 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63
64 IOReturn IOStorage::read(IOService * client,
65 UInt64 byteStart,
66 IOMemoryDescriptor * buffer,
67 UInt64 * actualByteCount = 0)
68 {
69 //
70 // Read data from the storage object at the specified byte offset into the
71 // specified buffer, synchronously. When the read completes, this method
72 // will return to the caller. The actual byte count field is optional.
73 //
74
75 IOStorageCompletion completion;
76 IOSyncer * completionSyncer;
77
78 // Initialize the lock we will synchronize against.
79
80 completionSyncer = IOSyncer::create();
81
82 // Fill in the completion information for this request.
83
84 completion.target = completionSyncer;
85 completion.action = storageCompletion;
86 completion.parameter = actualByteCount;
87
88 // Issue the asynchronous read.
89
90 read(client, byteStart, buffer, completion);
91
92 // Wait for the read to complete.
93
94 return completionSyncer->wait();
95 }
96
97 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98
99 IOReturn IOStorage::write(IOService * client,
100 UInt64 byteStart,
101 IOMemoryDescriptor * buffer,
102 UInt64 * actualByteCount = 0)
103 {
104 //
105 // Write data into the storage object at the specified byte offset from the
106 // specified buffer, synchronously. When the write completes, this method
107 // will return to the caller. The actual byte count field is optional.
108 //
109
110 IOStorageCompletion completion;
111 IOSyncer * completionSyncer;
112
113 // Initialize the lock we will synchronize against.
114
115 completionSyncer = IOSyncer::create();
116
117 // Fill in the completion information for this request.
118
119 completion.target = completionSyncer;
120 completion.action = storageCompletion;
121 completion.parameter = actualByteCount;
122
123 // Issue the asynchronous write.
124
125 write(client, byteStart, buffer, completion);
126
127 // Wait for the write to complete.
128
129 return completionSyncer->wait();
130 }
131
132 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
133
134 OSMetaClassDefineReservedUnused(IOStorage, 0);
135
136 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137
138 OSMetaClassDefineReservedUnused(IOStorage, 1);
139
140 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141
142 OSMetaClassDefineReservedUnused(IOStorage, 2);
143
144 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
145
146 OSMetaClassDefineReservedUnused(IOStorage, 3);
147
148 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149
150 OSMetaClassDefineReservedUnused(IOStorage, 4);
151
152 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
154 OSMetaClassDefineReservedUnused(IOStorage, 5);
155
156 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157
158 OSMetaClassDefineReservedUnused(IOStorage, 6);
159
160 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161
162 OSMetaClassDefineReservedUnused(IOStorage, 7);
163
164 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
165
166 OSMetaClassDefineReservedUnused(IOStorage, 8);
167
168 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169
170 OSMetaClassDefineReservedUnused(IOStorage, 9);
171
172 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
173
174 OSMetaClassDefineReservedUnused(IOStorage, 10);
175
176 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177
178 OSMetaClassDefineReservedUnused(IOStorage, 11);
179
180 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
181
182 OSMetaClassDefineReservedUnused(IOStorage, 12);
183
184 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185
186 OSMetaClassDefineReservedUnused(IOStorage, 13);
187
188 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
189
190 OSMetaClassDefineReservedUnused(IOStorage, 14);
191
192 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
193
194 OSMetaClassDefineReservedUnused(IOStorage, 15);