|
|
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 once.
26: */
27:
28: #import <bsd/sys/types.h>
29: #import <ansi/stdio.h>
30: #import <mach/kern_return.h>
31: #import <mach/mach.h>
32: #import <ansi/stdlib.h>
33: #import <bsd/libc.h>
34: #import "buflib.h"
35: #import "defaults.h"
36: #import <remote/NXConnection.h>
37: #import <driverkit/IODisk.h>
38: #import <driverkit/IODiskRwDistributed.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: u_int bytes_xfr;
51: const char *outstr;
52: IOData *rdata;
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: char do_unaligned=0; /* force non-page-aligned read
63: * buffer */
64:
65: /*
66: * FIXME - isn't there a better way to ensure that IOData gets
67: * linked into this executable? We need it to be linked so that
68: * DO decode can instantiate it.
69: */
70: targetId = [IOData alloc];
71: [targetId free];
72:
73: /*
74: * Get standard defaults from environment or defaults.h
75: */
76: get_default("byte_count", &byte_count, BYTE_COUNT_DEFAULT);
77: get_default_t("hostname", &hostname, HOST_DEFAULT);
78: get_default_t("devname", &devname, DEVICE_DEFAULT);
79:
80: for(arg=1; arg<argc; arg++) {
81: c = argv[arg][0];
82: switch(c) {
83: case 'y':
84: byte_count = atoi(&argv[arg][2]);
85: break;
86: case 'h':
87: hostname = &argv[arg][2];
88: break;
89: case 'd':
90: devname = &argv[arg][2];
91: break;
92: case 'b':
93: block_num = atoi(&argv[arg][2]);
94: break;
95: case 'p':
96: dump_data++;
97: break;
98: case 'u':
99: do_unaligned++;
100: break;
101: default:
102: usage(argv);
103: }
104: }
105: targetId = [NXConnection connectToName:devname
106: onHost:hostname];
107: if(targetId == nil) {
108: printf("connectToName:%s failed\n", devname);
109: exit(1);
110: }
111:
112: rtn = [targetId readAt:block_num
113: length:byte_count
114: data:&rdata
115: actualLength:&bytes_xfr];
116: if(rtn != IO_R_SUCCESS) {
117: outstr = [targetId stringFromReturn:rtn];
118: printf("read: %s\n", outstr);
119: exit(1);
120: }
121: if(bytes_xfr != byte_count) {
122: printf("bytes_xfr = %d; expected %d\n", bytes_xfr, byte_count);
123: }
124: if(dump_data)
125: dump_buf((u_char *)[rdata data], bytes_xfr);
126: else
127: printf("...ok\n");
128: exit(0);
129:
130: } /* main() */
131:
132: void usage(char **argv) {
133: printf("usage: %s [y=byte_count] [p (dump data)] [u(naligned buffer)] [b=block_num] [h=hostname] [d=devname]\n", argv[0]);
134: exit(1);
135: }
136:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.