From patchwork Tue Jan 10 15:39:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9508041 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 94DD8601EA for ; Tue, 10 Jan 2017 15:39:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85B1C285AC for ; Tue, 10 Jan 2017 15:39:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78EE62858A; Tue, 10 Jan 2017 15:39:39 +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 1C1E22858A for ; Tue, 10 Jan 2017 15:39:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939211AbdAJPji (ORCPT ); Tue, 10 Jan 2017 10:39:38 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:34079 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939184AbdAJPjg (ORCPT ); Tue, 10 Jan 2017 10:39:36 -0500 Received: by mail-wj0-f196.google.com with SMTP id qs7so50331779wjc.1 for ; Tue, 10 Jan 2017 07:39:36 -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=WzZ8z6AVjeBzhC0uMs6fwUrOQB6F+XK5Yx+7swUsO9s=; b=GcX4Zehi6pHd1b57TVU+IhVgUjYzEtJRCjI9GwAV1MCQoJKQxqfUPrg7IABCNM/UnL qYPFoXqHljSNEbXSQ2kS17S9GJiHxnfjcOYMD54babMryOPigfZByAizM4SeUVXRWdAs jjIt+GNNfMkJmu7c4V2XJ0QTmrM8B5YQFl2FYFEWulTbnWqJpd5gm97gL+kFGI0wTNCk Y/7JU4K5FRMo6f6OHOCmCOHxzTcfknOGByb0PTlRA+SNOujlx9ie2EOFMt/3rG1Fr/9Y v4m2MdxyV0uTCBAU42kHAP7aNgUD89VASOP4vKk0F1x6JHPS2xh/BPXTmBAYVE082ruK LOrw== 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=WzZ8z6AVjeBzhC0uMs6fwUrOQB6F+XK5Yx+7swUsO9s=; b=gTqOV9pDgQJ3NXol9sO64lTYOmE/YFbOYymFL8EP6nZVeG8ZV/P93mfg0qefZoU1Lk 2rl20t3Komo5ZPykyyR+B2daZSsL/ZfpRZ7Ffiw1AZTvvEPZ6OYrGrHcR9vk0DL9h3ZR 6s8zt7s98rko+SukZ6CC0p3aZ53U0F3taJoK9zh9CNkLIDfMb1qAQ5LYLQ3siGpdAv2T iYnCuxkgsXPfgen+5QbJUJeTTrlwquXsoYRSMcb8zlgWyaWxDiNBQEC2UYtQt0cp4iUJ F0zS+wDY5xTE7GJCLZbqjcW5LHMcKLfh7jU8OVwibyPzyGp+id1FQMPK8rh2IHyHbvD9 0JEw== X-Gm-Message-State: AIkVDXJ9nW0luRp3OzgprmQ3XXACrprwOeTUBBSgXZL7fz4ZA/v4ZKsIiyV655tWKlMqrw== X-Received: by 10.194.242.10 with SMTP id wm10mr2158626wjc.38.1484062775205; Tue, 10 Jan 2017 07:39:35 -0800 (PST) Received: from amir-VirtualBox.ctera.local (bzq-82-81-193-202.cablep.bezeqint.net. [82.81.193.202]) by smtp.gmail.com with ESMTPSA id cs4sm3792374wjd.42.2017.01.10.07.39.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Jan 2017 07:39:34 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Brian Foster , Christoph Hellwig , linux-xfs@vger.kernel.org Subject: [PATCH v7 4/6] xfs: replace xfs_mode_to_ftype table with switch statement Date: Tue, 10 Jan 2017 17:39:15 +0200 Message-Id: <1484062757-12433-5-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484062757-12433-1-git-send-email-amir73il@gmail.com> References: <1484062757-12433-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 The size of the xfs_mode_to_ftype[] conversion table was too small to handle an invalid value of mode=S_IFMT. Instead of fixing the table size, replace the conversion table with a conversion helper that uses a switch statement. Suggested-by: Christoph Hellwig Signed-off-by: Amir Goldstein Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2.c | 36 ++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2.h | 5 ++--- fs/xfs/xfs_iops.c | 2 +- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 4f7913f..eb64f38 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -36,21 +36,29 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; /* - * @mode, if set, indicates that the type field needs to be set up. - * This uses the transformation from file mode to DT_* as defined in linux/fs.h - * for file type specification. This will be propagated into the directory - * structure if appropriate for the given operation and filesystem config. + * Convert inode mode to directory entry filetype */ -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_mode_to_ftype(int mode) +{ + switch (mode & S_IFMT) { + case S_IFREG: + return XFS_DIR3_FT_REG_FILE; + case S_IFDIR: + return XFS_DIR3_FT_DIR; + case S_IFCHR: + return XFS_DIR3_FT_CHRDEV; + case S_IFBLK: + return XFS_DIR3_FT_BLKDEV; + case S_IFIFO: + return XFS_DIR3_FT_FIFO; + case S_IFSOCK: + return XFS_DIR3_FT_SOCK; + case S_IFLNK: + return XFS_DIR3_FT_SYMLINK; + default: + return XFS_DIR3_FT_UNKNOWN; + } +} /* * ASCII case-insensitive (ie. A-Z) support for directories that was diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 72df0dc..d4b77ab 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -35,10 +35,9 @@ struct xfs_dir2_data_unused; extern struct xfs_name xfs_name_dotdot; /* - * directory filetype conversion tables. + * Convert inode mode to directory entry filetype */ -#define S_SHIFT 12 -extern const unsigned char xfs_mode_to_ftype[]; +extern const unsigned char xfs_mode_to_ftype(int mode); /* * directory operations vector for encode/decode routines diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 308bebb..821f08d 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_mode_to_ftype(mode); } STATIC void