1 /* $NetBSD: fd.c,v 1.4 2007/11/11 05:20:27 isaki Exp $ */
4 * Copyright (c) 2001 MINOURA Makoto.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/param.h>
29 #include <sys/disklabel.h>
30 #include <machine/stdarg.h>
31 #include <lib/libsa/stand.h>
37 /* fdopen(struct open_file *f, int id, int part) */
39 fdopen(struct open_file
*f
, ...)
49 part
= va_arg(ap
, int);
54 sc
= alloc(sizeof (struct fd_softc
));
57 error
= IOCS_B_DRVCHK((0x90 + id
) << 8, 2);
61 /* detect the sector size */
62 error
= IOCS_B_RECALI((0x90 + id
) << 8);
63 error
= fd_check_format(id
, 0, &sc
->fmt
);
65 IOCS_B_DRVCHK((0x90 + id
) << 8, 3); /* unlock */
66 dealloc(sc
, sizeof(struct fd_softc
));
70 /* check the second side */
71 error
= fd_check_format(id
, 1, &fdfmt
);
72 if (error
== 0) /* valid second side; set the #heads */
73 sc
->fmt
.maxsec
.H
= fdfmt
.maxsec
.H
;
82 fdclose(struct open_file
*f
)
84 struct fd_softc
*sc
= f
->f_devdata
;
86 IOCS_B_DRVCHK((0x90 + sc
->unit
) << 8, 3);
87 dealloc(sc
, sizeof(struct fd_softc
));
92 fdstrategy(void *arg
, int rw
, daddr_t dblk
, size_t size
,
93 void *buf
, size_t *rsize
)
95 struct fd_softc
*sc
= arg
;
105 nbytes
= howmany(size
, 128 << sc
->fmt
.minsec
.N
)
106 * (128 << sc
->fmt
.minsec
.N
);
108 nhead
= sc
->fmt
.maxsec
.H
- sc
->fmt
.minsec
.H
+ 1;
109 nsect
= sc
->fmt
.maxsec
.R
- sc
->fmt
.minsec
.R
+ 1;
111 sect
= dblk
% nsect
+ sc
->fmt
.minsec
.R
;
112 head
= (dblk
/ nsect
) % nhead
+ sc
->fmt
.minsec
.H
;
113 cyl
= (dblk
/ nsect
) / nhead
+ sc
->fmt
.minsec
.C
;
115 error
= IOCS_B_READ((sc
->unit
+0x90)*256 + 0x70,
116 ((sc
->fmt
.minsec
.N
<< 24) |
122 if (error
& 0xf8ffff00) {