|
|
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.0 (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: /* ! 25: * Copyright 1997-1998 by Apple Computer, Inc., All rights reserved. ! 26: * Copyright 1994-1997 NeXT Software, Inc., All rights reserved. ! 27: * ! 28: * Post-Load command for IDE disks. Creates device nodes /dev/hd[0-3][a-h] ! 29: * and /dev/rhd[0-3][a-h]. ! 30: * units. ! 31: * ! 32: * HISTORY ! 33: * 30-Sep-94 Rakesh Dubey at NeXT ! 34: * Created from SCSI tape source. ! 35: */ ! 36: ! 37: #import <streams/streams.h> ! 38: #import <driverkit/IODeviceMaster.h> ! 39: #import <driverkit/IODevice.h> ! 40: #import <errno.h> ! 41: #import <libc.h> ! 42: ! 43: #import <ata_extern.h> ! 44: ! 45: #define PATH_NAME_SIZE 10 ! 46: #define DEV_STRING "/dev/" ! 47: #define IDE_INIT_ERR_STRING "Error initializing IDE driver" ! 48: ! 49: #define DEV_MOD_CHAR 020640 ! 50: #define DEV_MOD_BLOCK 060640 ! 51: ! 52: #define DEV_UMASK 0 ! 53: ! 54: #define NIDE_PARTITIONS 8 ! 55: ! 56: #define NIDE_DEVICES (MAX_IDE_DRIVES * MAX_IDE_CONTROLLERS) ! 57: ! 58: static int makeNode(char *deviceName, int iUnit, int major, int num, ! 59: unsigned short mode); ! 60: ! 61: int main(int argc, char **argv) ! 62: { ! 63: IOReturn ret; ! 64: IOObjectNumber tag; ! 65: IOString kind; ! 66: unsigned int count; ! 67: IODeviceMaster *devMaster; ! 68: int blockMajor, characterMajor; ! 69: int i, iUnit, iRet; ! 70: char path[PATH_NAME_SIZE]; ! 71: ! 72: iRet = 0; ! 73: ! 74: devMaster = [IODeviceMaster new]; ! 75: ! 76: /* ! 77: * The kernel creates first two. This needs some investigation. FIXME. ! 78: */ ! 79: for (iUnit = 2; iUnit < NIDE_DEVICES; iUnit ++) { ! 80: ! 81: bzero(path, PATH_NAME_SIZE); ! 82: sprintf(path, "%s%s%d", DEV_STRING, "hd", iUnit); ! 83: ! 84: /* ! 85: * Find this instance of the IDE driver ! 86: */ ! 87: ! 88: ret = [devMaster lookUpByDeviceName: path + strlen(DEV_STRING) ! 89: objectNumber: &tag ! 90: deviceKind: &kind]; ! 91: ! 92: #ifdef DEBUG ! 93: printf ("unit %d, obj name %s\n", iUnit, path); ! 94: printf ("ret = %d\n", ret); ! 95: #endif DEBUG ! 96: ! 97: /* ! 98: * If this device does not exist then we don't want to create nodes ! 99: * for it. This saves some time. ! 100: */ ! 101: if (ret != IO_R_SUCCESS) { ! 102: continue; ! 103: } ! 104: ! 105: /* ! 106: * Query the object for its major device number ! 107: */ ! 108: blockMajor = -1; ! 109: ret = [devMaster getIntValues:&blockMajor ! 110: forParameter:"BlockMajor" objectNumber:tag ! 111: count:&count]; ! 112: if (ret != IO_R_SUCCESS) { ! 113: printf("%s: couldn't get block major number: Returned %d.\n", ! 114: IDE_INIT_ERR_STRING, ret); ! 115: iRet = -1; ! 116: } ! 117: ! 118: characterMajor = -1; ! 119: ret = [devMaster getIntValues:&characterMajor ! 120: forParameter:"CharacterMajor" objectNumber:tag ! 121: count:&count]; ! 122: if (ret != IO_R_SUCCESS) { ! 123: printf("%s: couldn't get char major number: Returned %d.\n", ! 124: IDE_INIT_ERR_STRING, ret); ! 125: iRet = -1; ! 126: } ! 127: ! 128: /* ! 129: * Remove old devs and create new ones for this unit. ! 130: */ ! 131: for (i = 0; i < NIDE_PARTITIONS; i++) { ! 132: iRet = makeNode("hd", iUnit, blockMajor, i, DEV_MOD_BLOCK); ! 133: iRet = makeNode("rhd", iUnit, characterMajor, i, DEV_MOD_CHAR); ! 134: } ! 135: } ! 136: ! 137: exit(iRet); ! 138: } ! 139: ! 140: static int makeNode(char *deviceName, int iUnit, int major, int num, ! 141: unsigned short mode) ! 142: { ! 143: int iRet; ! 144: int minor; ! 145: char path[PATH_NAME_SIZE]; ! 146: ! 147: iRet = -1; ! 148: ! 149: #ifdef notdef ! 150: printf ("makeNode %s, iUnit %d num %d\n", deviceName, iUnit, num); ! 151: #endif notdef ! 152: ! 153: bzero(path, PATH_NAME_SIZE); ! 154: sprintf(path, "%s%s%d%c", DEV_STRING, deviceName, iUnit, num + 'a'); ! 155: ! 156: minor = iUnit * NIDE_PARTITIONS + num; ! 157: ! 158: if (unlink(path)) { ! 159: if (errno != ENOENT) { ! 160: printf("%s: could not delete old %s. Errno is %d\n", ! 161: IDE_INIT_ERR_STRING, path, errno); ! 162: iRet = -1; ! 163: } ! 164: } ! 165: ! 166: umask(DEV_UMASK); ! 167: if (mknod(path, mode, (major << 8) | minor)) { ! 168: printf("%s: could not create %s. Errno is %d\n", ! 169: IDE_INIT_ERR_STRING, path, errno); ! 170: iRet = -1; ! 171: } ! 172: ! 173: return iRet; ! 174: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.