|
|
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: * read.c - Read 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 <bsd/libc.h>
37: #import "buflib.h"
38: #import "defaults.h"
39:
40: void usage(char **argv);
41: void exit(int exitcode);
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 *rdata;
51: u_int bytes_xfr;
52: int loop_num;
53:
54: /*
55: * user-spec'd variables
56: */
57: u_char dump_data = 0; /* dump read data to stdout */
58: u_int byte_count=BYTE_COUNT_DEFAULT; /* bytes to read */
59: u_int block_num=0;
60: char *hostname=HOST_DEFAULT;
61: char *devname=DEVICE_DEFAULT;
62: int loop_count;
63: int quiet = 0;
64: char do_unaligned=0; /* force non-page-aligned read
65: * buffer */
66:
67: /*
68: * FIXME - isn't there a better way to ensure that IOData gets
69: * linked into this executable? We need it to be linked so that
70: * DO decode can instantiate it.
71: */
72: targetId = [IOData alloc];
73: [targetId free];
74:
75: if(argc < 2)
76: usage(argv);
77: loop_count = atoi(argv[1]);
78:
79: /*
80: * Get standard defaults from environment or defaults.h
81: */
82: get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT);
83: get_default_t("hostname", &hostname, HOST_DEFAULT);
84: get_default_t("devname", &devname, DEVICE_DEFAULT);
85:
86: for(arg=2; arg<argc; arg++) {
87: c = argv[arg][0];
88: switch(c) {
89: case 'y':
90: byte_count = atoi(&argv[arg][2]);
91: break;
92: case 'h':
93: hostname = &argv[arg][2];
94: break;
95: case 'd':
96: devname = &argv[arg][2];
97: break;
98: case 'b':
99: block_num = atoi(&argv[arg][2]);
100: break;
101: case 'p':
102: dump_data++;
103: break;
104: case 'u':
105: do_unaligned++;
106: break;
107: case 'q':
108: quiet++;
109: break;
110: default:
111: usage(argv);
112: }
113: }
114: targetId = [NXConnection connectToName:devname
115: onHost:hostname];
116: if(targetId == nil) {
117: printf("connectToName:%s failed\n", devname);
118: exit(1);
119: }
120: for(loop_num=0; loop_num<loop_count; loop_num++) {
121: rtn = [targetId readAt:block_num
122: length:byte_count
123: data:&rdata
124: actualLength:&bytes_xfr];
125: if(rtn != IO_R_SUCCESS) {
126: printf("read: %s\n", [targetId stringFromReturn:rtn]);
127: exit(1);
128: }
129: if(bytes_xfr != byte_count) {
130: printf("bytes_xfr = %d; expected %d\n",
131: bytes_xfr, byte_count);
132: }
133: if(dump_data)
134: dump_buf((u_char *)[rdata data], bytes_xfr);
135: else if(!quiet && (loop_num % 100 == 0)) {
136: printf(".");
137: fflush(stdout);
138: }
139: [rdata free];
140: }
141: if(!dump_data)
142: printf("...ok\n");
143: exit(0);
144:
145: } /* main() */
146:
147: void usage(char **argv) {
148: printf("usage: %s loop_count [y=byte_count] [p (dump data)] [q(uiet)] [u(unaligned)] [b=block_num] [h=hostname] [d=devname]\n", argv[0]);
149: exit(1);
150: }
151:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.