2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 #include <IOKit/assert.h>
24 #include <IOKit/IOLib.h>
25 #include <IOKit/IOSyncer.h>
26 #include <IOKit/storage/IOStorage.h>
28 #define super IOService
29 OSDefineMetaClass(IOStorage
, IOService
)
30 OSDefineAbstractStructors(IOStorage
, IOService
)
32 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
35 static void storageCompletion(void * target
,
38 UInt64 actualByteCount
)
41 // Internal completion routine for synchronous versions of read and write.
44 if (parameter
) *((UInt64
*)parameter
) = actualByteCount
;
45 ((IOSyncer
*)target
)->signal(status
);
48 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 bool IOStorage::open(IOService
* client
,
52 IOStorageAccess access
)
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.
59 return super::open(client
, options
, (void *) access
);
62 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64 IOReturn
IOStorage::read(IOService
* client
,
66 IOMemoryDescriptor
* buffer
,
67 UInt64
* actualByteCount
= 0)
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.
75 IOStorageCompletion completion
;
76 IOSyncer
* completionSyncer
;
78 // Initialize the lock we will synchronize against.
80 completionSyncer
= IOSyncer::create();
82 // Fill in the completion information for this request.
84 completion
.target
= completionSyncer
;
85 completion
.action
= storageCompletion
;
86 completion
.parameter
= actualByteCount
;
88 // Issue the asynchronous read.
90 read(client
, byteStart
, buffer
, completion
);
92 // Wait for the read to complete.
94 return completionSyncer
->wait();
97 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99 IOReturn
IOStorage::write(IOService
* client
,
101 IOMemoryDescriptor
* buffer
,
102 UInt64
* actualByteCount
= 0)
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.
110 IOStorageCompletion completion
;
111 IOSyncer
* completionSyncer
;
113 // Initialize the lock we will synchronize against.
115 completionSyncer
= IOSyncer::create();
117 // Fill in the completion information for this request.
119 completion
.target
= completionSyncer
;
120 completion
.action
= storageCompletion
;
121 completion
.parameter
= actualByteCount
;
123 // Issue the asynchronous write.
125 write(client
, byteStart
, buffer
, completion
);
127 // Wait for the write to complete.
129 return completionSyncer
->wait();
132 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
134 OSMetaClassDefineReservedUnused(IOStorage
, 0);
136 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
138 OSMetaClassDefineReservedUnused(IOStorage
, 1);
140 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142 OSMetaClassDefineReservedUnused(IOStorage
, 2);
144 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
146 OSMetaClassDefineReservedUnused(IOStorage
, 3);
148 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150 OSMetaClassDefineReservedUnused(IOStorage
, 4);
152 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 OSMetaClassDefineReservedUnused(IOStorage
, 5);
156 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158 OSMetaClassDefineReservedUnused(IOStorage
, 6);
160 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 OSMetaClassDefineReservedUnused(IOStorage
, 7);
164 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
166 OSMetaClassDefineReservedUnused(IOStorage
, 8);
168 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 OSMetaClassDefineReservedUnused(IOStorage
, 9);
172 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
174 OSMetaClassDefineReservedUnused(IOStorage
, 10);
176 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178 OSMetaClassDefineReservedUnused(IOStorage
, 11);
180 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 OSMetaClassDefineReservedUnused(IOStorage
, 12);
184 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 OSMetaClassDefineReservedUnused(IOStorage
, 13);
188 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
190 OSMetaClassDefineReservedUnused(IOStorage
, 14);
192 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194 OSMetaClassDefineReservedUnused(IOStorage
, 15);