|
|
1.1 ! root 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: IOReturn IOStorage::read(IOService * client, ! 51: UInt64 byteStart, ! 52: IOMemoryDescriptor * buffer, ! 53: UInt64 * actualByteCount = 0) ! 54: { ! 55: // ! 56: // Read data from the storage object at the specified byte offset into the ! 57: // specified buffer, synchronously. When the read completes, this method ! 58: // will return to the caller. The actual byte count field is optional. ! 59: // ! 60: ! 61: IOStorageCompletion completion; ! 62: IOSyncer * completionSyncer; ! 63: ! 64: // Initialize the lock we will synchronize against. ! 65: ! 66: completionSyncer = IOSyncer::create(); ! 67: ! 68: // Fill in the completion information for this request. ! 69: ! 70: completion.target = completionSyncer; ! 71: completion.action = storageCompletion; ! 72: completion.parameter = actualByteCount; ! 73: ! 74: // Issue the asynchronous read. ! 75: ! 76: read(client, byteStart, buffer, completion); ! 77: ! 78: // Wait for the read to complete. ! 79: ! 80: return completionSyncer->wait(); ! 81: } ! 82: ! 83: // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! 84: ! 85: IOReturn IOStorage::write(IOService * client, ! 86: UInt64 byteStart, ! 87: IOMemoryDescriptor * buffer, ! 88: UInt64 * actualByteCount = 0) ! 89: { ! 90: // ! 91: // Write data into the storage object at the specified byte offset from the ! 92: // specified buffer, synchronously. When the write completes, this method ! 93: // will return to the caller. The actual byte count field is optional. ! 94: // ! 95: ! 96: IOStorageCompletion completion; ! 97: IOSyncer * completionSyncer; ! 98: ! 99: // Initialize the lock we will synchronize against. ! 100: ! 101: completionSyncer = IOSyncer::create(); ! 102: ! 103: // Fill in the completion information for this request. ! 104: ! 105: completion.target = completionSyncer; ! 106: completion.action = storageCompletion; ! 107: completion.parameter = actualByteCount; ! 108: ! 109: // Issue the asynchronous write. ! 110: ! 111: write(client, byteStart, buffer, completion); ! 112: ! 113: // Wait for the write to complete. ! 114: ! 115: return completionSyncer->wait(); ! 116: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.