|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: /* IOStubDevice.m 1.0 02/07/91 (c) 1991 NeXT ! 25: * ! 26: * IOStubDevice.m - Implementation of "Device-specific" IOStub functions. ! 27: * ! 28: * HISTORY ! 29: * 07-Feb-91 Doug Mitchell at NeXT ! 30: * Created. ! 31: */ ! 32: ! 33: #import <bsd/sys/types.h> ! 34: #import <mach/mach.h> ! 35: #import <mach/vm_param.h> ! 36: #import <mach/mach_error.h> ! 37: #import <bsd/libc.h> ! 38: #import <driverkit/return.h> ! 39: #import <driverkit/IODevice.h> ! 40: #import "IOStub.h" ! 41: #import "IOStubThread.h" ! 42: #import "IOStubDevice.h" ! 43: #import "IOStubUxpr.h" ! 44: #import <machkit/NXLock.h> ! 45: ! 46: @implementation IOStub(Device) ! 47: ! 48: /* ! 49: * These are the methods which actually do the work of this device. All ! 50: * of these methods run in the IOStub_thread thread. ! 51: */ ! 52: - (void)deviceRead : (IOBuf_t *)IOBuf ! 53: { ! 54: char *source; ! 55: u_int block_size; ! 56: ! 57: xpr_stub("deviceRead:\n", 1,2,3,4,5); ! 58: block_size = [self blockSize]; ! 59: source = stub_data + IOBuf->offset * block_size; ! 60: bcopy(source, IOBuf->buf, IOBuf->bytesReq); ! 61: IOBuf->status = IO_R_SUCCESS; ! 62: if(IOBuf->pending) { ! 63: /* ! 64: * Async I/O. Notify client. ! 65: */ ! 66: #if SUPPORT_ASYNC ! 67: [self ioComplete:IOBuf->pending ! 68: dirRead : 1 ! 69: status : IO_R_SUCCESS ! 70: bytesXfr : IOBuf->bytesReq]; ! 71: IOFree(IOBuf, sizeof(*IOBuf)); ! 72: #else SUPPORT_ASYNC ! 73: IOLog("Bogus async request in deviceRead\n"); ! 74: exit(1); ! 75: #endif SUPPORT_ASYNC ! 76: } ! 77: else { ! 78: /* ! 79: * Synchronous I/O. Notify sleeping thread. ! 80: */ ! 81: *IOBuf->bytesXfr = IOBuf->bytesReq; ! 82: [IOBuf->waitLock unlockWith:YES]; ! 83: } ! 84: } ! 85: ! 86: - (void)deviceWrite : (IOBuf_t *)IOBuf ! 87: { ! 88: char *dest; ! 89: u_int block_size; ! 90: ! 91: xpr_stub("deviceWrite:\n", 1,2,3,4,5); ! 92: block_size = [self blockSize]; ! 93: dest = stub_data + IOBuf->offset * block_size; ! 94: bcopy(IOBuf->buf, dest, IOBuf->bytesReq); ! 95: IOBuf->status = IO_R_SUCCESS; ! 96: if(IOBuf->pending) { ! 97: #if SUPPORT_ASYNC ! 98: /* ! 99: * Async I/O. Notify client. ! 100: */ ! 101: [self ioComplete:IOBuf->pending ! 102: dirRead : 0 ! 103: status : IO_R_SUCCESS ! 104: bytesXfr : IOBuf->bytesReq]; ! 105: IOFree(IOBuf, sizeof(*IOBuf)); ! 106: #else SUPPORT_ASYNC ! 107: IOLog("Bogus async request in deviceZero\n"); ! 108: #endif SUPPORT_ASYNC ! 109: } ! 110: else { ! 111: /* ! 112: * Synchronous I/O. Notify sleeping thread. ! 113: */ ! 114: *IOBuf->bytesXfr = IOBuf->bytesReq; ! 115: [IOBuf->waitLock unlockWith:YES]; ! 116: } ! 117: } ! 118: ! 119: /* ! 120: * Zero all of memory. No dispatch for this one... ! 121: */ ! 122: - (void)deviceZero : (IOBuf_t *)IOBuf ! 123: { ! 124: u_int block_size; ! 125: u_int dev_size; ! 126: ! 127: xpr_stub("deviceZero:\n", 1,2,3,4,5); ! 128: block_size = [self blockSize]; ! 129: dev_size = [self diskSize]; ! 130: bzero(stub_data, block_size * dev_size); ! 131: IOBuf->status = IO_R_SUCCESS; ! 132: if(IOBuf->pending) { ! 133: #if SUPPORT_ASYNC ! 134: /* ! 135: * Async I/O. Notify client. ! 136: */ ! 137: [self ioComplete:IOBuf->pending ! 138: dirRead : 1 ! 139: status : IO_R_SUCCESS ! 140: bytesXfr : 0]; ! 141: IOFree(IOBuf, sizeof(*IOBuf)); ! 142: #else SUPPORT_ASYNC ! 143: IOLog("Bogus async request in deviceZero\n"); ! 144: #endif SUPPORT_ASYNC ! 145: } ! 146: else { ! 147: /* ! 148: * Synchronous I/O. Notify sleeping thread. ! 149: */ ! 150: [IOBuf->waitLock unlockWith:YES]; ! 151: } ! 152: } ! 153: ! 154: ! 155: @end ! 156:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.