From patchwork Wed Nov 21 19:06:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Potter X-Patchwork-Id: 10693095 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 3532C5A4 for ; Wed, 21 Nov 2018 19:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E2032B68D for ; Wed, 21 Nov 2018 19:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D4682BDB2; Wed, 21 Nov 2018 19:07:03 +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 91AE62B68D for ; Wed, 21 Nov 2018 19:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387648AbeKVFmd (ORCPT ); Thu, 22 Nov 2018 00:42:33 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40591 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387642AbeKVFmc (ORCPT ); Thu, 22 Nov 2018 00:42:32 -0500 Received: by mail-wr1-f68.google.com with SMTP id p4so6837350wrt.7 for ; Wed, 21 Nov 2018 11:07:00 -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=UrBNRC1KGmOhwZV9NlwduSQFxZFDihsRZ88cIaZ9Knk=; b=zC7/LgVRPYcwvvHA04uK/usGeVEKTrTG7xahQNM9mTgQjYOXfPeBpubZViAVJ4Bc/F Hp4M/+DTVT+RwNkdauAZ22HqMAVFmtmgNdVmqxHdz9FY9imOQJz4V+dSeG5q6hgTsNZD KafY4zPJGpZ67MEE216O6v/WsGz9QhQOExyBvy9idXzqeD0hm9wYyINx+0K51Qzrkjxs b79hTByTIzDyXXcMvko3XcNcVybM1J/qfSElaA9jvDaM94XvkVWPQ2Rgn6aS3los5h65 RnWucJDwrOwme1Klr5G342kS97Futc7GsG46w3E0QbYoy0+c93e5mIFkZTKWASNCqWyW FnUw== 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=UrBNRC1KGmOhwZV9NlwduSQFxZFDihsRZ88cIaZ9Knk=; b=NAiidYV41Bl/tN2MTsGX4oZ1ssJleY/OaF+hxti/gUHUnpz/Cg/yVFCNDhfmcXzVav 6w/zRNqixE8QkeODpubQONH7vGJE3ucJlIusccruIRF/RlhgxUuWoupN58rzVDLdMtNo qUcF/K0TNfOmYcpvmNmdxvlQRp3+0n4xWhcWumTHlyUrwf/MI2R5I7JU5ZVZPFoT3UJc kTC1Kf6HaKh+vkNJ+ACDWL28sCcZGay5cg2OkuYZ0jF84ab7IOckWzt1wQx/OsUXh6xn 0uDLHJB2mbjhhJW41ls8UmKtypYjIXoCIQdrhexB+oynE/ZF1HmrdZyfHCFvJGOPOCal sv8g== X-Gm-Message-State: AA+aEWbU5cYt6Tgt6FKkN5vGoODqdCySgpgNy6yaThUOj2R6efpTTMkG vmhunVF1QFNdBTKuTju2VIP7hA== X-Google-Smtp-Source: AFSGD/VtnPxC/j9num7B+9j34/kDllApeooeNd33bfvkWuTMz5LiAv22Zw2SBSrC48sRbSZ7VWUfSQ== X-Received: by 2002:a5d:45d0:: with SMTP id b16mr6659968wrs.86.1542827219353; Wed, 21 Nov 2018 11:06:59 -0800 (PST) Received: from pathfinder (62-64-249-96.dynamic.dsl.as9105.com. [62.64.249.96]) by smtp.gmail.com with ESMTPSA id n15sm17671649wrt.21.2018.11.21.11.06.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Nov 2018 11:06:58 -0800 (PST) Date: Wed, 21 Nov 2018 19:06:58 +0000 From: Phillip Potter To: jaegeuk@kernel.org Cc: 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 v4 07/09] f2fs: use common file type conversion Message-ID: <20181121190658.GA7731@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 - 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 Acked-by: Chao Yu Signed-off-by: Amir Goldstein Signed-off-by: Phillip Potter Reviewed-by: Jan Kara --- fs/f2fs/dir.c | 41 ++++++++++++++++------------------------- fs/f2fs/inline.c | 2 +- include/linux/f2fs_fs.h | 8 +++++--- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index bacc667950b6..113820f16c6d 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -36,37 +36,28 @@ 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 + */ + 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_ftype_to_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 7b0cff7e6051..34205d2e1cc2 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -458,7 +458,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 d7711048ef93..4b8a2ae348d8 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 must match common file type values in fs_types.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 */