Hi Denys,

it depends on your definition of the "problem".

Both, the current git version and my version, compile and work.

Current git version always define MTD_FILE_MODE_RAW (and sets it to 3)
regardless of whether the kernel version used provide the
MTD_FILE_MODE_RAW symbol or not. As your comment states
MTD_FILE_MODE_RAW is an enum value and thus the code "#if
!defined(ENUM_VALUE)" simply doesn't work as desired. Btw. there is no
way to make it work (except for adding dummy-defines like "#define
ENUM_VALUE ENUM_VALUE" to the kernel header providing the
corresponding symbol, but it's too late for that).

So if you define the problem as "doesn't compile or doesn't work" then
you're right my patch doesn't solve any problem.

If you define the "problem" as "the current git code uses non-working
language constructs, has a potential problem that the value of
MTD_FILE_MODE_RAW might change in future kernel versions" then it does
solve some problems.

Best regards,
Gene

p.s. btw. my patch is based on this buildroot commit
https://git.busybox.net/buildroot/commit/?id=fb995444b9b2ce3a38fbb1723151e9a923835da9

On Tue, Jan 23, 2018 at 2:42 PM, Denys Vlasenko
<[email protected]> wrote:
> On Tue, Jan 23, 2018 at 12:18 AM, Eugene Rudoy <[email protected]> wrote:
>> Unfortunately it is not possible in C to check for the existence of an enum
>> value at compile-time. Implement an alternative "kernel version check"-based
>> approach to workaround MTD_FILE_MODE_RAW related build problems with kernel
>> versions prior to 3.2.0
>>
>> The same approach is already used elsewhere in busybox,
>> e.g. in ecce3a1999f3c5ded4baebbc0b17c48d80fe2781
>>
>> Signed-off-by: Eugene Rudoy <[email protected]>
>> ---
>>  miscutils/nandwrite.c | 14 +++++++++-----
>>  1 file changed, 9 insertions(+), 5 deletions(-)
>>
>> diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
>> index 29c800612..bfa4ea478 100644
>> --- a/miscutils/nandwrite.c
>> +++ b/miscutils/nandwrite.c
>> @@ -53,12 +53,16 @@
>>  #include "libbb.h"
>>  #include <mtd/mtd-user.h>
>>
>> -/* Old headers call it MTD_MODE_RAW.
>> - * FIXME: In kernel headers, MTD_FILE_MODE_RAW is not a define,
>> - * it's an enum. How I can test for existence of an enum?
>> +#include <linux/version.h>
>> +/*
>> + * MTD_FILE_MODE_RAW is an enum (i.e. cannot be tested for using #ifdef) 
>> and is available since kernel 3.2
>> + * s. http://elixir.free-electrons.com/linux/v3.2/ident/MTD_FILE_MODE_RAW
>> + *
>> + * In versions before 3.2 it's called MTD_MODE_RAW
>> + * s. http://elixir.free-electrons.com/linux/v3.1/ident/MTD_MODE_RAW
>>   */
>> -#if !defined(MTD_FILE_MODE_RAW)
>> -# define MTD_FILE_MODE_RAW 3
>> +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)
>> +#define MTD_FILE_MODE_RAW MTD_MODE_RAW
>>  #endif
>
> It does not look to be fixing any actual problems?
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to