From patchwork Fri Oct 2 15:49:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7317381 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6F679F1B9 for ; Fri, 2 Oct 2015 15:50:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EAF8620862 for ; Fri, 2 Oct 2015 15:50:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DB772085F for ; Fri, 2 Oct 2015 15:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753047AbbJBPuM (ORCPT ); Fri, 2 Oct 2015 11:50:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:52593 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbbJBPuL (ORCPT ); Fri, 2 Oct 2015 11:50:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 974C1ACB8 for ; Fri, 2 Oct 2015 15:50:09 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 94A0EDAB51; Fri, 2 Oct 2015 17:49:09 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH] btrfs-progs: fix error checking in load_device_info Date: Fri, 2 Oct 2015 17:49:08 +0200 Message-Id: <1443800948-27933-1-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.1.3 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP load_device_info queries the FS_INFO ioctl and this may fail with EPERM on older kernels. The check did not verify the ioctl return value and incorrectly returned EPERM if it was previously stored in errno. This fixes 'btrfs fi usage' that will print the overall summary for all users (provided that the FS_INFO ioctl is already unprivileged). Signed-off-by: David Sterba --- cmds-fi-usage.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c index 54b8b1c1d996..50d633372023 100644 --- a/cmds-fi-usage.c +++ b/cmds-fi-usage.c @@ -504,7 +504,7 @@ static int cmp_device_info(const void *a, const void *b) static int load_device_info(int fd, struct device_info **device_info_ptr, int *device_info_count) { - int ret, i, ndevs, e; + int ret, i, ndevs; struct btrfs_ioctl_fs_info_args fi_args; struct btrfs_ioctl_dev_info_args dev_info; struct device_info *info; @@ -513,12 +513,11 @@ static int load_device_info(int fd, struct device_info **device_info_ptr, *device_info_ptr = 0; ret = ioctl(fd, BTRFS_IOC_FS_INFO, &fi_args); - e = errno; - if (e == EPERM) - return -e; if (ret < 0) { + if (errno == EPERM) + return -errno; fprintf(stderr, "ERROR: cannot get filesystem info - %s\n", - strerror(e)); + strerror(errno)); return 1; }