From patchwork Thu Dec 22 21:07:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9486871 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 21AB3601D3 for ; Thu, 22 Dec 2016 21:07:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BED426246 for ; Thu, 22 Dec 2016 21:07:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2DB226538; Thu, 22 Dec 2016 21:07:44 +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 92B6926246 for ; Thu, 22 Dec 2016 21:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966439AbcLVVHn (ORCPT ); Thu, 22 Dec 2016 16:07:43 -0500 Received: from mail-wj0-f193.google.com ([209.85.210.193]:33544 "EHLO mail-wj0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966157AbcLVVHm (ORCPT ); Thu, 22 Dec 2016 16:07:42 -0500 Received: by mail-wj0-f193.google.com with SMTP id kp2so37832878wjc.0; Thu, 22 Dec 2016 13:07:41 -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:in-reply-to:references; bh=RN086MYPrxpmA5V9PKQAPt/7acay3qybrd1EYTZ2rmU=; b=SX11VwBabrfyK6qSraYk+FD++e768S8DCSURYN07S8p9chfF+h3NxAbUOYsGQ1m3tO piZz3MWpJWMhaGYVSUdrT3O4xASWPDy930DN11pylVOoe5Cnc+DiAlHdSwtVrVhweP5j qUXhqzTjI99T9Ae1yHEKxA/vAkKRWDWak+6mV36U1VT1uap+7JkUpmUJudCfbc880cx9 0z63zR9LXxSM4VuZqT55tBhEtgk2gF1xsbCD8WH3WF3NQR7uhu9E4giF4PF0Z8DvawW3 0j8YA9bkG5QwxGNj3eIPIWUx8+xMDQcyVxMneIehdMJ7woTrF34WOhCxNgUUi4j8oi1O nXGA== 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:in-reply-to :references; bh=RN086MYPrxpmA5V9PKQAPt/7acay3qybrd1EYTZ2rmU=; b=GTt1QyG4/pUjQ15tZ9E6lnnK9WeK6XoFvBWBNFHCe8U59oAj7Ao7PNU1qQBULRQQrh CIE0QkEq7jSTzO08FYaXtP7S75/pWsLzN60O+MlyPlo6o78Lz+MYh/3nKj5k74Gco/Zc ctx/qYYtW3kxxIcgybZ7gwsSzn+ou56NfS6qpEVjPRoBBrt0JclKtf33dUGVQ0NMJNaz YgnEpJm1mpDZrZP6OsesSnEb+ytZwQg6S2lUyZqxJl9JHj4zYVIN7beZyZ5sAE4dVBNj yebudG1dksu+KO0p0zD9xcLEfIF8eBrXP3cbeYUQmvW62UYyczsNr/XtuX4ReSTuk1CH zyhg== X-Gm-Message-State: AIkVDXL5rYdbg+nJ1MjOGb3UodJumZAhF8M3Uit1RlmIGnkgynjFEB9Vw6yKcz7TPZOjtg== X-Received: by 10.194.111.196 with SMTP id ik4mr10833684wjb.90.1482440860862; Thu, 22 Dec 2016 13:07:40 -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 js10sm37402633wjb.19.2016.12.22.13.07.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Dec 2016 13:07:40 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Dave Chinner , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4] xfs: fix the size of xfs_mode_to_ftype table Date: Thu, 22 Dec 2016 23:07:21 +0200 Message-Id: <1482440841-10819-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482343293-9028-1-git-send-email-amir73il@gmail.com> References: <1482343293-9028-1-git-send-email-amir73il@gmail.com> 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 --- fs/xfs/libxfs/xfs_dir2.c | 17 ++++++++--------- fs/xfs/libxfs/xfs_dir2.h | 4 +++- fs/xfs/xfs_iops.c | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) Darrick, So my holiday season cleanup is now down to this one patch. I pulled back the common code and added the needed macros in xfs code, so this can be safely applied to xfsprogs as well. I will send a patch to xfsprogs later. Tested with generic/396 with -n ftype=0|1. Amir. v4: - independent fix patch for xfs v3: - resort to simpler cleanup with macros DT_MAX and S_DT() - mention the minor bug fix in commit message v2: - add private conversion from common to on-disk values v1: - use common conversion functions to get on-disk values diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index c58d72c..539f498 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -41,15 +41,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] = { + [DT_REG] = XFS_DIR3_FT_REG_FILE, + [DT_DIR] = XFS_DIR3_FT_DIR, + [DT_CHR] = XFS_DIR3_FT_CHRDEV, + [DT_BLK] = XFS_DIR3_FT_BLKDEV, + [DT_FIFO] = XFS_DIR3_FT_FIFO, + [DT_SOCK] = XFS_DIR3_FT_SOCK, + [DT_LNK] = XFS_DIR3_FT_SYMLINK, }; /* diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 0197590..a069c3e 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/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/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 308bebb..d2da9ca 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -103,7 +103,7 @@ xfs_dentry_to_name( { namep->name = dentry->d_name.name; namep->len = dentry->d_name.len; - namep->type = xfs_mode_to_ftype[(mode & S_IFMT) >> S_SHIFT]; + namep->type = xfs_dtype_to_ftype[S_DT(mode)]; } STATIC void