Limits on 4.2BSD lseek(2)?

Guy Harris guy at sun.uucp
Sat May 17 14:23:21 AEST 1986


(Third attempt at posting - the person who decided that the "rlogin" daemon
should send a SIGKILL to all processes in the "rlogin" session when the user
logs out should be shot.)

> This comes about because the dbm(3) library does not guarantee to
> deliver things aligned on the appropriate boundary.

To clarify: some machines, like the VAX on which "article" was probably
written, permit you to reference 2-byte and 4-byte quantities regardless of
what byte boundary they are aligned on.  Other machines, like machines using
the 68010 (of which the Sun-2 is one), will fail if you try to reference
such a quantity if it's not properly aligned.  The "*(long *) content.dptr"
reference is failing, not the "lseek"; it never even gets to call "lseek"
since it faults while setting up the argument list.

> What you need to do is (approximately):
> 
> 	dp = fetch(key);
> 	bcopy(offp, dp->d_data, sizeof(offp));
> 	lseek(fd, *offp, 0);
> 
> Declare offp so that it is guaranteed to be aligned, and copy all
> pointers you wish to dereference into it before dereff'ing them.

Not quite.  The problem is not that the pointer itself is not properly
aligned, it's that the object the pointer points to is not properly aligned.
The "bcopy" should copy this object to a properly-aligned object, whose value
should then be passed to "lseek" as its second argument.  After correcting
the usage of "dofetch", "bcopy", and the datum returned by "bcopy", the code
would read like:

	long offset;
	.
	.
	.
	content = dofetch(*argv);
	if (content.dptr == 0) {
	        printf("%s: No such key\n", *argv);
	        continue;
	}
	bcopy(content.dptr, (char *)&offset, sizeof offset);
	if (lseek(fd, offset, 0) < 0)
	        continue;
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.arpa



More information about the Comp.bugs.4bsd.ucb-fixes mailing list