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 */