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(-) diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 60b84e0..61fc7ec 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -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; -- 2.21.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
