git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Clean up sha1 file writing

From
Linus Torvalds <torvalds@osdl.org>
Date
May 24, 2006, 18:52 UTC
Message-ID
<Pine.LNX.4.64.0605241145490.5623@g5.osdl.org>
In-Reply-To
<E1Fixs4-0005pD-10@moooo.ath.cx>
On Wed, 24 May 2006, Matthias Lederhofer wrote:
> > checking for partial writes
>
> Just out of interest: is this to be safe on any OS or should this
> be checked always?

Any POSIX-conformant OS/filesystem should always do a full write for a regular file, unless a serious error happens.

HOWEVER. 

In practice, you can get partial writes at least over NFS (hey, it may not be posix, but it's _common_) when the filesystem has been mounted soft (and/or interruptible). And obviously if your file descriptor isn't a regular file, you can easily get partial writes.

Doing the loop is always safe, so it's worth doing it that way.
Show 5 quoted lines
> > +		size = write(fd, buf, len);
> > +		if (!size)
> > +			return error("file write: disk full");
>
> Shouldn't write to a full disk return -1 with ENOSPC?

In that case, the "size < 0" check will catch it. The "return zero for full" case is an alternate error return (it happens for block device files at the end, it could happen for other things too). So the "returns zero means full" is the portable/safe thing to do.

		Linus
Previous: Matthias LederhoferNext: H. Peter Anvin
Message 3 of 15 in “Clean up sha1 file writing”
  1. Linus TorvaldsMay 24, 2006
  2. Matthias LederhoferMay 24, 2006
  3. Linus TorvaldsMay 24, 2006
  4. H. Peter AnvinJun 2, 2006
  5. Linus TorvaldsJun 2, 2006
  6. H. Peter AnvinJun 4, 2006
  7. Linus TorvaldsJun 4, 2006
  8. Linus TorvaldsJun 4, 2006
  9. H. Peter AnvinJun 4, 2006
  10. Junio C HamanoMay 24, 2006
  11. Linus TorvaldsMay 24, 2006
  12. Junio C HamanoMay 25, 2006
  13. SeanMay 25, 2006
  14. Junio C HamanoMay 26, 2006
  15. cat-file: document -p optionJeff King, May 25, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.