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; }