- update to the blkgetsize patch :

There was a POTENTIAL RISK for your HARDDISKS with the previous
patch because it updated the concat_image_t object (BX_SPLIT_HD is on
by default). The behaviour of BX_SPLIT_HD is to open all filenames
incrementing the last letter. Guess what follows /dev/hda ?

You may now access block devices from within bochs, only
if --disable-split-hd is configured.

It has only been tested on linux and a WinNT guest.

There are issues with the current bios CHS translating scheme and
the guest OS translating scheme. For example my compaq system translates
a physical     38792/16/63 20GiB harddrive to
a logical      2586/240/63, which does not follow the bitshift algorithm.
I had to find a different PCHS that would translate in a compatible LCHS
I still have to investigate further, but I'm afraid everything I can do
will break some systems or the others.

Those issues should be explained in the documentation.
This commit is contained in:
Christophe Bothamy 2002-10-16 14:40:46 +00:00
parent 4ec9e8d5b1
commit 75ae39ed8b

View File

@ -1,11 +1,30 @@
----------------------------------------------------------------------
Patch name: patch.blkdevsize
Author: Ph. Marek, updated by cbothamy
Date: July 29th 2002
Date: 16 Oct 2002
Detailed description:
I added a configure check so the code will be included only
on system that supports it.
This is an update to the previous patch.
There was a potential risk for your harddisks with the previous
patch because it updated the concat_image_t object (BX_SPLIT_HD is on
by default). The behaviour of BX_SPLIT_HD is to open all filenames
incrementing the last letter. Guess what follows /dev/hda ?
You may now access block devices from within bochs, only
if --disable-split-hd is configured.
It has only been tested on linux and a WinNT guest.
There are issues with the current bios CHS translating scheme and
the guest OS translating scheme. For example my compaq system translates
a physical 38792/16/63 20GiB harddrive to
a logical 2586/240/63, which does not follow the bitshift algorithm.
I had to find a different PCHS that would translate in a compatible LCHS
I still have to investigate further, but I'm afraid everything I can do
will break some systems or the others.
Those issues should be explained in the documentation.
Original Detailed description:
I'm currently working to get bochs to support block devices (eg. /dev/hda) as
@ -18,39 +37,22 @@ Here's a patch to get the detection working.
Patch was created with:
cvs diff -u
Apply patch to what version:
cvs checked out on July 29th 2002
cvs checked out on 16 Oct 2002
Instructions:
To patch, go to main bochs directory.
Type "patch -p0 < THIS_PATCH_FILE".
----------------------------------------------------------------------
Index: bochs.h
===================================================================
RCS file: /cvsroot/bochs/bochs/bochs.h,v
retrieving revision 1.73
diff -u -r1.73 bochs.h
--- bochs.h 29 Jul 2002 09:52:03 -0000 1.73
+++ bochs.h 29 Jul 2002 09:58:34 -0000
@@ -62,6 +62,9 @@
# include <sys/types.h>
# include <sys/stat.h>
#endif
+#if BX_HAVE_BLKGETSIZE
+# include <sys/mount.h>
+#endif
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
Index: config.h.in
===================================================================
RCS file: /cvsroot/bochs/bochs/config.h.in,v
retrieving revision 1.50
diff -u -r1.50 config.h.in
--- config.h.in 5 Jun 2002 03:59:30 -0000 1.50
+++ config.h.in 29 Jul 2002 09:58:34 -0000
@@ -207,6 +207,7 @@
#define BX_HAVE_NANOSLEEP 0
#define BX_HAVE_ABORT 0
retrieving revision 1.87
diff -u -r1.87 config.h.in
--- config.h.in 13 Oct 2002 22:38:16 -0000 1.87
+++ config.h.in 16 Oct 2002 14:07:28 -0000
@@ -196,6 +196,7 @@
#define BX_HAVE_SOCKLEN_T 0
#define BX_HAVE_GETTIMEOFDAY 0
#define BX_HAVE_REALTIME_USEC BX_HAVE_GETTIMEOFDAY
+#define BX_HAVE_BLKGETSIZE 0
// This turns on Roland Mainz's idle hack. Presently it is specific to the X11
@ -58,23 +60,23 @@ diff -u -r1.50 config.h.in
Index: configure
===================================================================
RCS file: /cvsroot/bochs/bochs/configure,v
retrieving revision 1.82
diff -u -r1.82 configure
--- configure 16 Jul 2002 12:10:05 -0000 1.82
+++ configure 29 Jul 2002 09:58:36 -0000
@@ -844,7 +844,7 @@
--enable-new-pit use Greg Alexander's new PIT model
--enable-slowdown use Greg Alexander's slowdown timer
--enable-idle-hack use Roland Mainz's idle hack
- --enable-processors select number of processors (1,2,4)
+ --enable-processors select number of processors (1,2,4,8)
--enable-cpu-level select cpu level (3,4,5,6)
--enable-dynamic enable dynamic translation support
--enable-fetchdecode-cache enable fetchdecode-cache support
@@ -7559,6 +7559,62 @@
retrieving revision 1.150
diff -u -r1.150 configure
--- configure 11 Oct 2002 13:21:15 -0000 1.150
+++ configure 16 Oct 2002 14:07:33 -0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Id: configure.in,v 1.149 2002/10/11 01:11:10 kevinlawton Exp .
+# From configure.in Id: configure.in,v 1.150 2002/10/11 13:21:13 bdenney Exp .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.53.
#
@@ -7675,6 +7675,64 @@
_ACEOF
fi
+
+
+echo "$as_me:$LINENO: checking whether BLKGETSIZE is declared" >&5
+echo $ECHO_N "checking whether BLKGETSIZE is declared... $ECHO_C" >&6
+if test "${ac_cv_have_decl_BLKGETSIZE+set}" = set; then
@ -132,78 +134,109 @@ diff -u -r1.82 configure
+fi
+
echo "$as_me:$LINENO: checking for struct timeval" >&5
echo $ECHO_N "checking for struct timeval... $ECHO_C" >&6
@@ -7989,7 +8045,7 @@
;;
*)
echo " "
- echo "WARNING: processors != 1,2,4 can work, but you need to modify rombios.c manually"
+ echo "WARNING: processors != 1,2,4,8 can work, but you need to modify rombios.c manually"
echo "$as_me:$LINENO: result: $enable_val" >&5
echo "${ECHO_T}$enable_val" >&6
cat >>confdefs.h <<\_ACEOF
# Check whether --enable-largefile or --disable-largefile was given.
Index: configure.in
===================================================================
RCS file: /cvsroot/bochs/bochs/configure.in,v
retrieving revision 1.83
diff -u -r1.83 configure.in
--- configure.in 16 Jul 2002 12:08:38 -0000 1.83
+++ configure.in 29 Jul 2002 09:58:36 -0000
@@ -104,6 +104,7 @@
AC_CHECK_FUNCS(nanosleep, AC_DEFINE(BX_HAVE_NANOSLEEP))
AC_CHECK_FUNCS(abort, AC_DEFINE(BX_HAVE_ABORT))
AC_CHECK_TYPE(socklen_t, AC_DEFINE(BX_HAVE_SOCKLEN_T), , [#include <sys/socket.h>])
retrieving revision 1.150
diff -u -r1.150 configure.in
--- configure.in 11 Oct 2002 13:21:13 -0000 1.150
+++ configure.in 16 Oct 2002 14:07:33 -0000
@@ -126,6 +126,9 @@
AC_CHECK_TYPE(socklen_t, AC_DEFINE(BX_HAVE_SOCKLEN_T), , [#include <sys/types.h>
#include <sys/socket.h>])
+AC_CHECK_DECL(BLKGETSIZE, AC_DEFINE(BX_HAVE_BLKGETSIZE), , [#include <sys/mount.h>])
AC_MSG_CHECKING(for struct timeval)
AC_TRY_COMPILE([#include <sys/time.h>],
@@ -216,7 +217,7 @@
AC_MSG_CHECKING(for number of processors)
AC_ARG_ENABLE(processors,
- [ --enable-processors select number of processors (1,2,4)],
+ [ --enable-processors select number of processors (1,2,4,8)],
[case "$enableval" in
1)
AC_MSG_RESULT(1)
@@ -247,7 +248,7 @@
;;
*)
echo " "
- echo "WARNING: processors != [1,2,4] can work, but you need to modify rombios.c manually"
+ echo "WARNING: processors != [1,2,4,8] can work, but you need to modify rombios.c manually"
AC_MSG_RESULT($enable_val)
AC_DEFINE(BX_SMP_PROCESSORS, $enable_val)
AC_DEFINE(BX_BOOTSTRAP_PROCESSOR, 0)
+
+
dnl As of autoconf 2.53, the standard largefile test fails for Linux/gcc.
dnl It does not put the largefiles arguments into CFLAGS, even though Linux/gcc
dnl does need them. Since wxWindows had already solved this exact problem,
Index: bochs.h
===================================================================
RCS file: /cvsroot/bochs/bochs/bochs.h,v
retrieving revision 1.100
diff -u -r1.100 bochs.h
--- bochs.h 6 Oct 2002 14:16:13 -0000 1.100
+++ bochs.h 16 Oct 2002 14:07:33 -0000
@@ -70,6 +70,9 @@
# include <sys/types.h>
# include <sys/stat.h>
#endif
+#if BX_HAVE_BLKGETSIZE
+# include <sys/mount.h>
+#endif
#include <ctype.h>
#include <string.h>
#include <fcntl.h>
Index: iodev/harddrv.cc
===================================================================
RCS file: /cvsroot/bochs/bochs/iodev/harddrv.cc,v
retrieving revision 1.63
diff -u -r1.63 harddrv.cc
--- iodev/harddrv.cc 27 Jul 2002 18:42:31 -0000 1.63
+++ iodev/harddrv.cc 29 Jul 2002 09:58:37 -0000
@@ -2839,6 +2839,23 @@
retrieving revision 1.80
diff -u -r1.80 harddrv.cc
--- iodev/harddrv.cc 6 Oct 2002 20:19:03 -0000 1.80
+++ iodev/harddrv.cc 16 Oct 2002 14:07:35 -0000
@@ -3032,7 +3032,47 @@
BX_PANIC(("fstat() returns error!"));
}
- return fd;
+#if BX_HAVE_BLKGETSIZE
+ // On linux we can use block devices as harddrives. Get the size
+ if (S_ISBLK(stat_buf.st_mode)) {
+ // it's a block device. st_size will be 0, so set it to the correct size.
+
+ Bit64u size;
+ Bit32u size_in512k;
+
+ if (ioctl(fd,BLKGETSIZE,&(size_in512k))==-1) {
+ BX_PANIC(("size of block device %s can't be read",pathname));
+ size = 0;
+ }
+ else {
+ size = (Bit64u)(size_in512k) * 512;
+ }
+
+ if (sizeof(off_t) == 4) {
+ if (size > (0x7fffffff)) {
+ stat_buf.st_size = 0x7ffffe00; /* maximum size without overflow */
+ BX_ERROR(("size of disk image is too big, rounded to %d bytes", stat_buf.st_size));
+ }
+ else {
+ stat_buf.st_size = (Bit32u)size;
+ }
+ }
+ else if(sizeof(off_t) == 8) {
+ stat_buf.st_size = size;
+ }
+ else {
+ BX_PANIC(("size of off_t is unknown"));
+ stat_buf.st_size = 0;
+ }
+ }
+
+#endif // #if BX_HAVE_BLKGETSIZE
+
+ if ((stat_buf.st_size) == 0) {
+ BX_PANIC(("size of disk image '%s' is null",pathname));
+ }
+
+ return fd;
}
void default_image_t::close ()
@@ -3103,8 +3143,12 @@
if (ret) {
BX_PANIC(("fstat() returns error!"));
}
+#if BX_HAVE_BLKGETSIZE
+ // On some systems we can use block devices as harddrives. Get the size
+ if (S_ISBLK(stat_buf.st_mode))
+ {
+ // it's a block device. st_size will be 0, so set it to the correct size.
+ if (ioctl(fd_table[i],BLKGETSIZE,&(stat_buf.st_size))==-1)
+ BX_PANIC(("size of block device %s can't be read",pathname));
+ if (stat_buf.st_size > (0x7ffffff/512))
+ {
+ BX_ERROR(("size of disk image is too big, rounded down"));
+ stat_buf.st_size=0x7ffffe00; // maximum size without overflow
+ }
+ else
+ stat_buf.st_size*=512; // returned value is sectors
+ // what about an overflow here? should possibly use fstat64
+
+ if ((stat_buf.st_size) == 0) {
+ BX_PANIC(("size of disk image '%s' is null",pathname));
+ }
+#endif
if ((stat_buf.st_size % 512) != 0) {
BX_PANIC(("size of disk image must be multiple of 512 bytes"));
- BX_PANIC(("size of disk image must be multiple of 512 bytes"));
+ BX_PANIC(("size of disk image '%s' must be multiple of 512 bytes",pathname));
}
length_table[i] = stat_buf.st_size;
start_offset_table[i] = start_offset;