From haikugeek@westhost36.westhost.net  Wed Nov 28 05:41:01 2001
Return-Path: <haikugeek@westhost36.westhost.net>
Received: from westhost36.westhost.net (westhost36.westhost.net [216.71.84.209])
	by hub.freebsd.org (Postfix) with ESMTP id C7D1737B417
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 28 Nov 2001 05:41:00 -0800 (PST)
Received: (from haikugeek@localhost)
	by westhost36.westhost.net (8.11.6/8.11.6) id fASDeBg14536
	for FreeBSD-gnats-submit@freebsd.org; Wed, 28 Nov 2001 07:40:11 -0600
Message-Id: <200111281340.fASDeBg14536@westhost36.westhost.net>
Date: Wed, 28 Nov 2001 07:40:11 -0600
From: Jonathan Mini <mini@haikugeek.com>
Reply-To: Jonathan Mini <mini@haikugeek.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: libstand's write always returns 0 unless error.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         32350
>Category:       kern
>Synopsis:       libstand's write always returns 0 unless error.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    msmith
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 28 05:50:01 PST 2001
>Closed-Date:    Thu Nov 29 21:52:45 PST 2001
>Last-Modified:  Thu Nov 29 21:55:35 PST 2001
>Originator:     Jonathan Mini
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD groove.haikugeek.com FreeBSD 5.0-CURRENT #1: Sun Nov 18 02:30:58 GMT 2001 mini@:/usr/obj/usr/home/mini/work/src/sys/GENERIC i386

>Description:
	Libstand's implementation of write() returns 0 on success, instead of
	the number of bytes written.
>How-To-Repeat:
	Well, it's a little hard to reproduce unless you have my changes to
	allow ufs writes in libstand, as none of the filesystems accept
	write requests and no console access is done via the write()
	interface.

	However, if you apply this patch:

		http://www.haikugeek.com/freebsd/5.0-boot-libstand.diff

	.. which adds limited write support to the ufs code, and then
	open a file and write to it, you will see that write will return
	0 instead of the number of bytes written, e.g.:

		int fd,res;

		fd = open("/etc/motd",O_WRONLY);
		res = write(fd,"foo!",4);
		printf("write: %d bytes written.\n",res);

	will print:

		write: 0 bytes written.

>Fix:

	Apply this patch:

Index: lib/libstand/write.c
===================================================================
RCS file: /usr/FreeBSD/src/lib/libstand/write.c,v
retrieving revision 1.2
diff -c -r1.2 write.c
*** lib/libstand/write.c	2001/09/30 22:28:01	1.2
--- lib/libstand/write.c	2001/11/15 18:04:19
***************
*** 95,99 ****
  	resid = bcount;
  	if ((errno = (f->f_ops->fo_write)(f, dest, bcount, &resid)))
  		return (-1);
! 	return (0);
  }
--- 97,101 ----
  	resid = bcount;
  	if ((errno = (f->f_ops->fo_write)(f, dest, bcount, &resid)))
  		return (-1);
! 	return (bcount - resid);
  }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->msmith 
Responsible-Changed-By: alfred 
Responsible-Changed-When: Thu Nov 29 21:23:59 PST 2001 
Responsible-Changed-Why:  
Mike wants to handle this. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32350 
State-Changed-From-To: open->closed 
State-Changed-By: alfred 
State-Changed-When: Thu Nov 29 21:52:45 PST 2001 
State-Changed-Why:  
I assigned this to Mike Smith because I thought this was the loader 
write support, I committed and closed it because it's actually a subset 
of that patch that just corrects the semantics of the libstand write 
function. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=32350 
>Unformatted:
