ftruncate with LFS OFF (was Re: [PATCH v2 24/46] ftruncate: Use ftruncate64 if arch does not have the ftruncate syscall)

Vineet Gupta Vineet.Gupta1 at synopsys.com
Mon Dec 10 05:26:20 UTC 2012


On Saturday 08 December 2012 09:56 PM, Markos Chandras wrote:
> On 8 December 2012 08:49, Vineet Gupta <Vineet.Gupta1 at synopsys.com> wrote:
>> On Saturday 08 December 2012 12:22 PM, Vineet Gupta wrote:
>>> On Monday 26 November 2012 07:54 PM, Markos Chandras wrote:
>>>> From: Markos Chandras <markos.chandras at imgtec.com>
>>>>
>>>> Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
>>>> ---
>>>>  libc/sysdeps/linux/common/ftruncate.c | 9 +++++++++
>>>>  1 file changed, 9 insertions(+)
>>>>
>>>> diff --git a/libc/sysdeps/linux/common/ftruncate.c b/libc/sysdeps/linux/common/ftruncate.c
>>>> index 3bdef3f..72f86f9 100644
>>>> --- a/libc/sysdeps/linux/common/ftruncate.c
>>>> +++ b/libc/sysdeps/linux/common/ftruncate.c
>>>> @@ -11,5 +11,14 @@
>>>>  #include <unistd.h>
>>>>
>>>>
>>>> +#if defined(__NR_ftruncate64) && !defined(__NR_ftruncate)
>>>> +int ftruncate(int fd, __off_t length)
>>>> +{
>>>> +    return ftruncate64(fd, length);
>>>> +}
>>>> +libc_hidden_def(ftruncate);
>>>> +
>>>> +#else
>>>>  _syscall2(int, ftruncate, int, fd, __off_t, length)
>>>>  libc_hidden_def(ftruncate)
>>>> +#endif
>>>>
>>> In my local tests this fails with uClibc w/o LFS because ftruncate64()
>>> is only defined for LFS. Same goes for truncate64 and lseek64.
>>> So your libc (non LFS) will build fine but will have undefined refs
>>> which will show up when linking the app.
>>>
>>> arc-linux-uclibc-nm -u lib/libc.so.0
>>> ...
>>>          U ftruncate64
>>>          U lseek64
>>>          U truncate64
>>>
>>> There are 2 approaches to fix this - either fix the __UCLIBC_HAS_LFS__
>>> gaurd in ftruncate64.c (and friends) or replicate the logic in
>>> fruncate.c - which gets messy given that we need to handle both WORDSIZE
>>> 32 and 64.
>> Following works for me !
>> int ftruncate(int fd, __off_t length)
>> {
>> #if defined __UCLIBC_HAS_LFS__
>>     return ftruncate64(fd, length);
>> #elif __WORDSIZE == 32
>>     uint32_t high = 0;
>>     return INLINE_SYSCALL(ftruncate64, 3, fd,
>>         __LONG_LONG_PAIR (high, length));
>> /* No need to handle __WORDSIZE == 64 as kernel won't define
>> __NR_ftruncate64 */
>> #endif
>> }
> Hi Vineet,
>
> Yes I already said that uClibc does not build without LFS on the other
> thread. 

You did - sorry didn't notice that.

> The fix looks reasonable to me (probably similar fixes for the
> other syscalls apply too, except for the getdents one that looks a bit
> complicated.) However, I am affraid that the code might become a bit
> unreadable
> with all the #if/#def mess. 

!LFS support doesn't add lot more than what we already have. The 3 which
seem to fail for me are easily fixable. I've not seen any breakage with
getdents

> Another "workaround" for this is new
> architectures to always "select UCLIBC_HAS_LFS" in ther Kconfig files.

Remember uClibc is all about smaller code footprint - this is not
acceptable !


More information about the uClibc mailing list