freebsd-src/lib/libstand
John Polstra 719077d1be Fix a bug in lseek which caused the loader to fail on some gzipped
kernels.  The error message was "elf_loadexec: cannot seek".

Libstand maintains a read-ahead buffer for each open file, so that
it can read in chunks of 512 bytes for greater efficiency.  When
the loader tries to lseek forward in a file by a small amount, it
sometimes happens that the target file offset is already in the
read-ahead buffer.  But the lseek code simply discarded the contents
of that buffer and performed a seek directly on the underlying
file.  This resulted in an attempt to seek backwards in the file,
since some of the data has already been read into the read-ahead
buffer.  Gzipped data streams cannot seek backwards, so an error
was returned.

This commit adds code which checks to see if the desired file offset
is already in the read-ahead buffer.  If it is, the code simply
adjusts the buffer pointer and length, thereby avoiding a reverse
seek on the gzipped data stream.

I incorporated a suggestion from Matt Dillon which saved a little
bit of code in this fix.

Reviewed by:	dillon, gallatin, jhb
2001-08-29 23:33:22 +00:00
..
alpha We compile expressly on the alpha with -mno-fp-regs - so do not use them 2000-05-12 21:48:54 +00:00
i386 Removed duplicate VCS ID tags, as per style(9). 2001-08-13 14:06:34 +00:00
ia64 Removed duplicate VCS ID tags, as per style(9). 2001-08-13 14:06:34 +00:00
powerpc Make setjmp work our way, as opposed to NetBSD's. 2000-11-10 06:10:28 +00:00
__main.c
arp.c
assert.c Make include file consistent with the rest of libstand. 2001-07-31 15:49:50 +00:00
bcd.c Make libstand compile 2000-09-03 11:29:18 +00:00
bootp.c IN_CLASS*() macros assume host order and s_addr is network byte 2000-09-20 18:16:20 +00:00
bootp.h Add support to send the string 'PXEClient' as the Vendor class 2000-08-11 08:36:17 +00:00
bootparam.c
bootparam.h
bswap.c
cd9660.c Bail if we go beyond the directory size, not just if we hit it. 2001-08-23 17:08:26 +00:00
close.c Implement readahead buffering for non-raw files. This drastically improves 2000-09-05 09:52:50 +00:00
closeall.c
dev.c
dev_net.c Add a new field to the devsw structure; dv_print, to print all valid units 1998-10-31 02:48:29 +00:00
dev_net.h
dosfs.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00
dosfs.h
environment.c Cleanup warnings by adding missint prototypes, removing unneeded duplicate 2000-08-03 09:08:29 +00:00
ether.c More egcs warning fixes: 1999-04-25 22:29:30 +00:00
ext2fs.c Fix typo: compatability -> compatibility. 2001-02-06 12:05:58 +00:00
fstat.c
getopt.c
gets.c Add a new field to the devsw structure; dv_print, to print all valid units 1998-10-31 02:48:29 +00:00
globals.c
gzipfs.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00
if_ether.h Back out the previous change to the queue(3) interface. 2000-05-26 02:09:24 +00:00
in_cksum.c
inet_ntoa.c Use unsigned chars instead of signed chars when extracting bits of the 1998-09-23 21:35:40 +00:00
ioctl.c
iodesc.h
libstand.3 mdoc(7) police: s/BSD/.Bx/ where appropriate. 2001-08-14 10:01:54 +00:00
lseek.c Fix a bug in lseek which caused the loader to fail on some gzipped 2001-08-29 23:33:22 +00:00
Makefile MAN[1-9] -> MAN. 2001-03-27 17:27:19 +00:00
net.c Break out sendudp and readudp from net.c. This is for PXE, so it 2000-04-08 01:18:04 +00:00
net.h Don't always enable debugging for the network device code. 2000-11-10 06:06:55 +00:00
netif.c Compensate for header dethreading. 2001-05-01 09:37:01 +00:00
netif.h Cleanup warnings by adding missint prototypes, removing unneeded duplicate 2000-08-03 09:08:29 +00:00
nfs.c Expose the NFS root node, so that an evil consumer can use it to get the 2000-09-05 22:11:41 +00:00
nfsv2.h Fix comment. 2000-05-06 04:50:09 +00:00
nullfs.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00
open.c Backout last commit. It was wrong.. *sigh* 2000-09-10 01:17:47 +00:00
pager.c Silence -Wnon-const-format 2001-02-18 04:51:47 +00:00
printf.c Tidy up some loose ends. nullfs_read/write were returning the wrong value. 1999-12-27 08:45:14 +00:00
qdivrem.c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
quad.h $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
random.c Make libstand compile 2000-09-03 11:29:18 +00:00
rarp.c
read.c Implement readahead buffering for non-raw files. This drastically improves 2000-09-05 09:52:50 +00:00
readdir.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00
rpc.c
rpc.h
rpcv2.h
saioctl.h
sbrk.c Fix the real problem that broke the Alpha loader this last week. It 2000-05-12 22:43:20 +00:00
stand.h Replace functional bugs of ctypish functions in libstand with style 2001-05-14 16:49:20 +00:00
stat.c
strcasecmp.c Add strcasecmp source file required for dosfs operation. 1998-10-07 13:50:17 +00:00
strdup.c
strerror.c
strtol.c
tftp.c Reset errno so that subsequent TFTP requests don't fail after the 2001-06-30 21:39:09 +00:00
tftp.h
twiddle.c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
udp.c Correct the returned UDP datagram length. See the PR for a more comprehensive 2001-05-28 22:27:06 +00:00
ufs.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00
write.c
zalloc.c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
zalloc_defs.h A quick and dirty port of libstand to ia64. 2001-03-06 16:11:36 +00:00
zalloc_malloc.c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
zalloc_mem.h $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
zalloc_protos.h $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
zipfs.c Add a readdir function to the loader fsops vector, and implement the 2000-04-29 20:47:10 +00:00