From patchwork Wed Jan 11 08:24:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9509471 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 9AEBE60231 for ; Wed, 11 Jan 2017 08:24:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89837285E5 for ; Wed, 11 Jan 2017 08:24:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BCFD285F4; Wed, 11 Jan 2017 08:24:38 +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 505A9285E5 for ; Wed, 11 Jan 2017 08:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936353AbdAKIYg (ORCPT ); Wed, 11 Jan 2017 03:24:36 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:34983 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933746AbdAKIYf (ORCPT ); Wed, 11 Jan 2017 03:24:35 -0500 Received: by mail-wm0-f67.google.com with SMTP id l2so35346556wml.2 for ; Wed, 11 Jan 2017 00:24:35 -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=TGPL7yxYs306qgF7m3eXsxHA7zm4L6D/PEeLHMlJffA=; b=HIKb3eGMRB0LO4jBJw7cGSNrs6ePl6kNMvqosKDmqfK+QuHths2b0MSjNuNobYadkK /W/703489wpRUEpwwFrgIcti55urWYlPG5DZZ3UybhartuC3rZQPgyuijPa2fZLmgrZY +/cgcY52oD9WDNJfjkGZhmE53sA+rx1usb3OPzPvhEg0Bf8RDPoi6GnbIHwCEUlRmDPo /j3HrFFlSZZ1FbA8k0DD9LhQ45j2I9Y90KQvyBFFfHHpCRQMY6i5ufeTAkn0lrW1CWSa xlrWUTqP7K3qa24KqtGHYEKmt5smxEwgE2wzTRHltqJfrXJZcwehjJ0CCjA+VfY+W0xC 6PuA== 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=TGPL7yxYs306qgF7m3eXsxHA7zm4L6D/PEeLHMlJffA=; b=mr7DV7d3iqkhlzrghr5saDNyoVDwDdz3rKnBjKkV2lX2e8uHORGD7NBYKP1UvffvW0 sSh+Opkl5ejBK1I9yrmxfoZK6l3qrp5sK/A6N9AgzDmXrFMYUhBOUfpVfkcwd4fIjKvz dPy7Hs7v58j7Fdm8OJlPOHO7PaFXWgicYGt5GcEvg2jwGF8/8zFZP3fyLAcyHg25ELQP 6SkuXxEdag6fzH+yznzSWpe1+Xhx008rj2B5h+gu6SvB2pCdJ00QgjG1FpN7+UoVLEsY RbkGHTZhd+Vom8oMd2TV01Lq+r66yiunU8OlWclqlc3BSo78PnDz77z/ej3lEIzP6r/5 3SVQ== X-Gm-Message-State: AIkVDXImPUkoQjgFY2V47sgtVcmlxTO7kcBsB6SkWU+g5HHNw5LZNcZV54CrcFc8cIbMCQ== X-Received: by 10.223.153.15 with SMTP id x15mr4345567wrb.179.1484123074446; Wed, 11 Jan 2017 00:24:34 -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 l187sm7704670wml.6.2017.01.11.00.24.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 00:24:33 -0800 (PST) From: Amir Goldstein To: "Darrick J . Wong" Cc: Brian Foster , Christoph Hellwig , linux-xfs@vger.kernel.org Subject: [PATCH v8 4/6] xfs: replace xfs_mode_to_ftype table with switch statement Date: Wed, 11 Jan 2017 10:24:08 +0200 Message-Id: <1484123050-11064-5-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484123050-11064-1-git-send-email-amir73il@gmail.com> References: <1484123050-11064-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 Reviewed-by: Darrick J. Wong Signed-off-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- 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