From patchwork Mon Jan 21 00:54:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10773349 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 1E6456C2 for ; Mon, 21 Jan 2019 08:42:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CDC629BE1 for ; Mon, 21 Jan 2019 08:42:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0146229E87; Mon, 21 Jan 2019 08:42:40 +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 7E31829BE1 for ; Mon, 21 Jan 2019 08:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbfAUImk (ORCPT ); Mon, 21 Jan 2019 03:42:40 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53076 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728953AbfAUImj (ORCPT ); Mon, 21 Jan 2019 03:42:39 -0500 Received: by mail-wm1-f67.google.com with SMTP id m1so9896642wml.2 for ; Mon, 21 Jan 2019 00:42:38 -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=8/QTjrFCwBRYKHmKwEJ39khUV5npplGPpM/t91XHf5M=; b=mUirSZIFZ/++wS+LOh1iwSpQF3IYt0UZ8Egfg6cUCnd5VPSOfJUi6BGubQKHA9ln9Z jHn6iqC14Gv9vk3AyLS8G7Q9tA6I4Oo98D30usOsqI1WiRaPLsVNQVOlli1i50+b0KUZ M5HkA6Ap/pHFwpTYW5Yd/Ry20vxA2vMA0Na6SY2UrM7uncuiNin2JQvmXCQWr1pZeSmb DwGCs0Gn9YljCXbY4+WiTbxDLkDU2xxZlbY6CmaCcD/EFBaQlQsVAyK+ldtsQfSDYU0B eFOOGPL++ZUAJq3rrnkStirUNcUrVok9OFGm3p5zSAGruhvCKq/f2OdmXZrZfUhLyFSV fBaw== 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=8/QTjrFCwBRYKHmKwEJ39khUV5npplGPpM/t91XHf5M=; b=OpEECKazL/tutUiYCs8/cynh66Rka1VeQgTq5hjE6g14hDXGp7pU+/JwgMKqqORp9J oZuUDOj5TtU03l66e5nysjZ6hquuUv8Mmst+TiVHFYVIoLfES7xUTALjg84nkDo5RJ0c rT9LnrRFiKuwbzMTiuPNE0zHifB40FlcvBivYvRKm8I/huULl4TqJUU1duxy+oqASkzz 9u58ZPRFpIFsZcqkCmrqWQbKg470zo5pHxhcX16oIY8+dnybq+cYqY/5yXF2eP5AyaDf YKHQkKogZ8QqalBcuNLTzdsiDLj+tySOBmyvgVVIlVxcvJmH+3zHn3cd4wrhCyD4TGgj rByg== X-Gm-Message-State: AJcUukcoQ+u3h6Ntpda2Ntyt5Mr4Mjuglkm/gUMKfc0+64aHsxz14nDM oDFISE6bkMcqBRJBXfeUxPdGEA== X-Google-Smtp-Source: ALg8bN6OCeyCGMamZB5bkga7MTG1cLu1+r5yBsBaF6sIKYQaW3H+bzTfFJAQE4bYNhGy02Nhgy4IAA== X-Received: by 2002:a1c:7706:: with SMTP id t6mr21632806wmi.57.1548032077684; Sun, 20 Jan 2019 16:54:37 -0800 (PST) Received: from pathfinder ([90.222.17.17]) by smtp.gmail.com with ESMTPSA id p10sm35848812wrt.25.2019.01.20.16.54.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 20 Jan 2019 16:54:37 -0800 (PST) Date: Mon, 21 Jan 2019 00:54:36 +0000 From: Phillip Potter To: linux-nilfs@vger.kernel.org Cc: amir73il@gmail.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v5 08/09] nilfs2: use common file type conversion Message-ID: <20190121005436.GA32372@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 - 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/nilfs2/dir.c | 52 ++++++++++-------------------- include/uapi/linux/nilfs2_ondisk.h | 1 + 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 81394e22d0a0..278d80d434b4 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -229,35 +229,23 @@ 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_* types still match + * NILFS_FT_* types + */ + 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 +281,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_ftype_to_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..9223b616766b 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 must match common file type values in fs_types.h. */ enum { NILFS_FT_UNKNOWN,