FreeBSD errors on new dir code

Jeremy Allison jra at samba.org
Sat Jan 29 08:23:33 GMT 2005


On Fri, Jan 28, 2005 at 11:11:45PM -0800, Jeremy Allison wrote:
> On Fri, Jan 28, 2005 at 11:06:11PM -0800, Jeremy Allison wrote:
> 
> It means a seekdir(offset) followed by a telldir(offset)
> is returning a different value. Checking in the FreeBSD
> man pages I find :
> 
>      The telldir() function returns the current location associated with the
>      named directory stream.  Values returned by telldir() are good only for
>      the lifetime of the DIR pointer, dirp, from which they are derived.  If
>      the directory is closed and then reopened, prior values returned by
>      telldir() will no longer be valid.

Ok, we are officially screwed on FreeBSD.... From their
mailing list (see below) ...

Just one more reason why the *BSD of the month club
*sucks*.... :-).

To paraphrase John Betjeman:

"Come friendly bombs and fall on Berkley!
It isn't fit for humans now,
There isn't grass to graze a cow.
Swarm over, Death!

Come, bombs and blow to smithereens
Those air -conditioned, bright server rooms,
Tinned files, tinned directories, tinned disks, tinned green screens,
Tinned device drivers, tinned MacOS/X.

Mess up the mess they call an OS....
.....

Come, friendly bombs and fall on Berkley
To get it ready for the GPL.
The Linux'es are coming now;
The earth exhales."

:-).

Jeremy (in a poetic frame of mind this evening).

---------------------------------------------------------
> I'm trying to work out some inconsistent behavior in my app across
> platforms.  On FreeBSD, seekdir() doesn't seem to behave as I expect
> it to.  Here's a short program that demonstrates my confusion:
> 
>     off_t pos;
>     dirp = opendir(".");
>     ent = readdir(dirp);
>     pos = telldir(dirp);
>     ent = readdir(dirp);
>     seekdir(dirp, pos);
>     printf("First telldir:%d\nSecond telldir:%d\n", pos, telldir(dirp));
> 
> On other platforms, the first and second telldir() return the same
> value.  On the two FreeBSD machines I've tried it on, the first
> telldir() returns 1 and the second returns 0.
> 
>   Can anyone explain this?

Well, your first problem is that pos is a long long, but you only
printed a %d value.  Change pos to a "long" type, and you'll get the
correct result :)

First telldir:1
Second telldir:2

But your basic question still stands: why aren't they the same?

When telldir() is called, the base offset into the directory and
filecount past that offset are stored in a linked list (see the
getdirentries manpage; directory entries are read in blocks, so you
don't necessarily know the absolute offset to a particular entry).  A
cookie value is returned to the user, and that value is used to look up
the stored values when seekdir() is called later.  Each call to telldir
will return an integer one higher that the result of the previous call.  

I don't think there's any pstandard that says that telldir has to
return a seekable file offset, or that consecutive calls on the same
position must return the same value.  Think about a filesystem that
uses hashed or btree-based directories, for example; there may not be a
way to store the correct position in a single "long" value without
using a cookie like FreeBSD does.
---------------------------------------------------------


More information about the samba-technical mailing list