From patchwork Fri Oct 27 12:37:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10029725 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 4221D60567 for ; Fri, 27 Oct 2017 12:37:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 381A028F45 for ; Fri, 27 Oct 2017 12:37:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D1D128F4C; Fri, 27 Oct 2017 12:37:26 +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 DA94828F53 for ; Fri, 27 Oct 2017 12:37:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752633AbdJ0MhW (ORCPT ); Fri, 27 Oct 2017 08:37:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:46963 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752624AbdJ0MhU (ORCPT ); Fri, 27 Oct 2017 08:37:20 -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 8C131AB9D; Fri, 27 Oct 2017 12:37:18 +0000 (UTC) From: Nikolay Borisov To: linux-xfs@vger.kernel.org Cc: fstests@vger.kernel.org, Nikolay Borisov Subject: [PATCH 1/2] fiemap: Factor out actual fiemap call code Date: Fri, 27 Oct 2017 15:37:09 +0300 Message-Id: <1509107832-22286-2-git-send-email-nborisov@suse.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509107832-22286-1-git-send-email-nborisov@suse.com> References: <1509107832-22286-1-git-send-email-nborisov@suse.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will be needed to in a subsequent patch to avoid code duplication. No functional changes Signed-off-by: Nikolay Borisov --- io/fiemap.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/io/fiemap.c b/io/fiemap.c index e6fd66da753d..4a52bff974e8 100644 --- a/io/fiemap.c +++ b/io/fiemap.c @@ -211,6 +211,30 @@ calc_print_format( } } +static int +__fiemap(struct fiemap * fiemap, + int mapsize, + __u32 flags, + __u64 start, + __u64 length) { + + int ret; + + memset(fiemap, 0, mapsize); + fiemap->fm_flags = flags; + fiemap->fm_start = start; + fiemap->fm_length = length; + fiemap->fm_extent_count = EXTENT_BATCH; + ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap); + if (ret < 0) { + fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: " + "%s\n", progname, file->name, strerror(errno)); + return ret; + } + + return 0; +} + int fiemap_f( int argc, @@ -266,19 +290,11 @@ fiemap_f( while (!last && (cur_extent != max_extents)) { - memset(fiemap, 0, map_size); - fiemap->fm_flags = fiemap_flags; - fiemap->fm_start = last_logical; - fiemap->fm_length = -1LL; - fiemap->fm_extent_count = EXTENT_BATCH; - - ret = ioctl(file->fd, FS_IOC_FIEMAP, (unsigned long)fiemap); + ret = __fiemap(fiemap, map_size, fiemap_flags, last_logical, + len - covered_length); if (ret < 0) { - fprintf(stderr, "%s: ioctl(FS_IOC_FIEMAP) [\"%s\"]: " - "%s\n", progname, file->name, strerror(errno)); - free(fiemap); exitcode = 1; - return 0; + goto out; } /* No more extents to map, exit */