From patchwork Thu Dec 22 21:42:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9486907 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 D7553601D4 for ; Thu, 22 Dec 2016 21:43:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C511C282E2 for ; Thu, 22 Dec 2016 21:43:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5BFB283F3; Thu, 22 Dec 2016 21:43:17 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 4124E282E2 for ; Thu, 22 Dec 2016 21:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941291AbcLVVnQ (ORCPT ); Thu, 22 Dec 2016 16:43:16 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36503 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938907AbcLVVnP (ORCPT ); Thu, 22 Dec 2016 16:43:15 -0500 Received: by mail-wm0-f68.google.com with SMTP id m203so38326810wma.3 for ; Thu, 22 Dec 2016 13:43:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/bufCAgBIB+5a3MlGWGfPvLUHBMt10HEGZuC5FL7Lj0=; b=QixTMWnXmPHhn/vD4NpZbADCswSd+xr8NXtGz5qYuTp1gCZKPeJaKbZMtibKpd3Ovx 3QHMlzUYNOBFUSgOe1QSiNA2X+nb8SEpVw1pu4i4lEAOL/IAGGyeytSaQ4UESe83sqgR u7oNWXXp2D6SXWJerEN+g+YM+Znl33ZpbTPu1XzgKZITGqt5q9llG4BosDROvdGOe/oM BuG3uFCO5l3w1gcH7AADSLKw3RpTYsRM9U8BtnswPSut2vVzbqNii6pofd2QVKBiH1+b YhFoOchDpn/rrfI6vm/l9K+nevI5JMfINC0wd3WPjgEJyfP7JzAH+IahyZKsy9YLQ5mZ mXUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/bufCAgBIB+5a3MlGWGfPvLUHBMt10HEGZuC5FL7Lj0=; b=nYhqARUIIO3gRLj5ClXgdMs2eDdBV4QO1BIZOFIbj8iBe2vMyotqQsrQlmRbB4osct pHfgd+eYLyhgqLA/wZcv3x4aY9/EKeb0k8h2o/D2XwUKn9tVYAbXGFxnZGuCZdJ2n9F0 FQVF0zFYRrQLjP9+z3tgDkUAWd1CX7AFnLNLbCTNKu4BGqkJVVAyYhWcrJ9XEw2JodWu PuUrihGAACrgohiXIs9U18dlivB6v8LHraCvNGp7o/K7G2YdRDI7bGp2CQR/viHBUDHR uckwTmkjGp9o+mUudeQa7eTCGATbGQQ35UzhuUUp4xGzBBsVgn01nUPxpEU/N9zbdw8M idfg== X-Gm-Message-State: AIkVDXIU8S91TswY071axSo66XzE0d/lpfz9m3RBkEpFhP82D0u5NttahMBuzJ/NPQWUHA== X-Received: by 10.28.113.76 with SMTP id m73mr10632228wmc.114.1482442994042; Thu, 22 Dec 2016 13:43:14 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-180-107-203.red.bezeqint.net. [79.180.107.203]) by smtp.gmail.com with ESMTPSA id f126sm33926733wme.22.2016.12.22.13.43.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Dec 2016 13:43:13 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Eric Sandeen , Dave Chinner , linux-xfs@vger.kernel.org Subject: [PATCH] libxfs: fix the size of xfs_mode_to_ftype table Date: Thu, 22 Dec 2016 23:42:54 +0200 Message-Id: <1482442974-22117-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 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 Fix the size of the xfs_mode_to_ftype conversion table, which was too small to handle a malformed on-disk value of mode=S_IFMT. Use a convenience macros S_DT(mode) to convert from mode to dirent file type and change the name of the table to xfs_dtype_to_ftype to correctly describe its index values. Signed-off-by: Amir Goldstein --- libxfs/xfs_dir2.c | 17 ++++++++--------- libxfs/xfs_dir2.h | 4 +++- repair/dino_chunks.c | 3 +-- repair/phase6.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) Darrick, This is the matcing patch to the kernel fix patch. I used S_DT(S_IF*) values in this patch instead of DT_* values to avoid complicating the build. Assuming you want the kernel libxfs to stay in sync with this code feel free to copy&paste the table chunk into the kernel patch I sent you or I can re-send the kernel patch if you like. Tested that xfs_repair detects and fixes wrong file type values. Amir. diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 4180a93..8dd007d 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -39,15 +39,14 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; * for file type specification. This will be propagated into the directory * structure if appropriate for the given operation and filesystem config. */ -const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { - [0] = XFS_DIR3_FT_UNKNOWN, - [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, - [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, - [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, +const unsigned char xfs_dtype_to_ftype[S_DT_MAX] = { + [S_DT(S_IFREG)] = XFS_DIR3_FT_REG_FILE, + [S_DT(S_IFDIR)] = XFS_DIR3_FT_DIR, + [S_DT(S_IFCHR)] = XFS_DIR3_FT_CHRDEV, + [S_DT(S_IFBLK)] = XFS_DIR3_FT_BLKDEV, + [S_DT(S_IFIFO)] = XFS_DIR3_FT_FIFO, + [S_DT(S_IFSOCK)] = XFS_DIR3_FT_SOCK, + [S_DT(S_IFLNK)] = XFS_DIR3_FT_SYMLINK, }; /* diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index 89b9e24..8eeaa0c 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -35,7 +35,9 @@ extern struct xfs_name xfs_name_dotdot; * directory filetype conversion tables. */ #define S_SHIFT 12 -extern const unsigned char xfs_mode_to_ftype[]; +#define S_DT(mode) (((mode) & S_IFMT) >> S_SHIFT) +#define S_DT_MAX (S_DT(S_IFMT) + 1) +extern const unsigned char xfs_dtype_to_ftype[]; /* * directory operations vector for encode/decode routines diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c index 4db9512..dd893af 100644 --- a/repair/dino_chunks.c +++ b/repair/dino_chunks.c @@ -847,9 +847,8 @@ next_readbuf: * phase 6. */ di_mode = be16_to_cpu(dino->di_mode); - di_mode = (di_mode & S_IFMT) >> S_SHIFT; set_inode_ftype(ino_rec, irec_offset, - xfs_mode_to_ftype[di_mode]); + xfs_dtype_to_ftype[S_DT(di_mode)]); /* * store on-disk nlink count for comparing in phase 7 diff --git a/repair/phase6.c b/repair/phase6.c index 06eed16..941fffc 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -1082,7 +1082,7 @@ mv_orphanage( if ((err = -libxfs_iget(mp, NULL, ino, 0, &ino_p))) do_error(_("%d - couldn't iget disconnected inode\n"), err); - xname.type = xfs_mode_to_ftype[(VFS_I(ino_p)->i_mode & S_IFMT)>>S_SHIFT]; + xname.type = xfs_dtype_to_ftype[S_DT(VFS_I(ino_p)->i_mode)]; if (isa_dir) { irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, orphanage_ino),