root / prex-0.9.0 / usr / test / fdd / fdd.c @ 03e9c04a
History | View | Annotate | Download (3.33 KB)
1 | 03e9c04a | Brad Neuman | /*-
|
---|---|---|---|
2 | * Copyright (c) 2005-2006, Kohsuke Ohtani
|
||
3 | * All rights reserved.
|
||
4 | *
|
||
5 | * Redistribution and use in source and binary forms, with or without
|
||
6 | * modification, are permitted provided that the following conditions
|
||
7 | * are met:
|
||
8 | * 1. Redistributions of source code must retain the above copyright
|
||
9 | * notice, this list of conditions and the following disclaimer.
|
||
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
11 | * notice, this list of conditions and the following disclaimer in the
|
||
12 | * documentation and/or other materials provided with the distribution.
|
||
13 | * 3. Neither the name of the author nor the names of any co-contributors
|
||
14 | * may be used to endorse or promote products derived from this software
|
||
15 | * without specific prior written permission.
|
||
16 | *
|
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
27 | * SUCH DAMAGE.
|
||
28 | */
|
||
29 | |||
30 | /*
|
||
31 | * fdd.c - fdd driver test program.
|
||
32 | */
|
||
33 | |||
34 | #include <sys/prex.h> |
||
35 | #include <stdio.h> |
||
36 | #include <string.h> |
||
37 | #include <ctype.h> |
||
38 | |||
39 | int
|
||
40 | test_read(int sector)
|
||
41 | { |
||
42 | device_t fdd; |
||
43 | size_t size; |
||
44 | int error, i, j;
|
||
45 | static unsigned char disk_buf[512]; |
||
46 | unsigned char ch; |
||
47 | |||
48 | printf("open fd0\n");
|
||
49 | error = device_open("fd0", 0, &fdd); |
||
50 | if (error) {
|
||
51 | printf("open failed\n");
|
||
52 | return 0; |
||
53 | } |
||
54 | printf("opened\n");
|
||
55 | |||
56 | printf("fdd read: sector=%d buf=%x\n", sector, (u_int)disk_buf);
|
||
57 | size = 512;
|
||
58 | error = device_read(fdd, disk_buf, &size, sector); |
||
59 | if (error) {
|
||
60 | printf("read failed\n");
|
||
61 | device_close(fdd); |
||
62 | return 0; |
||
63 | } |
||
64 | printf("read comp: sector=%d buf=%x\n", sector, (u_int)disk_buf);
|
||
65 | |||
66 | for (i = 0; i < (512 / 16); i++) { |
||
67 | for (j = 0; j < 16; j++) |
||
68 | printf("%02x ", disk_buf[i * 16 + j]); |
||
69 | printf(" ");
|
||
70 | for (j = 0; j < 16; j++) { |
||
71 | ch = disk_buf[i * 16 + j];
|
||
72 | if (isprint(ch))
|
||
73 | putchar(ch); |
||
74 | else
|
||
75 | putchar('.');
|
||
76 | |||
77 | } |
||
78 | printf("\n");
|
||
79 | } |
||
80 | printf("\n");
|
||
81 | error = device_close(fdd); |
||
82 | if (error)
|
||
83 | printf("close failed\n");
|
||
84 | |||
85 | return 0; |
||
86 | } |
||
87 | |||
88 | int
|
||
89 | test_write(int sector)
|
||
90 | { |
||
91 | device_t fdd; |
||
92 | size_t size; |
||
93 | int error;
|
||
94 | static unsigned char disk_buf[512]; |
||
95 | |||
96 | printf("open fd0\n");
|
||
97 | error = device_open("fd0", 0, &fdd); |
||
98 | if (error) {
|
||
99 | printf("open failed\n");
|
||
100 | return 0; |
||
101 | } |
||
102 | printf("opened\n");
|
||
103 | |||
104 | size = 512;
|
||
105 | error = device_read(fdd, disk_buf, &size, sector); |
||
106 | if (error) {
|
||
107 | printf("read failed\n");
|
||
108 | device_close(fdd); |
||
109 | return 0; |
||
110 | } |
||
111 | printf("read comp sector=%d\n", sector);
|
||
112 | |||
113 | size = 512;
|
||
114 | error = device_write(fdd, disk_buf, &size, sector); |
||
115 | if (error) {
|
||
116 | printf("write failed\n");
|
||
117 | device_close(fdd); |
||
118 | return 0; |
||
119 | } |
||
120 | printf("write comp sector=%d\n", sector);
|
||
121 | |||
122 | error = device_close(fdd); |
||
123 | if (error)
|
||
124 | printf("close failed\n");
|
||
125 | return 0; |
||
126 | } |
||
127 | |||
128 | int
|
||
129 | main(int argc, char *argv[]) |
||
130 | { |
||
131 | test_read(0);
|
||
132 | test_read(1);
|
||
133 | test_read(2);
|
||
134 | |||
135 | test_write(1);
|
||
136 | |||
137 | return 0; |
||
138 | } |