From patchwork Wed Aug 21 07:32:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 2847559 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C6BEABF546 for ; Wed, 21 Aug 2013 07:32:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E72E20456 for ; Wed, 21 Aug 2013 07:32:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DA6B201D3 for ; Wed, 21 Aug 2013 07:32:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752221Ab3HUHca (ORCPT ); Wed, 21 Aug 2013 03:32:30 -0400 Received: from mga03.intel.com ([143.182.124.21]:49215 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752176Ab3HUHca (ORCPT ); Wed, 21 Aug 2013 03:32:30 -0400 Received: from azsmga002.ch.intel.com ([10.2.17.35]) by azsmga101.ch.intel.com with ESMTP; 21 Aug 2013 00:32:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.89,926,1367996400"; d="scan'208";a="284717833" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.173]) by AZSMGA002.ch.intel.com with ESMTP; 21 Aug 2013 00:32:27 -0700 Received: from andy by smile with local (Exim 4.80) (envelope-from ) id 1VC2tr-0007a1-BB; Wed, 21 Aug 2013 10:32:15 +0300 From: Andy Shevchenko To: Josef Bacik , Chris Mason , linux-btrfs@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v2] btrfs: reuse kbasename helper Date: Wed, 21 Aug 2013 10:32:13 +0300 Message-Id: <1377070333-29089-1-git-send-email-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 1.8.4.rc2 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 To get name of the file from a pathname let's use kbasename() helper. It allows to simplify code a bit. Signed-off-by: Andy Shevchenko --- Since v1: - fix build warnings fs/btrfs/send.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index d3f3b43..f5281cc 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "send.h" #include "backref.h" @@ -2581,7 +2582,6 @@ static int record_ref(struct list_head *head, u64 dir, u64 dir_gen, struct fs_path *path) { struct recorded_ref *ref; - char *tmp; ref = kmalloc(sizeof(*ref), GFP_NOFS); if (!ref) @@ -2591,20 +2591,14 @@ static int record_ref(struct list_head *head, u64 dir, ref->dir_gen = dir_gen; ref->full_path = path; - tmp = strrchr(ref->full_path->start, '/'); - if (!tmp) { - ref->name_len = ref->full_path->end - ref->full_path->start; - ref->name = ref->full_path->start; + ref->name = (char *)kbasename(ref->full_path->start); + ref->name_len = ref->full_path->end - ref->name; + ref->dir_path = ref->full_path->start; + if (ref->name == ref->full_path->start) ref->dir_path_len = 0; - ref->dir_path = ref->full_path->start; - } else { - tmp++; - ref->name_len = ref->full_path->end - tmp; - ref->name = tmp; - ref->dir_path = ref->full_path->start; + else ref->dir_path_len = ref->full_path->end - ref->full_path->start - 1 - ref->name_len; - } list_add_tail(&ref->list, head); return 0;