Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2001 07:40:11 -0600
From:      haikugeek@westhost36.westhost.net
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/32350: libstand's write always returns 0 unless error.
Message-ID:  <200111281340.fASDeBg14536@westhost36.westhost.net>

next in thread | raw e-mail | index | archive | help

>Number:         32350
>Category:       kern
>Synopsis:       libstand's write always returns 0 unless error.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 28 05:50:01 PST 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
 To: FreeBSD-gnats-submit@freebsd.org
 From: Jonathan Mini <mini@haikugeek.com>
 Reply-To: Jonathan Mini <mini@haikugeek.com>
 Cc: 
 X-send-pr-version: 3.113
 X-GNATS-Notify: 
 
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200111281340.fASDeBg14536>