Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!prls!pyramid!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs.4bsd,net.news.b Subject: Re: Limits on 4.2BSD lseek(2)? Message-ID: <3703@sun.uucp> Date: Sat, 17-May-86 00:23:21 EDT Article-I.D.: sun.3703 Posted: Sat May 17 00:23:21 1986 Date-Received: Sun, 18-May-86 15:00:34 EDT References: <717@smeagol.UUCP> <20656@styx.UUCP> Organization: Sun Microsystems, Inc. Lines: 47 Xref: linus net.bugs.4bsd:1773 net.news.b:1037 (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@sun.arpa