Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-04

Linux readdir syscall is superseded by getdents

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joost van der Sluis

Hello all,

I'm new to this list and I coudn't find out how to send in patches so i do it here...

On my system FPC doesn't work because the fpreaddir-function failes on larger directories. I saw that fpreaddir still uses the linux readdir-call, wich is superseded by getdents. (also the comments are wrong. The result of the readdir-call isn't the amount of bytes read. That's only the case by the getdents-call)

I've rewritten Fpreaddir (in rtl/linux/ossysc.inc) as follows:

-----
Function Fpreaddir(dirp : pdir) : pdirent; [public, alias
: 'FPC_SYSC_READDIR'];

{readdir is obsolete. Use getdents instead...}

var bytes : integer;
    dp    : pdirent;
begin
  repeat
  if dirp^.dd_nextoff >= dirp^.dd_size then
    begin
      bytes :=
do_SysCall(SysCall_nr_getdents,TSysParam(dirp^.dd_fd),TSysParam(dirp^.dd_buf),TSysParam(dirp^.dd_max));
      if bytes <= 0 then
	begin
	  fpreaddir := nil;
	  exit;
        end;
      dirp^.dd_size := bytes;
      dirp^.dd_nextoff := 0;
    end;
  dp := pdirent(ptrint(dirp^.dd_buf)+dirp^.dd_nextoff);
  dirp^.dd_nextoff := dirp^.dd_nextoff + dp^.d_reclen;
  dirp^.dd_loc := dirp^.dd_loc + dp^.d_reclen;
  until dp^.d_fileno  0; // Don't show deleted files
  Fpreaddir := dp;
end;

-----

and I had to change Fpopendir a little. Just added

---

  ptr^.dd_nextoff:= 0;

---

before the last line.

Oh, and btw: in install/install.sh the version-number is still 1.9.2, which causes the installation to fail. (symbolic links are wronly created)

Joost van der Sluis.

Reply by email

Peter Vreman
Show quoted text 10 lines
Hello all, I'm new to this list and I coudn't find out how to send in patches so i do it here... On my system FPC doesn't work because the fpreaddir-function failes on larger directories. I saw that fpreaddir still uses the linux readdir-call, wich is superseded by getdents. (also the comments are wrong. The result of the readdir-call isn't the amount of bytes read. That's only the case by the getdents-call)

I'll test/apply the patch after 1.9.4 is released

Reply by email

Jonas Maebe
to Peter Vreman
Peter Vreman wrote 7 lines
> On my system FPC doesn't work because the fpreaddir-function failes on > larger directories. I saw that fpreaddir still uses the linux > readdir-call, wich is superseded by getdents. (also the comments are > wrong. The result of the readdir-call isn't the amount of bytes > read. That's only the case by the getdents-call) I'll test/apply the patch after 1.9.4 is released

I think this is a critical bug. I've also got lots of troubles with the Linux compiler lately: it often gets in an endless loop. When I strace it, you can see it keeps fstat'ing "." and ".." in succession, without ever going to the next item. So it's probably related to this bug.

Jonas

Reply by email

Peter Vreman
to Jonas Maebe
Show quoted text 12 lines
>> On my system FPC doesn't work because the fpreaddir-function failes on >> larger directories. I saw that fpreaddir still uses the linux >> readdir-call, wich is superseded by getdents. (also the comments are >> wrong. The result of the readdir-call isn't the amount of bytes >> read. That's only the case by the getdents-call) > > I'll test/apply the patch after 1.9.4 is released I think this is a critical bug. I've also got lots of troubles with the Linux compiler lately: it often gets in an endless loop. When I strace it, you can see it keeps fstat'ing "." and ".." in succession, without ever going to the next item. So it's probably related to this bug.

When it is really a showstopper it would have been popped up earlier. I've run the compiler under all linux kernels upto 2.6.5-rc2 (including some x86_64 kernels) with ext3 filesystem without problems. So the readdir syscall is still fully supported.

And with changes like this short before a release there is always someone called Murphy that would popup...

Reply by email

Florian Klaempfl
to Peter Vreman
Peter Vreman wrote 15 lines
>>>On my system FPC doesn't work because the fpreaddir-function failes on >>>larger directories. I saw that fpreaddir still uses the linux >>>readdir-call, wich is superseded by getdents. (also the comments are >>>wrong. The result of the readdir-call isn't the amount of bytes >>>read. That's only the case by the getdents-call) >> >>I'll test/apply the patch after 1.9.4 is released > >I think this is a critical bug. I've also got lots of troubles with the >Linux compiler lately: it often gets in an endless loop. When I strace >it, you can see it keeps fstat'ing "." and ".." in succession, without >ever going to the next item. So it's probably related to this bug. When it is really a showstopper it would have been popped up earlier.

It could be processor dependend. Or do you talk about i386, Jonas?

I've run the compiler under all linux kernels upto 2.6.5-rc2 (including some x86_64 kernels) with ext3 filesystem without problems. So the readdir syscall is still fully supported.

Reply by email

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 10 lines
>> I think this is a critical bug. I've also got lots of troubles with >> the >> Linux compiler lately: it often gets in an endless loop. When I >> strace >> it, you can see it keeps fstat'ing "." and ".." in succession, >> without >> ever going to the next item. So it's probably related to this bug. > When it is really a showstopper it would have been popped up earlier. It could be processor dependend. Or do you talk about i386, Jonas?

Yes.

Jonas

Reply by email