|
|
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: /* ! 25: * locktest.c - open device with specified access and locking, wait for user ! 26: * action before closing. ! 27: */ ! 28: ! 29: #import <driverkit/IODevice.h> ! 30: #if IODEVICE_LOCKS ! 31: ! 32: #import <bsd/sys/types.h> ! 33: #import <driverkit/IOClient.h> ! 34: #import <ansi/stdio.h> ! 35: #import <bsd/libc.h> ! 36: #import "defaults.h" ! 37: #import "buflib.h" ! 38: ! 39: void usage(char **argv); ! 40: void exit(int exitcode); ! 41: char *gets(char *s); ! 42: ! 43: int main(int argc, char **argv) { ! 44: ! 45: char *hostname=HOST_DEFAULT; ! 46: char *devname=DEVICE_DEFAULT; ! 47: int arg; ! 48: char c[40]; ! 49: id idClient; ! 50: IOReturn rtn; ! 51: int intentions; ! 52: char outstr[100]; ! 53: ! 54: if(argc < 2) ! 55: usage(argv); ! 56: ! 57: /* ! 58: * Get standard defaults from environment or defaults.h ! 59: */ ! 60: get_default_t("hostname", &hostname, HOST_DEFAULT); ! 61: get_default_t("devname", &devname, DEVICE_DEFAULT); ! 62: ! 63: switch(argv[1][0]) { ! 64: case 'r': ! 65: intentions = IO_INT_READ; ! 66: break; ! 67: case 'w': ! 68: intentions = IO_INT_WRITE; ! 69: break; ! 70: case 'a': ! 71: intentions = IO_INT_READ|IO_INT_WRITE; ! 72: break; ! 73: default: ! 74: usage(argv); ! 75: } ! 76: for(arg=2; arg<argc; arg++) { ! 77: char c; ! 78: ! 79: c = argv[arg][0]; ! 80: switch(c) { ! 81: case 'h': ! 82: hostname = &argv[arg][2]; ! 83: break; ! 84: case 'd': ! 85: devname = &argv[arg][2]; ! 86: break; ! 87: case 'l': ! 88: switch(argv[arg][2]) { ! 89: case 'r': ! 90: intentions |= IO_INT_LOCK_READ; ! 91: break; ! 92: case 'w': ! 93: intentions |= IO_INT_LOCK_WRITE; ! 94: break; ! 95: case 'a': ! 96: intentions |= ! 97: (IO_INT_LOCK_READ | IO_INT_LOCK_WRITE); ! 98: break; ! 99: default: ! 100: usage(argv); ! 101: } ! 102: break; ! 103: case 'W': ! 104: intentions |= IO_INT_WAIT; ! 105: break; ! 106: default: ! 107: usage(argv); ! 108: } ! 109: } ! 110: rtn = [IOClient clientOpen:devname ! 111: hostName:hostname ! 112: intentions:intentions ! 113: idp:&idClient]; ! 114: if(rtn) { ! 115: [IOClient ioError:rtn ! 116: logString:"ioOpen" ! 117: outString:outstr]; ! 118: printf(outstr); ! 119: exit(1); ! 120: } ! 121: printf("\n...Device open; Hit CR to close: "); ! 122: gets(c); ! 123: rtn = [idClient ioClose]; ! 124: if(rtn) { ! 125: [IOClient ioError:rtn ! 126: logString:"ioClose" ! 127: outString:outstr]; ! 128: printf(outstr); ! 129: exit(1); ! 130: } ! 131: exit(0); ! 132: ! 133: } /* main() */ ! 134: ! 135: void usage(char **argv) { ! 136: printf("usage: %s r|w|a [l=r|w|a] [W(ait)] [h=hostname] [d=devname]\n", argv[0]); ! 137: exit(1); ! 138: } ! 139: ! 140: #endif IODEVICE_LOCKS ! 141: ! 142: ! 143:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.