From patchwork Sun Dec 25 11:13:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9488229 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 A34C160838 for ; Sun, 25 Dec 2016 11:14:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71C1E20499 for ; Sun, 25 Dec 2016 11:14:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52C5B26530; Sun, 25 Dec 2016 11:14:12 +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 D6D5920499 for ; Sun, 25 Dec 2016 11:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753135AbcLYLOJ (ORCPT ); Sun, 25 Dec 2016 06:14:09 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33454 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753008AbcLYLOI (ORCPT ); Sun, 25 Dec 2016 06:14:08 -0500 Received: by mail-wm0-f68.google.com with SMTP id u144so49345715wmu.0 for ; Sun, 25 Dec 2016 03:14:07 -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=jhRL6Y6cp/I11RKT6/TuLhHKfYi0mV3BeAtcY85G400=; b=QoiiDfg1MgPx9ndm2/Qluwf6RayHvjuPsf3UCqgT5FVI5PfXtE4YB70kRb+XQkBx4r M3DlvBlFnk74lp5UiGx4jw4oIWhjf8sHXI/dOXqU2UJFfz1hArG5IzbRGsbRp6fG5lWn dnp4OJjMc8hXgGC7uivwx8bXA7O26DL4KvVvOVy25e9ilGGB/dD+L4wY95i25PpBBhGG ay11S1t50BZvtUDpNenDv6IoDZKWvje6XUHEpv0C/pwDM3WWkjgch3V1ZTEONg0yoZJg EQm1TcsFYwl3Jk9+DyRyMqjgzDEV4NZv6PTVk98Q0CSFnzaUJogYFhLX2dNnqm4YmPBq 3Xvw== 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=jhRL6Y6cp/I11RKT6/TuLhHKfYi0mV3BeAtcY85G400=; b=CHW8w3WQM5J89RtQndPBbwqee/sAnmre7L4fV2eFFydrHAhITDkVdYLvJndbSrS/p4 rsgqVgMkNhVRkCcbzUJyxeK0XWwBtSvAv9v6lS9yTZfA5fRi1G7AShMqFuX3Bkr6Zon3 JSqb2RgFmRDQ27SYxdBF4HPywXyYkwkFNDH+G3GqLKZAlN4gd54mKuN92+JGydfwi8oG FlzN7ONAVKs20kj1zvfk0DQ5CrkSMHb2sLpvKVhNO0YROWLDJgjcdXzFNSmZIKyy7gP5 NkS2RFCuPfijjOzQ2WdMWTQTpi5oFAbE71RD18Uyq+PIjMKXJm2GKITAicX2iuCmiWVj cA8A== X-Gm-Message-State: AIkVDXKS+di99Abza77KnpQL7EgciH/yD8CFCWEjpAGCMYkQ4lX6H4XlIgCI51BUH0sW+g== X-Received: by 10.28.135.3 with SMTP id j3mr19125919wmd.96.1482664446689; Sun, 25 Dec 2016 03:14:06 -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 cl10sm49561372wjb.4.2016.12.25.03.14.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Dec 2016 03:14:06 -0800 (PST) From: Amir Goldstein To: Eric Sandeen Cc: "Darrick J . Wong" , Brian Foster , linux-xfs@vger.kernel.org Subject: [PATCH v2] libxfs: fix the size of xfs_mode_to_ftype table Date: Sun, 25 Dec 2016 13:13:48 +0200 Message-Id: <1482664428-17338-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 an invalid value of mode=S_IFMT. Use a convenience macro 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 | 18 +++++++++--------- libxfs/xfs_dir2.h | 4 +++- repair/dino_chunks.c | 3 +-- repair/phase6.c | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) Eric, This is a matching patch to the one I am sending Darrick for kernel, so that xfsprogs and kernel's libxfs will stay in sync. Tested xfs_repair with the new xfs/348 test with -n ftype=0|1. Amir. v2: - remove wrong argument about on-disk malformed mode from commit message - address Brian's review comments - test with new xfs/348 v1: - fix patch for xfsprogs derived from kernel patch diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 4180a93..e21fd33 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -39,15 +39,15 @@ 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+1] = { + [0] = XFS_DIR3_FT_UNKNOWN, + [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..0291f0f 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) +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),