|
|
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: /* SCSIDisk.m 1.0 01/02/91 (c) 1991 NeXT ! 25: * ! 26: * SCSIDisk.m - Implementation for SCSI Disk class. ! 27: * ! 28: * HISTORY ! 29: * 01-Feb-91 Doug Mitchell at NeXT ! 30: * Created. ! 31: */ ! 32: ! 33: #import <bsd/sys/types.h> ! 34: #import <bsd/libc.h> ! 35: #import <bsd/sys/file.h> ! 36: #import "SCSIDisk.h" ! 37: #import <bsd/dev/scsireg.h> ! 38: #import <bsd/dev/disk.h> ! 39: #import <errno.h> ! 40: #import "unixDiskUxpr.h" ! 41: #import <driverkit/volCheck.h> ! 42: ! 43: #define NUM_SCSI_THREADS 2 ! 44: #define SCSI_RAW_NAME "sd" ! 45: ! 46: @implementation SCSIDisk ! 47: ! 48: /* ! 49: * Probe hardware to determine how many instances to alloc and init. This ! 50: * is a hard coded kludge for now. ! 51: */ ! 52: #if 0 ! 53: + (void)IOProbe:serverId ! 54: { ! 55: int scsi_unit; ! 56: id scsiId = nil; ! 57: ! 58: /* ! 59: * Attempt to instantiate and init each possible scsi disk. ! 60: */ ! 61: for(scsi_unit=SCSI_UNIT_MIN; scsi_unit<=SCSI_UNIT_MAX; scsi_unit++) { ! 62: if(scsiId == nil) ! 63: scsiId = [self alloc]; ! 64: ! 65: /* ! 66: * Avoid free/alloc if this init fails. ! 67: */ ! 68: if([scsiId SCSIInit:scsi_unit ! 69: sender:serverId] == nil) ! 70: continue; ! 71: else { ! 72: /* ! 73: * Success. Have DiskObject superclass take care of ! 74: * the rest. ! 75: */ ! 76: [scsiId registerDevice]; ! 77: [scsiId registerDisk]; ! 78: scsiId = nil; ! 79: } ! 80: } ! 81: if(scsiId) ! 82: [scsiId free]; ! 83: } ! 84: ! 85: #endif 0 ! 86: ! 87: /* ! 88: * init one instance for specified disk. ! 89: */ ! 90: - SCSIInit:(int)diskNum ! 91: { ! 92: char *name; ! 93: int thread_num; ! 94: ! 95: xpr_ud("SCSIDisk : init: diskNum %d\n", diskNum, 2,3,4,5); ! 96: ! 97: [self setUnit:diskNum]; ! 98: name = malloc(10); ! 99: sprintf(name, "%s%d", SCSI_RAW_NAME, diskNum); ! 100: [self setName:(const char *)name]; ! 101: [self setDeviceKind:"Unix SCSI Disk"]; ! 102: [self setLocation:NULL]; ! 103: [self setDriveName:"Unix SCSI Disk"]; ! 104: [self setDiskType:PR_DRIVE_SCSI]; ! 105: [self setWriteProtected:0]; ! 106: ! 107: /* ! 108: * Do a unix open for each thread. All I/O here goes thru the live ! 109: * partition. ! 110: */ ! 111: sprintf(unix_name, "/dev/rsd%dh", diskNum); ! 112: for(thread_num=0; thread_num<NUM_SCSI_THREADS; thread_num++) { ! 113: unix_fd[thread_num] = open(unix_name, O_RDWR, 0); ! 114: if(unix_fd[thread_num] < 0) { ! 115: ! 116: /* ! 117: * Maybe it's read-only. ! 118: */ ! 119: unix_fd[thread_num] = open(unix_name, O_RDONLY, 0); ! 120: if(unix_fd[thread_num] < 0) { ! 121: perror("SCSIDisk open()"); ! 122: return(nil); ! 123: } ! 124: [self setWriteProtected:1]; ! 125: } ! 126: } ! 127: ! 128: /* ! 129: * Let superclass take care of initializing inherited instance ! 130: * variables. ! 131: */ ! 132: [self unixInit:NUM_SCSI_THREADS]; ! 133: if([self updatePhysicalParameters]) ! 134: return nil; ! 135: return self; ! 136: } ! 137: ! 138: /* ! 139: * Get physical parameters (dev_size, block_size, etc.) from new disk. ! 140: */ ! 141: - (IOReturn)updatePhysicalParameters ! 142: { ! 143: #if i386 ! 144: return(IO_R_IO); ! 145: #else ! 146: int rtn; ! 147: int formattedFlag; ! 148: struct capacity_reply capacity; ! 149: ! 150: /* ! 151: * Is it formatted? ! 152: */ ! 153: [self setRemovable:0]; // fixme ! 154: rtn = ioctl(unix_fd[0], DKIOCGFORMAT, &formattedFlag); ! 155: if(rtn) { ! 156: xpr_ud("SCSIDisk get format: errno %d\n", errno, 2,3,4,5); ! 157: return(IO_R_IO); ! 158: } ! 159: if(formattedFlag) { ! 160: [self setFormattedInternal:1]; ! 161: rtn = ioctl(unix_fd[0], SDIOCGETCAP, &capacity); ! 162: if(rtn) { ! 163: xpr_ud("SCSIDisk get capacity: errno %d\n", errno, ! 164: 2,3,4,5); ! 165: return(IO_R_IO); ! 166: } ! 167: [self setBlockSize:capacity.cr_blklen]; ! 168: [self setDiskSize:capacity.cr_lastlba + 1]; ! 169: } ! 170: else { ! 171: [self setBlockSize:-1]; ! 172: [self setDiskSize:0]; ! 173: [self setFormatted:0]; ! 174: } ! 175: ! 176: /* ! 177: * FIXME - get writeProtected via Inquiry command... ! 178: */ ! 179: return(IO_R_SUCCESS); ! 180: #endif ! 181: } ! 182:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.