From patchwork Mon Jan 21 00:54:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10772639 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 022EA1390 for ; Mon, 21 Jan 2019 07:18:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB1C29F0D for ; Mon, 21 Jan 2019 07:18:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D259229F10; Mon, 21 Jan 2019 07:18:16 +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 4927829F0D for ; Mon, 21 Jan 2019 07:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725976AbfAUHR5 (ORCPT ); Mon, 21 Jan 2019 02:17:57 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38589 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727630AbfAUHR4 (ORCPT ); Mon, 21 Jan 2019 02:17:56 -0500 Received: by mail-wr1-f68.google.com with SMTP id v13so21987454wrw.5 for ; Sun, 20 Jan 2019 23:17: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=g2pwAxxnRqmK6UpMSZkTtNDyPXMXCJYQJ4n71D5SADc=; b=y5KGbn/Sp9d7pEjFW4LRU7j6S7wjKgk21oP+uQ3dVvEtTK3RzBg9m8kTgpZLPof3Q5 cbVkvNf/xz2aXGyhCzQ/IOtPmdZ1m+xl+UZ8sUXSelI+5fZxznGREm+ZXNpzDA2qTjTd qvyFI2gQeFq6zmQ/K5C5paWx7RnrJ6v01U57jQV5/7ZIFvonLXBZNEd1IdhiS1RrhzgB jkuEuAnS54woKRABVCQnvQkRcbhs4pmcQ/S+l+qzDrvKLYhS2e4rr4MS5OozwFPaxk/m HsBMHY/brlS7Rx08lZ83Fk0GRaCLcGMW+jZUIkrGZSG2puFQ9kyz+XNtqgEpgsCy1HfB eTdg== 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=g2pwAxxnRqmK6UpMSZkTtNDyPXMXCJYQJ4n71D5SADc=; b=Igt6JmGkAEQ0DcFCByPHposNV1j8cg4MSe3v2XsSeRs/cDoO8WtgaLtqkdBglKN3VI MIeTiS2qyPCtuoDakkD4+9viHVdWHc6vmBqg8ViPDiAXGFfGSDm8fGzAlyd+RHN7Xoo+ wn0KUPY57cXPLMWBUoR+MG7a+KPep1RhA09B5Mfoksusw4MVfukVASRfZ9TlRZDooHTs yFZUccoQOvB4E9CGMCUpDsDnO5jACBRIHSJeDKzqnsjxPSJP088NNXVS6DVIFEXcOScG 47Ci0NP6svjxPFIlcSPYflIqiDlQJbh6Q+oe+YjDYepEt94doaLIq73ryKCZPnCIRUxc ly1g== X-Gm-Message-State: AJcUukdVLsgR2rQYjBSilA/p6Uf4N9PTcG6g5Gfsq93sU8ryOgCEHiR6 FaQHGPOC1FjHy4F/534oqj/jpBfRUnsz+0c6 X-Google-Smtp-Source: ALg8bN6/sn4JXVfqiPI4as1E5Akfc8byW0ijvuPuijdke1ibMJJigXeh5tsUvDiOAUW6pypv3WO0/A== X-Received: by 2002:adf:f785:: with SMTP id q5mr24952841wrp.9.1548032072851; Sun, 20 Jan 2019 16:54:32 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id g67sm101302456wmd.38.2019.01.20.16.54.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:32 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:31 +0000 From: Phillip Potter To: jack@suse.cz Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v5 04/09] ext2: use common file type conversion Message-ID: <20190121005431.GA32343@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 and remove EXT2_FT_* definitions - 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 | 35 ++++++----------------------------- fs/ext2/ext2.h | 16 ---------------- 2 files changed, 6 insertions(+), 45 deletions(-) diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c index 3b8114def693..13318e255ebf 100644 --- a/fs/ext2/dir.c +++ b/fs/ext2/dir.c @@ -252,33 +252,10 @@ 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; 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 +270,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 +312,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), diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index e770cd100a6a..93fcfe7bbb3b 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -603,22 +603,6 @@ struct ext2_dir_entry_2 { char name[]; /* File name, up to EXT2_NAME_LEN */ }; -/* - * Ext2 directory file types. Only the low 3 bits are used. The - * other bits are reserved for now. - */ -enum { - EXT2_FT_UNKNOWN = 0, - EXT2_FT_REG_FILE = 1, - EXT2_FT_DIR = 2, - EXT2_FT_CHRDEV = 3, - EXT2_FT_BLKDEV = 4, - EXT2_FT_FIFO = 5, - EXT2_FT_SOCK = 6, - EXT2_FT_SYMLINK = 7, - EXT2_FT_MAX -}; - /* * EXT2_DIR_PAD defines the directory entries boundaries * From patchwork Mon Jan 21 00:54:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10773081 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 EE1891390 for ; Mon, 21 Jan 2019 08:09:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF4D329E1A for ; Mon, 21 Jan 2019 08:09:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D37D929E1E; Mon, 21 Jan 2019 08:09: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=-6.4 required=2.0 tests=BAYES_00,DATE_IN_PAST_06_12, 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 6CB3729E1A for ; Mon, 21 Jan 2019 08:09:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728155AbfAUIJo (ORCPT ); Mon, 21 Jan 2019 03:09:44 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34925 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbfAUIJo (ORCPT ); Mon, 21 Jan 2019 03:09:44 -0500 Received: by mail-wr1-f68.google.com with SMTP id 96so22164006wrb.2 for ; Mon, 21 Jan 2019 00:09:43 -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=b1ecWGjFT6d1T5p3dxeI6vc6FF1dU5B029yQqjeDrsI=; b=DnY407LuA7nLzq5vKkQZV4bQgj7N9CdwGy9rCNBS8uWAROQrSnmH1OAgNe/9h3D2FO 66vSkBzopKOn5NQmYzBaDmpT7eSLYYSJoRM9HLhxiMIyqdX4VJPClwa2Z+YPa8qS80WC lJ7i2u82IngoeRO0JQXco6SEoDru73igNkKgbgZRx/X6W+l3e/TAgJ6cg+0gg4fwO+PE R1jOIY47NI9G7SK1VVBGmw8CTpsQQXbC6rRWDXiDwjGaPXqoS/pxle5sKb40O5hgWZFh IUwjIO+R7DuyVW8mcVm/d0wZRcGPQKXJDAkvqW/vEHm8s/MIArCGawMdryRFgTcrYwjY hswA== 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=b1ecWGjFT6d1T5p3dxeI6vc6FF1dU5B029yQqjeDrsI=; b=nIPdw1K0/uDmbpDmT03ED/y+coaPF5ZOqAs23mV9RjthQiu1D1Gcu7xPXb+XTJwBKG WsSLzksDWzVFq/Lc6w0rba/aE+Be3P4mPmWkETdlrBOc3fDVw5x1S0ZRIdxfO1WfUGcQ GRi4W8eR/+3cI2QozaSCoTHDn3PdSDi3ysLPPvzdJxR5Pt9UvzlSaL9ka+HVeGBKJR5A j4GOQy7FWi0GlWJrKCCIr87/n/XlMeTbksLajQTRDuksuuCCJLMuT8ITXtAs4zZeFcnD A3C+KZOwPAlIb0sy968bfAdEamZs0w/Bwb0K0Wj/fRHqur/TaE7OmfQ4sHEAkL9U4fGC WrGg== X-Gm-Message-State: AJcUukdXJgmgAl4dXc4aqyXeUeqchu8Gd8roovfG2PY/Pcp5ne2lV+mF hfSPaSBkDtH2AIlio/LvFCLHuA93cxQGJWP8 X-Google-Smtp-Source: ALg8bN7WntRVqDNhcrhn5iR8haEIz/6ZhcDG9NPsMdNTLmzgMibrML3hmiLF/jCrXOE2wAElOKwSFA== X-Received: by 2002:a5d:4acb:: with SMTP id y11mr25054213wrs.281.1548032075304; Sun, 20 Jan 2019 16:54:35 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id 198sm86101874wmt.36.2019.01.20.16.54.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:34 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:34 +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 v5 06/09] f2fs: use common file type conversion Message-ID: <20190121005434.GA32358@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 and remove F2FS_FT_* definitions - 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: Chao Yu --- fs/f2fs/dir.c | 27 ++------------------------- fs/f2fs/inline.c | 2 +- include/linux/f2fs_fs.h | 15 --------------- 3 files changed, 3 insertions(+), 41 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 50d0d36280fa..797e926388ea 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -36,37 +36,14 @@ 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]; + 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 d636cbcf68f2..8b4648221820 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..2961c3477e95 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -524,21 +524,6 @@ struct f2fs_dentry_block { __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; } __packed; -/* file types used in inode_info->flags */ -enum { - F2FS_FT_UNKNOWN, - F2FS_FT_REG_FILE, - F2FS_FT_DIR, - F2FS_FT_CHRDEV, - F2FS_FT_BLKDEV, - F2FS_FT_FIFO, - F2FS_FT_SOCK, - F2FS_FT_SYMLINK, - F2FS_FT_MAX -}; - -#define S_SHIFT 12 - #define F2FS_DEF_PROJID 0 /* default project ID */ #endif /* _LINUX_F2FS_FS_H */ From patchwork Mon Jan 21 00:54:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10772845 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 0DB276C2 for ; Mon, 21 Jan 2019 08:01:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F332829D62 for ; Mon, 21 Jan 2019 08:01:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E707329D67; Mon, 21 Jan 2019 08:01:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DATE_IN_PAST_06_12, 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 8107929D62 for ; Mon, 21 Jan 2019 08:01:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729117AbfAUIBd (ORCPT ); Mon, 21 Jan 2019 03:01:33 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:47032 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729119AbfAUIBc (ORCPT ); Mon, 21 Jan 2019 03:01:32 -0500 Received: by mail-wr1-f66.google.com with SMTP id l9so22031411wrt.13 for ; Mon, 21 Jan 2019 00:01:31 -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=GPJFHkvNVUYGWUif3SNSEtU8iMpkiMe9hRfFKZgGxFQ=; b=mQkKOq2MgH7QrCk3XxsrWSnKOqSWvAnORAMmjBmxU0qDB6EhFXXjOVzLBpMEcX/99w Tb4JxvV5+3/kIVoXMRVW8mo3sJh9UFZcXTWoukC6ooZBoO5VXZpYfhLizsZEWtCZPso6 LlLx0x83h4OBw7IoChuWp1jVrVBWllc+xcxSrbQ1+f2r4jn9NMqUS5XyytjraNxAMz0I 8IFsMscQ19RTJAkooeQilkAasKQRqQEzAe0wQcimMIAHvplFyyX3Nyk/5H9ZDdM7c0MV UhOOSsIohOr6NFPNZ0JxMAr0VWJwILJQn6yqIN9JKwlTne1n4oCY6D0X/8+JDxVzqOBL Xk6w== 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=GPJFHkvNVUYGWUif3SNSEtU8iMpkiMe9hRfFKZgGxFQ=; b=Q+V5nnNs23M6MEU0KiSMYmRIR5pcm8ndJPc4YC2gN8oe9QM2Kc15knwtW8vi6/omL9 eI+0zg5rcfbeJQiEbnInuHUAXturkjXRrKsItdLU+eC6A49eaNIqB7ww69XTytlD8ElT 6ypjeJvyDU1MwIPAZaro78qI5bPAGPF3XHdGwgAYc1ReMpkcAq18b2y6bNjFchVommm+ RyFrtv7aAMQlwVWroLJVH/r/m0MGHY9VXDFeoLxXQ+y70Hvou7AJRtRRnN/OYbyS4bCa IqZWDSJqzevpPk/wMoRhRZpnWiBOk51WbcRwEKD+1grSM9PmUShzOFpfxHzbrCbumjgD NWJQ== X-Gm-Message-State: AJcUukemNmPZfjEPyCEmrwapOFjuRoc/tB4YTCPU/3sITgQdwx2LV1YP fnlOnEOGjmniJ1387HkCGzuYr0lg8Ymz8h8k X-Google-Smtp-Source: ALg8bN6xt++620FobN8wu20+Gfpy7fhG8jh94x58XBe0q/PF2oc9ESuOWnYwJe7eYn5wszEEGoLl8Q== X-Received: by 2002:a5d:4a0c:: with SMTP id m12mr25252240wrq.38.1548032076513; Sun, 20 Jan 2019 16:54:36 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id g67sm101303111wmd.38.2019.01.20.16.54.35 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:35 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:35 +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 v5 07/09] ext4: use common file type conversion Message-ID: <20190121005435.GA32365@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 and define EXT4_FT_* to match shared FT_* - 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 | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 185a05d3257e..f43d002a30fd 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1925,16 +1925,16 @@ struct ext4_dir_entry_tail { * Ext4 directory file types. Only the low 3 bits are used. The * other bits are reserved for now. */ -#define EXT4_FT_UNKNOWN 0 -#define EXT4_FT_REG_FILE 1 -#define EXT4_FT_DIR 2 -#define EXT4_FT_CHRDEV 3 -#define EXT4_FT_BLKDEV 4 -#define EXT4_FT_FIFO 5 -#define EXT4_FT_SOCK 6 -#define EXT4_FT_SYMLINK 7 +#define EXT4_FT_UNKNOWN FT_UNKNOWN +#define EXT4_FT_REG_FILE FT_REG_FILE +#define EXT4_FT_DIR FT_DIR +#define EXT4_FT_CHRDEV FT_CHRDEV +#define EXT4_FT_BLKDEV FT_BLKDEV +#define EXT4_FT_FIFO FT_FIFO +#define EXT4_FT_SOCK FT_SOCK +#define EXT4_FT_SYMLINK FT_SYMLINK -#define EXT4_FT_MAX 8 +#define EXT4_FT_MAX FT_MAX #define EXT4_FT_DIR_CSUM 0xDE @@ -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); @@ -3065,22 +3062,12 @@ 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) { 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 Mon Jan 21 00:54:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10773091 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 8BD651390 for ; Mon, 21 Jan 2019 08:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D84D2965C for ; Mon, 21 Jan 2019 08:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 715A129E46; Mon, 21 Jan 2019 08:10:51 +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 03C7D2965C for ; Mon, 21 Jan 2019 08:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728536AbfAUIKu (ORCPT ); Mon, 21 Jan 2019 03:10:50 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36856 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726284AbfAUIKu (ORCPT ); Mon, 21 Jan 2019 03:10:50 -0500 Received: by mail-wr1-f66.google.com with SMTP id u4so22139894wrp.3 for ; Mon, 21 Jan 2019 00:10:48 -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=GYYBAmt096plwKM4npCEoqzw+1f6RWraXYbWmzNbVRE=; b=gBi9DYrxmXflRgupowchKydz2b7Ix7jx4swBsupzu2uoTbG9VPBw+8WBR4dWIz5pkT VhF1ayZE0Px5aVNDDmMhGlPwl1SuVlknAHX5KENIxhzfmqZcuvBsIPrE+MscHFaKqdzu OpvaV37pbXtH7m59wzMLlZ5OAGF13PUn0Ryx+OlGzMBUry10j8vVxTQKwEUbt8E0bH8z l4vJ3pWZqCNo/4JZoB+UEIaJJ773TRfxgqiJpqlv8agtp6IZtTkIlWoH1aoK/w1q17JG Huyba9L6kQXP96q8j1sjTfNxM2Suy9YSGpUIvuOxiU5jj7GnoGefU4xlKWXLyBV92l+k hUlQ== 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=GYYBAmt096plwKM4npCEoqzw+1f6RWraXYbWmzNbVRE=; b=gKxuRf/AF4Cix3Vj/yzXaK/ta7A87V2mCSOrwvV+7bRyipS3ZCWFquFMMbOk83LBHQ 0b25zziJvz9DHC8Tfi8NO/7OlomE1zw5knPvPT1MlR2QLk7uqZLFQ4+3Eeo1yfFWRW5x BCFhsYCSF3VaeV6rM0+zDU3vfAEI5m7sXFcsvqVuHmP4JsPLlcMfZe9B8EV5hmar/fgw m2hKVuxSZhI6LdVIhz9+77K1DTHN0GlxvXOgWJlvBKBX9UWwRK+DFq1EdtXL2YGopnOJ CRg+FwrTojbr/Iy16woE9+3IOUSZvFzdHHStIC27iUjn539e8iHZIQZdfjN4wPVIoahF efbA== X-Gm-Message-State: AJcUukcynuw7Rl/Usal337uTX/O/6UjQ2enj1E1jQglqpDT0ta/CO12r wBeAQRLsi+uftuzrQeuS5DS9kQ== X-Google-Smtp-Source: ALg8bN74eRO422skWUOvWaoMEsk+GM8vcysh0Fl3hCKbJSL4zmdrJ9G2kwMpk2qsRORCq5yTP3k/0A== X-Received: by 2002:adf:f504:: with SMTP id q4mr26510775wro.321.1548032081347; Sun, 20 Jan 2019 16:54:41 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id o5sm29062574wrw.46.2019.01.20.16.54.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:40 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:39 +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 v5 09/09] btrfs: use common file type conversion Message-ID: <20190121005439.GA32379@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 6f5d07415dab..b16c13d51be0 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -203,8 +203,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 43eb4535319d..f6ea1cbafd45 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); @@ -5746,10 +5735,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 @@ -5888,7 +5873,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); @@ -6293,7 +6278,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_* types still match + * BTRFS_FT_* 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 e974f4bb5378..421239b98db2 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