biosdisk_user.c revision 1.4.44.1 1 1.4.44.1 skrll /* $NetBSD: biosdisk_user.c,v 1.4.44.1 2004/08/03 10:36:25 skrll Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1998
5 1.1 drochner * Matthias Drochner. All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Redistribution and use in source and binary forms, with or without
8 1.1 drochner * modification, are permitted provided that the following conditions
9 1.1 drochner * are met:
10 1.1 drochner * 1. Redistributions of source code must retain the above copyright
11 1.1 drochner * notice, this list of conditions and the following disclaimer.
12 1.1 drochner * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 drochner * notice, this list of conditions and the following disclaimer in the
14 1.1 drochner * documentation and/or other materials provided with the distribution.
15 1.1 drochner *
16 1.1 drochner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 drochner * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 drochner * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 drochner * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 drochner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 drochner * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 drochner * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 drochner * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 drochner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 drochner * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 drochner *
27 1.1 drochner */
28 1.1 drochner
29 1.1 drochner #include "sanamespace.h"
30 1.1 drochner
31 1.1 drochner #include <stdio.h>
32 1.1 drochner #include <unistd.h>
33 1.1 drochner #include <fcntl.h>
34 1.1 drochner #include <err.h>
35 1.1 drochner
36 1.3 drochner #include "biosdisk_ll.h"
37 1.1 drochner #include "biosdisk_user.h"
38 1.1 drochner
39 1.1 drochner /*
40 1.1 drochner * Replacement for i386/stand/lib/bios_disk.S.
41 1.1 drochner * Allows to map BIOS-like device numbers to character
42 1.1 drochner * device nodes or plain files.
43 1.1 drochner * The actual mapping is defined in the external table
44 1.1 drochner * "emuldisktab".
45 1.1 drochner */
46 1.1 drochner
47 1.1 drochner static int currentdev, currentdte;
48 1.1 drochner static int fd = -1;
49 1.1 drochner
50 1.4 drochner int
51 1.4 drochner get_diskinfo(dev)
52 1.4 drochner int dev;
53 1.1 drochner {
54 1.4 drochner int i, retval;
55 1.1 drochner
56 1.1 drochner if (fd != -1) {
57 1.1 drochner close(fd);
58 1.1 drochner fd = -1;
59 1.1 drochner }
60 1.1 drochner
61 1.1 drochner i = 0;
62 1.1 drochner for (;;) {
63 1.1 drochner if (emuldisktab[i].biosdev == -1)
64 1.1 drochner break;
65 1.4 drochner if (emuldisktab[i].biosdev == dev)
66 1.1 drochner goto ok;
67 1.1 drochner i++;
68 1.1 drochner }
69 1.4 drochner warnx("unknown device %x", dev);
70 1.4 drochner return (0); /* triggers error in set_geometry() */
71 1.1 drochner
72 1.1 drochner ok:
73 1.1 drochner fd = open(emuldisktab[i].name, O_RDONLY, 0);
74 1.1 drochner if (fd < 0) {
75 1.1 drochner warn("open %s", emuldisktab[i].name);
76 1.4 drochner return (0);
77 1.1 drochner }
78 1.1 drochner
79 1.4 drochner currentdev = dev;
80 1.1 drochner currentdte = i;
81 1.3 drochner
82 1.4 drochner retval = ((emuldisktab[i].cyls - 1) & 0xff) << 16;
83 1.4 drochner retval |= ((emuldisktab[i].cyls - 1) & 0x300) << 6;
84 1.4 drochner retval |= emuldisktab[i].spt << 8;
85 1.4 drochner retval |= emuldisktab[i].heads - 1;
86 1.4 drochner return (retval);
87 1.1 drochner }
88 1.1 drochner
89 1.1 drochner int
90 1.1 drochner biosread(dev, cyl, head, sec, nsec, buf)
91 1.1 drochner int dev;
92 1.1 drochner int cyl, head, sec;
93 1.1 drochner int nsec;
94 1.1 drochner char *buf;
95 1.1 drochner {
96 1.1 drochner if (dev != currentdev) {
97 1.1 drochner warnx("biosread: unexpected device %x", dev);
98 1.1 drochner return (-1);
99 1.1 drochner }
100 1.1 drochner
101 1.1 drochner if (lseek(fd, ((cyl * emuldisktab[currentdte].heads + head)
102 1.1 drochner * emuldisktab[currentdte].spt + sec) * 512,
103 1.1 drochner SEEK_SET) == -1) {
104 1.1 drochner warn("lseek");
105 1.1 drochner return (-1);
106 1.1 drochner }
107 1.1 drochner if (read(fd, buf, nsec * 512) != nsec * 512) {
108 1.1 drochner warn("read");
109 1.1 drochner return (-1);
110 1.1 drochner }
111 1.1 drochner return (0);
112 1.2 drochner }
113 1.2 drochner
114 1.2 drochner int
115 1.2 drochner int13_extension(dev)
116 1.2 drochner int dev;
117 1.2 drochner {
118 1.2 drochner return (0);
119 1.3 drochner }
120 1.3 drochner
121 1.3 drochner void
122 1.3 drochner int13_getextinfo(dev, info)
123 1.3 drochner int dev;
124 1.3 drochner struct biosdisk_ext13info *info;
125 1.3 drochner {
126 1.2 drochner }
127 1.2 drochner
128 1.2 drochner struct ext {
129 1.2 drochner int8_t size;
130 1.2 drochner int8_t resvd;
131 1.2 drochner int16_t cnt;
132 1.2 drochner int16_t off;
133 1.2 drochner int16_t seg;
134 1.2 drochner int64_t sec;
135 1.2 drochner };
136 1.2 drochner
137 1.2 drochner int
138 1.2 drochner biosextread(dev, ext)
139 1.2 drochner int dev;
140 1.2 drochner struct ext *ext;
141 1.2 drochner {
142 1.2 drochner return (-1);
143 1.1 drochner }
144