Date: Tue, 28 Mar 2000 10:09:44 -0600 (CST) From: dnelson@emsphone.com To: FreeBSD-gnats-submit@freebsd.org Subject: bin/17640: lseek+read -> pread Message-ID: <200003281609.KAA93423@dan.emsphone.com>
next in thread | raw e-mail | index | archive | help
>Number: 17640 >Category: bin >Synopsis: lseek+read -> pread >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Mar 28 08:10:00 PST 2000 >Closed-Date: >Last-Modified: >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: >Unformatted: Dan Nelson 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?200003281609.KAA93423>