From owner-freebsd-questions@FreeBSD.ORG Sat Jul 10 21:28:57 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A51F9106564A for ; Sat, 10 Jul 2010 21:28:57 +0000 (UTC) (envelope-from batrick@batbytes.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 3F8158FC16 for ; Sat, 10 Jul 2010 21:28:56 +0000 (UTC) Received: by iwn35 with SMTP id 35so4262938iwn.13 for ; Sat, 10 Jul 2010 14:28:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.80.213 with SMTP id u21mr10987126ibk.173.1278797336390; Sat, 10 Jul 2010 14:28:56 -0700 (PDT) Received: by 10.231.172.20 with HTTP; Sat, 10 Jul 2010 14:28:56 -0700 (PDT) In-Reply-To: References: <87iq4nsr3a.fsf@kobe.laptop> Date: Sat, 10 Jul 2010 17:28:56 -0400 Message-ID: From: Patrick Donnelly To: "C. P. Ghost" , questions@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Subject: Re: Writes to Hard Disk Going Beyond Capacity X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Jul 2010 21:28:57 -0000 On Sat, Jul 10, 2010 at 2:38 PM, C. P. Ghost wrote: >> Are you aware of short writes? >> >> static int write_buf (int fd, const char *buf, size_t s) >> { >> =C2=A0ssize_t r =3D write(fd, buf, s); >> =C2=A0if (r =3D=3D -1) >> =C2=A0 =C2=A0fprintf(stderr, "write error: %s\n", strerror(errno)); >> =C2=A0return r >=3D 0; >> } >> >> What if write(2) returns less than s, but not -1? > > Or, to be more precise, is it possible that write(2) returns 0 for > some reason, perhaps because the device isn't ready and can't > accept more data, so it says that it wrote 0 bytes, but that you > are free to try again? > > On Solaris, the write(2) man page says: > > =C2=A0If a write() requests that more bytes be written than there is room > =C2=A0for=E2=80=94for example, if the write would exceed the process file= size > =C2=A0limit (see getrlimit(2) and ulimit(2)), the system file size limit, > =C2=A0or the free space on the device=E2=80=94only as many bytes as there= is room > =C2=A0for will be written. For example, suppose there is space for 20 > =C2=A0bytes more in a file before reaching a limit. A write() of 512-byte= s > =C2=A0returns 20. The next write() of a non-zero number of bytes gives a > =C2=A0failure return (except as noted for pipes and FIFO below). > > http://docs.sun.com/app/docs/doc/816-5167/write-2?l=3Den&n=3D1&a=3Dview > > Have you tried your program on [Open]Solaris too? What happens there? > Perhaps our write(2) isn't entirely IEEE Std 1003.1 compliant? Because > write(2) there says: > > =C2=A0If a write() requests that more bytes be written than there is room > =C2=A0for (for example, [XSI] [Option Start] the process' file size limit > =C2=A0or [Option End] the physical end of a medium), only as many bytes a= s > =C2=A0there is room for shall be written. For example, suppose there is > =C2=A0space for 20 bytes more in a file before reaching a limit. A write > =C2=A0of 512 bytes will return 20. The next write of a non-zero number of > =C2=A0bytes would give a failure return (except as noted below). (...) > > http://www.opengroup.org/onlinepubs/000095399/functions/write.html > > Hmmm... any C/POSIX standards lawyers/specialists here? write returning 0 appears to be the problem. That is indeed strange and I would guess it may be a bug? --=20 - Patrick Donnelly