From patchwork Wed Aug 23 15:11:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 9917589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE5B9603FA for ; Wed, 23 Aug 2017 15:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B04B328900 for ; Wed, 23 Aug 2017 15:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4C472899E; Wed, 23 Aug 2017 15:11:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FA3428900 for ; Wed, 23 Aug 2017 15:11:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932074AbdHWPL2 (ORCPT ); Wed, 23 Aug 2017 11:11:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:37211 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754129AbdHWPL1 (ORCPT ); Wed, 23 Aug 2017 11:11:27 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8A207AD16; Wed, 23 Aug 2017 15:11:26 +0000 (UTC) From: Nikolay Borisov To: sandeen@sandeen.net Cc: linux-xfs@vger.kernel.org, Nikolay Borisov Subject: [PATCH 2/4] fiemap: Introduce get_extent_count Date: Wed, 23 Aug 2017 18:11:20 +0300 Message-Id: <1503501082-16983-2-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503501082-16983-1-git-send-email-nborisov@suse.com> References: <5fc15693-7df3-c1bf-9f78-020eed30b567@sandeen.net> <1503501082-16983-1-git-send-email-nborisov@suse.com> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function will be used in future patches and will aid in implementing ranged fiemap queries Signed-off-by: Nikolay Borisov --- io/fiemap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/io/fiemap.c b/io/fiemap.c index d1584aba7818..30c49112e089 100644 --- a/io/fiemap.c +++ b/io/fiemap.c @@ -193,6 +193,22 @@ calc_print_format( } } +/* Use ssize so that we can return also an error code in case the ioctl fails */ +static ssize_t +get_extent_count(int fd, __u64 startoffset, __u64 len) +{ + struct fiemap fiemap = { 0 } ; + fiemap.fm_start = startoffset; + fiemap.fm_length = len; + if (ioctl(fd, FS_IOC_FIEMAP, (unsigned long)&fiemap) < 0) { + fprintf(stderr, _("%s: Failed to query fiemap extent count.\n"), + progname); + return -1; + } + + return fiemap.fm_mapped_extents; +} + int fiemap_f( int argc,