From patchwork Sat Oct 27 00:53:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10657991 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 E0AF313BF for ; Sat, 27 Oct 2018 00:53:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE9392C9CC for ; Sat, 27 Oct 2018 00:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCB6A2C9D3; Sat, 27 Oct 2018 00:53:40 +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 A5FE32C9C1 for ; Sat, 27 Oct 2018 00:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbeJ0Jcs (ORCPT ); Sat, 27 Oct 2018 05:32:48 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38496 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeJ0Jcs (ORCPT ); Sat, 27 Oct 2018 05:32:48 -0400 Received: by mail-wr1-f67.google.com with SMTP id d10-v6so2956613wrs.5 for ; Fri, 26 Oct 2018 17:53:35 -0700 (PDT) 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=PS9efVtN1fzYW3lGy9M0gUBp8MEDL14ctbO5sFGq1Fs=; b=EWjhvFjYc8bgG8dTnkdGoo0k2vD7ewyIYU4nCGXexhc8gCfCj5gEH97CDaQ3PecRoW lkijx0eQmyw0EQYpymzA+Bf7OwIRy/+c6vPeXtW+KqAJk9SugvykA7SKfl2pAITTOxU/ WSgjCS/GePxftkQ7mkzCLEq9V010DmL+BuNu/SOjHcJidwksXylW/8VIH2lYcqJJbH0+ pbZ+i0uWhqMVKEQCIWHywBHGSmIafHREeIp7T7njZxbGO1RTNMF08scHQ+vruS9/0hg5 o63mqH/YP44ggnWArn/DlMKyBYTxTf4F37aBmVZnKWFLpOvWpqj2NI9a0cuNV+mnS6dl Z5Bw== 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=PS9efVtN1fzYW3lGy9M0gUBp8MEDL14ctbO5sFGq1Fs=; b=U0mWnIVvqkIZRNOuxAPsf7zdFhR8lMWv+pN9N/FuRVPwKRdjY7Qc1y1XNzWBg9izRl Q4DkSeAGCZz+x0iv4Tk3aQniAfszOVUpBMAFpFPND69CctXCmveGEPvEOcT7+Q4tt/8q xzSCn70arNFq8eGYdJ2VTZa2OxGxFM2rJoxBgk3uLpNbI7wYILHm95jCm6M1TbI+yC6m KGJQOeTyySX9h37eSsUN6slP/IxkQWiy9bz5DVAvrdJlwwG1Aev6gFqoI4aTBOLwqNh9 zvkNJ70U2fTQUreef7WM5aIN/l3gRkpWQOpbZnZLxBarM5rvKJyWQlijs4K8g/3G0Jro MMRA== X-Gm-Message-State: AGRZ1gIfmFmSMNDY2+hEzapsud65gyDSB153xHertGtcr67u0OKlg+Wd zl2DUVnJXM7qWFNky6NGQhF4cg== X-Google-Smtp-Source: AJdET5e6yuG+QBaZuv14CRuTmtmg/uaSPogg9dd6E0EIbTHTyIjVaYzxDj2FEFryB1ipUbdILhSnlA== X-Received: by 2002:adf:e14b:: with SMTP id f11-v6mr7018958wri.42.1540601614597; Fri, 26 Oct 2018 17:53:34 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id x12-v6sm15670234wmd.32.2018.10.26.17.53.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:33 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:33 +0100 From: Phillip Potter To: viro@zeniv.linux.org.uk Cc: amir73il@gmail.com, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v3 01/10] fs: common implementation of file type Message-ID: <20181027005333.GA9931@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 bd702ad56c7f..9491208c115f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5711,6 +5711,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 897eae8faee1..1dc76c9ea309 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1663,22 +1664,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 Sat Oct 27 00:53:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10657993 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 F0F105A4 for ; Sat, 27 Oct 2018 00:53:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3B662C9C1 for ; Sat, 27 Oct 2018 00:53:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1F662BBB2; Sat, 27 Oct 2018 00:53:40 +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 D0F722BBB2 for ; Sat, 27 Oct 2018 00:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbeJ0Jct (ORCPT ); Sat, 27 Oct 2018 05:32:49 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40207 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbeJ0Jcs (ORCPT ); Sat, 27 Oct 2018 05:32:48 -0400 Received: by mail-wm1-f68.google.com with SMTP id b203-v6so2912401wme.5 for ; Fri, 26 Oct 2018 17:53:36 -0700 (PDT) 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=WptXaqKzOilBbBXuARJKF+ClrlgSWsdVLoH0WZF+AUw=; b=zsfSEbJH6zlHbqyhGA8OtuorYmMJ1ZTcyPBf9HjttyOcdB/elSifNW+EmYUJ7OvHDZ uxSFp4awzJ4wokTFqQDrYUMOAJ7niU1YrwK+4w6WZg6Z/03WvJ9FtEMd10nMTkY18dsO X4/U1wQ9vyGELjI48GSXznR+/EBZAe9W6i1kBGTPunBlaDwExSsFqYk5JSajnf4PJJFS +c0A9ARjQN10l1rf+zYGcX14Zb3UaG4y+vxXx6cpRtQsiUx0JxKvvzQfPSIg9bgenQhv YjOLj+4OiYxCJZIqQf2MzdQgu67/G3YNRO6FOqbHaxAtl18XFfmPEFQAWnZU8lWZ1tio WzxA== 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=WptXaqKzOilBbBXuARJKF+ClrlgSWsdVLoH0WZF+AUw=; b=OGETpzE/xkfL7TsQa7HwBUahnnF9cZ0MbarXrPYLDnIMAyHbu2aMwlNkBVLlm7Vt0r uvGgWju0AfjSvGL59PgKzIzSY1Jkg3EA5Oayp71GM7Aunk5sun5NTZuvGBx0DqCN11QL NRSudi9+zO2xcSy/DMrjVLGlTrAECIPoq49SgMJeHtDYrDOYEt7iVZfvxddnpsqZEDGy 4389Q+FTFZxMC+SedAoOKsVLoQbIffXXcuGLSp3qvc2uiY1TGd4Ok0QvRUV4DbxeZQ8r +oO37W/I98vamzUb2068j2ArMcuTup5d/LD0tiZG40MM5fNGk62UMEQ4QTKL6gB4xv48 csnA== X-Gm-Message-State: AGRZ1gL3CeOA3SpC1A2vQvwyqQ3whse6kNh+Jj6aZ+CLvbeLv1IBnxWE 1AR8HksOnN5Lmjz6sfYaEX9IZw== X-Google-Smtp-Source: AJdET5fcZ2MrapmeWs2JKLRvcI/7nHJVMk8igpOxtUBnmaJuVHvBnuKpeonYWGVsq134NXvttfrDjg== X-Received: by 2002:a1c:c708:: with SMTP id x8-v6mr7054264wmf.116.1540601615928; Fri, 26 Oct 2018 17:53:35 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id x17-v6sm9669755wrs.84.2018.10.26.17.53.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:35 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:34 +0100 From: Phillip Potter To: dushistov@mail.ru Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v3 02/10] ufs: use fs_umode_to_dtype() helper Message-ID: <20181027005334.GA9940@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 --- 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 Sat Oct 27 00:53:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10657995 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 30DB0180E for ; Sat, 27 Oct 2018 00:53:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23BDA286E5 for ; Sat, 27 Oct 2018 00:53:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F4132BBB2; Sat, 27 Oct 2018 00:53:41 +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 97AE42C4A6 for ; Sat, 27 Oct 2018 00:53:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726529AbeJ0Jcu (ORCPT ); Sat, 27 Oct 2018 05:32:50 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:33144 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbeJ0Jcu (ORCPT ); Sat, 27 Oct 2018 05:32:50 -0400 Received: by mail-wr1-f65.google.com with SMTP id u1-v6so2978560wrn.0 for ; Fri, 26 Oct 2018 17:53:38 -0700 (PDT) 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=y5r68PY8UFFLRUTTNh+yHW7vn1SZVaoDg2UPXDkZOJk=; b=bvvjxIEBspxkjV/6B2ROO/2uZctPD6jDyjzWsUYRlFlJVUfHit94Cinl4sHggiAW7K OZIc6Nzh3pY0scfwlYCc49xiMpKbMd0UWMzVjY6N2bZov4B3I6njTJAsbcLrng/VJ+hi bZJeax+x/UNld62Xh1xcUWXLsVNZkVEVg8lJAWOon2h0MFErt+u0dZK7ufadn/9dMUxt MOPQa42KkZhNi4qtv89E/0aF7ALIN9QY4mg/35OOOpeSGI++JLQTW5TQ7o+qnS4/Stgy gMGf9ebPh+BinvTlWN1zAqJ9SPUJMi8u4au3sUp4pYJfah4rv35SpfAHkX6xjtviGNrI E4iA== 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=y5r68PY8UFFLRUTTNh+yHW7vn1SZVaoDg2UPXDkZOJk=; b=mjhx2BRlJzvftZrqT6kts1WxUANgOQRMBjfcXC1s7mO6EaRB17B8R/MN9IR/es6rSZ N9pjSMozTVKwLk+OA1jg3JXUEKQq575q98xdnH4PeWuIH1n6UEt3g3bxHEyivsE3ycxB iIgv2kj4NWr2SGSgqnvl98lL1XdYCA3bbdZxAJN8j5RtwZqmGc6c14IQmCTQ4rjjUL1J LcQI4Js3lHjmpiQ6NtP0YqI8hGoqbyvmsqpgs3FT0sN62EWVUWKip+Gb6dNnzfS0jFZ3 FIOfhl/BCuc4mkGW15BKg45rlkYlY7kqP76qfiSae+7j8PXYuwLqTULsy2jA2qq34alh iu4Q== X-Gm-Message-State: AGRZ1gJW54PQqhdnLKc8n9nq9cSP2+PxM/3TZE+M7rgomeOA5e8PFwFF YODiLFwrnTLPDYffEkkfOX4ooX9xJlEG0Q== X-Google-Smtp-Source: AJdET5fIrSO37aBEefBJI5YabnXjPiOatRC2ATcHSU/8bnzHwKRw1gn8+XH+3ViQpZKZJ34OzztREg== X-Received: by 2002:adf:b593:: with SMTP id c19-v6mr7725290wre.223.1540601617147; Fri, 26 Oct 2018 17:53:37 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id 126-v6sm4281159wme.48.2018.10.26.17.53.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:36 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:35 +0100 From: Phillip Potter To: linux-fsdevel@vger.kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, slava@dubeyko.com Subject: [RFC][PATCH v3 03/10] hfsplus: use fs_umode_to_dtype() helper Message-ID: <20181027005335.GA9947@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 Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Vyacheslav Dubeyko --- 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 Sat Oct 27 00:53:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10657997 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 2DC065A4 for ; Sat, 27 Oct 2018 00:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 208712C898 for ; Sat, 27 Oct 2018 00:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F2BB2C9CC; Sat, 27 Oct 2018 00:53:43 +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 A8CDA2C898 for ; Sat, 27 Oct 2018 00:53:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726563AbeJ0Jcv (ORCPT ); Sat, 27 Oct 2018 05:32:51 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35483 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbeJ0Jcv (ORCPT ); Sat, 27 Oct 2018 05:32:51 -0400 Received: by mail-wm1-f65.google.com with SMTP id q12-v6so172112wmq.0 for ; Fri, 26 Oct 2018 17:53:39 -0700 (PDT) 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=PHX1SO3rRY7Yngp6/js7WU2kc5FJwnpwtmBjJqd2mLM=; b=XfrRFx8IwZhmvn76gY9Di7363sW372PdEAlMBR85z7k4Uwh/VWkOHDeDIxFS4YGm+I +31XyfjRP6iHmMbS+E5OamLZYg9eEK68D1Fz5qivU/6molJJPeL+wIvu9rRBR7IsCL5H wIlvMZ/khrhE4MfVzQ5X4PJ/uxpKSMjohYJmb7EiMZgfa46L1HQ17uZXBXDmsau64Rsy qn1fd3RKL3Cqm17BxbYTBcXyIOoV2ufxStfOZqBsoPV3L387TSmSbQMZaRxjTl/L/XAw OJ/tHNZJr3B/sIdoJtZe3XBtxh+PMn3LVah2b+5AXLB9bYYuzawz0cZKmu7CFWoZkB05 0H2A== 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=PHX1SO3rRY7Yngp6/js7WU2kc5FJwnpwtmBjJqd2mLM=; b=hVizri59MRw3hNhTdAxORjVl5V7xzZkwB65yaeyWcnt46ThtS94ilwr2Wex0mYDusi ES+sRq/sXkV8hFR5oF3Sf8OS+TZezI/nkh5dIE59KctqxEtwSo7Xp1cHxdOIFLZm7xwj nDY0fLzhzx2qoypTnxMRyLPdKuojqHaTKea9yOJYcHEqxaPqQMoRxiPHH1+ac7AFMy2S 0n0sjDYPLP6ww3fGAfbMkGmRgqJJKU4V25tjUcrqXRkR7gbj/CgzJxykiuRV0VRISz5A dh0K5t5eo+m83j2+/lz5jOClCPjwzzfXGz4bXN2LiK60hrCf0UakqtqRC+RQIiTw12Va /7pQ== X-Gm-Message-State: AGRZ1gKqsNJ9UiPBojJNjT03MApcmZ0P+khVSnGfA/n4ZYA90tXP0qCM qP3oK4qNhDWEuZlibEU+lT9zXw== X-Google-Smtp-Source: AJdET5dsDKVd2UrAemdPT9dsW4/XX4pb2FQJYiL/JO5NyJAm4QkAQmV7iBZRTky/3Wq/LYvtO9cypQ== X-Received: by 2002:a1c:a5c5:: with SMTP id o188-v6mr3257932wme.101.1540601618323; Fri, 26 Oct 2018 17:53:38 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id l67-v6sm14777393wma.20.2018.10.26.17.53.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:37 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:37 +0100 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 v3 04/10] ext2: use common file type conversion Message-ID: <20181027005337.GA9954@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 --- 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 Sat Oct 27 00:53:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10657999 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 D82315A4 for ; Sat, 27 Oct 2018 00:53:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4C8C2C33F for ; Sat, 27 Oct 2018 00:53:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C27CB2C9CC; Sat, 27 Oct 2018 00:53:43 +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 611742C898 for ; Sat, 27 Oct 2018 00:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbeJ0Jcw (ORCPT ); Sat, 27 Oct 2018 05:32:52 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55148 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbeJ0Jcw (ORCPT ); Sat, 27 Oct 2018 05:32:52 -0400 Received: by mail-wm1-f68.google.com with SMTP id r63-v6so2992315wma.4 for ; Fri, 26 Oct 2018 17:53:40 -0700 (PDT) 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=1mSd3gOLgZ1ULzd9hZfj9UsxEO/2pKWalj19MyeU2ss=; b=GMJSgSIVJw7R9x25VhUfv9gVyjPrgpbE/+X7yHUPOzXLa4pCrsoVT72Of2R076A9rL lGevs0cEsX6eWm523l/qOrQ+abcNFkV5rez1SUEtohnFtwbeZQpaRzZwGu6zmdramEw4 y28Qf4MPrXxixklwUB/8564w+r9eYrjDJqwYwlJ2J/A9L1QHqpVR71+1GqzHj5SH7CgS DOktMrqwYMiG81vvjtLNJ9I+I+kVY02IJgE8Ez8sjwaE+AOdFNPzIjTEv2OG4yOa8e43 AQqJI9k1ZnzW4xv8SBO9oXnKQUJHV3oupUskIBe6mWbXQ/Ep9yxb5s54qzDMFaR7r1oY F5XQ== 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=1mSd3gOLgZ1ULzd9hZfj9UsxEO/2pKWalj19MyeU2ss=; b=Y5sgs2ylE9hdLhELh4yPdQNOeEC1/6bwi9UD26k+XMF3ySACTPE4BDUYM5Gva8gsTD oIhYyk1WFIHqly5CfvnYz6OF7lhGB1gEHsNkwzrMtP0a5kdHyo3yxS1z4pnHy5T4fvpg 8hWJ3S3rJEJ9OCUAQoV+EoePqF0N8PTPs8sE7jj5pUC2pTarl26kZwWALV7ejVSsiFO2 1Iombua9WzZgQHZ/4BLCRR5NpYoTfaRtnbXFnF9viegtokC2dCMZVqapOZPhTHDEvJKl vhUPR5sbCPkAk3olyBFoMCnY7f7Ca2trXlVlGWEndBWPa3teyhYZAGU0dPWFEFD5wPls ikFQ== X-Gm-Message-State: AGRZ1gIN6O9zUJB+L9kFKh5V1JaOLW6WO5E2yVX1n+O3uEADl67+lvJm 95KXG0B6qbk4ZJTjsjLrQIjj/A== X-Google-Smtp-Source: AJdET5cAYCUnBJDhvTMrsB4A0TlUJkF7MD1PMiv+DMR+Hhs8Nhleeb/dFh+r3VVVKjuY5x8cq1Nv5Q== X-Received: by 2002:a1c:b7c1:: with SMTP id h184-v6mr7292922wmf.33.1540601619522; Fri, 26 Oct 2018 17:53:39 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id z18-v6sm5549867wrh.33.2018.10.26.17.53.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:38 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:38 +0100 From: Phillip Potter To: ooo@electrozaur.com Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v3 05/10] exofs: use common file type conversion Message-ID: <20181027005338.GA9961@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 exofs 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 --- fs/exofs/dir.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/fs/exofs/dir.c b/fs/exofs/dir.c index f0138674c1ed..7d0550d2bd4a 100644 --- a/fs/exofs/dir.c +++ b/fs/exofs/dir.c @@ -204,33 +204,24 @@ exofs_validate_entry(char *base, unsigned offset, unsigned mask) return (char *)p - base; } -static unsigned char exofs_filetype_table[EXOFS_FT_MAX] = { - [EXOFS_FT_UNKNOWN] = DT_UNKNOWN, - [EXOFS_FT_REG_FILE] = DT_REG, - [EXOFS_FT_DIR] = DT_DIR, - [EXOFS_FT_CHRDEV] = DT_CHR, - [EXOFS_FT_BLKDEV] = DT_BLK, - [EXOFS_FT_FIFO] = DT_FIFO, - [EXOFS_FT_SOCK] = DT_SOCK, - [EXOFS_FT_SYMLINK] = DT_LNK, -}; - -#define S_SHIFT 12 -static unsigned char exofs_type_by_mode[S_IFMT >> S_SHIFT] = { - [S_IFREG >> S_SHIFT] = EXOFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = EXOFS_FT_DIR, - [S_IFCHR >> S_SHIFT] = EXOFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = EXOFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = EXOFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = EXOFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] = EXOFS_FT_SYMLINK, -}; - static inline void exofs_set_de_type(struct exofs_dir_entry *de, struct inode *inode) { - umode_t mode = inode->i_mode; - de->file_type = exofs_type_by_mode[(mode & S_IFMT) >> S_SHIFT]; + /* + * compile-time asserts that generic FT_x types still match + * EXOFS_FT_x types + */ + BUILD_BUG_ON(EXOFS_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(EXOFS_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(EXOFS_FT_DIR != FT_DIR); + BUILD_BUG_ON(EXOFS_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(EXOFS_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(EXOFS_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(EXOFS_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(EXOFS_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(EXOFS_FT_MAX != FT_MAX); + + de->file_type = fs_umode_to_ftype(inode->i_mode); } static int @@ -280,16 +271,9 @@ exofs_readdir(struct file *file, struct dir_context *ctx) return -EIO; } if (de->inode_no) { - unsigned char t; - - if (de->file_type < EXOFS_FT_MAX) - t = exofs_filetype_table[de->file_type]; - else - t = DT_UNKNOWN; - if (!dir_emit(ctx, de->name, de->name_len, le64_to_cpu(de->inode_no), - t)) { + fs_ftype_to_dtype(de->file_type))) { exofs_put_page(page); return 0; } From patchwork Sat Oct 27 00:53:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10658001 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 BB6735A4 for ; Sat, 27 Oct 2018 00:53:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE5472AED8 for ; Sat, 27 Oct 2018 00:53:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACC3C2C9CF; Sat, 27 Oct 2018 00:53:45 +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 36B872AED8 for ; Sat, 27 Oct 2018 00:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbeJ0Jcy (ORCPT ); Sat, 27 Oct 2018 05:32:54 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39737 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbeJ0Jcx (ORCPT ); Sat, 27 Oct 2018 05:32:53 -0400 Received: by mail-wm1-f65.google.com with SMTP id y144-v6so2896553wmd.4 for ; Fri, 26 Oct 2018 17:53:41 -0700 (PDT) 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=5N2xVUBHPhw7AudvB1PS6mp/18GuiE6rSuJneF3xlM8=; b=VBtqoG+lh9A2jnChQlYSjXpfhRnSHG5YTrosfdRDt7dj+nvYE9J6oo8l2P+cjdXhqu 1OBSAwmnR7WcVFlO9czZcOTEoXhYp2r5tdczpDZ0u0031i01m8AKnY4mStYYtW8MD/7H +u2eW3XSryCi2KMnG9gXQSxh9yMy7VGls0gB2Z2Jzu/BO1/e7K5UdHBp92P4/Jp6v2lJ yMPMvouO+gDwM47DCctvQloVG3Bz8QV/wSMqcNjY4KfECnUyIsI1/i6kpBpNPxq1DRxr 9RE7KrZtS9AU4t9rsO2DwCRPGTptgOgjerslGX7q4IpTSaCrDkSr8sDkZK2yFeAl82fU migA== 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=5N2xVUBHPhw7AudvB1PS6mp/18GuiE6rSuJneF3xlM8=; b=flEpa9ot7wwlsx8xOs4mlUe5SngYlHNgrOqijwZKt5ERqsfKBz8OEPn7pmScshhfFR MvVoWYDJP4HxVeGS15F+BfcBVbt0J2EYAZ2Rg8qfkUAWSjN+1BXJ9bZ//JohzqJ/BSkB Rujr6tOoCpfwEr1pJRHVFL2aqMFbsPu3cc7i+pVIrrRpMaJtHZWo7+sUJeUOb3CO1Ual 7W26/6A1hixQ5H5YILReTlcbFMxZwne2Fdk9pjshg1Q6NvfG1jVzIHBAdSfAqwjHZM8P VKhbVB9bFmYk2T9A5uN42ORPdgH7gH2pfVNVxBoGDFwLypnOfVq32HvioDMxtpuEHlLL ycaw== X-Gm-Message-State: AGRZ1gKmJ9MqaX7MLXWe7Wbp0SEdj3L5oSy6EUtvsOMssfNy5tEIpaHM wI36fDwbygKaz1QQz1/Lv70e86oc63x3Yg== X-Google-Smtp-Source: AJdET5e92sjZniKhW5kqzNT0tjc+ATgTn/8SoU45/3Rl4JXXndyXNGhUqk9Nee8VoqEqQmWYHRbLYA== X-Received: by 2002:a1c:a184:: with SMTP id k126-v6mr113434wme.32.1540601620906; Fri, 26 Oct 2018 17:53:40 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id e14-v6sm9042917wrs.69.2018.10.26.17.53.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:40 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:39 +0100 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 v3 06/10] ext4: use common file type conversion Message-ID: <20181027005339.GA9968@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 --- 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 caff935fbeb8..88c65ce70413 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2361,16 +2361,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); @@ -3055,22 +3052,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 Sat Oct 27 00:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10658003 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 839CB13BF for ; Sat, 27 Oct 2018 00:53:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 722C12AED8 for ; Sat, 27 Oct 2018 00:53:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70ABD2C9D3; Sat, 27 Oct 2018 00:53:46 +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 EB20F2AED8 for ; Sat, 27 Oct 2018 00:53:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726740AbeJ0Jcz (ORCPT ); Sat, 27 Oct 2018 05:32:55 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38509 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbeJ0Jcz (ORCPT ); Sat, 27 Oct 2018 05:32:55 -0400 Received: by mail-wr1-f67.google.com with SMTP id d10-v6so2956785wrs.5 for ; Fri, 26 Oct 2018 17:53:43 -0700 (PDT) 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=RW/2NFHnHX6ODxx5TOnuTGUrdaVAPGTF+0x0OB3GQKU=; b=K+4YWE5mwlw9LyJAJgt5ODyt2hU9U195P7oDnJQmwAis2Jab4feaPO2PP/c8Lfc12z nx1oGMGNxKqI2kPpKu0enfInZ5isWn8xY78jmQHeRNJYz+46qGTZQ8Uwho17F2OAh2gd O0f5cuKCxP5muk466k5a8bFPI3qMFvueLrRypeERkt5W3T2zI0tMkin2zbMy3IO90ZDA Lin+XPRHhoc6Ub3lmhAszCMLdFPu1dRQ8BLJ7fjSq2AndzwVROBaFZgBOV6Ddp9QwpV+ Wv8rq/UOsYA915DtIqgENjhic3f2Qfv6lRhBlXVh5T0exIBuKZbJfX5GVezBq1wcjxlX R3Ig== 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=RW/2NFHnHX6ODxx5TOnuTGUrdaVAPGTF+0x0OB3GQKU=; b=TKSTdNAnLsY/RucU2ZkFwuaajH9loV8jfWeob+R8j5Zps/HR2g+ZK7tGyku61ASYuf xasluUHU4ryzQuTWgULmURC23ChmPICTYpGM4V8WN5+uo6Iw89fty43B0F+veDzUeS8L gBTxR0zgRuZYYCS8Tbp1uNTKvM14MdobmNAWlU6YYZ+YOw7futP6SnoNH2TZWjhShE11 wd8fHDMpT/dvWYKomHmFFKMtNmmXwqDKw5itAAqDZFTCIoKsJ+juFJkM7erIfpir03YH QJclk7Kka7Px3O5KF3Ck8491Yn0RvvH8pLcoBKPTrynSx1ubh6wYEa7avIkHFz9e6qvk VBRg== X-Gm-Message-State: AGRZ1gJ7hWH0lDBpsTjotI1dLCdJr2Pvq3naMhARnWHkxmul5VVtlvOA qJILY49YOkRMIYaQ5StJcZDAEg== X-Google-Smtp-Source: AJdET5fKkjs+tTOxaHv4in+/j8slbJPuM96yiDKA6tJhcsG7NK3+jEvRBlYOCTYiFtAjmssgMAWlFg== X-Received: by 2002:a5d:68c6:: with SMTP id p6-v6mr8030669wrw.34.1540601622261; Fri, 26 Oct 2018 17:53:42 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id i8-v6sm12818792wru.48.2018.10.26.17.53.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:41 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:40 +0100 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 v3 07/10] ocfs2: use common file type conversion Message-ID: <20181027005340.GA9975@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 --- 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 b048d4fa3959..05b691674417 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); @@ -1901,14 +1893,10 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode, continue; } 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 Sat Oct 27 00:53:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10658005 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 80A9B13BF for ; Sat, 27 Oct 2018 00:53:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 712502A955 for ; Sat, 27 Oct 2018 00:53:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D6D72C9D3; Sat, 27 Oct 2018 00:53:47 +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 F11142A955 for ; Sat, 27 Oct 2018 00:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726815AbeJ0Jc4 (ORCPT ); Sat, 27 Oct 2018 05:32:56 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34802 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726439AbeJ0Jc4 (ORCPT ); Sat, 27 Oct 2018 05:32:56 -0400 Received: by mail-wm1-f65.google.com with SMTP id f1-v6so5256392wmg.1 for ; Fri, 26 Oct 2018 17:53:44 -0700 (PDT) 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=bj/1q3LAqEtTmeDz3rFgLWh24GrQS1huq4sytJSNVik=; b=aIK8iD6POtWy/D9N15gVs/qjgXiTpOY1vjOblAGTLGFDEswTRZqNrTJPzrpKV6AEL2 dIIoZJ1580CwmWhlNYaS2R7pelj01u72Gg9PyvLLXKEBIp9mN4rqX35X83JadASxj1qA S0gstaWoqWAyxLzuX0t195/miy7eLwprcFczYt8u1yPkhubyDLQxLXZU3FHuUQnLrzIa rY87LtpJ7MIeqgWRlxbRg2MgyPRVqHHXJQyLmf3WwnhLPxUbP3GtDZGAsGgJ3jU/L8LJ s+XxmJyHYZxaEdmGJ8F9+AVceM+HtZ1D+bKLN2N7BQlqxg9CFWA6CHS/LMxJTlOjBMDk 7wCA== 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=bj/1q3LAqEtTmeDz3rFgLWh24GrQS1huq4sytJSNVik=; b=OfbOCF7bH029KQ9GeClz6icv+IDem3rCoes5jJ59PeSxs8v4QiCFpVkUPTT5+bdZf5 0ZmgyuRSjJ28weX+hS89OLtuj5zUF1X5V8PNJbtUWcdlS+uVPQe0glkA9o0O/cAvD1Do PzVW/zC+8KlBBwtBVfxnW6tHIK/Wta7uj6tYiJfmfzu4ezsXUqQ9Ff2tNbGNcRrxdYhp SB1Ekgd2Yniajs/L11IrBHeM8ThBKWrNIp/iHIUmumolNPi381Z6S14I4YWAgqb5oSIH 66mAE5UZ29NXm0EyR4TuIRSX4gRWnaF17qgLxAVz96OW/3MTgcT+/m49pohRqQG1c/SW jKjQ== X-Gm-Message-State: AGRZ1gIEjV1afuaaRhLrVnetrv+PgZeJaq8VWKF5tWH6QVaUCPRouw5F EY1Jub7LpKBG74D8U8NDoYiOtw== X-Google-Smtp-Source: AJdET5cSgQJLd35BGVCFjLemQYp1M3SyvVXY0u79OKg9cXsEjXsRiPZbz1jjO3Ge65jNkUr3EbyVZQ== X-Received: by 2002:a1c:287:: with SMTP id 129-v6mr7537566wmc.52.1540601623563; Fri, 26 Oct 2018 17:53:43 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id x8-v6sm28398046wrd.54.2018.10.26.17.53.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:42 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:42 +0100 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 v3 08/10] f2fs: use common file type conversion Message-ID: <20181027005342.GA9982@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 Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Acked-by: Chao Yu --- 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 ecc3a4e2be96..2e81d211cf27 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -39,37 +39,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 115dc219344b..d47448904f66 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -460,7 +460,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 f70f8ac9c4f4..14fc6a7a46f1 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 Sat Oct 27 00:53:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10658007 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 C963513BF for ; Sat, 27 Oct 2018 00:55:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC58B2CA23 for ; Sat, 27 Oct 2018 00:55:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B07FA2CA3B; Sat, 27 Oct 2018 00:55:23 +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 489D72CA23 for ; Sat, 27 Oct 2018 00:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbeJ0Jc6 (ORCPT ); Sat, 27 Oct 2018 05:32:58 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40483 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726828AbeJ0Jc6 (ORCPT ); Sat, 27 Oct 2018 05:32:58 -0400 Received: by mail-wr1-f68.google.com with SMTP id i17-v6so2900590wre.7 for ; Fri, 26 Oct 2018 17:53:45 -0700 (PDT) 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=30fX4qAR/0TNrtuEZ8+o/o0V542/IPhs2iRtfZCQSac=; b=GGfRo3RY9VUb5zSm0rj9lgLCZ9cyiOjNJ7BqebRPwQPQtgF4zMl7H386TKUAPWwEk2 4/Kp2cA9UXmdxLrgsVoP2h/nshNrnmSQwqjjNFWQqNAjgJuPTOho3pkFxWYMxFm69Ze6 wqlPanr6HR5fiuwIcmcJByiWMV29z16+PrJJp31jQWeBQ+sEfn4RW69Ny6V9lc4drJDw qZUUTeWk+TQy5bAlBZEjqbIB4agpmI1R9rViU4X8Bpj3sOoz1ujKKPwW2WwQIqpZatIr LM2rCBBrykXM29jTEI2A7qb7QuJ2hmCAxmX5GvB3SwVp8C9YovNf5IiJv/nrrYLgGaKy 2HOQ== 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=30fX4qAR/0TNrtuEZ8+o/o0V542/IPhs2iRtfZCQSac=; b=hHwDpbIfysDxOobY/2abSWTkDneaAJX0B5dcyH+7oXxMdaKrZSPIA79JT/Ul+/2rqz uzR/KvDYBQHiReQZnpw7iinCboXHxzIp5PSF0FPMs7pD0IW9QVJrOIsxavrtrRCK1cnn LPth6vSPnwWayOZXWmOP4rrfdcxgsk5wR01ywJORId1w+q57eVIyh4UgBN3Kmo+g0/Rc yrZaI/FH/GYVhN6WShkF982+hrYsNhlqhW8bbMkqcZ6gQTqw90BxNPxYJMrSISv9vC2+ cbVi4ytZcNOly9VKEUYDIZM10dcxL/We8/sjev9B/NkBARMKtdobAFGHmiGYFOmxqKit Q+tg== X-Gm-Message-State: AGRZ1gIWXUR7CLPnWxR4C/8Z+pGGCfhf3fICerIgw45vmg9VQd1bHG6r mP3veStMj2itieO3+NUgyqeTbg== X-Google-Smtp-Source: AJdET5fRaK3GqrgzIuuIqH9Kes01h+sysVAj+1+CCtqnHUZuTNy35ksh6t64yumQHBJD7a3yA4AluA== X-Received: by 2002:adf:b1db:: with SMTP id r27-v6mr7391590wra.95.1540601625041; Fri, 26 Oct 2018 17:53:45 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id r73-v6sm4282701wmb.37.2018.10.26.17.53.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:44 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:43 +0100 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 v3 09/10] nilfs2: use common file type conversion Message-ID: <20181027005343.GA9989@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 --- 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 Sat Oct 27 00:53:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10658009 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 2F36C17DE for ; Sat, 27 Oct 2018 00:55:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2163A2CA23 for ; Sat, 27 Oct 2018 00:55:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D5092CA33; Sat, 27 Oct 2018 00:55:24 +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 8F5CA28462 for ; Sat, 27 Oct 2018 00:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727339AbeJ0Jed (ORCPT ); Sat, 27 Oct 2018 05:34:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33154 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726828AbeJ0JdC (ORCPT ); Sat, 27 Oct 2018 05:33:02 -0400 Received: by mail-wr1-f66.google.com with SMTP id u1-v6so2978762wrn.0 for ; Fri, 26 Oct 2018 17:53:50 -0700 (PDT) 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=+IPHwtDg25aGwsv5fq54JsS+mjXOcSigJAt50TVqX/Y=; b=Zs4sCQ0481xtJyiDmmAkajqegEMiXmjHKnyPfK04WUL6OFIeh2oHcgKodJf7+CC7r1 Cyd13fNjofuJdNMQXBSdUw64v4ZTwNYOUjE7ArQ9+ipzkWqUl52OQ7a2JbIslvUJH0dR IPDK7HkmzNvL0+cnkb5AT96Mwq8G49wl/kRu+4+ckHwS9l/r8OetBX+yaD4M2kNTZ608 ChgqwYIf3RnoE1TGBGUbDIMYeKj42tndhWbd8M9VoPmQG7pDbjMDIjZrHf7GdJRzcnKH /82rz5f238/4AaXc9FC5fRzLSNLqTrMbdBqsig53NeLtTgcyFKyVC9H6sW365ueD8VqJ U/sw== 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=+IPHwtDg25aGwsv5fq54JsS+mjXOcSigJAt50TVqX/Y=; b=lKoC9v0j5QpJZw8a3wUsgM9Ni9etLk4lrZBBg10B7pJbwhCY7pZQQ/3y0WyB6Z3vcI 5/exMseNoHXmMgoARz59IJo1jarIZZquK+kTVj1eLHYb4f8DizdpgrbhkMzJ3GQtYASP Bz2cFqFMyiRIjcI2Lx3ZIMeMsausXFmUYsTsTvF8RKnYvPxuUtIE7MSieycM1geISKx5 QEpu+rfG8w4C4+DddlWMe3MwHc5STj1nnK/WMMJBGx7UqQUgXC0Nxtzz/rC6LsN3k0vN zZ1aOvdR0CxZxDDTuV47PKwSyTUFacJaW4VjmxsibW8aywkYilhFyQQzNhPchUFdMGiR nGng== X-Gm-Message-State: AGRZ1gLHZyTxXvp1Cc1fxsM4vD81D1NJ8G+tXpR8yXplR4yKLAWIfAr9 XhgRKjROmsf7/RLlK1Vfhy6K6A== X-Google-Smtp-Source: AJdET5cQIVXhol8DUKW9uf5hyNPIOPoKd/PDOoQrl073sW4yh/M2KKnS/nuIFygI773KAGzhnCzt+Q== X-Received: by 2002:adf:dd8f:: with SMTP id x15-v6mr3006378wrl.29.1540601629475; Fri, 26 Oct 2018 17:53:49 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id c2-v6sm10488546wrt.77.2018.10.26.17.53.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 17:53:48 -0700 (PDT) Date: Sat, 27 Oct 2018 01:53:48 +0100 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 v3 10/10] btrfs: use common file type conversion Message-ID: <20181027005348.GA9996@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 Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Acked-by: David Sterba --- 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 1343ac57b438..c7c6db6b4a35 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 f51b509f2d9b..c1da34e3a775 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1691,7 +1691,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 3ea5339603cf..089638719842 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -73,17 +73,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); @@ -5803,10 +5792,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 @@ -5879,6 +5864,19 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx) bool put = false; struct btrfs_key location; + /* + * 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); + if (!dir_emit_dots(file, ctx)) return 0; @@ -5945,7 +5943,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); @@ -6350,7 +6348,7 @@ 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]; + 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..a4f5fb56a45b 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