From patchwork Wed Nov 21 19:06:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B200B13BF for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AB602B68D for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D7982BDB2; Wed, 21 Nov 2018 19:06:57 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 9FBEA2B68D for ; Wed, 21 Nov 2018 19:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387600AbeKVFm0 (ORCPT ); Thu, 22 Nov 2018 00:42:26 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40810 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387582AbeKVFmZ (ORCPT ); Thu, 22 Nov 2018 00:42:25 -0500 Received: by mail-wm1-f65.google.com with SMTP id q26so6817747wmf.5 for ; Wed, 21 Nov 2018 11:06:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=bWSYU43r6zpEfhcN5eomDwvNR7Q7d8zlX0QbaaEk1Qg=; b=JmeH77EDRzgqViVZkQVodNpJAVT9vPtq7w2kFG4lh8ft8fpmjjV30jWiiqLcVgdZCH MR93oJNN0q5Uf/nzjoxgxTZh1IKah4nWjYWFu3KpLFpCjygmfmo/13HnExB46R25Oq4l hMTgXwV7Adi6nnJ/5BMrPGB68jMVuH1OlG9F/PZWnp0RHwYo026NxUv/sL1MlkY1Tsb0 Y1P7SGQmuI6JrIYcZGgbNw6gcu5NVEQwJt6AG+B3Q/XihcalhnQ71UbIiZWKCXiS6Frg F1hzm1WpauHnL7iQUCm3GkLerY6ovQ4p3dIZU9iOh75S40mrGpqKYzB9A+tIMRoYEpYY zXYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=bWSYU43r6zpEfhcN5eomDwvNR7Q7d8zlX0QbaaEk1Qg=; b=Jkr1jKRkcunOkCJd+gTBayYkX5PZ6goF1xiE9qSnmjBSLMozToqCl0uKVecCRKG1VA oU6i/O7istNUsbGi2tKzGm6RUgSznJpJNECAQGcwdzKfaY/2zyujKmAneUNkI1LlHavi 9Bgl7yAxPQrjNfdRzMPobvUUFpKmB9XiUzleG0junbJGjuaVsurO9NwuVqKJde/JR3Ti +Zd0Xw8TuJ1dl6LG+UQqyTZcBEfqx5blGqHhR1lzehnx1mrHaawrvSth/uYeEgGCvCP3 00zPQQCjgzsg83ZOoUuB/kb/QArmcyn5sAu/gXGg0n2RUgT2qIuvGyD6QMI4tfrGFbVi KowQ== X-Gm-Message-State: AA+aEWaL46o2qd+XkRmocq4HyKgvcAmGvgflFA/n0ShB8CZD2BHP10LM ftu2/TKNALN3QzkpaHK0GB7SHw== X-Google-Smtp-Source: AJdET5eSY6DWVaf7m84DjUD6T3hN3NAx2lXd6Tw7G+NCVnb30fEVI/ORGg7CarbKQSCroVcoyK05AA== X-Received: by 2002:a1c:9855:: with SMTP id a82mr6646135wme.20.1542827210825; Wed, 21 Nov 2018 11:06:50 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id v189-v6sm2235820wmd.40.2018.11.21.11.06.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:50 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:49 +0000 From: Phillip Potter To: viro@zeniv.linux.org.uk Cc: amir73il@gmail.com, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 01/09] fs: common implementation of file type Message-ID: <20181121190649.GA7689@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Many file systems use a copy&paste implementation of dirent to on-disk file type conversions. Create a common implementation to be used by file systems with some useful conversion helpers to reduce open coded file type conversions in file system code. Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter --- MAINTAINERS | 1 + fs/Makefile | 3 +- fs/fs_types.c | 105 +++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 17 +------ include/linux/fs_types.h | 73 +++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 17 deletions(-) create mode 100644 fs/fs_types.c create mode 100644 include/linux/fs_types.h diff --git a/MAINTAINERS b/MAINTAINERS index 77b11742785d..4cd052170160 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5727,6 +5727,7 @@ L: linux-fsdevel@vger.kernel.org S: Maintained F: fs/* F: include/linux/fs.h +F: include/linux/fs_types.h F: include/uapi/linux/fs.h FINTEK F75375S HARDWARE MONITOR AND FAN CONTROLLER DRIVER diff --git a/fs/Makefile b/fs/Makefile index 293733f61594..23fcd8c164a3 100644 --- a/fs/Makefile +++ b/fs/Makefile @@ -12,7 +12,8 @@ obj-y := open.o read_write.o file_table.o super.o \ attr.o bad_inode.o file.o filesystems.o namespace.o \ seq_file.o xattr.o libfs.o fs-writeback.o \ pnode.o splice.o sync.o utimes.o d_path.o \ - stack.o fs_struct.o statfs.o fs_pin.o nsfs.o + stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ + fs_types.o ifeq ($(CONFIG_BLOCK),y) obj-y += buffer.o block_dev.o direct-io.o mpage.o diff --git a/fs/fs_types.c b/fs/fs_types.c new file mode 100644 index 000000000000..6fc57f4b1dcb --- /dev/null +++ b/fs/fs_types.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +/* + * fs on-disk file type to dirent file type conversion + */ +static unsigned char fs_dtype_by_ftype[FT_MAX] = { + [FT_UNKNOWN] = DT_UNKNOWN, + [FT_REG_FILE] = DT_REG, + [FT_DIR] = DT_DIR, + [FT_CHRDEV] = DT_CHR, + [FT_BLKDEV] = DT_BLK, + [FT_FIFO] = DT_FIFO, + [FT_SOCK] = DT_SOCK, + [FT_SYMLINK] = DT_LNK +}; + +/** + * fs_ftype_to_dtype() - fs on-disk file type to dirent type. + * @filetype: The on-disk file type to convert. + * + * This function converts the on-disk file type value (FT_*) to the directory + * entry type (DT_*). + * + * Context: Any context. + * Return: + * * DT_UNKNOWN - Unknown type + * * DT_FIFO - FIFO + * * DT_CHR - Character device + * * DT_DIR - Directory + * * DT_BLK - Block device + * * DT_REG - Regular file + * * DT_LNK - Symbolic link + * * DT_SOCK - Local-domain socket + */ +unsigned char fs_ftype_to_dtype(unsigned int filetype) +{ + if (filetype >= FT_MAX) + return DT_UNKNOWN; + + return fs_dtype_by_ftype[filetype]; +} +EXPORT_SYMBOL_GPL(fs_ftype_to_dtype); + +/* + * dirent file type to fs on-disk file type conversion + * Values not initialized explicitly are FT_UNKNOWN (0). + */ +static unsigned char fs_ftype_by_dtype[DT_MAX] = { + [DT_REG] = FT_REG_FILE, + [DT_DIR] = FT_DIR, + [DT_LNK] = FT_SYMLINK, + [DT_CHR] = FT_CHRDEV, + [DT_BLK] = FT_BLKDEV, + [DT_FIFO] = FT_FIFO, + [DT_SOCK] = FT_SOCK, +}; + +/** + * fs_umode_to_ftype() - file mode to on-disk file type. + * @mode: The file mode to convert. + * + * This function converts the file mode value to the on-disk file type (FT_*). + * + * Context: Any context. + * Return: + * * FT_UNKNOWN - Unknown type + * * FT_REG_FILE - Regular file + * * FT_DIR - Directory + * * FT_CHRDEV - Character device + * * FT_BLKDEV - Block device + * * FT_FIFO - FIFO + * * FT_SOCK - Local-domain socket + * * FT_SYMLINK - Symbolic link + */ +unsigned char fs_umode_to_ftype(umode_t mode) +{ + return fs_ftype_by_dtype[S_DT(mode)]; +} +EXPORT_SYMBOL_GPL(fs_umode_to_ftype); + +/** + * fs_umode_to_dtype() - file mode to dirent file type. + * @mode: The file mode to convert. + * + * This function converts the file mode value to the directory + * entry type (DT_*). + * + * Context: Any context. + * Return: + * * DT_UNKNOWN - Unknown type + * * DT_FIFO - FIFO + * * DT_CHR - Character device + * * DT_DIR - Directory + * * DT_BLK - Block device + * * DT_REG - Regular file + * * DT_LNK - Symbolic link + * * DT_SOCK - Local-domain socket + */ +unsigned char fs_umode_to_dtype(umode_t mode) +{ + return fs_ftype_to_dtype(fs_umode_to_ftype(mode)); +} +EXPORT_SYMBOL_GPL(fs_umode_to_dtype); diff --git a/include/linux/fs.h b/include/linux/fs.h index c95c0807471f..47333ff1abb8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1694,22 +1695,6 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical, u64 phys, u64 len, u32 flags); int fiemap_check_flags(struct fiemap_extent_info *fieinfo, u32 fs_flags); -/* - * File types - * - * NOTE! These match bits 12..15 of stat.st_mode - * (ie "(i_mode >> 12) & 15"). - */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 - /* * This is the "filldir" function type, used by readdir() to let * the kernel specify what kind of dirent layout it wants to have. diff --git a/include/linux/fs_types.h b/include/linux/fs_types.h new file mode 100644 index 000000000000..7d147b2f1702 --- /dev/null +++ b/include/linux/fs_types.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_FS_TYPES_H +#define _LINUX_FS_TYPES_H + +/* + * This is a header for the common implementation of dirent + * to fs on-disk file type conversion. Although the fs on-disk + * bits are specific to every file system, in practice, many + * file systems use the exact same on-disk format to describe + * the lower 3 file type bits that represent the 7 POSIX file + * types. + * + * It is important to note that the definitions in this + * header MUST NOT change. This would break both the + * userspace ABI and the on-disk format of filesystems + * using this code. + * + * All those file systems can use this generic code for the + * conversions. + */ + +/* + * struct dirent file types + * exposed to user via getdents(2), readdir(3) + * + * These match bits 12..15 of stat.st_mode + * (ie "(i_mode >> 12) & 15"). + */ +#define S_DT_SHIFT 12 +#define S_DT(mode) (((mode) & S_IFMT) >> S_DT_SHIFT) +#define S_DT_MASK (S_IFMT >> S_DT_SHIFT) + +/* these are defined by POSIX and also present in glibc's dirent.h */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 +#define DT_WHT 14 + +#define DT_MAX (S_DT_MASK + 1) /* 16 */ + +/* + * fs on-disk file types. + * Only the low 3 bits are used for the POSIX file types. + * Other bits are reserved for fs private use. + * + * Note that no fs currently stores the whiteout type on-disk, + * so whiteout dirents are exposed to user as DT_CHR. + */ +#define FT_UNKNOWN 0 +#define FT_REG_FILE 1 +#define FT_DIR 2 +#define FT_CHRDEV 3 +#define FT_BLKDEV 4 +#define FT_FIFO 5 +#define FT_SOCK 6 +#define FT_SYMLINK 7 + +#define FT_MAX 8 + +/* + * declarations for helper functions, accompanying implementation + * is in fs/fs_types.c + */ +extern unsigned char fs_ftype_to_dtype(unsigned int filetype); +extern unsigned char fs_umode_to_ftype(umode_t mode); +extern unsigned char fs_umode_to_dtype(umode_t mode); + +#endif From patchwork Wed Nov 21 19:06:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDFF65A4 for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA1E22B68D for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDD4C2BBD8; Wed, 21 Nov 2018 19:06:57 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 66D702B694 for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387601AbeKVFm1 (ORCPT ); Thu, 22 Nov 2018 00:42:27 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:56027 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387566AbeKVFm0 (ORCPT ); Thu, 22 Nov 2018 00:42:26 -0500 Received: by mail-wm1-f68.google.com with SMTP id y139so6577038wmc.5 for ; Wed, 21 Nov 2018 11:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=b4xhfmuJsvdLPfnEGpFEWrPBrAzhegd7lc5tStSVP6U=; b=nIKMEB6Co8CrAWuEU1sodccyMRD9sm7v+0GbZJhYOll0ZKlYkdx9QKvJHmVglzw7OK JUVa8Efm575aw7/yWhM4y1krp3IPBtMm0JhRXUy0M3OxUT57/7f+U0AO57qf2jpVe/UW OTKoUrK7iYY8X7iH8eb6QiPDHRqOtaGSTPIH/qs8R/iqBbiUB9X53yRSdfJHI0vlCJVR TpwFqF0Md9pnKw9pwrLqTmifxOJx8pF+yMtf+7oZXbcI8OUwaap4TUtGuSOk9v22gm3F hVdKZqOE0vN7TFC/5xMaZcMLZ1wEorDCmDGPyVJ+EtstIqSSoi1lYwTXB0JejebsPjWd uXbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=b4xhfmuJsvdLPfnEGpFEWrPBrAzhegd7lc5tStSVP6U=; b=BdqTRYDHfWI0IX2WRADOEzgpmYCmPRiA4kqZl6mm3gOQtMPzzxjzJEG6mzOzXOLOC2 FgIj3aoGpQOnr5qn6tLVYQk7hDFS6Irw1U9sIC0LIyeNZV02EhH0D2aUI3weOsiN5c6E GDWt462kKEbNvandIsWwsoIGg5p14ASVANl9a+zsnKOihU9An4v9VkRGFEaTvkQW680d TqZ9vEM/1setGHYA2kVm+YEeco7Kc/B3meDDTo73RQK4iA8W3s3hN3heKohCmCXsaxSl mB4nMq7spC3QlCOBf+D0a6IMiW8SfLZCLlQmY1RfU6WnvvQ24njjdOlOQP5Z8m80rTfH 4cYA== X-Gm-Message-State: AGRZ1gIVUHjZ4DhLKxLk5TKHhClwSYqcp6C9SfTrrXTIjcOJOUGtm8h0 BlnOr2wdyCIK+cw+Bx+3JqvFvg== X-Google-Smtp-Source: AJdET5faQYXN7b2twJMfnQ9kcz9tHj3YmerYDtI+Q5hPUmkcObqItecriahRVLf5edqh3hWMeeUdTQ== X-Received: by 2002:a7b:c5d1:: with SMTP id n17mr6928515wmk.152.1542827212263; Wed, 21 Nov 2018 11:06:52 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id g129sm1856252wmf.39.2018.11.21.11.06.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:51 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:50 +0000 From: Phillip Potter To: dushistov@mail.ru Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 02/09] ufs: use fs_umode_to_dtype() helper Message-ID: <20181121190650.GA7696@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace switch statement with common lookup table implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ufs/util.h | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/fs/ufs/util.h b/fs/ufs/util.h index 1fd3011ea623..8c7759860739 100644 --- a/fs/ufs/util.h +++ b/fs/ufs/util.h @@ -158,34 +158,7 @@ ufs_set_de_type(struct super_block *sb, struct ufs_dir_entry *de, int mode) if ((UFS_SB(sb)->s_flags & UFS_DE_MASK) != UFS_DE_44BSD) return; - /* - * TODO turn this into a table lookup - */ - switch (mode & S_IFMT) { - case S_IFSOCK: - de->d_u.d_44.d_type = DT_SOCK; - break; - case S_IFLNK: - de->d_u.d_44.d_type = DT_LNK; - break; - case S_IFREG: - de->d_u.d_44.d_type = DT_REG; - break; - case S_IFBLK: - de->d_u.d_44.d_type = DT_BLK; - break; - case S_IFDIR: - de->d_u.d_44.d_type = DT_DIR; - break; - case S_IFCHR: - de->d_u.d_44.d_type = DT_CHR; - break; - case S_IFIFO: - de->d_u.d_44.d_type = DT_FIFO; - break; - default: - de->d_u.d_44.d_type = DT_UNKNOWN; - } + de->d_u.d_44.d_type = fs_umode_to_dtype(mode); } static inline u32 From patchwork Wed Nov 21 19:06:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC2F65A4 for ; Wed, 21 Nov 2018 19:06:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9899A2B68D for ; Wed, 21 Nov 2018 19:06:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C9792BBD8; Wed, 21 Nov 2018 19:06:58 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E5F4C2B68D for ; Wed, 21 Nov 2018 19:06:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387604AbeKVFm2 (ORCPT ); Thu, 22 Nov 2018 00:42:28 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35368 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731652AbeKVFm1 (ORCPT ); Thu, 22 Nov 2018 00:42:27 -0500 Received: by mail-wm1-f66.google.com with SMTP id c126so6838341wmh.0 for ; Wed, 21 Nov 2018 11:06:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=TmS1fJ2p3HHs72FwPm8tH2F4GxL8g3gv4cjnbLcwU/E=; b=yafzqe5MZZhM5MdmzFDoCRzFEzDSu1VHjahsyzHwiAGFI4iSD7bQS/K7tCKw2O4fXK YWwtLMRMdLSD57mMBt75S4Dc8PqT++XLcxZrZe+w0tdxr2lfSS0S09WxUQ5RjnLsly+G hO0oA04ilfr7vgPJk4eD/ouqxCcA5W27E683y2fHzT+BFzGlz+jKLkioRpOMIX6dS9aJ YUYkeTofABbbtcoSpyoutQnTdWgdbl6xn/AQxggaYEt9G8VYP3/SMEwtMgt5bgseKLnm FbX/OoKBWvJCCd5UrEJ+Un9CWawm0S9lDviYqa22gqdd/39ksbcjTdqyP0dzI35EcOWw E67Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=TmS1fJ2p3HHs72FwPm8tH2F4GxL8g3gv4cjnbLcwU/E=; b=KfWGflaiEzouyovd8+PLIyVYxEUwM/5KtdbUcSKnxI4C/29R73mnyX9/DXjVD+9+Af 1/g/V9Kx02vCLNyrqUYu7riaqFZqz2Kdvf/GqvdKgKyAJTV/LS2VgRx9WInciugs56wB psozQ1w73MSN+ymDY7SltnkcxSPN3/hNRB3IIfN0d9DLyIiuKhrBCavDL0X68TkL8XMM xzIeE+GXbZiBL+xZdStqhqNbM6sPaFxVZxjJieXBckQnbHio3/JtWpGwTO/P18xzwnqy OToi6M3lnBgJ15DEWlCBpNCroR3uy0DEp0ICCIzGyRnfyw/46fQZYbyGcC0nt6BMFlQx Th9w== X-Gm-Message-State: AGRZ1gKX2DKlwnUeN2szAzVGmh4fwMyGOXvDhzHTJmne3SyMXs5htbrQ 5PkxDfgl1Om4FBf9Bw5YMzYWtQeB4Np/8Q== X-Google-Smtp-Source: AFSGD/UEazrZInxWaX3VGpr+4tTCYceztWUzByum6j1NU6RhYXLh2PnMnLQjEZTzgBjZ552rZ7E1rQ== X-Received: by 2002:a1c:f614:: with SMTP id w20-v6mr6657254wmc.136.1542827213706; Wed, 21 Nov 2018 11:06:53 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id x10sm15237507wrn.29.2018.11.21.11.06.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:53 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:52 +0000 From: Phillip Potter To: linux-fsdevel@vger.kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, slava@dubeyko.com Subject: [RFC][PATCH v4 03/09] hfsplus: use fs_umode_to_dtype() helper Message-ID: <20181121190652.GA7703@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace if/else statements with common lookup table implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Reviewed-by: Vyacheslav Dubeyko Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/hfsplus/dir.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c index f37662675c3a..7b798a46c8ac 100644 --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -223,7 +223,6 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) break; } else if (type == HFSPLUS_FILE) { u16 mode; - unsigned type = DT_UNKNOWN; if (fd.entrylength < sizeof(struct hfsplus_cat_file)) { pr_err("small file entry\n"); @@ -232,21 +231,10 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) } mode = be16_to_cpu(entry.file.permissions.mode); - if (S_ISREG(mode)) - type = DT_REG; - else if (S_ISLNK(mode)) - type = DT_LNK; - else if (S_ISFIFO(mode)) - type = DT_FIFO; - else if (S_ISCHR(mode)) - type = DT_CHR; - else if (S_ISBLK(mode)) - type = DT_BLK; - else if (S_ISSOCK(mode)) - type = DT_SOCK; if (!dir_emit(ctx, strbuf, len, - be32_to_cpu(entry.file.id), type)) + be32_to_cpu(entry.file.id), + fs_umode_to_dtype(mode))) break; } else { pr_err("bad catalog entry type\n"); From patchwork Wed Nov 21 19:06:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F80F13B5 for ; Wed, 21 Nov 2018 19:18:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59E782C343 for ; Wed, 21 Nov 2018 19:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D5752C34A; Wed, 21 Nov 2018 19:18:57 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 D71202C343 for ; Wed, 21 Nov 2018 19:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387608AbeKVFm3 (ORCPT ); Thu, 22 Nov 2018 00:42:29 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39597 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387602AbeKVFm2 (ORCPT ); Thu, 22 Nov 2018 00:42:28 -0500 Received: by mail-wr1-f68.google.com with SMTP id b13so6853374wrx.6 for ; Wed, 21 Nov 2018 11:06:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=mHTiNOHUO3nA1QO3XFEye0LzKiE5YqwnxNna/rvgGtw=; b=nmxpKWzNH70CsefUZ7I+Zg7sesehrnb+gC9k7qepYnlaAvhOEAVFzCvTaxmccqxmVu d33AY4WYApOf0ZCB+ILLfvMqWor1q5qiRBpaicdE5sqTCByo2TvoIEnm6Z65vv0NpFqt n9hEXTirE1cvyB+dvQn0g1lxYN8fbtu5UYfWFJ7k3g5CfOe/2EDh+a2dMaINscwf1J72 4QTQJTvz+HwNLdMzXrFMo1KBB4TlNifkNavfbQt6DKEfjOouCCSlQ9wOuTBvqGiArlBj f9ztoco29AamJx4ahrPvsPx3PMyAqroL8RiN+aO5Fhgjg6uQzI3YsBg6Q5D2lkK7538E k8/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=mHTiNOHUO3nA1QO3XFEye0LzKiE5YqwnxNna/rvgGtw=; b=LI4XIQURorfKy6s+jlpJ1tgt2FmZaXEdi2duyIiX9Qel323dyfNQefuA0Bs9b8Kwc8 LRP0usmCK2V4bpScy1Zci/RubtGBS6G3xgXo4u3eVNhwByWJbo4HTWW47dGK9DW5S6tt mCwYk47cnvO3yewl6pXC8+2jH50gzUpVYMiiKp6lf2yO9h1bBy4yTK2JhAHdEYfNKmsl 0XT2+lkUauXE28NkuGwIXSYxhMWAngVHOFk6sKFlhsuuBPPTGKdGBCT/rutjcOTTfdjT Qip1lu09mBD9l1LNoSR9KuOtraANFby95m0ffJ3AWVBsqd5UeDfeY1gUqDeoyl2KKXWw 7ZWQ== X-Gm-Message-State: AA+aEWZa0rMH3210rr5t1wJd6s8lLkmRzhyYHHRPvE/dd9YcCJrIajID PYINSpQnLjNCEWlAA4sc3MjELA== X-Google-Smtp-Source: AFSGD/VwoXeuW9UgERTjvpXL3HocbdqjDNJ9zuA/Uh/9qhTy55ZxPTc3+Bt30Fq3ngTNqp2TLeGRLA== X-Received: by 2002:adf:c745:: with SMTP id b5-v6mr6798317wrh.197.1542827215144; Wed, 21 Nov 2018 11:06:55 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id h125-v6sm866692wmf.48.2018.11.21.11.06.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:54 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:53 +0000 From: Phillip Potter To: jack@suse.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 04/09] ext2: use common file type conversion Message-ID: <20181121190653.GA7710@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the ext2 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ext2/dir.c | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c index 3b8114def693..bd30fe266373 100644 --- a/fs/ext2/dir.c +++ b/fs/ext2/dir.c @@ -252,33 +252,24 @@ ext2_validate_entry(char *base, unsigned offset, unsigned mask) return (char *)p - base; } -static unsigned char ext2_filetype_table[EXT2_FT_MAX] = { - [EXT2_FT_UNKNOWN] = DT_UNKNOWN, - [EXT2_FT_REG_FILE] = DT_REG, - [EXT2_FT_DIR] = DT_DIR, - [EXT2_FT_CHRDEV] = DT_CHR, - [EXT2_FT_BLKDEV] = DT_BLK, - [EXT2_FT_FIFO] = DT_FIFO, - [EXT2_FT_SOCK] = DT_SOCK, - [EXT2_FT_SYMLINK] = DT_LNK, -}; - -#define S_SHIFT 12 -static unsigned char ext2_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = EXT2_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = EXT2_FT_DIR, - [S_IFCHR >> S_SHIFT] = EXT2_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = EXT2_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = EXT2_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = EXT2_FT_SOCK, - [S_IFLNK >> S_SHIFT] = EXT2_FT_SYMLINK, -}; - static inline void ext2_set_de_type(ext2_dirent *de, struct inode *inode) { - umode_t mode = inode->i_mode; + /* + * compile-time asserts that generic FT_x types still match + * EXT2_FT_x types + */ + BUILD_BUG_ON(EXT2_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(EXT2_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(EXT2_FT_DIR != FT_DIR); + BUILD_BUG_ON(EXT2_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(EXT2_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(EXT2_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(EXT2_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(EXT2_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(EXT2_FT_MAX != FT_MAX); + if (EXT2_HAS_INCOMPAT_FEATURE(inode->i_sb, EXT2_FEATURE_INCOMPAT_FILETYPE)) - de->file_type = ext2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + de->file_type = fs_umode_to_ftype(inode->i_mode); else de->file_type = 0; } @@ -293,14 +284,14 @@ ext2_readdir(struct file *file, struct dir_context *ctx) unsigned long n = pos >> PAGE_SHIFT; unsigned long npages = dir_pages(inode); unsigned chunk_mask = ~(ext2_chunk_size(inode)-1); - unsigned char *types = NULL; bool need_revalidate = !inode_eq_iversion(inode, file->f_version); + bool has_filetype; if (pos > inode->i_size - EXT2_DIR_REC_LEN(1)) return 0; - if (EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE)) - types = ext2_filetype_table; + has_filetype = + EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE); for ( ; n < npages; n++, offset = 0) { char *kaddr, *limit; @@ -335,8 +326,8 @@ ext2_readdir(struct file *file, struct dir_context *ctx) if (de->inode) { unsigned char d_type = DT_UNKNOWN; - if (types && de->file_type < EXT2_FT_MAX) - d_type = types[de->file_type]; + if (has_filetype) + d_type = fs_ftype_to_dtype(de->file_type); if (!dir_emit(ctx, de->name, de->name_len, le32_to_cpu(de->inode), From patchwork Wed Nov 21 19:06:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3139913BF for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C5B62B68D for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1061A2BDB2; Wed, 21 Nov 2018 19:07:01 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 902D12B68D for ; Wed, 21 Nov 2018 19:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387641AbeKVFma (ORCPT ); Thu, 22 Nov 2018 00:42:30 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41847 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387605AbeKVFma (ORCPT ); Thu, 22 Nov 2018 00:42:30 -0500 Received: by mail-wr1-f65.google.com with SMTP id x10so6833925wrs.8 for ; Wed, 21 Nov 2018 11:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=gGQXa+bDUcpquIe5sRQ7xsaexBbdvK/U9/WH/jF100k=; b=Rg8tCXt5XLrIGzAsjwzp70WvYmzORv1+XcuoTe26kA3XU5GPEb7MlFQ4/E6R6h0vyI 1VqOEvC2ys83WHW7evoVbvep+utPd4jB8DZU/ChcLk3JDUR/VneNK7nLhPq/HtCGZr9c BYqJH8XTM35i8c0x7jkSYvM9A9SmsSQTnGOKMLEi2ZaGZfXgJmV9dO4W40kAfi6GkZlP V4Q9Bgl0dZxGbi0iC0dE4y+CO0UgW5B481BMziGBbMTXRN8oSJyILam1seRhkv6oFrbQ y4tieXg5YHgWYdQ5z022z/uRic1C/DoArOJC6Y7USXFIVaCXqkDxgtHG9gJHRjWScDQF jj3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=gGQXa+bDUcpquIe5sRQ7xsaexBbdvK/U9/WH/jF100k=; b=lbXYNMMxYzDsvgOTPx/PCn67XpXiPgTKJnuaD7wM391SGca+RSi1Gf7xqjyxS65FpB AnH5TltI71S2hpw624gjsynHgaH1kTTWo83YmiFEKJdNhtCZG+LNarXMko9vXmplWlUw 1DeVBNStTnHR+6fwbH/JGh1LoxSfcfXlG1Nn0BcKrudrGAEPJu6D25T5MyV4W7lhAaFg 0DskNm45jDWvmdQt1IDjTp/1hABGJkFx8cS75Y9wksVhYvr8VSAD5FOk0DGDZBUBzXj2 tbXoghsU4bnxeYN3VbhjrDcUtgU7qzfo0k+vftaM2cAQIFkMbD26Sm10uSktqbgTLdGC 49UQ== X-Gm-Message-State: AA+aEWZ3oEDZEPbb6QuRLVsvVnl+z9+Oamse1JVErbWB3f+nKUuDWhSl BedzbTDHBikdm2+Dym+QdxO60g== X-Google-Smtp-Source: AFSGD/Uz8vZWfYl1gdOQuGkVRlYfYmux+3kmevXH7z1UhPR4WuVp7rigkjToaLIwLp5K5EBqxQdRhQ== X-Received: by 2002:adf:eec9:: with SMTP id a9mr6786787wrp.242.1542827216548; Wed, 21 Nov 2018 11:06:56 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id q14sm5699342wrw.39.2018.11.21.11.06.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:56 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:55 +0000 From: Phillip Potter To: tytso@mit.edu Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 05/09] ext4: use common file type conversion Message-ID: <20181121190655.GA7717@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the ext4 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3f89d0ab08fc..c45d701ba4f4 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2357,16 +2357,13 @@ static inline void ext4_update_dx_flag(struct inode *inode) if (!ext4_has_feature_dir_index(inode->i_sb)) ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); } -static const unsigned char ext4_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; static inline unsigned char get_dtype(struct super_block *sb, int filetype) { - if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) + if (!ext4_has_feature_filetype(sb)) return DT_UNKNOWN; - return ext4_filetype_table[filetype]; + return fs_ftype_to_dtype(filetype); } extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf, int buf_size); @@ -3052,22 +3049,26 @@ extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t, extern int ext4_handle_dirty_dirent_node(handle_t *handle, struct inode *inode, struct buffer_head *bh); -#define S_SHIFT 12 -static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { - [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, - [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, - [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, -}; static inline void ext4_set_de_type(struct super_block *sb, struct ext4_dir_entry_2 *de, umode_t mode) { + /* + * compile-time asserts that generic FT_x types still match + * EXT4_FT_x types + */ + BUILD_BUG_ON(EXT4_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(EXT4_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(EXT4_FT_DIR != FT_DIR); + BUILD_BUG_ON(EXT4_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(EXT4_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(EXT4_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(EXT4_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(EXT4_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(EXT4_FT_MAX != FT_MAX); + if (ext4_has_feature_filetype(sb)) - de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + de->file_type = fs_umode_to_ftype(mode); } /* readpages.c */ From patchwork Wed Nov 21 19:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 855D113BF for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70C832B68D for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64BB22BDB2; Wed, 21 Nov 2018 19:07:02 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 EB7852B68D for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387644AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43053 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387566AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id r10so6817874wrs.10 for ; Wed, 21 Nov 2018 11:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=Dw6w3uY1DDyQl8IcoLCwjiDDoSj/lFO6lm1g9LcDF4E=; b=fyO8aUX3dv+PTPuZg/hR3f9m0MwRzKNrcwiCR7jZDN0NgwpILQFvmC6M91uMsW+Qvd 3nb176jbbRdhtjFhlRfJEh8VeQ6tgY1Upc2JGCzt+7Rzb///yYHI5TnAhpLaY1HflMsG Y9dlFs46lUzlbrH14RYcDdsT7u7YxbFKz+LGFfDTjPgVfmUj7L+x0d1tlhIVKJYXfiuf jkhCakJ2Wwsc37jZ69o+STiT3siMN6Axl3C4DOCCEAQi9wbuzN9NmgGomdEf06dDRUTO 9O98EuS6a8H5y9+0XpK+HEXwhsAdMMVdJOww8jrxrmfvtQoWhzS27NUsu3m8Y5Qegpww gcrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=Dw6w3uY1DDyQl8IcoLCwjiDDoSj/lFO6lm1g9LcDF4E=; b=msFm6FAG7D/CfQ+CRbCLeVDGT/N3bVC/7ay5e82CpfKSFPfC1ITvXSgNQe0IK15ere CXpQHYZtxnZkgXG05WItTZwXwFfKLx1WuxrjdsMghIq5di723rUjCvOAsrUfTUHi+VAK opb4+sQ4SBJkIhKbHFgKnYj1vIvsmnBuPGJeMDxCip9Ujb8ymhvt4rdramzPwm0sNAYj XKtn/ArPacspyxmK47UfN2dggwe421s1uy/lvY7q9aNJ8spyrRb1SVg+9DY/3q6T5OvZ K9LeYp3FPUhyVaGdvqxLOYuxDMgxxJqoGPh3LsidPvHUsNNyOUbcHJNHczJwwJl7HBzb Rg9g== X-Gm-Message-State: AA+aEWZBEmhBEn4VtCcwGBC2EStV+4hC073NtoQ2YTlXl1xLIG1eh85k ARxRhh1rmFiipPQRw6W3eBtNww== X-Google-Smtp-Source: AFSGD/U7B5sS0ALZmYBU6unQGVqCRN7RkpMvGeoqmZfgMJl3+Yq18PiUTI4PJ2+0SjURb/ca8Sp95w== X-Received: by 2002:adf:b109:: with SMTP id l9-v6mr4560111wra.290.1542827217962; Wed, 21 Nov 2018 11:06:57 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id i13sm28850181wrw.32.2018.11.21.11.06.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:57 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:56 +0000 From: Phillip Potter To: mark@fasheh.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, jlbec@evilplan.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [RFC][PATCH v4 06/09] ocfs2: use common file type conversion Message-ID: <20181121190656.GA7724@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the ocfs2 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ocfs2/dir.c | 18 +++--------------- fs/ocfs2/ocfs2_fs.h | 27 +++++++++++++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index c121abbdfc7d..9e6dea014ab9 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -69,10 +69,6 @@ #define NAMEI_RA_BLOCKS 4 #define NAMEI_RA_SIZE (NAMEI_RA_CHUNKS * NAMEI_RA_BLOCKS) -static unsigned char ocfs2_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; - static int ocfs2_do_extend_dir(struct super_block *sb, handle_t *handle, struct inode *dir, @@ -1803,13 +1799,9 @@ static int ocfs2_dir_foreach_blk_id(struct inode *inode, } offset += le16_to_cpu(de->rec_len); if (le64_to_cpu(de->inode)) { - unsigned char d_type = DT_UNKNOWN; - - if (de->file_type < OCFS2_FT_MAX) - d_type = ocfs2_filetype_table[de->file_type]; - if (!dir_emit(ctx, de->name, de->name_len, - le64_to_cpu(de->inode), d_type)) + le64_to_cpu(de->inode), + fs_ftype_to_dtype(de->file_type))) goto out; } ctx->pos += le16_to_cpu(de->rec_len); @@ -1900,14 +1892,10 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode, break; } if (le64_to_cpu(de->inode)) { - unsigned char d_type = DT_UNKNOWN; - - if (de->file_type < OCFS2_FT_MAX) - d_type = ocfs2_filetype_table[de->file_type]; if (!dir_emit(ctx, de->name, de->name_len, le64_to_cpu(de->inode), - d_type)) { + fs_ftype_to_dtype(de->file_type))) { brelse(bh); return 0; } diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 7071ad0dec90..daf836e5df43 100644 --- a/fs/ocfs2/ocfs2_fs.h +++ b/fs/ocfs2/ocfs2_fs.h @@ -424,17 +424,6 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { #define OCFS2_LINKS_HI_SHIFT 16 #define OCFS2_DX_ENTRIES_MAX (0xffffffffU) -#define S_SHIFT 12 -static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, - [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, - [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, -}; - /* * Convenience casts @@ -1629,7 +1618,21 @@ static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, umode_t mode) { - de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * OCFS2_FT_x types + */ + BUILD_BUG_ON(OCFS2_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(OCFS2_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(OCFS2_FT_DIR != FT_DIR); + BUILD_BUG_ON(OCFS2_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(OCFS2_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(OCFS2_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(OCFS2_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(OCFS2_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(OCFS2_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(mode); } static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd) From patchwork Wed Nov 21 19:06:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3532C5A4 for ; Wed, 21 Nov 2018 19:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E2032B68D for ; Wed, 21 Nov 2018 19:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D4682BDB2; Wed, 21 Nov 2018 19:07:03 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 91AE62B68D for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387648AbeKVFmd (ORCPT ); Thu, 22 Nov 2018 00:42:33 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40591 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387642AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id p4so6837350wrt.7 for ; Wed, 21 Nov 2018 11:07:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=UrBNRC1KGmOhwZV9NlwduSQFxZFDihsRZ88cIaZ9Knk=; b=zC7/LgVRPYcwvvHA04uK/usGeVEKTrTG7xahQNM9mTgQjYOXfPeBpubZViAVJ4Bc/F Hp4M/+DTVT+RwNkdauAZ22HqMAVFmtmgNdVmqxHdz9FY9imOQJz4V+dSeG5q6hgTsNZD KafY4zPJGpZ67MEE216O6v/WsGz9QhQOExyBvy9idXzqeD0hm9wYyINx+0K51Qzrkjxs b79hTByTIzDyXXcMvko3XcNcVybM1J/qfSElaA9jvDaM94XvkVWPQ2Rgn6aS3los5h65 RnWucJDwrOwme1Klr5G342kS97Futc7GsG46w3E0QbYoy0+c93e5mIFkZTKWASNCqWyW FnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=UrBNRC1KGmOhwZV9NlwduSQFxZFDihsRZ88cIaZ9Knk=; b=NAiidYV41Bl/tN2MTsGX4oZ1ssJleY/OaF+hxti/gUHUnpz/Cg/yVFCNDhfmcXzVav 6w/zRNqixE8QkeODpubQONH7vGJE3ucJlIusccruIRF/RlhgxUuWoupN58rzVDLdMtNo qUcF/K0TNfOmYcpvmNmdxvlQRp3+0n4xWhcWumTHlyUrwf/MI2R5I7JU5ZVZPFoT3UJc kTC1Kf6HaKh+vkNJ+ACDWL28sCcZGay5cg2OkuYZ0jF84ab7IOckWzt1wQx/OsUXh6xn 0uDLHJB2mbjhhJW41ls8UmKtypYjIXoCIQdrhexB+oynE/ZF1HmrdZyfHCFvJGOPOCal sv8g== X-Gm-Message-State: AA+aEWbU5cYt6Tgt6FKkN5vGoODqdCySgpgNy6yaThUOj2R6efpTTMkG vmhunVF1QFNdBTKuTju2VIP7hA== X-Google-Smtp-Source: AFSGD/VtnPxC/j9num7B+9j34/kDllApeooeNd33bfvkWuTMz5LiAv22Zw2SBSrC48sRbSZ7VWUfSQ== X-Received: by 2002:a5d:45d0:: with SMTP id b16mr6659968wrs.86.1542827219353; Wed, 21 Nov 2018 11:06:59 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id n15sm17671649wrt.21.2018.11.21.11.06.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:58 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:58 +0000 From: Phillip Potter To: jaegeuk@kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, yuchao0@huawei.com, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 07/09] f2fs: use common file type conversion Message-ID: <20181121190658.GA7731@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the f2fs file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Acked-by: Chao Yu Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/f2fs/dir.c | 41 ++++++++++++++++------------------------- fs/f2fs/inline.c | 2 +- include/linux/f2fs_fs.h | 8 +++++--- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index bacc667950b6..113820f16c6d 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -36,37 +36,28 @@ static unsigned int bucket_blocks(unsigned int level) return 4; } -static unsigned char f2fs_filetype_table[F2FS_FT_MAX] = { - [F2FS_FT_UNKNOWN] = DT_UNKNOWN, - [F2FS_FT_REG_FILE] = DT_REG, - [F2FS_FT_DIR] = DT_DIR, - [F2FS_FT_CHRDEV] = DT_CHR, - [F2FS_FT_BLKDEV] = DT_BLK, - [F2FS_FT_FIFO] = DT_FIFO, - [F2FS_FT_SOCK] = DT_SOCK, - [F2FS_FT_SYMLINK] = DT_LNK, -}; - -static unsigned char f2fs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = F2FS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = F2FS_FT_DIR, - [S_IFCHR >> S_SHIFT] = F2FS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = F2FS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = F2FS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = F2FS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = F2FS_FT_SYMLINK, -}; - static void set_de_type(struct f2fs_dir_entry *de, umode_t mode) { - de->file_type = f2fs_type_by_mode[(mode & S_IFMT) >> S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * F2FS_FT_x types + */ + BUILD_BUG_ON(F2FS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(F2FS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(F2FS_FT_DIR != FT_DIR); + BUILD_BUG_ON(F2FS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(F2FS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(F2FS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(F2FS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(F2FS_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(F2FS_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(mode); } unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de) { - if (de->file_type < F2FS_FT_MAX) - return f2fs_filetype_table[de->file_type]; - return DT_UNKNOWN; + return fs_ftype_to_dtype(de->file_type); } static unsigned long dir_block_index(unsigned int level, diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 7b0cff7e6051..34205d2e1cc2 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -458,7 +458,7 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry) new_name.len = le16_to_cpu(de->name_len); ino = le32_to_cpu(de->ino); - fake_mode = f2fs_get_de_type(de) << S_SHIFT; + fake_mode = f2fs_get_de_type(de) << S_DT_SHIFT; err = f2fs_add_regular_entry(dir, &new_name, NULL, NULL, ino, fake_mode); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index d7711048ef93..4b8a2ae348d8 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -524,7 +524,11 @@ struct f2fs_dentry_block { __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; } __packed; -/* file types used in inode_info->flags */ +/* + * file types used in inode_info->flags + * + * Values must match common file type values in fs_types.h. + */ enum { F2FS_FT_UNKNOWN, F2FS_FT_REG_FILE, @@ -537,8 +541,6 @@ enum { F2FS_FT_MAX }; -#define S_SHIFT 12 - #define F2FS_DEF_PROJID 0 /* default project ID */ #endif /* _LINUX_F2FS_FS_H */ From patchwork Wed Nov 21 19:06:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4822213BF for ; Wed, 21 Nov 2018 19:07:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31C232B68D for ; Wed, 21 Nov 2018 19:07:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 25E012BDB2; Wed, 21 Nov 2018 19:07:05 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 B1B2B2B68D for ; Wed, 21 Nov 2018 19:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387566AbeKVFmf (ORCPT ); Thu, 22 Nov 2018 00:42:35 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50910 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387645AbeKVFme (ORCPT ); Thu, 22 Nov 2018 00:42:34 -0500 Received: by mail-wm1-f68.google.com with SMTP id 125so6658844wmh.0 for ; Wed, 21 Nov 2018 11:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=s2DDd3eT8uI17OfUO/qfYZtAyqcOnpiG2Q6vDRswi4w=; b=dWz/kU3e91NztzcMUzfvEyZQdZ8OYqDDjZ5FdGa3B8MOHnwdpMPQJlbQQJE8WZWDbu W51lXG67EMMKhORd6vedspBHZdiFKdNxE0jYSgLMJzon+QU5eZYxVWp6ZB+xf4965zRt FyQzQKk+oOdeUNGHRsVuIDfyRyD4OQgwaFj7ZXIMZv2+g5sZ0hXE9EoBvn7r47kr7rY1 H//8ODJWDrNOWDrFQ9SDmva8PcFC3V4lMkyEJRbXHScEk6KzGiLd6ZDnVkKl7lR70fTm svZqpMpDhrA0cw+jm3NOvG/RLgTZ+71LqPvamGwctqDNkTtFiL4c19/rLc3Lh0g+WQq9 xZXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=s2DDd3eT8uI17OfUO/qfYZtAyqcOnpiG2Q6vDRswi4w=; b=QkACmsqx2zL71Vjh8+ktulmGmbX3U6s/PjqFSaKbJ1Yo/sUrYDU1akMvH0gu5k9h9R rvZ2Z9fR+6ifWzZ5U4tL7084a0eKcoUStC+7VOtobxKwE01otQXLXJRtkHMnaGKf/ohc WC0Tvhv80maWpdD4mXywmVdUiVM5awzd4MU0e3kTEQDXjJRQEIJqnuwO0aDrAc5DnkeM YVRsEzKhPlO74aktpOQKQ+GzBiN6TDcvXHFoTP7MsMLkqNfFzIMQdAsNf3hBAUJbVzF4 7jewW2ymwbH/8Qcv8PrUwsS2rxE+5kzO1/Kt5CcG0n/h4XYy3IarjayJdwLKQWseVE0Z zmBg== X-Gm-Message-State: AA+aEWZrmAgHi8MEh8pDUO06u7SuMM44SARt741/BgisIvJA1pCu75Sk L75KkHfSvRYDiYRGCVNFmr5hwg== X-Google-Smtp-Source: AJdET5fHpRHhmsltMWcOsFP21acca/ZtBhSfvWLxQgx2lnqFdESAaaJjmNaOQ0flDPkx4M8LLPY3cA== X-Received: by 2002:a1c:ab07:: with SMTP id u7-v6mr6941703wme.16.1542827220891; Wed, 21 Nov 2018 11:07:00 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id b129sm1133938wmd.24.2018.11.21.11.06.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:07:00 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:59 +0000 From: Phillip Potter To: linux-nilfs@vger.kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 08/09] nilfs2: use common file type conversion Message-ID: <20181121190659.GA7738@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the nilfs2 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/nilfs2/dir.c | 52 ++++++++++-------------------- include/uapi/linux/nilfs2_ondisk.h | 1 + 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 81394e22d0a0..278d80d434b4 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -229,35 +229,23 @@ static struct nilfs_dir_entry *nilfs_next_entry(struct nilfs_dir_entry *p) nilfs_rec_len_from_disk(p->rec_len)); } -static unsigned char -nilfs_filetype_table[NILFS_FT_MAX] = { - [NILFS_FT_UNKNOWN] = DT_UNKNOWN, - [NILFS_FT_REG_FILE] = DT_REG, - [NILFS_FT_DIR] = DT_DIR, - [NILFS_FT_CHRDEV] = DT_CHR, - [NILFS_FT_BLKDEV] = DT_BLK, - [NILFS_FT_FIFO] = DT_FIFO, - [NILFS_FT_SOCK] = DT_SOCK, - [NILFS_FT_SYMLINK] = DT_LNK, -}; - -#define S_SHIFT 12 -static unsigned char -nilfs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = NILFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = NILFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = NILFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = NILFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = NILFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = NILFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = NILFS_FT_SYMLINK, -}; - static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *inode) { - umode_t mode = inode->i_mode; - - de->file_type = nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * NILFS_FT_x types + */ + BUILD_BUG_ON(NILFS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(NILFS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(NILFS_FT_DIR != FT_DIR); + BUILD_BUG_ON(NILFS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(NILFS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(NILFS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(NILFS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(NILFS_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(NILFS_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(inode->i_mode); } static int nilfs_readdir(struct file *file, struct dir_context *ctx) @@ -293,15 +281,9 @@ static int nilfs_readdir(struct file *file, struct dir_context *ctx) return -EIO; } if (de->inode) { - unsigned char t; - - if (de->file_type < NILFS_FT_MAX) - t = nilfs_filetype_table[de->file_type]; - else - t = DT_UNKNOWN; - if (!dir_emit(ctx, de->name, de->name_len, - le64_to_cpu(de->inode), t)) { + le64_to_cpu(de->inode), + fs_ftype_to_dtype(de->file_type))) { nilfs_put_page(page); return 0; } diff --git a/include/uapi/linux/nilfs2_ondisk.h b/include/uapi/linux/nilfs2_ondisk.h index a7e66ab11d1d..9223b616766b 100644 --- a/include/uapi/linux/nilfs2_ondisk.h +++ b/include/uapi/linux/nilfs2_ondisk.h @@ -309,6 +309,7 @@ struct nilfs_dir_entry { /* * NILFS directory file types. Only the low 3 bits are used. The * other bits are reserved for now. + * Values must match common file type values in fs_types.h. */ enum { NILFS_FT_UNKNOWN, From patchwork Wed Nov 21 19:07:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2109C13B5 for ; Wed, 21 Nov 2018 19:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE030209CE for ; Wed, 21 Nov 2018 19:18:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF5B42793B; Wed, 21 Nov 2018 19:18:32 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 194C72C31D for ; Wed, 21 Nov 2018 19:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387726AbeKVFmn (ORCPT ); Thu, 22 Nov 2018 00:42:43 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37631 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387698AbeKVFmn (ORCPT ); Thu, 22 Nov 2018 00:42:43 -0500 Received: by mail-wm1-f68.google.com with SMTP id p2-v6so6823609wmc.2 for ; Wed, 21 Nov 2018 11:07:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=sJLnXDsHznYw/y9+C7wzShyN9Wwvr5DZWWyzY2HDX0I=; b=OMYbg7JZSmDEAg2btyiC4uhV4ufqzXeOyrn8WVZprSoKb8ZIzFxCaecgzx6xPMOGbo siTtSv+WJoLa+kuIZNkoTWgPUtx7Wt0JddxV0iz2+F4//K/Pl5OD8Rv6jePxyHC+6vXg 1G2s8FXUU4wt9GxXIs1DFdtbEZiZrOH3fbnxMss3COAbYFbUaITO8Er6ew7ql70Lyt4E nSWx2WSslAGcQH9aAsmncbrnNQb0LKXDIsF9zxbOhYSgQRcl5vlEZytygczt0UeAksPh 6X0QLOUZwf5enjSKbvKkLkYrsNVuwH8gXpaxeoxLguEUBuyV4VGEiQ9w8ZZS+kHsTqwg maeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=sJLnXDsHznYw/y9+C7wzShyN9Wwvr5DZWWyzY2HDX0I=; b=nSxsmQAX4YV4c/2iw5qO3suklAGgw+ummlzu8asv6RUDcRvIEZ5AbV2fd3biOh6FIt 2PNz9zFWy3FKrG9qf7Fei77KqVyryhPVOC0Nco4R8QIrjmi3Am9FxYdC904Nir0lKxFx XU89ALbBjf6zEGeevBTTgx0ist8v+6Df99XLgGksX6fTcZll1HSPSpHuPTkhTmvReIaI o0orUusbGp0A4It1JKxzBS+M6Yl24apPX6DOBiDAOpFvvUnuGU9VlPCrNkymPcPcQQNZ FfjRfOjNpWAWDYC5qJBAaGen0DFTdP+ElK+jPS/+tM8rEr60N/Xw4os0hUpsa3rKOyqu 1w0g== X-Gm-Message-State: AA+aEWbf0qUQyC7lr/Xx5Eb+FJfmzI1Zazx8F/q7jz3ZVb3Gt2eQXWV9 OklunEsL2JNmFTdTSx3VIS0UYn0Dv4r/7t5J X-Google-Smtp-Source: AJdET5c+AY+IB9B2qHxzIpqC1lwDLldJ1F1raub0NfwxmDQJ1gREmkbAxWpo6XTOy+LqnNOYNihBkw== X-Received: by 2002:a1c:2304:: with SMTP id j4mr6831819wmj.14.1542827228217; Wed, 21 Nov 2018 11:07:08 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id y8sm1903282wmg.13.2018.11.21.11.07.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:07:07 -0800 (PST) Date: Wed, 21 Nov 2018 19:07:06 +0000 From: Phillip Potter To: clm@fb.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, jbacik@fb.com, dsterba@suse.com, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [RFC][PATCH v4 09/09] btrfs: use common file type conversion Message-ID: <20181121190706.GA7745@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the btrfs file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Acked-by: David Sterba Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/btrfs/btrfs_inode.h | 2 -- fs/btrfs/delayed-inode.c | 2 +- fs/btrfs/inode.c | 32 +++++++++++++++----------------- include/uapi/linux/btrfs_tree.h | 2 ++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 97d91e55b70a..bb01c804485f 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -196,8 +196,6 @@ struct btrfs_inode { struct inode vfs_inode; }; -extern unsigned char btrfs_filetype_table[]; - static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) { return container_of(inode, struct btrfs_inode, vfs_inode); diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index c669f250d4a0..e61947f5eb76 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1692,7 +1692,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, name = (char *)(di + 1); name_len = btrfs_stack_dir_name_len(di); - d_type = btrfs_filetype_table[di->type]; + d_type = fs_ftype_to_dtype(di->type); btrfs_disk_key_to_cpu(&location, &di->location); over = !dir_emit(ctx, name, name_len, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9ea4c6f0352f..8b7b1b29e2ad 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -72,17 +72,6 @@ struct kmem_cache *btrfs_trans_handle_cachep; struct kmem_cache *btrfs_path_cachep; struct kmem_cache *btrfs_free_space_cachep; -#define S_SHIFT 12 -static const unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, -}; - static int btrfs_setsize(struct inode *inode, struct iattr *attr); static int btrfs_truncate(struct inode *inode, bool skip_writeback); static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); @@ -5793,10 +5782,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, return d_splice_alias(inode, dentry); } -unsigned char btrfs_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; - /* * All this infrastructure exists because dir_emit can fault, and we are holding * the tree lock when doing readdir. For now just allocate a buffer and copy @@ -5935,7 +5920,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) name_ptr = (char *)(entry + 1); read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1), name_len); - put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)], + put_unaligned(fs_ftype_to_dtype(btrfs_dir_type(leaf, di)), &entry->type); btrfs_dir_item_key_to_cpu(leaf, di, &location); put_unaligned(location.objectid, &entry->ino); @@ -6340,7 +6325,20 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, static inline u8 btrfs_inode_type(struct inode *inode) { - return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * BTRFS_FT_x types + */ + BUILD_BUG_ON(BTRFS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(BTRFS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(BTRFS_FT_DIR != FT_DIR); + BUILD_BUG_ON(BTRFS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(BTRFS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(BTRFS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(BTRFS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(BTRFS_FT_SYMLINK != FT_SYMLINK); + + return fs_umode_to_ftype(inode->i_mode); } /* diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index aff1356c2bb8..4126ed7ee89a 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -307,6 +307,8 @@ * * Used by: * struct btrfs_dir_item.type + * + * Values 0..7 must match common file type values in fs_types.h. */ #define BTRFS_FT_UNKNOWN 0 #define BTRFS_FT_REG_FILE 1