From patchwork Wed Nov 21 19:06:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3139913BF for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C5B62B68D for ; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1061A2BDB2; Wed, 21 Nov 2018 19:07:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 902D12B68D for ; Wed, 21 Nov 2018 19:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387641AbeKVFma (ORCPT ); Thu, 22 Nov 2018 00:42:30 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41847 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387605AbeKVFma (ORCPT ); Thu, 22 Nov 2018 00:42:30 -0500 Received: by mail-wr1-f65.google.com with SMTP id x10so6833925wrs.8 for ; Wed, 21 Nov 2018 11:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philpotter-co-uk.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=gGQXa+bDUcpquIe5sRQ7xsaexBbdvK/U9/WH/jF100k=; b=Rg8tCXt5XLrIGzAsjwzp70WvYmzORv1+XcuoTe26kA3XU5GPEb7MlFQ4/E6R6h0vyI 1VqOEvC2ys83WHW7evoVbvep+utPd4jB8DZU/ChcLk3JDUR/VneNK7nLhPq/HtCGZr9c BYqJH8XTM35i8c0x7jkSYvM9A9SmsSQTnGOKMLEi2ZaGZfXgJmV9dO4W40kAfi6GkZlP V4Q9Bgl0dZxGbi0iC0dE4y+CO0UgW5B481BMziGBbMTXRN8oSJyILam1seRhkv6oFrbQ y4tieXg5YHgWYdQ5z022z/uRic1C/DoArOJC6Y7USXFIVaCXqkDxgtHG9gJHRjWScDQF jj3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=gGQXa+bDUcpquIe5sRQ7xsaexBbdvK/U9/WH/jF100k=; b=lbXYNMMxYzDsvgOTPx/PCn67XpXiPgTKJnuaD7wM391SGca+RSi1Gf7xqjyxS65FpB AnH5TltI71S2hpw624gjsynHgaH1kTTWo83YmiFEKJdNhtCZG+LNarXMko9vXmplWlUw 1DeVBNStTnHR+6fwbH/JGh1LoxSfcfXlG1Nn0BcKrudrGAEPJu6D25T5MyV4W7lhAaFg 0DskNm45jDWvmdQt1IDjTp/1hABGJkFx8cS75Y9wksVhYvr8VSAD5FOk0DGDZBUBzXj2 tbXoghsU4bnxeYN3VbhjrDcUtgU7qzfo0k+vftaM2cAQIFkMbD26Sm10uSktqbgTLdGC 49UQ== X-Gm-Message-State: AA+aEWZ3oEDZEPbb6QuRLVsvVnl+z9+Oamse1JVErbWB3f+nKUuDWhSl BedzbTDHBikdm2+Dym+QdxO60g== X-Google-Smtp-Source: AFSGD/Uz8vZWfYl1gdOQuGkVRlYfYmux+3kmevXH7z1UhPR4WuVp7rigkjToaLIwLp5K5EBqxQdRhQ== X-Received: by 2002:adf:eec9:: with SMTP id a9mr6786787wrp.242.1542827216548; Wed, 21 Nov 2018 11:06:56 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id q14sm5699342wrw.39.2018.11.21.11.06.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:56 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:55 +0000 From: Phillip Potter To: tytso@mit.edu Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v4 05/09] ext4: use common file type conversion Message-ID: <20181121190655.GA7717@pathfinder> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Deduplicate the ext4 file type conversion implementation - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3f89d0ab08fc..c45d701ba4f4 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2357,16 +2357,13 @@ static inline void ext4_update_dx_flag(struct inode *inode) if (!ext4_has_feature_dir_index(inode->i_sb)) ext4_clear_inode_flag(inode, EXT4_INODE_INDEX); } -static const unsigned char ext4_filetype_table[] = { - DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK -}; static inline unsigned char get_dtype(struct super_block *sb, int filetype) { - if (!ext4_has_feature_filetype(sb) || filetype >= EXT4_FT_MAX) + if (!ext4_has_feature_filetype(sb)) return DT_UNKNOWN; - return ext4_filetype_table[filetype]; + return fs_ftype_to_dtype(filetype); } extern int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf, int buf_size); @@ -3052,22 +3049,26 @@ extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t, extern int ext4_handle_dirty_dirent_node(handle_t *handle, struct inode *inode, struct buffer_head *bh); -#define S_SHIFT 12 -static const unsigned char ext4_type_by_mode[(S_IFMT >> S_SHIFT) + 1] = { - [S_IFREG >> S_SHIFT] = EXT4_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] = EXT4_FT_DIR, - [S_IFCHR >> S_SHIFT] = EXT4_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] = EXT4_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] = EXT4_FT_FIFO, - [S_IFSOCK >> S_SHIFT] = EXT4_FT_SOCK, - [S_IFLNK >> S_SHIFT] = EXT4_FT_SYMLINK, -}; static inline void ext4_set_de_type(struct super_block *sb, struct ext4_dir_entry_2 *de, umode_t mode) { + /* + * compile-time asserts that generic FT_x types still match + * EXT4_FT_x types + */ + BUILD_BUG_ON(EXT4_FT_UNKNOWN != FT_UNKNOWN); + BUILD_BUG_ON(EXT4_FT_REG_FILE != FT_REG_FILE); + BUILD_BUG_ON(EXT4_FT_DIR != FT_DIR); + BUILD_BUG_ON(EXT4_FT_CHRDEV != FT_CHRDEV); + BUILD_BUG_ON(EXT4_FT_BLKDEV != FT_BLKDEV); + BUILD_BUG_ON(EXT4_FT_FIFO != FT_FIFO); + BUILD_BUG_ON(EXT4_FT_SOCK != FT_SOCK); + BUILD_BUG_ON(EXT4_FT_SYMLINK != FT_SYMLINK); + BUILD_BUG_ON(EXT4_FT_MAX != FT_MAX); + if (ext4_has_feature_filetype(sb)) - de->file_type = ext4_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; + de->file_type = fs_umode_to_ftype(mode); } /* readpages.c */