|
|
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: * ux - user-level XPR utility. ! 27: * ! 28: * HISTORY ! 29: * 22-Feb-91 Doug Mitchell at NeXT ! 30: * Created. ! 31: */ ! 32: ! 33: #import <bsd/sys/types.h> ! 34: #import <driverkit/debuggingMsg.h> ! 35: #import <mach/mach.h> ! 36: #import <servers/netname.h> ! 37: #import <bsd/libc.h> ! 38: #import <mach/mach_error.h> ! 39: ! 40: static void usage(char **argv); ! 41: static int ux_clear(port_name_t serverPort, ! 42: port_name_t localPort); ! 43: static int ux_setmask(port_name_t serverPort, ! 44: port_name_t localPort, ! 45: u_int bitmask); ! 46: static int ux_dump(port_name_t serverPort, ! 47: port_name_t localPort, ! 48: int numbufs); ! 49: static int ux_simplemsg(port_name_t serverPort, ! 50: port_name_t localPort, ! 51: int msg_id, ! 52: u_int maskValue, ! 53: u_int index, ! 54: char *op); ! 55: ! 56: /* ! 57: * Template for creating IODDMMsg's. ! 58: */ ! 59: static IODDMMsg msgTemplate = { ! 60: ! 61: { // header ! 62: 0, // msg_unused ! 63: 1, // msg_simple ! 64: sizeof(IODDMMsg), // msg_size ! 65: MSG_TYPE_NORMAL, // msg_type ! 66: PORT_NULL, // msg_local_port ! 67: PORT_NULL, // msg_remote_port - TO ! 68: // BE FILLED IN ! 69: 0 // msg_id - TO BE ! 70: // FILLED IN ! 71: }, ! 72: { // argType ! 73: MSG_TYPE_INTEGER_32, // msg_type_name ! 74: sizeof(int) * 8, // msg_type_size ! 75: 5, // msg_type_number ! 76: 1, // msg_type_inline ! 77: 0, // msg_type_longform ! 78: 0, // msg_type_deallocate ! 79: 0 // msg_type_unused ! 80: }, ! 81: 0, // index ! 82: 0, // maskValue ! 83: 0, // status ! 84: 0, // timestampHighInt ! 85: 0, // timestampLowInt ! 86: 0, // cpuNumber ! 87: { // stringType ! 88: MSG_TYPE_CHAR, // msg_type_name ! 89: 1, // msg_type_size ! 90: IO_DDM_STRING_LENGTH, // msg_type_number ! 91: 1, // msg_type_inline ! 92: 0, // msg_type_longform ! 93: 0, // msg_type_deallocate ! 94: 0 // msg_type_unused ! 95: }, ! 96: 0 // the string ! 97: }; ! 98: ! 99: typedef enum { ACT_CLEAR, ACT_DUMP, ACT_SETMASK, ACT_NONE } action_t; ! 100: ! 101: int main(int argc, char **argv) ! 102: { ! 103: port_name_t serverPort, localPort; ! 104: action_t action = ACT_NONE; ! 105: int numbufs = -1; ! 106: int optarg = -1; ! 107: char *hostname = ""; ! 108: u_int bitmask = 0; ! 109: int rtn; ! 110: netname_name_t nn_portName, nn_hostName; ! 111: kern_return_t krtn; ! 112: ! 113: if(argc < 3) ! 114: usage(argv); ! 115: switch(argv[2][0]) { ! 116: case 'd': ! 117: action = ACT_DUMP; ! 118: optarg = 3; ! 119: if(argc > 3) { ! 120: switch(argv[3][0]) { ! 121: case 'b': ! 122: numbufs = atoi(&argv[3][2]); ! 123: optarg++; ! 124: break; ! 125: default: ! 126: break; ! 127: } ! 128: } ! 129: break; ! 130: case 'c': ! 131: optarg = 3; ! 132: action = ACT_CLEAR; ! 133: break; ! 134: ! 135: case 's': ! 136: optarg = 4; ! 137: action = ACT_SETMASK; ! 138: bitmask = atoi(argv[3]); ! 139: break; ! 140: ! 141: default: ! 142: usage(argv); ! 143: } ! 144: ! 145: while(optarg < argc) { ! 146: switch(argv[optarg][0]) { ! 147: case 'h': ! 148: hostname = argv[optarg]; ! 149: break; ! 150: default: ! 151: usage(argv); ! 152: } ! 153: } ! 154: ! 155: /* ! 156: * Connect to the server. ! 157: */ ! 158: strcpy(nn_portName, argv[1]); ! 159: strcpy(nn_hostName, hostname); ! 160: if(netname_look_up(name_server_port, ! 161: nn_hostName, ! 162: nn_portName, ! 163: &serverPort) != KERN_SUCCESS) { ! 164: printf("Couldn't connect to device %s\n", argv[1]); ! 165: exit(1); ! 166: } ! 167: ! 168: krtn = port_allocate(task_self(), &localPort); ! 169: if(krtn) { ! 170: mach_error("port_allocate", krtn); ! 171: exit(1); ! 172: } ! 173: ! 174: /* ! 175: * Lock the xpr state. ! 176: */ ! 177: if(ux_simplemsg(serverPort, ! 178: localPort, ! 179: IO_LOCK_DDM_MSG, ! 180: 0, 0, ! 181: "Lock")) ! 182: exit(1); ! 183: ! 184: /* ! 185: * What do we want to do...? ! 186: */ ! 187: switch(action) { ! 188: case ACT_CLEAR: ! 189: rtn = ux_clear(serverPort, localPort); ! 190: break; ! 191: case ACT_SETMASK: ! 192: rtn = ux_setmask(serverPort, localPort, bitmask); ! 193: break; ! 194: case ACT_DUMP: ! 195: rtn = ux_dump(serverPort, localPort, numbufs); ! 196: break; ! 197: default: ! 198: printf("bogus bogality\n"); ! 199: exit(1); ! 200: } ! 201: ! 202: /* ! 203: * Unlock the xpr state. ! 204: */ ! 205: ux_simplemsg(serverPort, ! 206: localPort, ! 207: IO_UNLOCK_DDM_MSG, ! 208: 0, 0, ! 209: "Unlock"); ! 210: return(rtn); ! 211: } ! 212: ! 213: static void usage(char **argv) ! 214: { ! 215: printf("Usage: \n"); ! 216: printf("\t%s server_name d(ump) [b=buffer_count] [h=hostname]\n", ! 217: argv[0]); ! 218: printf("\t%s server_name s(etmask) bitmask [h=hostname]\n", argv[0]); ! 219: printf("\t%s server_name c(lear) [h=hostname]\n", argv[0]); ! 220: exit(1); ! 221: } ! 222: ! 223: static int ux_simplemsg(port_name_t serverPort, ! 224: port_name_t localPort, ! 225: int msg_id, ! 226: u_int maskValue, ! 227: u_int index, ! 228: char *op) ! 229: { ! 230: IODDMMsg msg; ! 231: kern_return_t krtn; ! 232: ! 233: msg = msgTemplate; ! 234: msg.header.msg_remote_port = serverPort; ! 235: msg.header.msg_local_port = localPort; ! 236: msg.header.msg_id = msg_id; ! 237: msg.index = index; ! 238: msg.maskValue = maskValue; ! 239: krtn = msg_rpc(&msg.header, ! 240: MSG_OPTION_NONE, ! 241: sizeof(msg), ! 242: 0, ! 243: 0); ! 244: if(krtn) { ! 245: printf("%s: msg_rpc failure\n", op); ! 246: mach_error("msg_rpc", krtn); ! 247: return(1); ! 248: } ! 249: return(0); ! 250: } ! 251: ! 252: /* ! 253: * All of these functions assume that the xpr buffer has already been locked. ! 254: */ ! 255: static int ux_clear(port_name_t serverPort, port_name_t localPort) ! 256: { ! 257: return(ux_simplemsg(serverPort, ! 258: localPort, ! 259: IO_CLEAR_DDM_MSG, ! 260: 0, 0, ! 261: "Clear")); ! 262: } ! 263: ! 264: static int ux_setmask(port_name_t serverPort, ! 265: port_name_t localPort, ! 266: u_int bitmask) ! 267: { ! 268: return(ux_simplemsg(serverPort, ! 269: localPort, ! 270: IO_SET_DDM_MASK_MSG, ! 271: bitmask, ! 272: 0, // index ! 273: "Set Mask")); ! 274: } ! 275: ! 276: static int ux_dump(port_name_t serverPort, ! 277: port_name_t localPort, ! 278: int numbufs) ! 279: { ! 280: int offset; ! 281: IODDMMsg msg; ! 282: kern_return_t krtn; ! 283: unsigned long long timestamp; ! 284: ! 285: msg = msgTemplate; ! 286: ! 287: /* ! 288: * Careful with this loop - numbufs == -1 means "run forever". ! 289: */ ! 290: for(offset=0; offset!=numbufs; offset++) { ! 291: msg.header.msg_remote_port = serverPort; ! 292: msg.header.msg_local_port = localPort; ! 293: msg.header.msg_id = IO_GET_DDM_ENTRY_MSG; ! 294: msg.index = offset; ! 295: krtn = msg_rpc(&msg.header, ! 296: MSG_OPTION_NONE, ! 297: sizeof(msg), ! 298: 0, ! 299: 0); ! 300: if(krtn) { ! 301: mach_error("ux_dump: msg_rpc failure", krtn); ! 302: return(1); ! 303: } ! 304: switch(msg.status) { ! 305: case IO_DDM_SUCCESS: ! 306: /* ! 307: * Display one string. ! 308: */ ! 309: timestamp = IONsTimeFromDDMMsg(&msg); ! 310: printf("%10u c:%d %s", (unsigned)timestamp, ! 311: msg.cpuNumber, msg.string); ! 312: break; ! 313: ! 314: case IO_NO_DDM_BUFFER: ! 315: /* ! 316: * This is OK, it means we got to the end of the ! 317: * buffer. ! 318: */ ! 319: printf("\n"); ! 320: return(0); ! 321: ! 322: default: ! 323: printf("ux_dump: Bogus xpr status (%d)\n", msg.status); ! 324: return(1); ! 325: } ! 326: } ! 327: return(0); ! 328: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.