Re: write(2) fails for large sizes in 64 bit applications
Re: write(2) fails for large sizes in 64 bit applications
- Subject: Re: write(2) fails for large sizes in 64 bit applications
- From: Anton Altaparmakov <email@hidden>
- Date: Thu, 28 May 2009 10:38:08 +0100
Hi,
Yes you are quite right. If you look in the kernel source code you
can see that it is a hard limit...
http://www.opensource.apple.com/source/xnu/xnu-1228.12.14/bsd/kern/sys_generic.c
The write() system call in turn calls write_nocancel() which in turn
calls dofilewrite() which at the top of the function contains:
// LP64todo - do we want to raise this?
if (nbyte > INT_MAX)
return (EINVAL);
Which is what you are seeing.
Best regards,
Anton
On 28 May 2009, at 10:22, Robert Homann wrote:
Hi all!
I have just discovered that write(2) fails when trying to write blocks
larger than 2^31-1 in a program compiled for 64 bit mode (gcc -m64).
Maybe I am doing something wrong, but I suspect a bug in the
implementation of write().
When nbytes is set to 2^31 or greater, write() returns -1 and sets
errno to EINVAL. This behavior would probably be OK in 32 bit mode,
but I don't see how it would be correct in a 64 bit application. I
would expect write() to either return the number of bytes written, or
-1 with errno set to EINTR in case of an interrupted system call (or
an errno value different from EINVAL in case of other kinds of
failures).
I can work around this problem when calling write() in a loop while
limiting the number of bytes written at a time to 2^31-1; the
resulting file is as large as it should be, so it is not a file system
limitation. The same code (without the workaround) works well on 64
bit
Solaris and Linux.
Therefore, I think the implementation of write() is buggy; or at
least, its unexpected behavior in 64 bit mode should be documented on
the man page. What do you think?
Best regards,
Robert Homann
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer, http://www.linux-ntfs.org/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden