tags:

views:

30

answers:

1

When can a short write to a file descriptor occur in FreeBSD 7.2 ? I mean the situation when "write" system call returns less bytes written than requested. I'm speaking about descriptors to ordinary files in ufs filesystem which we can get with a call to open().

A: 

write() can return fewer bytes written than requested:

There is a process context switch or a SIGINT is received, write() is not atomic. write() returns fewer bytes when EOF occurs before the whole buffer is read.

If the fd is set to non-blocking, then other transient conditions may cause write() to return having written fewer bytes than requested - this is implementation defined behavior. An example is transient disk full errors, on filesystems like /tmp. NFS filesystems do not play well sometimes: an error return from close() may be the only way you detect a disk full error on a write() to an NFS mounted file.

jim mcnamara