|
|
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: /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved. ! 25: * ! 26: * ConfigUfs.c - Unix File System routines used by ConfigScan. ! 27: * ! 28: * HISTORY ! 29: * 14-Apr-91 Doug Mitchell at NeXT ! 30: * Created. ! 31: */ ! 32: ! 33: #import <bsd/sys/types.h> ! 34: #import <driverkit/userConfigServer.h> ! 35: #import "ConfigPrivate.h" ! 36: #import "ConfigUtils.h" ! 37: #import "ConfigScan.h" ! 38: #import "ConfigUfs.h" ! 39: #import <bsd/sys/dir.h> ! 40: #import <bsd/libc.h> ! 41: #include <sys/stat.h> ! 42: ! 43: typedef struct { ! 44: file_id_t fid; ! 45: filename_t filename; ! 46: u_short dev_revision; ! 47: } exec_file_t; ! 48: ! 49: ! 50: /* ! 51: * Search for an executable appropriate for handling device specified by ! 52: * dev_type and slot_id. Returns TRUE if executable found. ! 53: * ! 54: * This is totally UFS dependent. Maybe when we have an idea of what will ! 55: * replace UFS, we can make some of this more general. ! 56: */ ! 57: #define FAKE_FILE 0 ! 58: #if FAKE_FILE ! 59: filename_t some_file; ! 60: file_id_t some_fid = 0; ! 61: ! 62: boolean_t get_driver_file( ! 63: IODeviceType dev_type, ! 64: IOSlotId slot_id, ! 65: filename_t *filename, // returned ! 66: file_id_t *fid) // returned ! 67: { ! 68: xpr_common("get_driver_file\n", 1,2,3,4,5); ! 69: /* ! 70: * Fake a name for now. ! 71: */ ! 72: if(dev_type == IO_SLOT_DEVICE_TYPE) ! 73: sprintf(some_file, "devs_%04X_0000", slot_id); ! 74: else ! 75: sprintf(some_file, "devr_%04X_0000", dev_type); ! 76: strncpy((char *)filename, (const char *)some_file, FILENAME_SIZE); ! 77: *fid = some_fid++; ! 78: xpr_common("...returning filename %s\n", ! 79: IOCopyString(some_file), 2,3,4,5); ! 80: return(TRUE); ! 81: } ! 82: ! 83: #else FAKE_FILE ! 84: ! 85: static boolean_t no_driver_dir_note = FALSE; ! 86: ! 87: boolean_t get_driver_file( ! 88: IODeviceType dev_type, ! 89: IOSlotId slot_id, ! 90: filename_t *filename, // returned ! 91: file_id_t *fid) // returned ! 92: { ! 93: exec_file_t exec_file; ! 94: IODeviceTypeUn dev_type_u; ! 95: filename_t file_prefix; ! 96: int prefix_length; ! 97: struct direct **namelist; ! 98: int i; ! 99: u_short revision; ! 100: boolean_t rtn; ! 101: struct stat statbuf; ! 102: ! 103: xpr_common("get_driver_file: dev_type 0x%x slot_id 0x%x\n", ! 104: dev_type, slot_id, 3,4,5); ! 105: ! 106: /* ! 107: * Start out with a null file. ! 108: */ ! 109: dev_type_u.deviceType = dev_type; ! 110: xpr_common("dev_type_u.dev_type 0x%x ir.dev_index 0x%x\n", ! 111: dev_type_u.deviceType, dev_type_u.deviceTypeIr.deviceIndex, ! 112: 3,4,5); ! 113: exec_file.fid = FID_NULL; ! 114: exec_file.filename[0] = '\0'; ! 115: exec_file.dev_revision = 0; ! 116: ! 117: /* ! 118: * Generate the filename portion which must match exactly. ! 119: */ ! 120: if(dev_type == IO_SLOT_DEVICE_TYPE) { ! 121: sprintf(file_prefix, "devs_%08X_", slot_id); ! 122: } ! 123: else { ! 124: sprintf(file_prefix, "devr_%04X_", ! 125: (unsigned)dev_type_u.deviceTypeIr.deviceIndex); ! 126: } ! 127: prefix_length = strlen(file_prefix); ! 128: ! 129: /* ! 130: * stat DRIVER_PATH first to make sure it exists. ! 131: */ ! 132: if(stat(DRIVER_PATH, &statbuf)) { ! 133: xpr_common("get_driver_file: %s NOT FOUND\n", ! 134: DRIVER_PATH,2,3,4,5); ! 135: if(!no_driver_dir_note) { ! 136: no_driver_dir_note = TRUE; ! 137: printf("Warning: %s does not exist\n", DRIVER_PATH); ! 138: } ! 139: return FALSE; ! 140: } ! 141: if((statbuf.st_mode & S_IFDIR) == 0) { ! 142: if(!no_driver_dir_note) { ! 143: no_driver_dir_note = TRUE; ! 144: printf("Warning: %s is not a directory\n", ! 145: DRIVER_PATH); ! 146: } ! 147: return FALSE; ! 148: } ! 149: no_driver_dir_note = FALSE; ! 150: ! 151: /* ! 152: * read in the DRIVER_PATH directory, check each entry. Each time ! 153: * we get a valid filename with a revision greater than the one ! 154: * we have, use that one. ! 155: */ ! 156: scandir(DRIVER_PATH, &namelist, NULL, NULL); ! 157: for(i=0; namelist[i]; i++) { ! 158: if(strncmp(namelist[i]->d_name, file_prefix, prefix_length)) ! 159: continue; // bad prefix ! 160: if(get_driver_rev(namelist[i]->d_name, &revision)) ! 161: continue; // bad filename format ! 162: if(revision >= exec_file.dev_revision) { ! 163: /* ! 164: * Let's use this one. ! 165: */ ! 166: exec_file.fid = namelist[i]->d_fileno; ! 167: strcpy(exec_file.filename, namelist[i]->d_name); ! 168: exec_file.dev_revision = revision; ! 169: } ! 170: } ! 171: if(exec_file.filename[0]) { ! 172: xpr_common("get_driver_file: returning filename %s\n", ! 173: IOCopyString(exec_file.filename), 2,3,4,5); ! 174: strcpy((char *)filename, exec_file.filename); ! 175: *fid = exec_file.fid; ! 176: rtn = TRUE; ! 177: } ! 178: else { ! 179: xpr_common("get_driver_file: DRIVER NOT FOUND\n", 1,2,3,4,5); ! 180: rtn = FALSE; ! 181: } ! 182: ! 183: /* ! 184: * Free the namelist we got with scandir(). ! 185: */ ! 186: for(i=0; namelist[i]; i++) { ! 187: free(namelist[i]); ! 188: } ! 189: free(namelist); ! 190: return(rtn); ! 191: } ! 192: ! 193: #endif FAKE_FILE ! 194: ! 195:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.