[Mono-dev] How to write files > 4GB with pwrite in Mono C# in 32-bit OS?

Jonathan Pryor jonpryor at vt.edu
Sun Mar 26 13:11:10 UTC 2017


On Mar 18, 2017, at 5:47 PM, pedrom71 <pedrosanzm71 at gmail.com> 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:

	https://github.com/mono/mono/blob/9b824c3/support/unistd.c#L60-L67

Specifically, it asserts that your `offset` value can fit within a `off_t`. On 32-bit platforms, `off_t` is usually a 32-bit value, so your 64-bit value cannot fit, so it returns EOVERFLOW.

Though I also see:

	https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

> 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.

 - Jon



More information about the Mono-devel-list mailing list