From patchwork Wed Nov 6 23:15:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 3149681 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4E45D9F3C4 for ; Wed, 6 Nov 2013 23:16:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6CE3120630 for ; Wed, 6 Nov 2013 23:16:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FC5A205AD for ; Wed, 6 Nov 2013 23:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751983Ab3KFXP7 (ORCPT ); Wed, 6 Nov 2013 18:15:59 -0500 Received: from sandeen.net ([63.231.237.45]:56119 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750955Ab3KFXP5 (ORCPT ); Wed, 6 Nov 2013 18:15:57 -0500 Received: by sandeen.net (Postfix, from userid 500) id 17C72654E640; Wed, 6 Nov 2013 17:15:57 -0600 (CST) From: Eric Sandeen To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/16] btrfs-progs: fix error returns in get_df() Date: Wed, 6 Nov 2013 17:15:41 -0600 Message-Id: <1383779755-18228-3-git-send-email-sandeen@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1383779755-18228-1-git-send-email-sandeen@redhat.com> References: <1383779755-18228-1-git-send-email-sandeen@redhat.com> 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, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 get_df returns -ERRNO, or maybe (+)errno, or even 0 in the case where we inexplicably got 0 total_spaces from the BTRFS_IOC_SPACE_INFO. Consistently return a negative error number, and return -ENOENT rather than 0 for total_spaces == 0, so that the caller will know that **sargs_ret hasn't been set up. Signed-off-by: Eric Sandeen Reviewed-by: Anand Jain --- cmds-filesystem.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 0bfd710..e6642ef 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -106,11 +106,12 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret) fprintf(stderr, "ERROR: couldn't get space info - %s\n", strerror(e)); free(sargs); - return ret; + return -e; } + /* This really should never happen */ if (!sargs->total_spaces) { free(sargs); - return 0; + return -ENOENT; } count = sargs->total_spaces; free(sargs); @@ -128,7 +129,7 @@ static int get_df(int fd, struct btrfs_ioctl_space_args **sargs_ret) fprintf(stderr, "ERROR: get space info count %llu - %s\n", count, strerror(e)); free(sargs); - return ret; + return -e; } *sargs_ret = sargs; return 0;