|
|
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: * write.c - Write to stub server 'n' times ! 26: */ ! 27: ! 28: #import <bsd/sys/types.h> ! 29: #import <remote/NXConnection.h> ! 30: #import <driverkit/IODisk.h> ! 31: #import <driverkit/IODiskRwDistributed.h> ! 32: #import <ansi/stdio.h> ! 33: #import <mach/kern_return.h> ! 34: #import <mach/mach.h> ! 35: #import <ansi/stdlib.h> ! 36: #import "defaults.h" ! 37: #import "buflib.h" ! 38: ! 39: void usage(char **argv); ! 40: void exit(int exitcode); ! 41: void fill_buf(u_char *p, int size, char d); ! 42: void mach_error(char *c, kern_return_t e); ! 43: ! 44: int main(int argc, char **argv) { ! 45: ! 46: int arg; ! 47: char c; ! 48: id targetId; ! 49: IOReturn rtn; ! 50: IOData *wdata; ! 51: u_int bytes_xfr; ! 52: int loop_num; ! 53: ! 54: /* ! 55: * user-spec'd variables ! 56: */ ! 57: u_int byte_count=BYTE_COUNT_DEFAULT; /* bytes to write */ ! 58: u_int block_num=0; ! 59: char *hostname=HOST_DEFAULT; ! 60: char *devname=DEVICE_DEFAULT; ! 61: char data_patt = 'z'; ! 62: int loop_count; ! 63: int quiet = 0; ! 64: ! 65: if(argc < 2) ! 66: usage(argv); ! 67: loop_count = atoi(argv[1]); ! 68: ! 69: /* ! 70: * Get standard defaults from environment or defaults.h ! 71: */ ! 72: get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT); ! 73: get_default_t("hostname", &hostname, HOST_DEFAULT); ! 74: get_default_t("devname", &devname, DEVICE_DEFAULT); ! 75: ! 76: for(arg=2; arg<argc; arg++) { ! 77: c = argv[arg][0]; ! 78: switch(c) { ! 79: case 'y': ! 80: byte_count = atoi(&argv[arg][2]); ! 81: break; ! 82: case 'h': ! 83: hostname = &argv[arg][2]; ! 84: break; ! 85: case 'd': ! 86: devname = &argv[arg][2]; ! 87: break; ! 88: case 'b': ! 89: block_num = atoi(&argv[arg][2]); ! 90: break; ! 91: case 'p': ! 92: data_patt = argv[arg][2]; ! 93: break; ! 94: case 'q': ! 95: quiet++; ! 96: break; ! 97: default: ! 98: usage(argv); ! 99: } ! 100: } ! 101: targetId = [NXConnection connectToName:devname ! 102: onHost:hostname]; ! 103: if(targetId == nil) { ! 104: printf("connectToName:%s failed\n", devname); ! 105: exit(1); ! 106: } ! 107: wdata = [[IOData alloc] initWithSize:byte_count]; ! 108: [wdata setFreeFlag:NO]; ! 109: fill_buf((u_char *)[wdata data], (int)byte_count, data_patt); ! 110: for(loop_num=0; loop_num<loop_count; loop_num++) { ! 111: rtn = [targetId writeAt:block_num ! 112: length:byte_count ! 113: data:wdata ! 114: actualLength:&bytes_xfr]; ! 115: if(rtn != IO_R_SUCCESS) { ! 116: printf("write: %s\n", [targetId stringFromReturn:rtn]); ! 117: exit(1); ! 118: } ! 119: if(bytes_xfr != byte_count) { ! 120: printf("bytes_xfr = %d; expected %d\n", ! 121: bytes_xfr, byte_count); ! 122: } ! 123: if(!quiet && (loop_num % 100 == 0)) { ! 124: printf("."); ! 125: fflush(stdout); ! 126: } ! 127: } ! 128: printf("...ok\n"); ! 129: exit(0); ! 130: ! 131: } /* main() */ ! 132: ! 133: void usage(char **argv) { ! 134: printf("usage: %s loop_count [y=byte_count] [q(uiet)] [b=block_num] [p={z,1,i,d}] [h=hostname] [d=devname]\n", argv[0]); ! 135: exit(1); ! 136: } ! 137: ! 138: void fill_buf(u_char *buf, int size, char data_patt) { ! 139: ! 140: int i; ! 141: ! 142: printf("\n"); ! 143: for(i=0; i<size; i++) { ! 144: switch(data_patt) { ! 145: case 'z': ! 146: *buf++ = 0; ! 147: break; ! 148: case '1': ! 149: *buf++ = 0xff; ! 150: break; ! 151: case 'i': ! 152: *buf++ = (u_char)i; ! 153: break; ! 154: case 'd': ! 155: *buf++ = 0xff - (u_char)i; ! 156: break; ! 157: default: ! 158: printf("bogus data_patt (%c) in fill_buf()\n", ! 159: data_patt); ! 160: exit(1); ! 161: } ! 162: } ! 163: } /* fill_buf() */ ! 164: ! 165: ! 166: ! 167:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.