From patchwork Wed Aug 17 09:23:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hidetoshi Seto X-Patchwork-Id: 1073292 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7H9OOlu005142 for ; Wed, 17 Aug 2011 09:24:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752515Ab1HQJXz (ORCPT ); Wed, 17 Aug 2011 05:23:55 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:37089 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752115Ab1HQJXv (ORCPT ); Wed, 17 Aug 2011 05:23:51 -0400 Received: from m2.gw.fujitsu.co.jp (unknown [10.0.50.72]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id 4B1B93EE0B5 for ; Wed, 17 Aug 2011 18:23:49 +0900 (JST) Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 2FE1A45DE81 for ; Wed, 17 Aug 2011 18:23:49 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 1808145DE61 for ; Wed, 17 Aug 2011 18:23:49 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id F3DC91DB803A for ; Wed, 17 Aug 2011 18:23:48 +0900 (JST) Received: from m107.s.css.fujitsu.com (m107.s.css.fujitsu.com [10.240.81.147]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id BDCB71DB802C for ; Wed, 17 Aug 2011 18:23:48 +0900 (JST) Received: from m107.css.fujitsu.com (m107 [127.0.0.1]) by m107.s.css.fujitsu.com (Postfix) with ESMTP id 8DCE3680009; Wed, 17 Aug 2011 18:23:48 +0900 (JST) Received: from [127.0.0.1] (iqs-mon.soft.fujitsu.com [10.124.101.137]) by m107.s.css.fujitsu.com (Postfix) with ESMTP id 2D9A4680013; Wed, 17 Aug 2011 18:23:48 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Received: from FMVDA2A041[10.124.101.137] by FMVDA2A041 (FujitsuOutboundMailChecker v1.3.1/9992[10.124.101.137]); Wed, 17 Aug 2011 18:23:46 +0900 (JST) Message-ID: <4E4B888D.6070904@jp.fujitsu.com> Date: Wed, 17 Aug 2011 18:23:25 +0900 From: Hidetoshi Seto User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org CC: chris.mason@oracle.com Subject: [PATCH] btrfs: fix d_off in the first dirent Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 17 Aug 2011 09:24:24 +0000 (UTC) Since the d_off in the first dirent for "." (that originates from the 4th argument "offset" of filldir() for the 2nd dirent for "..") is wrongly assigned in btrfs_real_readdir(), telldir returns same offset for different locations. | # mkfs.btrfs /dev/sdb1 | # mount /dev/sdb1 fs0 | # cd fs0 | # touch file0 file1 | # ../test | telldir: 0 | readdir: d_off = 2, d_name = "." | telldir: 2 | readdir: d_off = 2, d_name = ".." | telldir: 2 | readdir: d_off = 3, d_name = "file0" | telldir: 3 | readdir: d_off = 2147483647, d_name = "file1" | telldir: 2147483647 To fix this problem, pass filp->f_pos (which is loff_t) instead of the wrong constant value. | # ../test | telldir: 0 | readdir: d_off = 1, d_name = "." | telldir: 1 | readdir: d_off = 2, d_name = ".." | telldir: 2 | readdir: d_off = 3, d_name = "file0" : At the moment the "offset" for "." is unused because there is no preceding dirent, however it is better to pass filp->f_pos to follow grammatical usage. Signed-off-by: Hidetoshi Seto --- fs/btrfs/inode.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 15fceef..9c1297b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4125,7 +4125,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, /* special case for "." */ if (filp->f_pos == 0) { - over = filldir(dirent, ".", 1, 1, btrfs_ino(inode), DT_DIR); + over = filldir(dirent, ".", 1, + filp->f_pos, inode->i_ino, DT_DIR); if (over) return 0; filp->f_pos = 1; @@ -4134,7 +4135,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, if (filp->f_pos == 1) { u64 pino = parent_ino(filp->f_path.dentry); over = filldir(dirent, "..", 2, - 2, pino, DT_DIR); + filp->f_pos, pino, DT_DIR); if (over) return 0; filp->f_pos = 2;