svn commit: r253862 - head/sys/boot/ficl

Jan Beich jbeich at tormail.org
Mon Aug 5 04:53:05 UTC 2013


Marcel Moolenaar <marcel at xcllnt.net> writes:

> On Aug 4, 2013, at 2:06 PM, Jan Beich <jbeich at tormail.org> wrote:
>
>> Marcel Moolenaar <marcel at 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);


More information about the svn-src-all mailing list