2 /* $OpenBSD: unixdev.c,v 1.6 2007/06/16 00:26:33 deraadt Exp $ */
5 * Copyright (c) 1996-1998 Michael Shalayeff
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 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
31 #include <sys/param.h>
32 #include <sys/reboot.h>
34 #include <machine/stdarg.h>
40 #include "compat_linux.h"
42 static struct btinfo_bootdisk bi_disk
;
45 unixstrategy(void *devdata
, int rw
, daddr_t blk
, size_t size
, void *buf
,
49 int fd
= (int)devdata
;
53 printf("unixstrategy: %s %d bytes @ %d\n",
54 ((rw
== F_READ
) ? "reading" : "writing"), (int)size
, (int)blk
);
57 off
= (off_t
)blk
* DEV_BSIZE
;
58 if ((rc
= ulseek(fd
, off
, SEEK_SET
)) >= 0)
59 rc
= (rw
== F_READ
) ? uread(fd
, buf
, size
) :
60 uwrite(fd
, buf
, size
);
71 unixopen(struct open_file
*f
, ...)
79 u_int unit
, partition
;
83 dev
= va_arg(ap
, int);
84 devname
= va_arg(ap
, char *);
85 unit
= va_arg(ap
, u_int
);
86 partition
= va_arg(ap
, u_int
);
87 fname
= va_arg(ap
, char *);
93 dip
= dkdevice(devname
, unit
);
97 /* Try for disklabel again (might be removable media). */
98 if (dip
->bios_info
.flags
& BDI_BADLABEL
) {
99 const char *st
= bios_getdisklabel(&dip
->bios_info
,
106 dip
->bios_info
.flags
&= ~BDI_BADLABEL
;
107 dip
->bios_info
.flags
|= BDI_GOODLABEL
;
112 dospart
= bios_getdospart(&dip
->bios_info
);
113 bios_devpath(dip
->bios_info
.bios_number
, dospart
, path
);
114 f
->f_devdata
= (void *)uopen(path
, LINUX_O_RDONLY
);
115 if ((int)f
->f_devdata
== -1)
118 bi_disk
.biosdev
= dip
->bios_info
.bios_number
;
119 bi_disk
.partition
= partition
;
120 bi_disk
.labelsector
=
121 dip
->disklabel
.d_partitions
[partition
].p_offset
+ LABELSECTOR
;
122 bi_disk
.label
.type
= dip
->disklabel
.d_type
;
123 memcpy(bi_disk
.label
.packname
, dip
->disklabel
.d_packname
, 16);
124 bi_disk
.label
.checksum
= dip
->disklabel
.d_checksum
;
125 BI_ADD(&bi_disk
, BTINFO_BOOTDISK
, sizeof(bi_disk
));
131 unixclose(struct open_file
*f
)
134 return uclose((int)f
->f_devdata
);
138 unixioctl(struct open_file
*f
, u_long cmd
, void *data
)
141 return uioctl((int)f
->f_devdata
, cmd
, data
);
145 ulseek(int fd
, off_t off
, int wh
)
147 extern long ulseek32(int, long, int);
150 /* XXX only SEEK_SET is used, so anything else can fail for now. */
152 if (wh
== SEEK_SET
) {
153 if (ulseek32(fd
, 0, SEEK_SET
) != 0)
155 while (off
> OFFT_OFFSET_MAX
) {
156 off
-= OFFT_OFFSET_MAX
;
157 if (ulseek32(fd
, OFFT_OFFSET_MAX
, SEEK_CUR
) < 0 &&
158 errno
!= LINUX_EOVERFLOW
)
161 r
= ulseek32(fd
, (long)off
, SEEK_CUR
);
162 if (r
== -1 && errno
== LINUX_EOVERFLOW
)
165 r
= ulseek32(fd
, (long)off
, wh
);