in reply to failing to use getdents system call on Linux

Have you looked at what Perl and C pass to the syscalls and what they get back using truss or strace?

If that data is still as you'd expect it, then it's maybe how you unpack things. Maybe you can show us a small representative piece of data and the corresponding code that unpacks the data? That would help us get closer to seeing what you see on your machine.

Replies are listed 'Best First'.
Re^2: failing to use getdents system call on Linux
by glasswalk3r (Friar) on Nov 03, 2016 at 19:26 UTC

    Thanks Corion, I updated the node with the information you requested (inside readmore tags).

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

      Your C code uses a much larger buffer. Maybe that circumvents some edge case that your Perl logic doesn't handle.

      Also, the buffer handling is different between your C and Perl programs. With Perl, you cut from the front of your buffer while with C, you walk a pointer over it. I would rewrite the Perl program to use substr maybe to mimic the C code closer.

      Also, is there a reason why you're avoiding readdir?

        I'll try to do those suggestions and see what happens next.

        About substr, I am already using it... so I'm not sure what do you mean by using it to emulate the C pointer. Even though I'm modifying the original buffer, I would expect that I would get at least the first entry correctly... I played around with unpack, but my guess is that I just don't have the same data on the perl buffer (neither identify what is being available over there, my guess is that I missing a long integer.

        This is to solve a very specific problem with NFS exports: some directories got clobbered with so many files (above 300k) that even listing them with ls takes a lot of time. Unfortunately, I don't have root access to evaluate what is going over there, but using getdents allow me to get the list of files much more quickly.

        That's what I need in most cases (I'll simply remove the files from there, no need to stat them.readdir() presents the same issues as ls.

        Alceu Rodrigues de Freitas Junior
        ---------------------------------
        "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill