From patchwork Tue Oct 23 20:19:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10653615 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 7CEBE13A9 for ; Tue, 23 Oct 2018 20:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 689462A38A for ; Tue, 23 Oct 2018 20:20:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 672332A3F3; Tue, 23 Oct 2018 20:20:31 +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 E10BF2A413 for ; Tue, 23 Oct 2018 20:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728980AbeJXEo7 (ORCPT ); Wed, 24 Oct 2018 00:44:59 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34906 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727726AbeJXEo6 (ORCPT ); Wed, 24 Oct 2018 00:44:58 -0400 Received: by mail-wr1-f68.google.com with SMTP id w5-v6so3105035wrt.2 for ; Tue, 23 Oct 2018 13:20:01 -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=izaZWa7XxJQGYb95ad5VL7uwpGF17o/DYcFIrwT2VP8=; b=zglv6r9IswmrApGQqYnwRA+44e3nOPrKcEsnAhjpdVjLacMCNeZjlodqMw0yt/VnRF T117GzZthiUDQnQ5a8nPRbxOcfSeGvJ6UtYbURGp2y9rIQy7bmr48pKl7qaAzajqVbsC 5Yshuq8L2C8dg8lDs780BiE63fDEnhIf6vt5K1aNAi7rAv4jgOSeMkTFWe/jWixjlP9l wz7bwboHm9UrrIOc0iFHZvStZOHKKoKiqknudYmvbHEh0D/BiwdaqbEyBTV+jRS3vhXS hWbSXuC9rhpGNQTcMObG1CqI3i/ke/AvCkaVbqhmSCZ4BEz18s8faB/gOSEUSqewg5MD N7Dg== 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=izaZWa7XxJQGYb95ad5VL7uwpGF17o/DYcFIrwT2VP8=; b=pdpEllrSyIqswFGd8SiSsB6zIdxWn3Aq/71OFyveBeMxwpPTuWn4stl1vs/U7i6Mx6 SvDw1ozO7V5LaQRrW/bJqi8YJ4eoiFp6eeLdUirnlh0KXBxTC1ezaM/UzpAuWYV2ACBv xUTewOXCGM10BxxCaGd1IpZRdBNlJa1SyOhzvHIBhlYTEySWHQMPj8ie2puaSTbmsorY LUcaZFY6/WzWEUapvQAA9fS4ZYaekuFl4nsXi7q9p+riPQMoLtl19Q22zmsokqXm7dle 42RZRQyfeWD34bu7EDU3lviJkqBIcCzGtEBpoKIUS4/jn8DC/UAEIrDddgp9G0jDqhIa Z3Aw== X-Gm-Message-State: AGRZ1gIjRDhvrBr/IMYwilUf6ub328tdhaa2+8s/EgULpWqRd+O338sw +rtkmTIBPSitYB/DFQDHe/aRpg== X-Google-Smtp-Source: AJdET5cyGmE3+Yp/Vsz7efD7YbSBa6tJnFGxnd7SvN9ann3a6ffItfqV1EXNuJFzPI7pqwugMzd98w== X-Received: by 2002:adf:e485:: with SMTP id i5-v6mr12282364wrm.145.1540326000253; Tue, 23 Oct 2018 13:20:00 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id 193-v6sm3667414wmj.21.2018.10.23.13.19.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 13:19:59 -0700 (PDT) Date: Tue, 23 Oct 2018 21:19:59 +0100 From: Phillip Potter To: ooo@electrozaur.com Cc: linux-kernel@vger.kernel.org, amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v2 05/10] exofs: use common file type conversion Message-ID: <20181023201959.GA15715@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. Original patch by Amir Goldstein. v2: - This version does not remove EXOFS_FT_x enum from fs/exofs/common.h, as these values are now used in compile-time checks added by Phillip Potter to make sure they remain the same as FT_x values v1: - Initial implementation Signed-off-by: Phillip Potter --- fs/exofs/dir.c | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/fs/exofs/dir.c b/fs/exofs/dir.c index f0138674c1ed..2e3161ca9014 100644 --- a/fs/exofs/dir.c +++ b/fs/exofs/dir.c @@ -204,33 +204,10 @@ 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]; + de->file_type = fs_umode_to_ftype(inode->i_mode); } static int @@ -279,17 +256,27 @@ exofs_readdir(struct file *file, struct dir_context *ctx) exofs_put_page(page); 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; + /* + * compile-time asserts that generic FT_x types + * still match EXOFS_FT_x types - no need to list + * for other functions as well as build will + * fail either way + */ + 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); + if (de->inode_no) { if (!dir_emit(ctx, de->name, de->name_len, le64_to_cpu(de->inode_no), - t)) { + fs_dtype(de->file_type))) { exofs_put_page(page); return 0; } From patchwork Tue Oct 23 20:20:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10653607 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 75C611759 for ; Tue, 23 Oct 2018 20:20:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DC2B2A3E5 for ; Tue, 23 Oct 2018 20:20:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5246A2A3EC; Tue, 23 Oct 2018 20:20:07 +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 E0FA12A3E5 for ; Tue, 23 Oct 2018 20:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729039AbeJXEpB (ORCPT ); Wed, 24 Oct 2018 00:45:01 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53760 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728894AbeJXEpA (ORCPT ); Wed, 24 Oct 2018 00:45:00 -0400 Received: by mail-wm1-f67.google.com with SMTP id f8-v6so691971wmc.3 for ; Tue, 23 Oct 2018 13:20:02 -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=JftqL+okrKcXPO7UtivHdzpGqZmRsOYm/0Ei3vm9z68=; b=qee9r6V/5gl2gOpRgL/ZHnnDH2EdJqBaKpVL+D9n/OU5RWd2KOLdHYmjA69IpNtf2A awrBTUmQHYVXHySJS1USAcBPw/sYpRlnhvqWVi8fdgDGPGFedRFhktg2txc7Fzl+dNz5 6anSY5Ghr4Ju0Xk0Mt/Cg/z0ypwV2z6WK4m+cZD9TKQMFdGfxo72wHY+hbCJHghU83iw gY1dvpfzMS36J9hQmnVtXNIOLnCtqirzO/X0IxEWLo7djkmkkV86nNBnjGIyrbikgVEj XxOKt8IzWLlV8MbD6/n8+/1UNS4obVmgT/4O2hyIosLMr/75+R5s/8QOL3IUD1u8dsBC /cDA== 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=JftqL+okrKcXPO7UtivHdzpGqZmRsOYm/0Ei3vm9z68=; b=OihacWwUuY8VtVb2uw9OaTn5MHX3X1dHBaR1mxGd61+GU2wRDE5frbxKS9dLy2rlsS iMr083wzPndy/kuqKRq85s0ljbJabIXjKiFupYpJGPjibm6w83w3IWxuytdeR8sWMfzH 3yHqimnXoLqiZt+WCfP8Mw5Umj2MQLaWGAH+fH5Hqy3mNiJvx2+y03pyS/nrvun4Q1Fu dHdYzG+LLRe77crvyp9JqBXnplTXuKh2JhPHkobJuWhBsG1xbXcYkP80+drO2s8kIyCo /Zvd13b6VMltV5pInY7+IloxHLkL2iP3QVZNt7Xr0JW0UUL+GhHAgelo0jGRVui/1l0F QdCg== X-Gm-Message-State: ABuFfoi05/paz7oc9WIXghy6CUSu204Wdb111fVG0vAH4AqbKYyxeJzN /geCtk4R7nJ1qlNKy50rzdbj3A== X-Google-Smtp-Source: ACcGV61PN2RjenVxMBBP51NVI5/8WWcvrDaqcLFt5NesZFBqHsx2P8YiaI9WYjPxU7SfJucptj2pow== X-Received: by 2002:a1c:6655:: with SMTP id a82-v6mr22673396wmc.10.1540326001598; Tue, 23 Oct 2018 13:20:01 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id m2-v6sm2524761wrj.80.2018.10.23.13.20.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 13:20:00 -0700 (PDT) Date: Tue, 23 Oct 2018 21:20:00 +0100 From: Phillip Potter To: tytso@mit.edu Cc: linux-kernel@vger.kernel.org, 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 v2 06/10] ext4: use common file type conversion Message-ID: <20181023202000.GA15724@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. Original patch by Amir Goldstein. v2: - Rebased against Linux 4.19 by Phillip Potter - This version does not replace the EXT4_FT_x defines from fs/ext4/ext4.h, as these values are now used in compile-time checks added by Phillip Potter to make sure they remain the same as FT_x values v1: - Initial implementation Signed-off-by: Phillip Potter --- fs/ext4/ext4.h | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index caff935fbeb8..4cb77a2cacdf 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_dtype(filetype); } extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf, int buf_size); @@ -3055,22 +3052,28 @@ 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 - no need to list + * for other functions as well as build will + * fail either way + */ + 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 Tue Oct 23 20:20:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10653613 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 7F4DD13A9 for ; Tue, 23 Oct 2018 20:20:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69ED72A40D for ; Tue, 23 Oct 2018 20:20:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E4BF2A404; Tue, 23 Oct 2018 20:20:26 +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 D664B2A412 for ; Tue, 23 Oct 2018 20:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727667AbeJXEpQ (ORCPT ); Wed, 24 Oct 2018 00:45:16 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33455 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728903AbeJXEpB (ORCPT ); Wed, 24 Oct 2018 00:45:01 -0400 Received: by mail-wr1-f67.google.com with SMTP id u1-v6so3113509wrn.0 for ; Tue, 23 Oct 2018 13:20:03 -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=A/jiG96sg0/Qi5Ypt2KE8HkbyupaifGhdu3oPA0BQsI=; b=f15T7iMME5asxnV69hCKOrgoXtdxbOS5TxcXhdynPgkC590ZoMFAFdolJvKwvQJYO8 ccLS4fSC5LJbzrvYSAV+xiQHwKcCWmEcxMBK9B5df0JgVshC/uTyxrh9f8Q0bXtvwc6y +AdIOlhVbM9RM7qmgmY5wOFUotmngIiJb3yd6MrwxrG8SuUcMOUsQCBQiGTQu/MV3M+M jogvsCxoWbeIiYFMPsxY0FlwX3H3Zds50EFeAd/YF+aDOgDiNh64kW+cTmMjxsqlNPBX DEiHcRHqxG8+/sDw2FBS3TN7JlB3z8PuKF1GjTocl5tL51Yv0y3pFf27Bo2++VOKPwVh Q/RA== 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=A/jiG96sg0/Qi5Ypt2KE8HkbyupaifGhdu3oPA0BQsI=; b=R5S7kYPbJwFePgKWch0kXKqlm7uKG2Z2eQfiNSVLz3GKMX2+kfncls3uDp7Y5clxTz LToKKx7pXhMJTrqQst0wmbQR8brsT7PJGxBmLafFrOE1tZ30L2koTzpauq/TQsIn+7lY /tNJRGlhSJhLz6To/nusq6DUVn8U3rYlbxpmbWkHcp2BA2X3h7BShx4Ca8+Z9TAh/biC /XQOJoPikg85PNIq1nDTfSlO5RvO5IlLQuNP2UTOUfMv8E6/v8+mFuuvE2/1nfD1on9j fM1OFdk7GT3yjW1I7WlDpNvgtr8RwLDOBquMjjfJhzNqblrtL6n48pqX+jQZGCZBsk0n aZ9Q== X-Gm-Message-State: AGRZ1gL3wHK0uRwmEiZsHk0l30EhZ6secfFgPKtlc+eNUTHNaKL2nYeY HGms6RYHpvIiqXcTCnNCCakaPgjqVf2GKmF+ X-Google-Smtp-Source: AJdET5dWs1WpKf4w89OuTfD4liCVVN6bkdEFfQpJJzulV9iYjGoUNeFQXN9+XdyP5O61h6eZ0GQZmA== X-Received: by 2002:a5d:6a47:: with SMTP id t7-v6mr7612669wrw.78.1540326002875; Tue, 23 Oct 2018 13:20:02 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id e196-v6sm4687560wmf.43.2018.10.23.13.20.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 13:20:02 -0700 (PDT) Date: Tue, 23 Oct 2018 21:20:01 +0100 From: Phillip Potter To: mark@fasheh.com Cc: linux-kernel@vger.kernel.org, amir73il@gmail.com, viro@zeniv.linux.org.uk, jlbec@evilplan.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [RFC][PATCH v2 07/10] ocfs2: use common file type conversion Message-ID: <20181023202001.GA15731@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. Original patch by Amir Goldstein. v2: - This version does not replace the OCFS2_FT_x defines from fs/ocfs2/ocfs2_fs.h, as these values are now used in compile-time checks added by Phillip Potter to make sure they remain the same as FT_x values v1: - Initial implementation Signed-off-by: Phillip Potter --- fs/ocfs2/dir.c | 32 ++++++++++++++++++-------------- fs/ocfs2/ocfs2_fs.h | 13 +------------ 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index b048d4fa3959..8a628633cb5c 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,25 @@ 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]; + /* + * compile-time asserts that generic FT_x types + * still match OCFS2_FT_x types - no need to list + * in other functions as well as build will + * fail either way + */ + 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); if (!dir_emit(ctx, de->name, de->name_len, - le64_to_cpu(de->inode), d_type)) + le64_to_cpu(de->inode), + fs_dtype(de->file_type))) goto out; } ctx->pos += le16_to_cpu(de->rec_len); @@ -1901,14 +1909,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_dtype(de->file_type))) { brelse(bh); return 0; } diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h index 7071ad0dec90..a08e2622ace7 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,7 @@ 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]; + de->file_type = fs_umode_to_ftype(mode); } static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd) From patchwork Tue Oct 23 20:20:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10653609 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 1B7CB13A9 for ; Tue, 23 Oct 2018 20:20:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 083A22A3E4 for ; Tue, 23 Oct 2018 20:20:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0D132A3F1; Tue, 23 Oct 2018 20:20:09 +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 9947B2A3E4 for ; Tue, 23 Oct 2018 20:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729051AbeJXEpD (ORCPT ); Wed, 24 Oct 2018 00:45:03 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:38448 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727576AbeJXEpC (ORCPT ); Wed, 24 Oct 2018 00:45:02 -0400 Received: by mail-wm1-f66.google.com with SMTP id b14-v6so488401wmj.3 for ; Tue, 23 Oct 2018 13:20:05 -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=PVWfVWT4ECCVj7C6DbvMBrAHgWzq8LcG4MQkwdUjwlc=; b=17hMlnfjRpw42xR239fooG/+xzC3NgK29J0arw2o7K0mzF/W15Urybq7+o7IqlrlEs TWmiIuZJgrnD15/lyMVH3mVHjcq3jSrVggz6RiiiBI6JDa6AgOqtfraUsgfWiriqmh15 Zh/NMylSHg9hWxHNrQwULjlYjcwKng/elpWiV/fzPJolQcsSa7UOQiAqaUxzK18JBbJl sasR2fDA89fqkibbxSoptHyivFe5sgwLRFheKSAhSF4hm5iaUIoCjurKIRndZTQSw23U jU3iKUqBJBPdvmJApkGxAuHQI4doPOKw2izW67TQ+SovG7qYxI56hNOr3h/r/kTOFX8I Gpow== 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=PVWfVWT4ECCVj7C6DbvMBrAHgWzq8LcG4MQkwdUjwlc=; b=PWbThbRADvVN0wa5is24piFicw3MrbV30zlnlS4ndYxcanRZF1BuNU1ZNRrutZlgg1 OQkLKKAkhlarT3GYL0p3IHVE2tPst3uigKhIYMvZ/vjJqCiPeoPc2t+EfzgUPprOBRdU QiSoLxqpSMLyNYRwpCDTX1CiwkHrsd04KyAqUn3NABSk7EAIQCoq9DlBErwHBzVq8n77 +7YaihkXU9jjVOl93HlzCy2qWwdh1NrSEgRZjMTM5npMs62MHpJvreSDaSld1xZa+gPb jdaVoFdcV31F1xhL3nKRa4mdo24148dtcEU79yFJ/Vi8WsXHJ3vd302XyGcAlSF10ASw JL+A== X-Gm-Message-State: AGRZ1gIqopGZ4zBXbx7HxAV/yrd2qBLcQs3rXKKAyJgjtppF+LDLbLrG 4ZLJRfawuCxF1EFuGF1iiWoyrA== X-Google-Smtp-Source: AJdET5fTyA/urAjwIn8tQLPylnlOoJmqQ8aDexaHQXU1M0ALqvcNSPWrgRfW3Ohj8s7pbhL7ivTjuw== X-Received: by 2002:a1c:454:: with SMTP id 81-v6mr3335135wme.148.1540326004113; Tue, 23 Oct 2018 13:20:04 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id a84-v6sm2529120wmf.46.2018.10.23.13.20.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 13:20:03 -0700 (PDT) Date: Tue, 23 Oct 2018 21:20:02 +0100 From: Phillip Potter To: jaegeuk@kernel.org Cc: linux-kernel@vger.kernel.org, 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 v2 08/10] f2fs: use common file type conversion Message-ID: <20181023202002.GA15738@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. Original patch by Amir Goldstein. v2: - Rebased against Linux 4.19 by Phillip Potter - Compile-time checks added by Phillip Potter to make sure the F2FS_FT_x enum values stay same as FT_x values v1: - Initial implementation Signed-off-by: Phillip Potter --- fs/f2fs/dir.c | 43 +++++++++++++++++------------------------ fs/f2fs/inline.c | 2 +- include/linux/f2fs_fs.h | 8 +++++--- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index ecc3a4e2be96..dcb503da0d86 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -39,37 +39,30 @@ 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 - no need to list + * in other functions as well as build will + * fail either way + */ + 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_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..fb8ad4d87132 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 should match common file type values in file_type.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 Tue Oct 23 20:20:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10653611 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 F3AF413A9 for ; Tue, 23 Oct 2018 20:20:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCD792A3EB for ; Tue, 23 Oct 2018 20:20:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB5A22A3FC; Tue, 23 Oct 2018 20:20:14 +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 6D5A12A3EB for ; Tue, 23 Oct 2018 20:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729086AbeJXEpE (ORCPT ); Wed, 24 Oct 2018 00:45:04 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51846 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729040AbeJXEpD (ORCPT ); Wed, 24 Oct 2018 00:45:03 -0400 Received: by mail-wm1-f66.google.com with SMTP id 143-v6so3069903wmf.1 for ; Tue, 23 Oct 2018 13:20:06 -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=jSWvX4QxrsoC+ZiESoxasWdqpZ9hWx9gFFsef9JZrNg=; b=nmOCSLyY/o648Zx1j6VahFWJsTKRtVgwiKM6YiDRixuYevAjr6y84Y5V6M2TxMMhku RUJvawazuUOV11ZO8bTvmHMpzqkq3L+kFG3dXLxomNtxwwOR8hUBZWwd45TKCT4AgA2j LDw9GiMTVvrxzWhhGvIq7Or7icdmuH5MTAXYipZ7RJGMXWDAmqexd3X2nSn7cBLK3sig gAOOHGIs4Tza1uOKfn0cSMy+DgI9cY1AOy1s++zqFIsxcaNIanShGM+xwXU3JzMaYXOC Aa+J29/IfWv9G3LyW9WsdGZdHCQUdgzqpgIWky3eUF/AMlNak7iusxNvfsnYRSfp4Cmj iRTw== 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=jSWvX4QxrsoC+ZiESoxasWdqpZ9hWx9gFFsef9JZrNg=; b=qDrBGSaavshaQA5V2o2aSgYN+88x8Jp+7ecv7BA8SBSuBsKqVaSYYB//A2bXN5ToLM hAR7ZXSeYfEYdDqvUFSGTeyvwFf4HXDi29xgTMYryn1A/Ad7nsVWv/vSncUbKKovoUsf Pb5rqWeGAGGwD1bTCQp/JgHk0naphdIIsUc+KHCfA81ZwRkQcGdmPQJTeD1MCu0ZPIgZ ivyFCluUdLmozn17nSiiFgvMRW69a12pe7WCu5ZLQhw1Qi+yKXfH0kqhMJVUgB130rDn mnOaYUmQnyH5undWc5buCIzuzsGflGzs7xTruKe/RplZd/Q84YYoDGwMTPesYFVP4OUq c6yg== X-Gm-Message-State: ABuFfoiA2brfnbw9cf/3zlB3ucGIpwAy+gACqUM4kDvWvRkv8kSz40OX WocM6uaHkaQzKR6WrQBrWCUNMA== X-Google-Smtp-Source: ACcGV62CkJWOfwMoq/Yj3fPlZ1mbZRYVCy0z6ZabJ6ipvTg/3HYXNyK1K1Teh01kuPkZDojRx5jh+w== X-Received: by 2002:a1c:9f41:: with SMTP id i62-v6mr23061793wme.53.1540326005409; Tue, 23 Oct 2018 13:20:05 -0700 (PDT) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id z185-v6sm4373951wmz.47.2018.10.23.13.20.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 13:20:04 -0700 (PDT) Date: Tue, 23 Oct 2018 21:20:04 +0100 From: Phillip Potter To: linux-nilfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v2 09/10] nilfs2: use common file type conversion Message-ID: <20181023202004.GA15745@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. Original patch by Amir Goldstein. v2: - Compile-time checks added by Phillip Potter to make sure the NILFS_FT_x enum values stay same as FT_x values v1: - Initial implementation Signed-off-by: Phillip Potter --- fs/nilfs2/dir.c | 54 +++++++++++------------------- include/uapi/linux/nilfs2_ondisk.h | 1 + 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 81394e22d0a0..168238278d24 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -229,35 +229,25 @@ 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 - no need to list + * in other functions as well as build will + * fail either way + */ + 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 +283,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_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..90362b1957f1 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 should match common file type values in file_type.h. */ enum { NILFS_FT_UNKNOWN,