In article <[email protected]>,
Peter Howkins <[email protected]> wrote:
> On Mon, Feb 15, 2016 at 11:55:44PM +0000, Theo Markettos wrote:
> >
> > I've also applied a patch from Sprow to support 4GB files.
> >
> > Please let me know if there are any new bugs this has introduced.
>
> For the long explanation of why this HostFS patch is not included in
> RPCEmu, please see this post from 2011.
>
> http://www.riscos.info/pipermail/rpcemu/2011-October/001383.html
I recall that discussion at the time, and the thread continued
http://www.riscos.info/pipermail/rpcemu/2011-October/001384.html
then fell silent.
The tests performed in the post you've highlighted didn't really elicit any
new information:
Old FileSwitch + 4GB files + vanilla HostFS => doesn't work
Old FileSwitch + 4GB files + 4GB HostFS => doesn't work
New FileSwitch + 4GB files + vanilla HostFS => doesn't work
New FileSwitch + 4GB files + 4GB HostFS => does work
the point being that having the underlying HostFS being 4GB capable is
harmless for OS versions that it already doesn't work on, it's only when
coupled with RISC OS 5.20 and (chronologically) later that you get benefit.
RISC OS 3/4/6 don't handle > 2G files gracefully out of the tin, and nor do
they with an updated HostFS.
Patch attached for 0.8.14 for reference,
Sprow.
diff -ru rpcemu-0.8.14-orig/src/hostfs.c rpcemu-0.8.14/src/hostfs.c
--- rpcemu-0.8.14-orig/src/hostfs.c 2016-02-08 14:07:58 +0000
+++ rpcemu-0.8.14/src/hostfs.c 2016-02-16 08:25:58 +0000
@@ -17,6 +17,8 @@
*/
+#define _LARGEFILE_SOURCE
+#define _LARGEFILE64_SOURCE
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -50,6 +52,34 @@
# define mkdir(name, mode) _mkdir(name)
#endif
+/* Windows doesn't have an ftruncate64() implementation, so map
+ this to the equivalent Kernel call */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#define NOGDI
+#include <windows.h>
+int ftruncate64(int fd, off64_t length)
+{
+ HANDLE h;
+ int64_t present;
+
+ h = (HANDLE)_get_osfhandle(fd);
+ if (h == (HANDLE)-1) {
+ errno = EBADF;
+ return -1;
+ }
+
+ present = _lseeki64(fd, (int64_t)length, SEEK_SET);
+ if (present != (int64_t)length) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ /* If the call fails blame it on the system */
+ errno = ENOSYS;
+ return SetEndOfFile(h) ? 0 : -1;
+}
+#endif
+
typedef int bool;
#define true ((bool) 1)
@@ -892,8 +922,8 @@
}
/* Find the extent of the file */
- fseek(open_file[idx], 0L, SEEK_END);
- state->Reg[3] = ftell(open_file[idx]);
+ fseeko64(open_file[idx], 0LL, SEEK_END);
+ state->Reg[3] = ftello64(open_file[idx]);
rewind(open_file[idx]); /* Return to start */
state->Reg[1] = idx; /* Our filing system's handle */
@@ -920,7 +950,7 @@
hostfs_ensure_buffer_size(state->Reg[3]);
- fseek(f, (long) state->Reg[4], SEEK_SET);
+ fseeko64(f, (off64_t) state->Reg[4], SEEK_SET);
fread(buffer, 1, state->Reg[3], f);
@@ -947,7 +977,7 @@
hostfs_ensure_buffer_size(state->Reg[3]);
- fseek(f, (long) state->Reg[4], SEEK_SET);
+ fseeko64(f, (off64_t) state->Reg[4], SEEK_SET);
for (i = 0; i < state->Reg[3]; i++) {
buffer[i] = ARMul_LoadByte(state, ptr);
@@ -988,7 +1018,7 @@
/* Set file to required extent */
/* FIXME Not defined if file is increased in size */
- if (ftruncate(fd, (off_t) state->Reg[2])) {
+ if (ftruncate64(fd, (off64_t) state->Reg[2])) {
fprintf(stderr, "hostfs_args_3_write_file_extent() bad ftruncate(): %s
%d\n",
strerror(errno), errno);
return;
@@ -1008,9 +1038,9 @@
dbug_hostfs("\tr1 = %u (our file handle)\n", state->Reg[1]);
dbug_hostfs("\tr2 = %u (size of file to ensure)\n", state->Reg[2]);
- fseek(f, 0L, SEEK_END);
+ fseeko64(f, 0LL, SEEK_END);
- state->Reg[2] = (ARMword) ftell(f);
+ state->Reg[2] = (ARMword) ftello64(f);
}
static void
@@ -1029,7 +1059,7 @@
dbug_hostfs("\tr2 = %u (file offset at which to write)\n", state->Reg[2]);
dbug_hostfs("\tr3 = %u (number of zero bytes to write)\n", state->Reg[3]);
- fseek(f, (long) state->Reg[2], SEEK_SET);
+ fseeko64(f, (off64_t) state->Reg[2], SEEK_SET);
hostfs_ensure_buffer_size(BUFSIZE);
memset(buffer, 0, BUFSIZE);
diff -ru rpcemu-0.8.14-orig/src/rpcemu.h rpcemu-0.8.14/src/rpcemu.h
--- rpcemu-0.8.14-orig/src/rpcemu.h 2016-02-08 14:07:58 +0000
+++ rpcemu-0.8.14/src/rpcemu.h 2016-02-16 08:26:14 +0000
@@ -40,6 +40,7 @@
#define fseeko64(_a, _b, _c) fseeko(_a, _b, _c)
#define ftello64(stream) ftello(stream)
#define fopen64(_a, _b) fopen(_a, _b)
+#define ftruncate64(_a, _b) ftruncate(_a, _b)
#define off64_t off_t
#endif
_______________________________________________
Rpcemu mailing list
[email protected]
http://www.riscos.info/cgi-bin/mailman/listinfo/rpcemu