[fpc-devel] Re: FindFile / FindNext does work with > 253 character length files

Sergei Gorelkin sergei_gorelkin at mail.ru
Sat Mar 15 17:05:03 CET 2008


Sergei Gorelkin wrote:

> It turns out that for longer filenames fpreaddir() failes with errno=22 
> (invalid argument).
> 
Here is what I could find out:

In fpc, sizeof(dirent) is equal to 275, while gcc reports 
sizeof(dirent64)=276. Moreover, Linux kernel expects buffer for 
getdents64 syscall rounded up to 8 bytes (see fs/readdir.c in kernel 
source tree, macros ROUND_UP64 and NAME_OFFSET). Using these macros, we 
can calculate that for 255 char filename, a 280-byte buffer is expected 
(and value of 280 *is* returned in d_reclen field when filename length 
is 255). But that is still not working, for the reason I could not 
figure out. Only adding eight more bytes, i.e. using 288 bytes buffer, 
makes that syscall finally succeed with a 255 char filename.

A quick fix seems to just extend Dirent record with extra bytes, but 
perhaps there exists a more clean and consistent solution.

Best regards,
Sergei.



More information about the fpc-devel mailing list