From owner-freebsd-hackers Fri Nov 15 07:33:21 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id HAA20867 for hackers-outgoing; Fri, 15 Nov 1996 07:33:21 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id HAA20832 for ; Fri, 15 Nov 1996 07:33:11 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.7.6/8.6.9) id CAA16817; Sat, 16 Nov 1996 02:29:19 +1100 Date: Sat, 16 Nov 1996 02:29:19 +1100 From: Bruce Evans Message-Id: <199611151529.CAA16817@godzilla.zeta.org.au> To: jgreco@brasil.moneng.mei.com, terry@lambert.org Subject: Re: Sockets question... Cc: hackers@FreeBSD.ORG, jdp@polstra.com, scrappy@ki.net Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >% man 2 read >(SunOS version) >... >READ(2V) SYSTEM CALLS READ(2V) > > system guarantees to read the number of bytes requested if > the descriptor references a normal file which has that many > bytes left before the EOF (end of file), but in no other > case. > >Key words, "but in no other case".. FreeBSD says the same thing in the same words except for English improvements. It lies :-). Short reads are possible even for normal files because the read might be into a partially invalid buffer. ffs_read() returns the blocks that are successfully read instead of unwinding the read and returning an EFAULT error. Example: --- #include #include #define SIZE 0x10000 main() { void *buf; int n; buf = malloc(0x10000); n = read(0, buf, 0x10000); printf("read %d\n", n); } --- This prints 65536 here. A watertight example can be probably be constructed using mmap(). Short writes to normal files are more likely. They occur when the disk fills up and for partially invalid buffers. There are more serious problems for the latter case. Bruce