Date: Sun, 4 Aug 2013 20:56:13 -0700 From: Marcel Moolenaar <marcel@xcllnt.net> To: Jan Beich <jbeich@tormail.org> 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: <953FDB6A-11EF-46D3-85D8-634952AF9309@xcllnt.net> In-Reply-To: <1V65V2-0001RI-Fu@internal.tormail.org> References: <201308011806.r71I6xpd088690@svn.freebsd.org> <1V65V2-0001RI-Fu@internal.tormail.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
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.
FYI,
--
Marcel Moolenaar
marcel@xcllnt.net
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?953FDB6A-11EF-46D3-85D8-634952AF9309>
