Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 05 Aug 2013 04:52:38 +0000
From:      Jan Beich <jbeich@tormail.org>
To:        Marcel Moolenaar <marcel@xcllnt.net>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, Marcel Moolenaar <marcel@FreeBSD.org>, src-committers@freebsd.org
Subject:   Re: svn commit: r253862 - head/sys/boot/ficl
Message-ID:  <1V6Cmb-000M0k-0l@internal.tormail.org>
In-Reply-To: <953FDB6A-11EF-46D3-85D8-634952AF9309@xcllnt.net> (Marcel Moolenaar's message of "Sun, 4 Aug 2013 20:56:13 -0700")
References:  <201308011806.r71I6xpd088690@svn.freebsd.org> <1V65V2-0001RI-Fu@internal.tormail.org> <953FDB6A-11EF-46D3-85D8-634952AF9309@xcllnt.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Marcel Moolenaar <marcel@xcllnt.net> writes:

> On Aug 4, 2013, at 2:06 PM, Jan Beich <jbeich@tormail.org> wrote:
>
>> Marcel Moolenaar <marcel@FreeBSD.org> writes:
>> 
>>> +    static union { 
>>> +	struct dirent dirent;
>>> +	char buf[512];
>>> +    } u;
>>> +    off_t off;
>>> +    int len;
>> [...]
>>> +    /*
>>> +     * The readdirfd() function is specific to the loader environment.
>>> +     * We do the best we can to make freaddir work, but it's not at
>>> +     * all guaranteed.
>>> +     */
>>> +    off = lseek(fd, 0LL, SEEK_CUR);
>>> +    len = getdents(fd, u.buf, sizeof(u.buf));
>>> +    d = (len != -1) ? &u.dirent : NULL;
>>> +    if (d != NULL)
>>> +	lseek(fd, off + d->d_reclen, SEEK_SET);
>> 
>> How did you test?
>
> On amd64 with UFS. The problem is that using d_reclen to get to
> the next dirent is highly non-portable and depends on the FS
> used:
>
> fbsdvm64% uname -m
> amd64
> fbsdvm64% pwd
> /usr/src/sys/boot/ficl
> fbsdvm64% ./testmain 
> ficl Version 3.03
> Aug  4 2013 
>
> ok> s" /bin" 0 fopen . cr
> 3
> ok> 3 freaddir . type cr
> -1 .
> ok> 3 freaddir . type cr
> -1 ..
> ok> 3 freaddir . type cr
> -1 chflags
> ok> 3 freaddir . type cr
> -1 [
> ok> 3 freaddir . type cr
> -1 cat
> ok> 3 freaddir . type cr
> -1 domainname
> ok> 3 freaddir . type cr
> -1 chio
> ok> 3 freaddir . type cr
> -1 chmod
> ok> 3 freaddir . type cr
> -1 cp
> ok> 3 freaddir . type cr
> -1 csh

Except there'd be no FICL_FALSE after the last entry. Try running
my lsdir function.

>
> It's probably not going to work on any other FS. The
> alternative is to just not support freaddir due to lack
> of runtime support.

What's the issue with my version in bin/172542 ? It doesn't
use d_reclen but relies on a side-effect of readdir() call.

>>  +    static DIR *dir;
>>  +    if (lseek(fd, 0, SEEK_CUR) == 0)
>>  +       dir = fdopendir(fd);
>>  +    if (dir != NULL)
>>  +       d = readdir(dir);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1V6Cmb-000M0k-0l>