f2fs-tools: fix an improper #ifdef wrap for Android
PATCH 1/1 f2fs-tools: fix an improper #ifdef wrap for Android
Commit 595fd57a4fd3 ("f2fs-tools: get kernel version via uname(2)") introduced support for reading kernel version without /proc/version's presence but improperly wrapped an #ifdef macro for Android, causing f2fs-tools usage on every Android devices to display "Info: No support kernel version!".
Fix this by properly wrapping the problematic #ifdef macro.
Also remove 'c.kd = -2' as it will be set to -1 upon open(2) failure and the rest of the source code isn't doing anything special with 'kd == -2'.
Additionally, show the message when uname(2) also fails from get_kernel_uname_version().
--- lib/libf2fs.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)
lib/libf2fs.c +12 -16
@@ -751,23 +751,23 @@ void get_kernel_version(__u8 *version)void get_kernel_uname_version (__u8 *version) { +memset (version,0 ,VERSION_LEN ); +#ifdef HAVE_SYS_UTSNAME_H struct utsname buf; -memset (version,0 ,VERSION_LEN ); -if (uname (&buf)) -return ; - +if (uname (&buf) ==0 ) {#if !defined(WITH_KERNEL_VERSION ) -snprintf ((char *)version, -VERSION_LEN ,"%s %s" , buf.release, buf.version); +snprintf ((char *)version, +VERSION_LEN ,"%s %s" , buf.release, buf.version);#else -snprintf ((char *)version, -VERSION_LEN ,"%s" , buf.release); +snprintf ((char *)version, +VERSION_LEN ,"%s" , buf.release);#endif -#else -memset (version,0 ,VERSION_LEN ); + }#endif + +MSG (0 ,"\tInfo: Unable to get the kernel version!\n" ); }#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE )
@@ -845,15 +845,11 @@ int get_device_info(int i) } } -if (c.kd ==-1 ) {#if !defined(WITH_ANDROID ) && defined(__linux__) +// If this fails, we'll retry with get_kernel_uname_version() +if (c.kd ==-1 ) c.kd =open ("/proc/version" ,O_RDONLY );#endif -if (c.kd <0 ) { -MSG (0 ,"\tInfo: No support kernel version!\n" ); - c.kd =-2 ; - } - }if (c.sparse_mode) { dev->total_sectors = c.device_size / dev->sector_size;
Signature · 1 line
2.21.0
Quoted 61 lines · Park Ju Hyung
Commit
595fd57a4fd3("f2fs-tools: get kernel version via uname(2)") introduced support for reading kernel version without /proc/version's presence but improperly wrapped an #ifdef macro for Android, causing f2fs-tools usage on every Android devices to display "Info: No support kernel version!".Fix this by properly wrapping the problematic #ifdef macro.
Also remove 'c.kd = -2' as it will be set to -1 upon open(2) failure and the rest of the source code isn't doing anything special with 'kd == -2'.
Additionally, show the message when uname(2) also fails from
get_kernel_uname_version().Signed-off-by Park Ju Hyung <[email protected]>--- lib/libf2fs.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-)lib/libf2fs.c +10
-10@@ -751,23 +751,23 @@ void get_kernel_version(__u8 *version)void get_kernel_uname_version (__u8 *version) { +memset (version,0 ,VERSION_LEN ); +#ifdef HAVE_SYS_UTSNAME_H struct utsname buf; -memset (version,0 ,VERSION_LEN ); -if (uname (&buf)) -return ; - +if (uname (&buf) ==0 ) {#if !defined(WITH_KERNEL_VERSION ) -snprintf ((char *)version, -VERSION_LEN ,"%s %s" , buf.release, buf.version); +snprintf ((char *)version, +VERSION_LEN ,"%s %s" , buf.release, buf.version);#else -snprintf ((char *)version, -VERSION_LEN ,"%s" , buf.release); +snprintf ((char *)version, +VERSION_LEN ,"%s" , buf.release);#endif -#else -memset (version,0 ,VERSION_LEN ); + }#endif + +MSG (0 ,"\tInfo: Unable to get the kernel version!\n" ); }#if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE )@@ -845,15 +845,11 @@ int get_device_info(int i) } }
lib/libf2fs.c int get_device_info(int i) · line 854
Quoted 10 lines
lib/libf2fs.c +2
-4-if (c.kd ==-1 ) {#if !defined(WITH_ANDROID ) && defined(__linux__) +// If this fails, we'll retry with get_kernel_uname_version() +if (c.kd ==-1 ) c.kd =open ("/proc/version" ,O_RDONLY );#endif -if (c.kd <0 ) { -MSG (0 ,"\tInfo: No support kernel version!\n" ); - c.kd =-2 ;
If there are multiple devices, we don't need to get the version redundantly.
Quoted 14 lines
lib/libf2fs.c +0
-2- } - }if (c.sparse_mode) { dev->total_sectors = c.device_size / dev->sector_size;Signature · 8 lines
2.21.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Jaegeuk,
Quoted 5 lines · Jaegeuk Kim
lib/libf2fs.c int get_device_info(int i) · line 854
Quoted 3 lines
lib/libf2fs.c +0
-3-if (c.kd <0 ) { -MSG (0 ,"\tInfo: No support kernel version!\n" ); - c.kd =-2 ;If there are multiple devices, we don't need to get the version redundantly.
Oh, didn't think of that case.
Can we just read the kernel version and store to memory from initialization of the program?
I see that the code for getting the kernel version is already duplicated in 2 different files: fsck/mount.c and mkfs/f2fs_format.c
/* get kernel version */
if (c.kd >= 0) {
dev_read_version(c.version, 0, VERSION_LEN);
get_kernel_version(c.version);
} else {
get_kernel_uname_version(c.version);
}Thanks.
Hi Ju Hyung,
Quoted 7 lines · Ju Hyung Park
Hi Jaegeuk,
Quoted 4 lines · Jaegeuk Kim
Quoted 3 lines
lib/libf2fs.c +0
-3-if (c.kd <0 ) { -MSG (0 ,"\tInfo: No support kernel version!\n" ); - c.kd =-2 ;
Quoted 8 lines
Quoted 1 line
If there are multiple devices, we don't need to get the version redundantly.
Oh, didn't think of that case.
Can we just read the kernel version and store to memory from initialization of the program?
I see that the code for getting the kernel version is already duplicated in 2 different files:fsck/mount.candmkfs/f2fs_format.c
The intention was to separate mkfs.f2fs from fsck.f2fs, since mkfs.f2fs should be run as standalone.
Quoted 10 lines
/* get kernel version */
if (c.kd >= 0) { dev_read_version(c.version, 0, VERSION_LEN); get_kernel_version(c.version); } else { get_kernel_uname_version(c.version); }Thanks.