From dan@dan.emsphone.com  Tue Mar 28 08:09:51 2000
Return-Path: <dan@dan.emsphone.com>
Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101])
	by hub.freebsd.org (Postfix) with ESMTP id 4858A37C056
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 28 Mar 2000 08:09:47 -0800 (PST)
	(envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.9.3/8.9.3) id KAA93423;
	Tue, 28 Mar 2000 10:09:44 -0600 (CST)
	(envelope-from dan)
Message-Id: <200003281609.KAA93423@dan.emsphone.com>
Date: Tue, 28 Mar 2000 10:09:44 -0600 (CST)
From: dnelson@emsphone.com
Sender: dan@dan.emsphone.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: lseek+read  -> pread
X-Send-Pr-Version: 3.2

>Number:         17640
>Category:       bin
>Synopsis:       lseek();read() -> pread() in dump and fsck
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mikeh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 28 08:10:00 PST 2000
>Closed-Date:    Sat Jul 14 06:51:44 PDT 2001
>Last-Modified:  Sat Jul 14 06:53:52 PDT 2001
>Originator:     Dan Nelson
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Executive Marketing Services, Inc.
>Environment:

FreeBSD dan.emsphone.com 5.0-CURRENT FreeBSD 5.0-CURRENT #52: Mon Mar 20 10:01:54 CST 2000     dan@dan.emsphone.com:/usr/src/sys/compile/DANSMP  i386

, but applies to 4.0 and 3.* as well.

	

>Description:

Simple replacement of an lseek()/read() combo with a single pread(). 
Halves the number of syscalls.

	

>How-To-Repeat:

	

>Fix:

I've been running the following code for a couple months, and both dump
and fsck work fine.


Index: sbin/dump/traverse.c
===================================================================
RCS file: /home/ncvs/src/sbin/dump/traverse.c,v
retrieving revision 1.10
diff -b -u -r1.10 traverse.c
--- sbin/dump/traverse.c	1999/08/28 00:12:39	1.10
+++ sbin/dump/traverse.c	2000/03/24 05:33:51
@@ -556,10 +556,7 @@
 	extern int errno;
 
 loop:
-	if (lseek(diskfd, ((off_t)blkno << dev_bshift), 0) !=
-						((off_t)blkno << dev_bshift))
-		msg("bread: lseek fails\n");
-	if ((cnt = read(diskfd, buf, size)) == size)
+	if ((cnt = pread(diskfd, buf, size, (off_t)blkno << dev_bshift)) == size)
 		return;
 	if (blkno + (size / dev_bsize) > fsbtodb(sblock, sblock->fs_size)) {
 		/*
Index: sbin/fsck/utilities.c
===================================================================
RCS file: /home/ncvs/src/sbin/fsck/utilities.c,v
retrieving revision 1.11
diff -b -u -r1.11 utilities.c
--- sbin/fsck/utilities.c	1999/08/28 00:12:49	1.11
+++ sbin/fsck/utilities.c	1999/11/25 05:54:06
@@ -327,11 +327,9 @@
 
 	offset = blk;
 	offset *= dev_bsize;
-	if (lseek(fd, offset, 0) < 0)
-		rwerror("SEEK", blk);
-	else if (read(fd, buf, (int)size) == size)
+	if (pread(fd, buf, (int)size, offset) == size)
 		return (0);
-	rwerror("READ", blk);
+	rwerror("PREAD", blk);
 	if (lseek(fd, offset, 0) < 0)
 		rwerror("SEEK", blk);
 	errs = 0;

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mikeh 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Sat Jun 16 08:13:40 PDT 2001 
Responsible-Changed-Why:  
I'll commit the change to dump after I take a look at it. It appears that 
the fsck part doesn't apply anymore. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=17640 
State-Changed-From-To: open->analyzed 
State-Changed-By: mikeh 
State-Changed-When: Sat Jun 30 22:05:15 PDT 2001 
State-Changed-Why:  
Committed, thanks! (MFC in 2 weeks) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=17640 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mikeh 
State-Changed-When: Sat Jul 14 06:51:44 PDT 2001 
State-Changed-Why:  
Fix MFC'd. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=17640 
>Unformatted:
 Dan Nelson
