---------------------------------------------------------------------- Patch name: patch.blkdevsize Author: Ph. Marek, updated by cbothamy Date: July 29th 2002 Detailed description: I added a configure check so the code will be included only on system that supports it. Original Detailed description: I'm currently working to get bochs to support block devices (eg. /dev/hda) as harddisks. I downloaded the current release http://prdownloads.sourceforge.net/bochs/bochs-1.4.tar.gz and found that size detection doesn't work. 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 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 # include #endif +#if BX_HAVE_BLKGETSIZE +# include +#endif #include #include #include 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 #define BX_HAVE_SOCKLEN_T 0 +#define BX_HAVE_BLKGETSIZE 0 // This turns on Roland Mainz's idle hack. Presently it is specific to the X11 // gui. If people try to enable it elsewhere, give a compile error after the 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 @@ 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 + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +#include + +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +#ifndef BLKGETSIZE + char *p = (char *) BLKGETSIZE; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_decl_BLKGETSIZE=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_have_decl_BLKGETSIZE=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_decl_BLKGETSIZE" >&5 +echo "${ECHO_T}$ac_cv_have_decl_BLKGETSIZE" >&6 +if test $ac_cv_have_decl_BLKGETSIZE = yes; then + cat >>confdefs.h <<\_ACEOF +#define BX_HAVE_BLKGETSIZE 1 +_ACEOF + +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 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 ]) +AC_CHECK_DECL(BLKGETSIZE, AC_DEFINE(BX_HAVE_BLKGETSIZE), , [#include ]) AC_MSG_CHECKING(for struct timeval) AC_TRY_COMPILE([#include ], @@ -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) 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 @@ 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 + } +#endif if ((stat_buf.st_size % 512) != 0) { BX_PANIC(("size of disk image must be multiple of 512 bytes")); }