719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 1) // SPDX-License-Identifier: GPL-2.0-or-later
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 2) /*
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 3) * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 4) */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 5)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 6) #include <linux/fs_context.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 7) #include <linux/fs_parser.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 8) #include <linux/module.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 9) #include <linux/init.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 10) #include <linux/time.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 11) #include <linux/mount.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 12) #include <linux/cred.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 13) #include <linux/statfs.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 14) #include <linux/seq_file.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 15) #include <linux/blkdev.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 16) #include <linux/fs_struct.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 17) #include <linux/iversion.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 18) #include <linux/nls.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 19) #include <linux/buffer_head.h>
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 20)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 21) #include "exfat_raw.h"
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 22) #include "exfat_fs.h"
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 23)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 24) static char exfat_default_iocharset[] = CONFIG_EXFAT_DEFAULT_IOCHARSET;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 25) static struct kmem_cache *exfat_inode_cachep;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 26)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 27) static void exfat_free_iocharset(struct exfat_sb_info *sbi)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 28) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 29) if (sbi->options.iocharset != exfat_default_iocharset)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 30) kfree(sbi->options.iocharset);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 31) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 32)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 33) static void exfat_delayed_free(struct rcu_head *p)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 34) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 35) struct exfat_sb_info *sbi = container_of(p, struct exfat_sb_info, rcu);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 36)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 37) unload_nls(sbi->nls_io);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 38) exfat_free_iocharset(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 39) exfat_free_upcase_table(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 40) kfree(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 41) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 42)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 43) static void exfat_put_super(struct super_block *sb)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 44) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 45) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 46)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 47) mutex_lock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 48) exfat_free_bitmap(sbi);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 49) brelse(sbi->boot_bh);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 50) mutex_unlock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 51)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 52) call_rcu(&sbi->rcu, exfat_delayed_free);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 53) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 54)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 55) static int exfat_sync_fs(struct super_block *sb, int wait)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 56) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 57) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 58) int err = 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 59)
2c7f8937ef915 (Tetsuhiro Kohada 2020-06-16 11:18:07 +0900 60) if (!wait)
2c7f8937ef915 (Tetsuhiro Kohada 2020-06-16 11:18:07 +0900 61) return 0;
2c7f8937ef915 (Tetsuhiro Kohada 2020-06-16 11:18:07 +0900 62)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 63) /* If there are some dirty buffers in the bdev inode */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 64) mutex_lock(&sbi->s_lock);
2c7f8937ef915 (Tetsuhiro Kohada 2020-06-16 11:18:07 +0900 65) sync_blockdev(sb->s_bdev);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 66) if (exfat_clear_volume_dirty(sb))
2c7f8937ef915 (Tetsuhiro Kohada 2020-06-16 11:18:07 +0900 67) err = -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 68) mutex_unlock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 69) return err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 70) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 71)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 72) static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 73) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 74) struct super_block *sb = dentry->d_sb;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 75) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 76) unsigned long long id = huge_encode_dev(sb->s_bdev->bd_dev);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 77)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 78) if (sbi->used_clusters == EXFAT_CLUSTERS_UNTRACKED) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 79) mutex_lock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 80) if (exfat_count_used_clusters(sb, &sbi->used_clusters)) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 81) mutex_unlock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 82) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 83) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 84) mutex_unlock(&sbi->s_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 85) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 86)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 87) buf->f_type = sb->s_magic;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 88) buf->f_bsize = sbi->cluster_size;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 89) buf->f_blocks = sbi->num_clusters - 2; /* clu 0 & 1 */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 90) buf->f_bfree = buf->f_blocks - sbi->used_clusters;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 91) buf->f_bavail = buf->f_bfree;
6d1349c769ea2 (Al Viro 2020-09-18 16:45:50 -0400 92) buf->f_fsid = u64_to_fsid(id);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 93) /* Unicode utf16 255 characters */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 94) buf->f_namelen = EXFAT_MAX_FILE_LEN * NLS_MAX_CHARSET_SIZE;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 95) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 96) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 97)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 98) static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 99) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 100) struct exfat_sb_info *sbi = EXFAT_SB(sb);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 101) struct boot_sector *p_boot = (struct boot_sector *)sbi->boot_bh->b_data;
cdc06129a6cea (Jason Yan 2020-04-16 13:34:26 +0900 102) bool sync;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 103)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 104) /* retain persistent-flags */
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 105) new_flags |= sbi->vol_flags_persistent;
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 106)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 107) /* flags are not changed */
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 108) if (sbi->vol_flags == new_flags)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 109) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 110)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 111) sbi->vol_flags = new_flags;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 112)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 113) /* skip updating volume dirty flag,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 114) * if this volume has been mounted with read-only
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 115) */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 116) if (sb_rdonly(sb))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 117) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 118)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 119) p_boot->vol_flags = cpu_to_le16(new_flags);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 120)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 121) if ((new_flags & VOLUME_DIRTY) && !buffer_dirty(sbi->boot_bh))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 122) sync = true;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 123) else
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 124) sync = false;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 125)
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 126) set_buffer_uptodate(sbi->boot_bh);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 127) mark_buffer_dirty(sbi->boot_bh);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 128)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 129) if (sync)
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 130) sync_dirty_buffer(sbi->boot_bh);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 131) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 132) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 133)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 134) int exfat_set_volume_dirty(struct super_block *sb)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 135) {
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 136) struct exfat_sb_info *sbi = EXFAT_SB(sb);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 137)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 138) return exfat_set_vol_flags(sb, sbi->vol_flags | VOLUME_DIRTY);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 139) }
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 140)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 141) int exfat_clear_volume_dirty(struct super_block *sb)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 142) {
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 143) struct exfat_sb_info *sbi = EXFAT_SB(sb);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 144)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 145) return exfat_set_vol_flags(sb, sbi->vol_flags & ~VOLUME_DIRTY);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 146) }
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 147)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 148) static int exfat_show_options(struct seq_file *m, struct dentry *root)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 149) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 150) struct super_block *sb = root->d_sb;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 151) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 152) struct exfat_mount_options *opts = &sbi->options;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 153)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 154) /* Show partition info */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 155) if (!uid_eq(opts->fs_uid, GLOBAL_ROOT_UID))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 156) seq_printf(m, ",uid=%u",
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 157) from_kuid_munged(&init_user_ns, opts->fs_uid));
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 158) if (!gid_eq(opts->fs_gid, GLOBAL_ROOT_GID))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 159) seq_printf(m, ",gid=%u",
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 160) from_kgid_munged(&init_user_ns, opts->fs_gid));
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 161) seq_printf(m, ",fmask=%04o,dmask=%04o", opts->fs_fmask, opts->fs_dmask);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 162) if (opts->allow_utime)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 163) seq_printf(m, ",allow_utime=%04o", opts->allow_utime);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 164) if (opts->utf8)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 165) seq_puts(m, ",iocharset=utf8");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 166) else if (sbi->nls_io)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 167) seq_printf(m, ",iocharset=%s", sbi->nls_io->charset);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 168) if (opts->errors == EXFAT_ERRORS_CONT)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 169) seq_puts(m, ",errors=continue");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 170) else if (opts->errors == EXFAT_ERRORS_PANIC)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 171) seq_puts(m, ",errors=panic");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 172) else
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 173) seq_puts(m, ",errors=remount-ro");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 174) if (opts->discard)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 175) seq_puts(m, ",discard");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 176) if (opts->time_offset)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 177) seq_printf(m, ",time_offset=%d", opts->time_offset);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 178) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 179) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 180)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 181) static struct inode *exfat_alloc_inode(struct super_block *sb)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 182) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 183) struct exfat_inode_info *ei;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 184)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 185) ei = kmem_cache_alloc(exfat_inode_cachep, GFP_NOFS);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 186) if (!ei)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 187) return NULL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 188)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 189) init_rwsem(&ei->truncate_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 190) return &ei->vfs_inode;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 191) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 192)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 193) static void exfat_free_inode(struct inode *inode)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 194) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 195) kmem_cache_free(exfat_inode_cachep, EXFAT_I(inode));
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 196) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 197)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 198) static const struct super_operations exfat_sops = {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 199) .alloc_inode = exfat_alloc_inode,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 200) .free_inode = exfat_free_inode,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 201) .write_inode = exfat_write_inode,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 202) .evict_inode = exfat_evict_inode,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 203) .put_super = exfat_put_super,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 204) .sync_fs = exfat_sync_fs,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 205) .statfs = exfat_statfs,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 206) .show_options = exfat_show_options,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 207) };
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 208)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 209) enum {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 210) Opt_uid,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 211) Opt_gid,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 212) Opt_umask,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 213) Opt_dmask,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 214) Opt_fmask,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 215) Opt_allow_utime,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 216) Opt_charset,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 217) Opt_errors,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 218) Opt_discard,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 219) Opt_time_offset,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 220)
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 221) /* Deprecated options */
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 222) Opt_utf8,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 223) Opt_debug,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 224) Opt_namecase,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 225) Opt_codepage,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 226) };
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 227)
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 228) static const struct constant_table exfat_param_enums[] = {
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 229) { "continue", EXFAT_ERRORS_CONT },
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 230) { "panic", EXFAT_ERRORS_PANIC },
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 231) { "remount-ro", EXFAT_ERRORS_RO },
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 232) {}
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 233) };
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 234)
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 235) static const struct fs_parameter_spec exfat_parameters[] = {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 236) fsparam_u32("uid", Opt_uid),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 237) fsparam_u32("gid", Opt_gid),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 238) fsparam_u32oct("umask", Opt_umask),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 239) fsparam_u32oct("dmask", Opt_dmask),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 240) fsparam_u32oct("fmask", Opt_fmask),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 241) fsparam_u32oct("allow_utime", Opt_allow_utime),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 242) fsparam_string("iocharset", Opt_charset),
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 243) fsparam_enum("errors", Opt_errors, exfat_param_enums),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 244) fsparam_flag("discard", Opt_discard),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 245) fsparam_s32("time_offset", Opt_time_offset),
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 246) __fsparam(NULL, "utf8", Opt_utf8, fs_param_deprecated,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 247) NULL),
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 248) __fsparam(NULL, "debug", Opt_debug, fs_param_deprecated,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 249) NULL),
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 250) __fsparam(fs_param_is_u32, "namecase", Opt_namecase,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 251) fs_param_deprecated, NULL),
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 252) __fsparam(fs_param_is_u32, "codepage", Opt_codepage,
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 253) fs_param_deprecated, NULL),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 254) {}
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 255) };
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 256)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 257) static int exfat_parse_param(struct fs_context *fc, struct fs_parameter *param)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 258) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 259) struct exfat_sb_info *sbi = fc->s_fs_info;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 260) struct exfat_mount_options *opts = &sbi->options;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 261) struct fs_parse_result result;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 262) int opt;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 263)
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 264) opt = fs_parse(fc, exfat_parameters, param, &result);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 265) if (opt < 0)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 266) return opt;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 267)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 268) switch (opt) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 269) case Opt_uid:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 270) opts->fs_uid = make_kuid(current_user_ns(), result.uint_32);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 271) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 272) case Opt_gid:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 273) opts->fs_gid = make_kgid(current_user_ns(), result.uint_32);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 274) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 275) case Opt_umask:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 276) opts->fs_fmask = result.uint_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 277) opts->fs_dmask = result.uint_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 278) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 279) case Opt_dmask:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 280) opts->fs_dmask = result.uint_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 281) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 282) case Opt_fmask:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 283) opts->fs_fmask = result.uint_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 284) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 285) case Opt_allow_utime:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 286) opts->allow_utime = result.uint_32 & 0022;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 287) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 288) case Opt_charset:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 289) exfat_free_iocharset(sbi);
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 290) opts->iocharset = param->string;
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 291) param->string = NULL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 292) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 293) case Opt_errors:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 294) opts->errors = result.uint_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 295) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 296) case Opt_discard:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 297) opts->discard = 1;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 298) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 299) case Opt_time_offset:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 300) /*
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 301) * Make the limit 24 just in case someone invents something
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 302) * unusual.
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 303) */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 304) if (result.int_32 < -24 * 60 || result.int_32 > 24 * 60)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 305) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 306) opts->time_offset = result.int_32;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 307) break;
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 308) case Opt_utf8:
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 309) case Opt_debug:
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 310) case Opt_namecase:
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 311) case Opt_codepage:
907fa893258ba (Namjae Jeon 2020-05-22 08:10:10 +0900 312) break;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 313) default:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 314) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 315) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 316)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 317) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 318) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 319)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 320) static void exfat_hash_init(struct super_block *sb)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 321) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 322) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 323) int i;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 324)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 325) spin_lock_init(&sbi->inode_hash_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 326) for (i = 0; i < EXFAT_HASH_SIZE; i++)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 327) INIT_HLIST_HEAD(&sbi->inode_hashtable[i]);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 328) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 329)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 330) static int exfat_read_root(struct inode *inode)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 331) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 332) struct super_block *sb = inode->i_sb;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 333) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 334) struct exfat_inode_info *ei = EXFAT_I(inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 335) struct exfat_chain cdir;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 336) int num_subdirs, num_clu = 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 337)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 338) exfat_chain_set(&ei->dir, sbi->root_dir, 0, ALLOC_FAT_CHAIN);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 339) ei->entry = -1;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 340) ei->start_clu = sbi->root_dir;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 341) ei->flags = ALLOC_FAT_CHAIN;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 342) ei->type = TYPE_DIR;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 343) ei->version = 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 344) ei->hint_bmap.off = EXFAT_EOF_CLUSTER;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 345) ei->hint_stat.eidx = 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 346) ei->hint_stat.clu = sbi->root_dir;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 347) ei->hint_femp.eidx = EXFAT_HINT_NONE;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 348)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 349) exfat_chain_set(&cdir, sbi->root_dir, 0, ALLOC_FAT_CHAIN);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 350) if (exfat_count_num_clusters(sb, &cdir, &num_clu))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 351) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 352) i_size_write(inode, num_clu << sbi->cluster_size_bits);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 353)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 354) num_subdirs = exfat_count_dir_entries(sb, &cdir);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 355) if (num_subdirs < 0)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 356) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 357) set_nlink(inode, num_subdirs + EXFAT_MIN_SUBDIR);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 358)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 359) inode->i_uid = sbi->options.fs_uid;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 360) inode->i_gid = sbi->options.fs_gid;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 361) inode_inc_iversion(inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 362) inode->i_generation = 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 363) inode->i_mode = exfat_make_mode(sbi, ATTR_SUBDIR, 0777);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 364) inode->i_op = &exfat_dir_inode_operations;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 365) inode->i_fop = &exfat_dir_operations;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 366)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 367) inode->i_blocks = ((i_size_read(inode) + (sbi->cluster_size - 1))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 368) & ~(sbi->cluster_size - 1)) >> inode->i_blkbits;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 369) EXFAT_I(inode)->i_pos = ((loff_t)sbi->root_dir << 32) | 0xffffffff;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 370) EXFAT_I(inode)->i_size_aligned = i_size_read(inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 371) EXFAT_I(inode)->i_size_ondisk = i_size_read(inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 372)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 373) exfat_save_attr(inode, ATTR_SUBDIR);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 374) inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 375) current_time(inode);
81df1ad40644b (Eric Sandeen 2020-04-21 11:13:10 +0900 376) exfat_truncate_atime(&inode->i_atime);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 377) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 378) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 379)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 380) static int exfat_calibrate_blocksize(struct super_block *sb, int logical_sect)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 381) {
b0516833d8096 (Tetsuhiro Kohada 2020-04-21 10:58:58 +0900 382) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 383)
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 384) if (!is_power_of_2(logical_sect)) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 385) exfat_err(sb, "bogus logical sector size %u", logical_sect);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 386) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 387) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 388)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 389) if (logical_sect < sb->s_blocksize) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 390) exfat_err(sb, "logical sector size too small for device (logical sector size = %u)",
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 391) logical_sect);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 392) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 393) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 394)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 395) if (logical_sect > sb->s_blocksize) {
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 396) brelse(sbi->boot_bh);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 397) sbi->boot_bh = NULL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 398)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 399) if (!sb_set_blocksize(sb, logical_sect)) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 400) exfat_err(sb, "unable to set blocksize %u",
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 401) logical_sect);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 402) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 403) }
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 404) sbi->boot_bh = sb_bread(sb, 0);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 405) if (!sbi->boot_bh) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 406) exfat_err(sb, "unable to read boot sector (logical sector size = %lu)",
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 407) sb->s_blocksize);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 408) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 409) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 410) }
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 411) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 412) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 413)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 414) static int exfat_read_boot_sector(struct super_block *sb)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 415) {
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 416) struct boot_sector *p_boot;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 417) struct exfat_sb_info *sbi = EXFAT_SB(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 418)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 419) /* set block size to read super block */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 420) sb_min_blocksize(sb, 512);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 421)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 422) /* read boot sector */
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 423) sbi->boot_bh = sb_bread(sb, 0);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 424) if (!sbi->boot_bh) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 425) exfat_err(sb, "unable to read boot sector");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 426) return -EIO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 427) }
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 428) p_boot = (struct boot_sector *)sbi->boot_bh->b_data;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 429)
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 430) /* check the validity of BOOT */
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 431) if (le16_to_cpu((p_boot->signature)) != BOOT_SIGNATURE) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 432) exfat_err(sb, "invalid boot record signature");
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 433) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 434) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 435)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 436) if (memcmp(p_boot->fs_name, STR_EXFAT, BOOTSEC_FS_NAME_LEN)) {
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 437) exfat_err(sb, "invalid fs_name"); /* fs_name may unprintable */
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 438) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 439) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 440)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 441) /*
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 442) * must_be_zero field must be filled with zero to prevent mounting
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 443) * from FAT volume.
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 444) */
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 445) if (memchr_inv(p_boot->must_be_zero, 0, sizeof(p_boot->must_be_zero)))
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 446) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 447)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 448) if (p_boot->num_fats != 1 && p_boot->num_fats != 2) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 449) exfat_err(sb, "bogus number of FAT structure");
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 450) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 451) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 452)
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 453) /*
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 454) * sect_size_bits could be at least 9 and at most 12.
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 455) */
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 456) if (p_boot->sect_size_bits < EXFAT_MIN_SECT_SIZE_BITS ||
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 457) p_boot->sect_size_bits > EXFAT_MAX_SECT_SIZE_BITS) {
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 458) exfat_err(sb, "bogus sector size bits : %u\n",
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 459) p_boot->sect_size_bits);
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 460) return -EINVAL;
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 461) }
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 462)
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 463) /*
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 464) * sect_per_clus_bits could be at least 0 and at most 25 - sect_size_bits.
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 465) */
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 466) if (p_boot->sect_per_clus_bits > EXFAT_MAX_SECT_PER_CLUS_BITS(p_boot)) {
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 467) exfat_err(sb, "bogus sectors bits per cluster : %u\n",
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 468) p_boot->sect_per_clus_bits);
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 469) return -EINVAL;
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 470) }
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 471)
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 472) sbi->sect_per_clus = 1 << p_boot->sect_per_clus_bits;
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 473) sbi->sect_per_clus_bits = p_boot->sect_per_clus_bits;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 474) sbi->cluster_size_bits = p_boot->sect_per_clus_bits +
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 475) p_boot->sect_size_bits;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 476) sbi->cluster_size = 1 << sbi->cluster_size_bits;
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 477) sbi->num_FAT_sectors = le32_to_cpu(p_boot->fat_length);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 478) sbi->FAT1_start_sector = le32_to_cpu(p_boot->fat_offset);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 479) sbi->FAT2_start_sector = le32_to_cpu(p_boot->fat_offset);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 480) if (p_boot->num_fats == 2)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 481) sbi->FAT2_start_sector += sbi->num_FAT_sectors;
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 482) sbi->data_start_sector = le32_to_cpu(p_boot->clu_offset);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 483) sbi->num_sectors = le64_to_cpu(p_boot->vol_length);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 484) /* because the cluster index starts with 2 */
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 485) sbi->num_clusters = le32_to_cpu(p_boot->clu_count) +
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 486) EXFAT_RESERVED_CLUSTERS;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 487)
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 488) sbi->root_dir = le32_to_cpu(p_boot->root_cluster);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 489) sbi->dentries_per_clu = 1 <<
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 490) (sbi->cluster_size_bits - DENTRY_SIZE_BITS);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 491)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 492) sbi->vol_flags = le16_to_cpu(p_boot->vol_flags);
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 493) sbi->vol_flags_persistent = sbi->vol_flags & (VOLUME_DIRTY | MEDIA_FAILURE);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 494) sbi->clu_srch_ptr = EXFAT_FIRST_CLUSTER;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 495) sbi->used_clusters = EXFAT_CLUSTERS_UNTRACKED;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 496)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 497) /* check consistencies */
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 498) if ((u64)sbi->num_FAT_sectors << p_boot->sect_size_bits <
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 499) (u64)sbi->num_clusters * 4) {
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 500) exfat_err(sb, "bogus fat length");
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 501) return -EINVAL;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 502) }
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 503)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 504) if (sbi->data_start_sector <
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 505) (u64)sbi->FAT1_start_sector +
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 506) (u64)sbi->num_FAT_sectors * p_boot->num_fats) {
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 507) exfat_err(sb, "bogus data start sector");
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 508) return -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 509) }
78c276f5495aa (Namjae Jeon 2021-02-01 09:23:37 +0900 510)
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 511) if (sbi->vol_flags & VOLUME_DIRTY)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 512) exfat_warn(sb, "Volume was not properly unmounted. Some data may be corrupt. Please run fsck.");
7018ec68f0824 (Tetsuhiro Kohada 2020-07-31 14:58:26 +0900 513) if (sbi->vol_flags & MEDIA_FAILURE)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 514) exfat_warn(sb, "Medium has reported failures. Some data may be lost.");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 515)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 516) /* exFAT file size is limited by a disk volume size */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 517) sb->s_maxbytes = (u64)(sbi->num_clusters - EXFAT_RESERVED_CLUSTERS) <<
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 518) sbi->cluster_size_bits;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 519)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 520) /* check logical sector size */
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 521) if (exfat_calibrate_blocksize(sb, 1 << p_boot->sect_size_bits))
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 522) return -EIO;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 523)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 524) return 0;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 525) }
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 526)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 527) static int exfat_verify_boot_region(struct super_block *sb)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 528) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 529) struct buffer_head *bh = NULL;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 530) u32 chksum = 0;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 531) __le32 *p_sig, *p_chksum;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 532) int sn, i;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 533)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 534) /* read boot sector sub-regions */
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 535) for (sn = 0; sn < 11; sn++) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 536) bh = sb_bread(sb, sn);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 537) if (!bh)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 538) return -EIO;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 539)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 540) if (sn != 0 && sn <= 8) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 541) /* extended boot sector sub-regions */
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 542) p_sig = (__le32 *)&bh->b_data[sb->s_blocksize - 4];
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 543) if (le32_to_cpu(*p_sig) != EXBOOT_SIGNATURE)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 544) exfat_warn(sb, "Invalid exboot-signature(sector = %d): 0x%08x",
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 545) sn, le32_to_cpu(*p_sig));
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 546) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 547)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 548) chksum = exfat_calc_chksum32(bh->b_data, sb->s_blocksize,
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 549) chksum, sn ? CS_DEFAULT : CS_BOOT_SECTOR);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 550) brelse(bh);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 551) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 552)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 553) /* boot checksum sub-regions */
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 554) bh = sb_bread(sb, sn);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 555) if (!bh)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 556) return -EIO;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 557)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 558) for (i = 0; i < sb->s_blocksize; i += sizeof(u32)) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 559) p_chksum = (__le32 *)&bh->b_data[i];
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 560) if (le32_to_cpu(*p_chksum) != chksum) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 561) exfat_err(sb, "Invalid boot checksum (boot checksum : 0x%08x, checksum : 0x%08x)",
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 562) le32_to_cpu(*p_chksum), chksum);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 563) brelse(bh);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 564) return -EINVAL;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 565) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 566) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 567) brelse(bh);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 568) return 0;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 569) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 570)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 571) /* mount the file system volume */
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 572) static int __exfat_fill_super(struct super_block *sb)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 573) {
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 574) int ret;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 575) struct exfat_sb_info *sbi = EXFAT_SB(sb);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 576)
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 577) ret = exfat_read_boot_sector(sb);
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 578) if (ret) {
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 579) exfat_err(sb, "failed to read boot sector");
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 580) goto free_bh;
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 581) }
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 582)
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 583) ret = exfat_verify_boot_region(sb);
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 584) if (ret) {
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 585) exfat_err(sb, "invalid boot region");
476189c0ef3b6 (Tetsuhiro Kohada 2020-05-31 18:30:17 +0900 586) goto free_bh;
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 587) }
33404a159828a (Tetsuhiro Kohada 2020-05-29 19:14:57 +0900 588)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 589) ret = exfat_create_upcase_table(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 590) if (ret) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 591) exfat_err(sb, "failed to load upcase table");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 592) goto free_bh;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 593) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 594)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 595) ret = exfat_load_bitmap(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 596) if (ret) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 597) exfat_err(sb, "failed to load alloc-bitmap");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 598) goto free_upcase_table;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 599) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 600)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 601) ret = exfat_count_used_clusters(sb, &sbi->used_clusters);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 602) if (ret) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 603) exfat_err(sb, "failed to scan clusters");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 604) goto free_alloc_bitmap;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 605) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 606)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 607) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 608)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 609) free_alloc_bitmap:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 610) exfat_free_bitmap(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 611) free_upcase_table:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 612) exfat_free_upcase_table(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 613) free_bh:
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 614) brelse(sbi->boot_bh);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 615) return ret;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 616) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 617)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 618) static int exfat_fill_super(struct super_block *sb, struct fs_context *fc)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 619) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 620) struct exfat_sb_info *sbi = sb->s_fs_info;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 621) struct exfat_mount_options *opts = &sbi->options;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 622) struct inode *root_inode;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 623) int err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 624)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 625) if (opts->allow_utime == (unsigned short)-1)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 626) opts->allow_utime = ~opts->fs_dmask & 0022;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 627)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 628) if (opts->discard) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 629) struct request_queue *q = bdev_get_queue(sb->s_bdev);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 630)
b7e038a92449f (Pali Rohár 2020-03-17 22:46:52 +0100 631) if (!blk_queue_discard(q)) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 632) exfat_warn(sb, "mounting with \"discard\" option, but the device does not support discard");
b7e038a92449f (Pali Rohár 2020-03-17 22:46:52 +0100 633) opts->discard = 0;
b7e038a92449f (Pali Rohár 2020-03-17 22:46:52 +0100 634) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 635) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 636)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 637) sb->s_flags |= SB_NODIRATIME;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 638) sb->s_magic = EXFAT_SUPER_MAGIC;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 639) sb->s_op = &exfat_sops;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 640)
674a9985b8e35 (Eric Sandeen 2020-04-17 14:43:49 +0900 641) sb->s_time_gran = 10 * NSEC_PER_MSEC;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 642) sb->s_time_min = EXFAT_MIN_TIMESTAMP_SECS;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 643) sb->s_time_max = EXFAT_MAX_TIMESTAMP_SECS;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 644)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 645) err = __exfat_fill_super(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 646) if (err) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 647) exfat_err(sb, "failed to recognize exfat type");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 648) goto check_nls_io;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 649) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 650)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 651) /* set up enough so that it can read an inode */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 652) exfat_hash_init(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 653)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 654) if (!strcmp(sbi->options.iocharset, "utf8"))
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 655) opts->utf8 = 1;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 656) else {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 657) sbi->nls_io = load_nls(sbi->options.iocharset);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 658) if (!sbi->nls_io) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 659) exfat_err(sb, "IO charset %s not found",
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 660) sbi->options.iocharset);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 661) err = -EINVAL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 662) goto free_table;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 663) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 664) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 665)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 666) if (sbi->options.utf8)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 667) sb->s_d_op = &exfat_utf8_dentry_ops;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 668) else
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 669) sb->s_d_op = &exfat_dentry_ops;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 670)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 671) root_inode = new_inode(sb);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 672) if (!root_inode) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 673) exfat_err(sb, "failed to allocate root inode");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 674) err = -ENOMEM;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 675) goto free_table;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 676) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 677)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 678) root_inode->i_ino = EXFAT_ROOT_INO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 679) inode_set_iversion(root_inode, 1);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 680) err = exfat_read_root(root_inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 681) if (err) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 682) exfat_err(sb, "failed to initialize root inode");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 683) goto put_inode;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 684) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 685)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 686) exfat_hash_inode(root_inode, EXFAT_I(root_inode)->i_pos);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 687) insert_inode_hash(root_inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 688)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 689) sb->s_root = d_make_root(root_inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 690) if (!sb->s_root) {
d1727d55c0327 (Joe Perches 2020-04-24 13:31:12 +0900 691) exfat_err(sb, "failed to get the root dentry");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 692) err = -ENOMEM;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 693) goto put_inode;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 694) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 695)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 696) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 697)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 698) put_inode:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 699) iput(root_inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 700) sb->s_root = NULL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 701)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 702) free_table:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 703) exfat_free_upcase_table(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 704) exfat_free_bitmap(sbi);
181a9e8009a8a (Tetsuhiro Kohada 2020-05-29 19:14:56 +0900 705) brelse(sbi->boot_bh);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 706)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 707) check_nls_io:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 708) unload_nls(sbi->nls_io);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 709) exfat_free_iocharset(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 710) sb->s_fs_info = NULL;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 711) kfree(sbi);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 712) return err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 713) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 714)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 715) static int exfat_get_tree(struct fs_context *fc)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 716) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 717) return get_tree_bdev(fc, exfat_fill_super);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 718) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 719)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 720) static void exfat_free(struct fs_context *fc)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 721) {
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 722) struct exfat_sb_info *sbi = fc->s_fs_info;
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 723)
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 724) if (sbi) {
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 725) exfat_free_iocharset(sbi);
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 726) kfree(sbi);
f341a7d8dcc4e (Al Viro 2020-06-03 09:48:36 +0900 727) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 728) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 729)
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 730) static int exfat_reconfigure(struct fs_context *fc)
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 731) {
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 732) fc->sb_flags |= SB_NODIRATIME;
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 733)
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 734) /* volume flag will be updated in exfat_sync_fs */
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 735) sync_filesystem(fc->root->d_sb);
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 736) return 0;
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 737) }
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 738)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 739) static const struct fs_context_operations exfat_context_ops = {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 740) .parse_param = exfat_parse_param,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 741) .get_tree = exfat_get_tree,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 742) .free = exfat_free,
a0271a15cf2cf (Hyunchul Lee 2020-06-16 14:34:45 +0900 743) .reconfigure = exfat_reconfigure,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 744) };
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 745)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 746) static int exfat_init_fs_context(struct fs_context *fc)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 747) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 748) struct exfat_sb_info *sbi;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 749)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 750) sbi = kzalloc(sizeof(struct exfat_sb_info), GFP_KERNEL);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 751) if (!sbi)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 752) return -ENOMEM;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 753)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 754) mutex_init(&sbi->s_lock);
5c2d728507299 (Hyeongseok Kim 2021-03-02 14:05:20 +0900 755) mutex_init(&sbi->bitmap_lock);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 756) ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 757) DEFAULT_RATELIMIT_BURST);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 758)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 759) sbi->options.fs_uid = current_uid();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 760) sbi->options.fs_gid = current_gid();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 761) sbi->options.fs_fmask = current->fs->umask;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 762) sbi->options.fs_dmask = current->fs->umask;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 763) sbi->options.allow_utime = -1;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 764) sbi->options.iocharset = exfat_default_iocharset;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 765) sbi->options.errors = EXFAT_ERRORS_RO;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 766)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 767) fc->s_fs_info = sbi;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 768) fc->ops = &exfat_context_ops;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 769) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 770) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 771)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 772) static struct file_system_type exfat_fs_type = {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 773) .owner = THIS_MODULE,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 774) .name = "exfat",
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 775) .init_fs_context = exfat_init_fs_context,
9acd0d53800c5 (Valdis Kletnieks 2020-03-02 15:21:45 +0900 776) .parameters = exfat_parameters,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 777) .kill_sb = kill_block_super,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 778) .fs_flags = FS_REQUIRES_DEV,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 779) };
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 780)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 781) static void exfat_inode_init_once(void *foo)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 782) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 783) struct exfat_inode_info *ei = (struct exfat_inode_info *)foo;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 784)
8ff006e57ad3a (Namjae Jeon 2020-09-29 09:09:49 +0900 785) spin_lock_init(&ei->cache_lru_lock);
8ff006e57ad3a (Namjae Jeon 2020-09-29 09:09:49 +0900 786) ei->nr_caches = 0;
8ff006e57ad3a (Namjae Jeon 2020-09-29 09:09:49 +0900 787) ei->cache_valid_id = EXFAT_CACHE_VALID + 1;
8ff006e57ad3a (Namjae Jeon 2020-09-29 09:09:49 +0900 788) INIT_LIST_HEAD(&ei->cache_lru);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 789) INIT_HLIST_NODE(&ei->i_hash_fat);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 790) inode_init_once(&ei->vfs_inode);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 791) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 792)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 793) static int __init init_exfat_fs(void)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 794) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 795) int err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 796)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 797) err = exfat_cache_init();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 798) if (err)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 799) return err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 800)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 801) exfat_inode_cachep = kmem_cache_create("exfat_inode_cache",
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 802) sizeof(struct exfat_inode_info),
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 803) 0, SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 804) exfat_inode_init_once);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 805) if (!exfat_inode_cachep) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 806) err = -ENOMEM;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 807) goto shutdown_cache;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 808) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 809)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 810) err = register_filesystem(&exfat_fs_type);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 811) if (err)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 812) goto destroy_cache;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 813)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 814) return 0;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 815)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 816) destroy_cache:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 817) kmem_cache_destroy(exfat_inode_cachep);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 818) shutdown_cache:
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 819) exfat_cache_shutdown();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 820) return err;
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 821) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 822)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 823) static void __exit exit_exfat_fs(void)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 824) {
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 825) /*
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 826) * Make sure all delayed rcu free inodes are flushed before we
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 827) * destroy cache.
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 828) */
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 829) rcu_barrier();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 830) kmem_cache_destroy(exfat_inode_cachep);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 831) unregister_filesystem(&exfat_fs_type);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 832) exfat_cache_shutdown();
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 833) }
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 834)
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 835) module_init(init_exfat_fs);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 836) module_exit(exit_exfat_fs);
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 837)
cd76ac258cd92 (Thomas Backlund 2020-04-04 23:29:43 +0300 838) MODULE_ALIAS_FS("exfat");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 839) MODULE_LICENSE("GPL");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 840) MODULE_DESCRIPTION("exFAT filesystem support");
719c1e1829166 (Namjae Jeon 2020-03-02 15:21:33 +0900 841) MODULE_AUTHOR("Samsung Electronics Co., Ltd.");