|
|
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: * wrclp.m - write/read/compare loop
26: */
27:
28: #import <bsd/sys/types.h>
29: #import <driverkit/IOClient.h>
30: #import <ansi/stdio.h>
31: #import <mach/kern_return.h>
32: #import <mach/mach.h>
33: #import <ansi/stdlib.h>
34: #import <ansi/stdio.h>
35: #import <bsd/fcntl.h>
36: #import "buflib.h"
37: #import "defaults.h"
38:
39: void usage(char **argv);
40: void exit(int exitcode);
41: void mach_error(char *c, kern_return_t e);
42: void fill_buf(u_char *buf, register int size, char data_patt);
43:
44: int main(int argc, char **argv) {
45:
46: int arg;
47: char c;
48: id idClient;
49: IOReturn rtn;
50: char *rbuf, *wbuf;
51: kern_return_t krtn;
52: u_int bytes_xfr;
53: int loop_num;
54: char outstr[100];
55:
56: /*
57: * user-spec'd variables
58: */
59: u_int byte_count=BYTE_COUNT_DEFAULT; /* bytes to read */
60: u_int block_num=0;
61: char *hostname=HOST_DEFAULT;
62: char *devname=DEVICE_DEFAULT;
63: int loop_count;
64: int open_each_loop=0;
65: int async = 0;
66:
67: if(argc < 2)
68: usage(argv);
69: loop_count = atoi(argv[1]);
70:
71: /*
72: * Get standard defaults from environment or defaults.h
73: */
74: get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT);
75: get_default_t("hostname", &hostname, HOST_DEFAULT);
76: get_default_t("devname", &devname, DEVICE_DEFAULT);
77:
78: for(arg=2; arg<argc; arg++) {
79: c = argv[arg][0];
80: switch(c) {
81: case 'y':
82: byte_count = atoi(&argv[arg][2]);
83: break;
84: case 'h':
85: hostname = &argv[arg][2];
86: break;
87: case 'd':
88: devname = &argv[arg][2];
89: break;
90: case 'b':
91: block_num = atoi(&argv[arg][2]);
92: break;
93: case 'o':
94: open_each_loop++;
95: break;
96: case 'a':
97: async++;
98: break;
99: default:
100: usage(argv);
101: }
102: }
103: rtn = [IOClient clientOpen:devname
104: hostName:hostname
105: intentions:(IO_INT_READ|IO_INT_WRITE)
106: idp:&idClient];
107: if(rtn) {
108: [IOClient ioError:rtn logString:"clientOpen" outString:outstr];
109: printf(outstr);
110: exit(1);
111: }
112: krtn = vm_allocate(task_self(),
113: (vm_address_t *)&rbuf,
114: byte_count,
115: TRUE);
116: if(krtn) {
117: mach_error("vm_allocate(rbuf)", krtn);
118: exit(1);
119: }
120: krtn = vm_allocate(task_self(),
121: (vm_address_t *)&wbuf,
122: byte_count,
123: TRUE);
124: if(krtn) {
125: mach_error("vm_allocate(wbuf)", krtn);
126: exit(1);
127: }
128: for(loop_num=0; loop_num<loop_count; loop_num++) {
129: /*
130: * initialize read/write buffers. Data = loop #.
131: */
132: fill_buf((u_char *)wbuf, byte_count, (char)loop_num);
133: fill_buf((u_char *)rbuf, byte_count, 0);
134:
135: if(async) {
136: rtn = [idClient ioWriteAsync:block_num
137: bytesReq:byte_count
138: buf:wbuf
139: queueId:block_num+1];
140: if(rtn)
141: goto write_error;
142: rtn = [idClient ioWriteWait:block_num+1
143: bytesXfr:&bytes_xfr];
144: }
145: else {
146: rtn = [idClient ioWrite:block_num
147: bytesReq:byte_count
148: buf:wbuf
149: bytesXfr:&bytes_xfr];
150: }
151: write_error:
152: if(rtn != IO_R_SUCCESS) {
153: [IOClient ioError:rtn
154: logString: async ? "ioWriteAsync" : "ioWrite"
155: outString:outstr];
156: printf(outstr);
157: exit(1);
158: }
159: if(async) {
160: rtn = [idClient ioReadAsync:block_num
161: bytesReq:byte_count
162: queueId:block_num+1];
163: if(rtn)
164: goto read_error;
165: rtn = [idClient ioReadWait:block_num+1
166: buf:rbuf
167: bytesXfr:&bytes_xfr];
168: }
169: else {
170: rtn = [idClient ioRead:block_num
171: bytesReq:byte_count
172: buf:rbuf
173: bytesXfr:&bytes_xfr];
174: }
175: read_error:
176: if(rtn != IO_R_SUCCESS) {
177: [IOClient ioError:rtn
178: logString: async ? "ioReadAsync" : "ioRead"
179: outString:outstr];
180: printf(outstr);
181: exit(1);
182: }
183: if(bytes_xfr != byte_count) {
184: printf("bytes_xfr = %d; expected %d\n", bytes_xfr,
185: byte_count);
186: }
187: if(buf_comp(byte_count, (u_char *)wbuf, (u_char *)rbuf))
188: exit(1);
189: if(loop_num % 100 == 0) {
190: printf(".");
191: fflush(stdout);
192: }
193: if(open_each_loop && (loop_num<loop_count)) {
194: rtn = [idClient ioClose];
195: if(rtn) {
196: [IOClient ioError:rtn
197: logString:"ioClose"
198: outString:outstr];
199: printf(outstr);
200: exit(1);
201: }
202: rtn = [IOClient clientOpen:devname
203: hostName:hostname
204: intentions:(IO_INT_READ|IO_INT_WRITE)
205: idp:&idClient];
206: if(rtn) {
207: [IOClient ioError:rtn
208: logString:"clientOpen"
209: outString:outstr];
210: printf(outstr);
211: exit(1);
212: }
213: }
214: }
215: rtn = [idClient ioClose];
216: if(rtn) {
217: [IOClient ioError:rtn
218: logString:"ioClose"
219: outString:outstr];
220: printf(outstr);
221: exit(1);
222: }
223: printf("\n...ok\n");
224: exit(0);
225:
226: } /* main() */
227:
228: void usage(char **argv) {
229: printf("usage: %s loop_count [options]\n", argv[0]);
230: printf("Options:\n");
231: printf("\ty=byte_count\n");
232: printf("\to(pen_each_lp)\n");
233: printf("\tb=block_num\n");
234: printf("\th=hostname\n");
235: printf("\td=devname\n");
236: printf("\ta(async I/O)\n");
237: exit(1);
238: }
239:
240: void fill_buf(u_char *buf, register int size, char data_patt) {
241:
242: register int i;
243:
244: for(i=0; i<size; i++)
245: *buf++ = data_patt++;
246: } /* fill_buf() */
247:
248:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.