From: Linus Torvalds <torvalds@osdl.org>
To: Matthias Lederhofer <matled@gmx.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: Clean up sha1 file writing
Date: Wed, 24 May 2006 11:52:22 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0605241145490.5623@g5.osdl.org> (raw)
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.
> > + 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
next prev parent reply other threads:[~2006-05-24 18:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-24 15:30 Clean up sha1 file writing Linus Torvalds
2006-05-24 18:14 ` Matthias Lederhofer
2006-05-24 18:52 ` Linus Torvalds [this message]
2006-06-02 18:44 ` H. Peter Anvin
2006-06-02 21:17 ` Linus Torvalds
2006-06-04 18:25 ` H. Peter Anvin
2006-06-04 18:39 ` Linus Torvalds
2006-06-04 18:40 ` Linus Torvalds
2006-06-04 19:05 ` H. Peter Anvin
2006-05-24 20:46 ` Junio C Hamano
2006-05-24 23:35 ` Linus Torvalds
2006-05-25 0:19 ` Junio C Hamano
[not found] ` <20060524203108.70b6c596.seanlkml@sympatico.ca>
2006-05-25 0:31 ` Sean
2006-05-25 1:22 ` [PATCH] cat-file: document -p option Jeff King
2006-05-26 5:36 ` Clean up sha1 file writing Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0605241145490.5623@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=git@vger.kernel.org \
--cc=matled@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).