Subject: Re: bug#9077: coreutils-8.12: fiemap.h uses "struct fiemap_extent fm_extents[0]; "

From: Pádraig Brady <[email-masked]>
Date: Sat, 16 Jul 2011 09:37:38 +0100

On 15/07/11 23:45, Paul Eggert wrote:
> On 07/15/11 02:49, Pádraig Brady wrote:
>> +#ifdef __linux__
>> +  struct fiemap_extent fm_extents[0];
>> +#endif
> 
> This assumes that all GNU/Linux compiles will
> use a compiler that allows size-zero arrays;
> also, it assumes that sizeof (struct fiemap)
> == offsetof (struct fiemap, fm_extents).
> Although both assumptions are probably
> portable in practice in this particular case,
> it's better to avoid them, if avoiding them is easy.
> This will help future-proof the code if we alter the
> data structures, as altering them might cause problems
> such as what I recently encountered in GNU Emacs's C code.
> 
> How about the following further patch?  It should do the trick.

I tested that and it didn't work.
Even though the *fiemap structs are the same in mem
with and without the change, the ioctl() is returning ENOTTY
when the array is of size 1.  I guess this is because
the array element is unpacked for the ioctl which
is then failing kernel checks.

cheers,
Pádraig.