How to write files > 4GB with pwrite in Mono C# in 32-bit OS?
I'm trying to write a new file with size > 64 gb using mono c# and Mono.Posix
library, with the Syscall.pwrite() function. But in a 32-bit OS, I get error
EOVERFLOW when the offset reach 4GB.
This is the example code I'm using:
public unsafe static void Main (string args)
int fd = Syscall.open("/dev/null", OpenFlags.O_WRONLY);
long bLen = 4096;
long fLen = 5368709120;
byte buffer = new byte[bLen];
long c = 0;
long res = -1;
if (fd == -1)
fixed (byte *pb = buffer)
res = Syscall.pwrite(fd, pb, (ulong)bLen, c);
if (res == -1)
while (c < fLen);
Re: How to write files > 4GB with pwrite in Mono C# in 32-bit OS?
On Mar 18, 2017, at 5:47 PM, pedrom71 <[hidden email]> wrote:
> I'm trying to write a new file with size > 64 gb using mono c# and Mono.Posix
> library, with the Syscall.pwrite() function. But in a 32-bit OS, I get error
> EOVERFLOW when the offset reach 4GB.
Because libMonoPosixHelper.so believes you can’t do that:
> Macro: _FILE_OFFSET_BITS
> If the macro is defined to the value 64, the large file interface replaces the old interface. I.e., the functions are not made available under different names (as they are with _LARGEFILE64_SOURCE).
This doesn’t mention what happens with `off_t`, but I also see:
http://users.suse.com/~aj/linux_lfs.html > Compile your programs with "gcc -D_FILE_OFFSET_BITS=64". This forces all file access calls to use the 64 bit variants. Several types change also, e.g. off_t becomes off64_t.
This strongly implies that your libMonoPosixHelper.so isn’t being compiled with `-D_FILE_OFFSET_BITS=64`. You should investigate the compilation flags that are used when building within the mono/support directory.