Re: [Patch] New VHD support... now with added dynamics
Posted: Sun 15 Nov, 2020 9:03 am
PCem forum
https://pcem-emulator.co.uk/phpBB3/
Thank you Sarah. I originally used _wfopen(), so that change is fine by me. Those '_s' functions were something I kind of glossed over during my review of the code. I know for next time!SarahWalker wrote: ↑Sun 15 Nov, 2020 9:03 amCommitted at 322b25a4. I also unilaterally removed the use of _wfopen_s, commit 95e6819f.
Code: Select all
diff --git a/src/wx-config.c b/src/wx-config.c
index 2421d67..9f24e2c 100644
--- a/src/wx-config.c
+++ b/src/wx-config.c
@@ -1842,9 +1842,13 @@ static int hdnew_dlgproc(void* hdlg, int message, INT_PARAM wParam, LONG_PARAM l
return TRUE;
}
}
+ wx_messagebox(hdlg, "Differencing VHD image created.\n\n"
+ "WARNING: Do not open or modify the parent image(s) while this file exists.", "PCem", WX_MB_OK);
+ }
+ if (hd_format != 3)
+ {
+ wx_messagebox(hdlg, "Drive created, remember to partition and format the new drive.", "PCem", WX_MB_OK);
}
-
- wx_messagebox(hdlg, "Drive created, remember to partition and format the new drive.", "PCem", WX_MB_OK);
wx_enddialog(hdlg, 1);
return TRUE;
Code: Select all
Segmentation fault (core dumped)
Nooooo, not the dreaded segfaultLaucian wrote: ↑Wed 18 Nov, 2020 2:47 am I finally had more time to test out the changes. It compiles fine now.
Under Linux I am experiencingwhenever I create a new VHD or attach an existing one to a machine.Code: Select all
Segmentation fault (core dumped)
Code: Select all
diff --git a/src/minivhd/cwalk.c b/src/minivhd/cwalk.c
index 265de0f..f0c4842 100644
--- a/src/minivhd/cwalk.c
+++ b/src/minivhd/cwalk.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
diff --git a/src/minivhd/minivhd_convert.c b/src/minivhd/minivhd_convert.c
index 231e0f9..1de6f46 100644
--- a/src/minivhd/minivhd_convert.c
+++ b/src/minivhd/minivhd_convert.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/minivhd/minivhd_create.c b/src/minivhd/minivhd_create.c
index 9e34ece..c47c7d8 100644
--- a/src/minivhd/minivhd_create.c
+++ b/src/minivhd/minivhd_create.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/minivhd/minivhd_io.c b/src/minivhd/minivhd_io.c
index 8e9172e..ddd1717 100644
--- a/src/minivhd/minivhd_io.c
+++ b/src/minivhd/minivhd_io.c
@@ -3,6 +3,9 @@
* \brief Sector reading and writing implementations
*/
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <string.h>
#include "minivhd_internal.h"
diff --git a/src/minivhd/minivhd_manage.c b/src/minivhd/minivhd_manage.c
index 75e0953..e9473c0 100644
--- a/src/minivhd/minivhd_manage.c
+++ b/src/minivhd/minivhd_manage.c
@@ -2,7 +2,9 @@
* \file
* \brief VHD management functions (open, close, read write etc)
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/src/minivhd/minivhd_struct_rw.c b/src/minivhd/minivhd_struct_rw.c
index 66f2289..c77fa60 100644
--- a/src/minivhd/minivhd_struct_rw.c
+++ b/src/minivhd/minivhd_struct_rw.c
@@ -2,7 +2,9 @@
* \file
* \brief Header and footer serialize/deserialize functions
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/src/minivhd/minivhd_struct_rw.h b/src/minivhd/minivhd_struct_rw.h
index 0b1e018..ee49bb6 100644
--- a/src/minivhd/minivhd_struct_rw.h
+++ b/src/minivhd/minivhd_struct_rw.h
@@ -1,5 +1,5 @@
#ifndef MINIVHD_STRUCT_RW_H
-#define minivhd_struct_rw
+#define MINIVHD_STRUCT_RW_H
#include "minivhd_internal.h"
diff --git a/src/minivhd/minivhd_util.c b/src/minivhd/minivhd_util.c
index d8f44ca..edede96 100644
--- a/src/minivhd/minivhd_util.c
+++ b/src/minivhd/minivhd_util.c
@@ -2,7 +2,9 @@
* \file
* \brief Utility functions
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -152,7 +154,7 @@ FILE* mvhd_fopen(const char* path, const char* mode, int* err) {
}
}
#else
- f = fopen64(path, mode);
+ f = fopen(path, mode);
if (f == NULL) {
mvhd_errno = errno;
*err = MVHD_ERR_FILE;
@@ -254,7 +256,7 @@ int64_t mvhd_ftello64(FILE* stream)
#ifdef _MSC_VER
return _ftelli64(stream);
#else
- return ftello64(stream);
+ return ftello(stream);
#endif
}
@@ -263,7 +265,7 @@ int mvhd_fseeko64(FILE* stream, int64_t offset, int origin)
#ifdef _MSC_VER
return _fseeki64(stream, offset, origin);
#else
- return fseeko64(stream, offset, origin);
+ return fseeko(stream, offset, origin);
#endif
}
Thanks. If you notice any issues with differencing disks, please let me know. It's probably the bit I'm least confident about. Especially since it has to do a lot of file path manipulation, which is an even bigger cross platform pain than the large file support was. Sometimes I hate C...Laucian wrote: ↑Wed 18 Nov, 2020 8:23 pm I just tested and it is working fine under Linux now. As usual cross-platform support is a bit of a pain.
Thank you very much for the work on the patch, differencing images are such a lifesaver when it comes to managing Windows 9x and a large software library.
Whyyyyyyyyyyyyy!!!!!!SarahWalker wrote: ↑Wed 18 Nov, 2020 8:47 pm With the most recent patch it no longer builds for me on mingw. ftello and fseeko don't exist.
Code: Select all
diff --git a/src/minivhd/cwalk.c b/src/minivhd/cwalk.c
index 265de0f..f0c4842 100644
--- a/src/minivhd/cwalk.c
+++ b/src/minivhd/cwalk.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
diff --git a/src/minivhd/minivhd_convert.c b/src/minivhd/minivhd_convert.c
index 231e0f9..1de6f46 100644
--- a/src/minivhd/minivhd_convert.c
+++ b/src/minivhd/minivhd_convert.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/minivhd/minivhd_create.c b/src/minivhd/minivhd_create.c
index 9e34ece..c47c7d8 100644
--- a/src/minivhd/minivhd_create.c
+++ b/src/minivhd/minivhd_create.c
@@ -1,3 +1,6 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/minivhd/minivhd_io.c b/src/minivhd/minivhd_io.c
index 8e9172e..ddd1717 100644
--- a/src/minivhd/minivhd_io.c
+++ b/src/minivhd/minivhd_io.c
@@ -3,6 +3,9 @@
* \brief Sector reading and writing implementations
*/
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <string.h>
#include "minivhd_internal.h"
diff --git a/src/minivhd/minivhd_manage.c b/src/minivhd/minivhd_manage.c
index 75e0953..e9473c0 100644
--- a/src/minivhd/minivhd_manage.c
+++ b/src/minivhd/minivhd_manage.c
@@ -2,7 +2,9 @@
* \file
* \brief VHD management functions (open, close, read write etc)
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/src/minivhd/minivhd_struct_rw.c b/src/minivhd/minivhd_struct_rw.c
index 66f2289..c77fa60 100644
--- a/src/minivhd/minivhd_struct_rw.c
+++ b/src/minivhd/minivhd_struct_rw.c
@@ -2,7 +2,9 @@
* \file
* \brief Header and footer serialize/deserialize functions
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/src/minivhd/minivhd_struct_rw.h b/src/minivhd/minivhd_struct_rw.h
index 0b1e018..ee49bb6 100644
--- a/src/minivhd/minivhd_struct_rw.h
+++ b/src/minivhd/minivhd_struct_rw.h
@@ -1,5 +1,5 @@
#ifndef MINIVHD_STRUCT_RW_H
-#define minivhd_struct_rw
+#define MINIVHD_STRUCT_RW_H
#include "minivhd_internal.h"
diff --git a/src/minivhd/minivhd_util.c b/src/minivhd/minivhd_util.c
index d8f44ca..5bfc599 100644
--- a/src/minivhd/minivhd_util.c
+++ b/src/minivhd/minivhd_util.c
@@ -2,7 +2,9 @@
* \file
* \brief Utility functions
*/
-
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -152,7 +154,7 @@ FILE* mvhd_fopen(const char* path, const char* mode, int* err) {
}
}
#else
- f = fopen64(path, mode);
+ f = fopen(path, mode);
if (f == NULL) {
mvhd_errno = errno;
*err = MVHD_ERR_FILE;
@@ -253,8 +255,10 @@ int64_t mvhd_ftello64(FILE* stream)
{
#ifdef _MSC_VER
return _ftelli64(stream);
-#else
+#elif defined(__MINGW32__)
return ftello64(stream);
+#else /* This should work with linux (with _FILE_OFFSET_BITS), and hopefully OS X and BSD */
+ return ftello(stream);
#endif
}
@@ -262,8 +266,10 @@ int mvhd_fseeko64(FILE* stream, int64_t offset, int origin)
{
#ifdef _MSC_VER
return _fseeki64(stream, offset, origin);
-#else
+#elif defined(__MINGW32__)
return fseeko64(stream, offset, origin);
+#else /* This should work with linux (with _FILE_OFFSET_BITS), and hopefully OS X and BSD */
+ return fseeko(stream, offset, origin);
#endif
}
SA1988 wrote: ↑Fri 20 Nov, 2020 8:00 pm Just tried NT, first part of installation can be done normally, but during boot, I get gibberish during ntldr or unknown hard error on the dynamic VHD I'm using, this doesn't happen with fixed size VHD or plain RAW.
Note that the file system is FAT16, not NTFS, of the dynamic vhd I'm using.
Ok, this WAS a MiniVHD bug, a fairly nasty one too. BUT it only manifested itself for some types of multi-sector writes, which PCem doesn't appear to do, but if it ever does, would have bit PCem as well. sards3 has authored a fix and is in the set of patches attached.
Thank you very much.
There is still compile problem exists on CentOS. Your VHD code uses C99 extensions but it's not enabled by default on CentOS. To solve this problem, configure.ac file must be modified as described below, or all VHD related code must be rewritten to avoid using C99 extensions.shermanp wrote: ↑Sat 21 Nov, 2020 11:10 amSA1988 wrote: ↑Fri 20 Nov, 2020 8:00 pm Just tried NT, first part of installation can be done normally, but during boot, I get gibberish during ntldr or unknown hard error on the dynamic VHD I'm using, this doesn't happen with fixed size VHD or plain RAW.
Note that the file system is FAT16, not NTFS, of the dynamic vhd I'm using.Ok, this WAS a MiniVHD bug, a fairly nasty one too. BUT it only manifested itself for some types of multi-sector writes, which PCem doesn't appear to do, but if it ever does, would have bit PCem as well. sards3 has authored a fix and is in the set of patches attached.
Patch 0002-Remove-duplicate-typedef-from-minivhd_internal.patch is my preferred alternative to Greatpsycho's two minivhd patches.
There's also a mass EOF fixup, and added some functions to the public header that should have always been there.
Unless any other bugs crop up, I'm hoping this will be it for now.
(Note, I've done individual patches, as well as a all-in-one diff)
Code: Select all
AC_MSG_CHECKING([whether to enable debugging])
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug], [build debug executable]))
if test "$enable_debug" = "yes"; then
CFLAGS="-Wall -O0 -g -D_DEBUG -fcommon"
CXXFLAGS="-Wall -O0 -g -D_DEBUG -fcommon"
AC_MSG_RESULT([yes])
else
CFLAGS="-O3 -fcommon"
CXXFLAGS="-O3 -fcommon"
AC_MSG_RESULT([no])
fi
Code: Select all
AC_MSG_CHECKING([whether to enable debugging])
AC_ARG_ENABLE(debug,
AC_HELP_STRING([--enable-debug], [build debug executable]))
if test "$enable_debug" = "yes"; then
CFLAGS="-Wall -O0 -g -D_DEBUG -fcommon -std=gnu99"
CXXFLAGS="-Wall -O0 -g -D_DEBUG -fcommon"
AC_MSG_RESULT([yes])
else
CFLAGS="-O3 -fcommon -std=gnu99"
CXXFLAGS="-O3 -fcommon"
AC_MSG_RESULT([no])
fi
Really? It's the end of 2020, and there's still compilers which don't compile code from a 20 year old standard out-of-the box? Sheesh.Greatpsycho wrote: ↑Sun 22 Nov, 2020 7:38 am
There is still compile problem exists on CentOS. Your VHD code uses C99 extensions but it's not enabled by default on CentOS. To solve this problem, configure.ac file must be modified as described below, or all VHD related code must be rewritten to avoid using C99 extensions.
pcem-compile-error.png
Old configure.acNew configure.acCode: Select all
AC_MSG_CHECKING([whether to enable debugging]) AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [build debug executable])) if test "$enable_debug" = "yes"; then CFLAGS="-Wall -O0 -g -D_DEBUG -fcommon" CXXFLAGS="-Wall -O0 -g -D_DEBUG -fcommon" AC_MSG_RESULT([yes]) else CFLAGS="-O3 -fcommon" CXXFLAGS="-O3 -fcommon" AC_MSG_RESULT([no]) fi
Code: Select all
AC_MSG_CHECKING([whether to enable debugging]) AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [build debug executable])) if test "$enable_debug" = "yes"; then CFLAGS="-Wall -O0 -g -D_DEBUG -fcommon -std=gnu99" CXXFLAGS="-Wall -O0 -g -D_DEBUG -fcommon" AC_MSG_RESULT([yes]) else CFLAGS="-O3 -fcommon -std=gnu99" CXXFLAGS="-O3 -fcommon" AC_MSG_RESULT([no]) fi
May not be possible on an old version of CentOS.
The compiler only complaining about declaration in the for loop. This patch removes declaration in the for loop and solves compile problem on CentOS.shermanp wrote: ↑Sun 22 Nov, 2020 10:25 amMay not be possible on an old version of CentOS.
I shouldn't think adding -std=gnu99" to configure.ac would cause too many issues though, although maaaybe it would need to be linux or gcc specific?
EDIT: If the only thing the compiler is complaining about is the declaration in the for loop, I could probably change that in MiniVHD.
Feel free to integrate this into PCem Sarah, I've committed the changes to MiniVHD as-is.Greatpsycho wrote: ↑Sun 22 Nov, 2020 11:35 am The compiler only complaining about declaration in the for loop. This patch removes declaration in the for loop and solves compile problem on CentOS.