From: Park Ju Hyung Subject: [PATCH] f2fs-tools: fix an improper #ifdef wrap for Android Date: Tue, 16 Apr 2019 16:59:58 +0900 Message-ID: <20190416075958.11857-1-qkrwngud825@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hGJ0z-0000Gz-Iv for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Apr 2019 08:00:25 +0000 Received: from mail-pg1-f193.google.com ([209.85.215.193]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1hGJ0x-008LmE-N5 for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Apr 2019 08:00:25 +0000 Received: by mail-pg1-f193.google.com with SMTP id j26so9923688pgl.5 for ; Tue, 16 Apr 2019 01:00:23 -0700 (PDT) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: linux-f2fs-devel@lists.sourceforge.net 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 --- 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