// SPDX-License-Identifier: GPL-2.0
/*
 *
 * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
 *
 *
 *                 terminology
 *
 * cluster - allocation unit     - 512,1K,2K,4K,...,2M
 * vcn - virtual cluster number  - Offset inside the file in clusters.
 * vbo - virtual byte offset     - Offset inside the file in bytes.
 * lcn - logical cluster number  - 0 based cluster in clusters heap.
 * lbo - logical byte offset     - Absolute position inside volume.
 * run - maps VCN to LCN         - Stored in attributes in packed form.
 * attr - attribute segment      - std/name/data etc records inside MFT.
 * mi  - MFT inode               - One MFT record(usually 1024 bytes or 4K), consists of attributes.
 * ni  - NTFS inode              - Extends linux inode. consists of one or more mft inodes.
 * index - unit inside directory - 2K, 4K, <=page size, does not depend on cluster size.
 *
 * WSL - Windows Subsystem for Linux
 * https://docs.microsoft.com/en-us/windows/wsl/file-permissions
 * It stores uid/gid/mode/dev in xattr
 *
 * ntfs allows up to 2^64 clusters per volume.
 * It means you should use 64 bits lcn to operate with ntfs.
 * Implementation of ntfs.sys uses only 32 bits lcn.
 * Default ntfs3 uses 32 bits lcn too.
 * ntfs3 built with CONFIG_NTFS3_64BIT_CLUSTER (ntfs3_64) uses 64 bits per lcn.
 *
 *
 *     ntfs limits, cluster size is 4K (2^12)
 * -----------------------------------------------------------------------------
 * | Volume size   | Clusters | ntfs.sys | ntfs3  | ntfs3_64 | mkntfs | chkdsk |
 * -----------------------------------------------------------------------------
 * | < 16T, 2^44   |  < 2^32  |  yes     |  yes   |   yes    |  yes   |  yes   |
 * | > 16T, 2^44   |  > 2^32  |  no      |  no    |   yes    |  yes   |  yes   |
 * ----------------------------------------------------------|------------------
 *
 * To mount large volumes as ntfs one should use large cluster size (up to 2M)
 * The maximum volume size in this case is 2^32 * 2^21 = 2^53 = 8P
 *
 *     ntfs limits, cluster size is 2M (2^21)
 * -----------------------------------------------------------------------------
 * | < 8P, 2^53    |  < 2^32  |  yes     |  yes   |   yes    |  yes   |  yes   |
 * | > 8P, 2^53    |  > 2^32  |  no      |  no    |   yes    |  yes   |  yes   |
 * ----------------------------------------------------------|------------------
 *
 */

#include <linux/blkdev.h>
#include <linux/buffer_head.h>
#include <linux/exportfs.h>
#include <linux/fs.h>
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#include <linux/log2.h>
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/nls.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/statfs.h>

#include "debug.h"
#include "ntfs.h"
#include "ntfs_fs.h"
#ifdef CONFIG_NTFS3_LZX_XPRESS
#include "lib/lib.h"
#endif

#ifdef CONFIG_PRINTK
/*
 * ntfs_printk - Trace warnings/notices/errors.
 *
 * Thanks Joe Perches <joe@perches.com> for implementation
 */
void ntfs_printk(const struct super_block *sb, const char *fmt, ...)
{
	struct va_format vaf;
	va_list args;
	int level;
	struct ntfs_sb_info *sbi = sb->s_fs_info;

	/* Should we use different ratelimits for warnings/notices/errors? */
	if (!___ratelimit(&sbi->msg_ratelimit, "ntfs3"))
		return;

	va_start(args, fmt);

	level = printk_get_level(fmt);
	vaf.fmt = printk_skip_level(fmt);
	vaf.va = &args;
	printk("%c%cntfs3(%s): %pV\n", KERN_SOH_ASCII, level, sb->s_id, &vaf);

	va_end(args);
}

static char s_name_buf[512];
static atomic_t s_name_buf_cnt = ATOMIC_INIT(1); // 1 means 'free s_name_buf'.

/*
 * ntfs_inode_printk
 *
 * Print warnings/notices/errors about inode using name or inode number.
 */
void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)
{
	struct super_block *sb = inode->i_sb;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	char *name;
	va_list args;
	struct va_format vaf;
	int level;

	if (!___ratelimit(&sbi->msg_ratelimit, "ntfs3"))
		return;

	/* Use static allocated buffer, if possible. */
	name = atomic_dec_and_test(&s_name_buf_cnt) ?
		       s_name_buf :
		       kmalloc(sizeof(s_name_buf), GFP_NOFS);

	if (name) {
		struct dentry *de = d_find_alias(inode);

		if (de) {
			int len;
			spin_lock(&de->d_lock);
			len = snprintf(name, sizeof(s_name_buf), " \"%s\"",
				       de->d_name.name);
			spin_unlock(&de->d_lock);
			if (len <= 0)
				name[0] = 0;
			else if (len >= sizeof(s_name_buf))
				name[sizeof(s_name_buf) - 1] = 0;
		} else {
			name[0] = 0;
		}
		dput(de); /* Cocci warns if placed in branch "if (de)" */
	}

	va_start(args, fmt);

	level = printk_get_level(fmt);
	vaf.fmt = printk_skip_level(fmt);
	vaf.va = &args;

	printk("%c%cntfs3(%s): ino=%lx,%s %pV\n", KERN_SOH_ASCII, level,
	       sb->s_id, inode->i_ino, name ? name : "", &vaf);

	va_end(args);

	atomic_inc(&s_name_buf_cnt);
	if (name != s_name_buf)
		kfree(name);
}
#endif

/*
 * Shared memory struct.
 *
 * On-disk ntfs's upcase table is created by ntfs formatter.
 * 'upcase' table is 128K bytes of memory.
 * We should read it into memory when mounting.
 * Several ntfs volumes likely use the same 'upcase' table.
 * It is good idea to share in-memory 'upcase' table between different volumes.
 * Unfortunately winxp/vista/win7 use different upcase tables.
 */
static DEFINE_SPINLOCK(s_shared_lock);

static struct {
	void *ptr;
	u32 len;
	int cnt;
} s_shared[8];

/*
 * ntfs_set_shared
 *
 * Return:
 * * @ptr - If pointer was saved in shared memory.
 * * NULL - If pointer was not shared.
 */
void *ntfs_set_shared(void *ptr, u32 bytes)
{
	void *ret = NULL;
	int i, j = -1;

	spin_lock(&s_shared_lock);
	for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
		if (!s_shared[i].cnt) {
			j = i;
		} else if (bytes == s_shared[i].len &&
			   !memcmp(s_shared[i].ptr, ptr, bytes)) {
			s_shared[i].cnt += 1;
			ret = s_shared[i].ptr;
			break;
		}
	}

	if (!ret && j != -1) {
		s_shared[j].ptr = ptr;
		s_shared[j].len = bytes;
		s_shared[j].cnt = 1;
		ret = ptr;
	}
	spin_unlock(&s_shared_lock);

	return ret;
}

/*
 * ntfs_put_shared
 *
 * Return:
 * * @ptr - If pointer is not shared anymore.
 * * NULL - If pointer is still shared.
 */
void *ntfs_put_shared(void *ptr)
{
	void *ret = ptr;
	int i;

	spin_lock(&s_shared_lock);
	for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
		if (s_shared[i].cnt && s_shared[i].ptr == ptr) {
			if (--s_shared[i].cnt)
				ret = NULL;
			break;
		}
	}
	spin_unlock(&s_shared_lock);

	return ret;
}

static inline void put_mount_options(struct ntfs_mount_options *options)
{
	kfree(options->nls_name);
	unload_nls(options->nls);
	kfree(options);
}

enum Opt {
	Opt_uid,
	Opt_gid,
	Opt_umask,
	Opt_dmask,
	Opt_fmask,
	Opt_immutable,
	Opt_discard,
	Opt_force,
	Opt_sparse,
	Opt_nohidden,
	Opt_hide_dot_files,
	Opt_windows_names,
	Opt_showmeta,
	Opt_acl,
	Opt_iocharset,
	Opt_prealloc,
	Opt_nocase,
	Opt_err,
};

// clang-format off
static const struct fs_parameter_spec ntfs_fs_parameters[] = {
	fsparam_uid("uid",		Opt_uid),
	fsparam_gid("gid",		Opt_gid),
	fsparam_u32oct("umask",		Opt_umask),
	fsparam_u32oct("dmask",		Opt_dmask),
	fsparam_u32oct("fmask",		Opt_fmask),
	fsparam_flag("sys_immutable",	Opt_immutable),
	fsparam_flag("discard",		Opt_discard),
	fsparam_flag("force",		Opt_force),
	fsparam_flag("sparse",		Opt_sparse),
	fsparam_flag("nohidden",	Opt_nohidden),
	fsparam_flag("hide_dot_files",	Opt_hide_dot_files),
	fsparam_flag("windows_names",	Opt_windows_names),
	fsparam_flag("showmeta",	Opt_showmeta),
	fsparam_flag("acl",		Opt_acl),
	fsparam_string("iocharset",	Opt_iocharset),
	fsparam_flag("prealloc",	Opt_prealloc),
	fsparam_flag("nocase",		Opt_nocase),
	{}
};
// clang-format on

/*
 * Load nls table or if @nls is utf8 then return NULL.
 *
 * It is good idea to use here "const char *nls".
 * But load_nls accepts "char*".
 */
static struct nls_table *ntfs_load_nls(char *nls)
{
	struct nls_table *ret;

	if (!nls)
		nls = CONFIG_NLS_DEFAULT;

	if (strcmp(nls, "utf8") == 0)
		return NULL;

	if (strcmp(nls, CONFIG_NLS_DEFAULT) == 0)
		return load_nls_default();

	ret = load_nls(nls);
	if (ret)
		return ret;

	return ERR_PTR(-EINVAL);
}

static int ntfs_fs_parse_param(struct fs_context *fc,
			       struct fs_parameter *param)
{
	struct ntfs_mount_options *opts = fc->fs_private;
	struct fs_parse_result result;
	int opt;

	opt = fs_parse(fc, ntfs_fs_parameters, param, &result);
	if (opt < 0)
		return opt;

	switch (opt) {
	case Opt_uid:
		opts->fs_uid = result.uid;
		break;
	case Opt_gid:
		opts->fs_gid = result.gid;
		break;
	case Opt_umask:
		if (result.uint_32 & ~07777)
			return invalf(fc, "ntfs3: Invalid value for umask.");
		opts->fs_fmask_inv = ~result.uint_32;
		opts->fs_dmask_inv = ~result.uint_32;
		opts->fmask = 1;
		opts->dmask = 1;
		break;
	case Opt_dmask:
		if (result.uint_32 & ~07777)
			return invalf(fc, "ntfs3: Invalid value for dmask.");
		opts->fs_dmask_inv = ~result.uint_32;
		opts->dmask = 1;
		break;
	case Opt_fmask:
		if (result.uint_32 & ~07777)
			return invalf(fc, "ntfs3: Invalid value for fmask.");
		opts->fs_fmask_inv = ~result.uint_32;
		opts->fmask = 1;
		break;
	case Opt_immutable:
		opts->sys_immutable = 1;
		break;
	case Opt_discard:
		opts->discard = 1;
		break;
	case Opt_force:
		opts->force = 1;
		break;
	case Opt_sparse:
		opts->sparse = 1;
		break;
	case Opt_nohidden:
		opts->nohidden = 1;
		break;
	case Opt_hide_dot_files:
		opts->hide_dot_files = 1;
		break;
	case Opt_windows_names:
		opts->windows_names = 1;
		break;
	case Opt_showmeta:
		opts->showmeta = 1;
		break;
	case Opt_acl:
		if (!result.negated)
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
			fc->sb_flags |= SB_POSIXACL;
#else
			return invalf(
				fc, "ntfs3: Support for ACL not compiled in!");
#endif
		else
			fc->sb_flags &= ~SB_POSIXACL;
		break;
	case Opt_iocharset:
		kfree(opts->nls_name);
		opts->nls_name = param->string;
		param->string = NULL;
		break;
	case Opt_prealloc:
		opts->prealloc = 1;
		break;
	case Opt_nocase:
		opts->nocase = 1;
		break;
	default:
		/* Should not be here unless we forget add case. */
		return -EINVAL;
	}
	return 0;
}

static int ntfs_fs_reconfigure(struct fs_context *fc)
{
	struct super_block *sb = fc->root->d_sb;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct ntfs_mount_options *new_opts = fc->fs_private;
	int ro_rw;

	/* If ntfs3 is used as legacy ntfs enforce read-only mode. */
	if (is_legacy_ntfs(sb)) {
		fc->sb_flags |= SB_RDONLY;
		goto out;
	}

	ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY);
	if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) {
		errorf(fc,
		       "ntfs3: Couldn't remount rw because journal is not replayed. Please umount/remount instead\n");
		return -EINVAL;
	}

	new_opts->nls = ntfs_load_nls(new_opts->nls_name);
	if (IS_ERR(new_opts->nls)) {
		new_opts->nls = NULL;
		errorf(fc, "ntfs3: Cannot load iocharset %s",
		       new_opts->nls_name);
		return -EINVAL;
	}
	if (new_opts->nls != sbi->options->nls)
		return invalf(
			fc,
			"ntfs3: Cannot use different iocharset when remounting!");

	if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) &&
	    !new_opts->force) {
		errorf(fc,
		       "ntfs3: Volume is dirty and \"force\" flag is not set!");
		return -EINVAL;
	}

out:
	sync_filesystem(sb);
	swap(sbi->options, fc->fs_private);

	return 0;
}

#ifdef CONFIG_PROC_FS
static struct proc_dir_entry *proc_info_root;

/*
 * ntfs3_volinfo:
 *
 * The content of /proc/fs/ntfs3/<dev>/volinfo
 *
 * ntfs3.1
 * cluster size
 * number of clusters
 * total number of mft records
 * number of used mft records ~= number of files + folders
 * real state of ntfs "dirty"/"clean"
 * current state of ntfs "dirty"/"clean"
*/
static int ntfs3_volinfo(struct seq_file *m, void *o)
{
	struct super_block *sb = m->private;
	struct ntfs_sb_info *sbi = sb->s_fs_info;

	seq_printf(m, "ntfs%d.%d\n%u\n%zu\n%zu\n%zu\n%s\n%s\n",
		   sbi->volume.major_ver, sbi->volume.minor_ver,
		   sbi->cluster_size, sbi->used.bitmap.nbits,
		   sbi->mft.bitmap.nbits,
		   sbi->mft.bitmap.nbits - wnd_zeroes(&sbi->mft.bitmap),
		   sbi->volume.real_dirty ? "dirty" : "clean",
		   (sbi->volume.flags & VOLUME_FLAG_DIRTY) ? "dirty" : "clean");

	return 0;
}

static int ntfs3_volinfo_open(struct inode *inode, struct file *file)
{
	return single_open(file, ntfs3_volinfo, pde_data(inode));
}

/* read /proc/fs/ntfs3/<dev>/label */
static int ntfs3_label_show(struct seq_file *m, void *o)
{
	struct super_block *sb = m->private;
	struct ntfs_sb_info *sbi = sb->s_fs_info;

	seq_printf(m, "%s\n", sbi->volume.label);

	return 0;
}

/* write /proc/fs/ntfs3/<dev>/label */
static ssize_t ntfs3_label_write(struct file *file, const char __user *buffer,
				 size_t count, loff_t *ppos)
{
	int err;
	struct super_block *sb = pde_data(file_inode(file));
	ssize_t ret = count;
	u8 *label;

	if (sb_rdonly(sb))
		return -EROFS;

	label = kmalloc(count, GFP_NOFS);

	if (!label)
		return -ENOMEM;

	if (copy_from_user(label, buffer, ret)) {
		ret = -EFAULT;
		goto out;
	}
	while (ret > 0 && label[ret - 1] == '\n')
		ret -= 1;

	err = ntfs_set_label(sb->s_fs_info, label, ret);

	if (err < 0) {
		ntfs_err(sb, "failed (%d) to write label", err);
		ret = err;
		goto out;
	}

	*ppos += count;
	ret = count;
out:
	kfree(label);
	return ret;
}

static int ntfs3_label_open(struct inode *inode, struct file *file)
{
	return single_open(file, ntfs3_label_show, pde_data(inode));
}

static const struct proc_ops ntfs3_volinfo_fops = {
	.proc_read = seq_read,
	.proc_lseek = seq_lseek,
	.proc_release = single_release,
	.proc_open = ntfs3_volinfo_open,
};

static const struct proc_ops ntfs3_label_fops = {
	.proc_read = seq_read,
	.proc_lseek = seq_lseek,
	.proc_release = single_release,
	.proc_open = ntfs3_label_open,
	.proc_write = ntfs3_label_write,
};

#endif

static struct kmem_cache *ntfs_inode_cachep;

static struct inode *ntfs_alloc_inode(struct super_block *sb)
{
	struct ntfs_inode *ni = alloc_inode_sb(sb, ntfs_inode_cachep, GFP_NOFS);

	if (!ni)
		return NULL;

	memset(ni, 0, offsetof(struct ntfs_inode, vfs_inode));
	mutex_init(&ni->ni_lock);
	return &ni->vfs_inode;
}

static void ntfs_free_inode(struct inode *inode)
{
	struct ntfs_inode *ni = ntfs_i(inode);

	mutex_destroy(&ni->ni_lock);
	kmem_cache_free(ntfs_inode_cachep, ni);
}

static void init_once(void *foo)
{
	struct ntfs_inode *ni = foo;

	inode_init_once(&ni->vfs_inode);
}

/*
 * Noinline to reduce binary size.
 */
static noinline void ntfs3_put_sbi(struct ntfs_sb_info *sbi)
{
	wnd_close(&sbi->mft.bitmap);
	wnd_close(&sbi->used.bitmap);

	if (sbi->mft.ni) {
		iput(&sbi->mft.ni->vfs_inode);
		sbi->mft.ni = NULL;
	}

	if (sbi->security.ni) {
		iput(&sbi->security.ni->vfs_inode);
		sbi->security.ni = NULL;
	}

	if (sbi->reparse.ni) {
		iput(&sbi->reparse.ni->vfs_inode);
		sbi->reparse.ni = NULL;
	}

	if (sbi->objid.ni) {
		iput(&sbi->objid.ni->vfs_inode);
		sbi->objid.ni = NULL;
	}

	if (sbi->volume.ni) {
		iput(&sbi->volume.ni->vfs_inode);
		sbi->volume.ni = NULL;
	}

	ntfs_update_mftmirr(sbi, 0);

	indx_clear(&sbi->security.index_sii);
	indx_clear(&sbi->security.index_sdh);
	indx_clear(&sbi->reparse.index_r);
	indx_clear(&sbi->objid.index_o);
}

static void ntfs3_free_sbi(struct ntfs_sb_info *sbi)
{
	kfree(sbi->new_rec);
	kvfree(ntfs_put_shared(sbi->upcase));
	kvfree(sbi->def_table);
	kfree(sbi->compress.lznt);
#ifdef CONFIG_NTFS3_LZX_XPRESS
	xpress_free_decompressor(sbi->compress.xpress);
	lzx_free_decompressor(sbi->compress.lzx);
#endif
	kfree(sbi);
}

static void ntfs_put_super(struct super_block *sb)
{
	struct ntfs_sb_info *sbi = sb->s_fs_info;

#ifdef CONFIG_PROC_FS
	// Remove /proc/fs/ntfs3/..
	if (sbi->procdir) {
		remove_proc_entry("label", sbi->procdir);
		remove_proc_entry("volinfo", sbi->procdir);
		remove_proc_entry(sb->s_id, proc_info_root);
		sbi->procdir = NULL;
	}
#endif

	/* Mark rw ntfs as clear, if possible. */
	ntfs_set_state(sbi, NTFS_DIRTY_CLEAR);
	ntfs3_put_sbi(sbi);
}

static int ntfs_statfs(struct dentry *dentry, struct kstatfs *buf)
{
	struct super_block *sb = dentry->d_sb;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct wnd_bitmap *wnd = &sbi->used.bitmap;

	buf->f_type = sb->s_magic;
	buf->f_bsize = sbi->cluster_size;
	buf->f_blocks = wnd->nbits;

	buf->f_bfree = buf->f_bavail = wnd_zeroes(wnd);
	buf->f_fsid.val[0] = sbi->volume.ser_num;
	buf->f_fsid.val[1] = (sbi->volume.ser_num >> 32);
	buf->f_namelen = NTFS_NAME_LEN;

	return 0;
}

static int ntfs_show_options(struct seq_file *m, struct dentry *root)
{
	struct super_block *sb = root->d_sb;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct ntfs_mount_options *opts = sbi->options;
	struct user_namespace *user_ns = seq_user_ns(m);

	seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid));
	seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid));
	if (opts->dmask)
		seq_printf(m, ",dmask=%04o", opts->fs_dmask_inv ^ 0xffff);
	if (opts->fmask)
		seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff);
	if (opts->sys_immutable)
		seq_puts(m, ",sys_immutable");
	if (opts->discard)
		seq_puts(m, ",discard");
	if (opts->force)
		seq_puts(m, ",force");
	if (opts->sparse)
		seq_puts(m, ",sparse");
	if (opts->nohidden)
		seq_puts(m, ",nohidden");
	if (opts->hide_dot_files)
		seq_puts(m, ",hide_dot_files");
	if (opts->windows_names)
		seq_puts(m, ",windows_names");
	if (opts->showmeta)
		seq_puts(m, ",showmeta");
	if (sb->s_flags & SB_POSIXACL)
		seq_puts(m, ",acl");
	if (opts->nls)
		seq_printf(m, ",iocharset=%s", opts->nls->charset);
	else
		seq_puts(m, ",iocharset=utf8");
	if (opts->prealloc)
		seq_puts(m, ",prealloc");
	if (opts->nocase)
		seq_puts(m, ",nocase");

	return 0;
}

/*
 * ntfs_shutdown - super_operations::shutdown
 */
static void ntfs_shutdown(struct super_block *sb)
{
	set_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->flags);
}

/*
 * ntfs_sync_fs - super_operations::sync_fs
 */
static int ntfs_sync_fs(struct super_block *sb, int wait)
{
	int err = 0, err2;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct ntfs_inode *ni;
	struct inode *inode;

	if (unlikely(ntfs3_forced_shutdown(sb)))
		return -EIO;

	ni = sbi->security.ni;
	if (ni) {
		inode = &ni->vfs_inode;
		err2 = _ni_write_inode(inode, wait);
		if (err2 && !err)
			err = err2;
	}

	ni = sbi->objid.ni;
	if (ni) {
		inode = &ni->vfs_inode;
		err2 = _ni_write_inode(inode, wait);
		if (err2 && !err)
			err = err2;
	}

	ni = sbi->reparse.ni;
	if (ni) {
		inode = &ni->vfs_inode;
		err2 = _ni_write_inode(inode, wait);
		if (err2 && !err)
			err = err2;
	}

	if (!err)
		ntfs_set_state(sbi, NTFS_DIRTY_CLEAR);

	ntfs_update_mftmirr(sbi, wait);

	return err;
}

static const struct super_operations ntfs_sops = {
	.alloc_inode = ntfs_alloc_inode,
	.free_inode = ntfs_free_inode,
	.evict_inode = ntfs_evict_inode,
	.put_super = ntfs_put_super,
	.statfs = ntfs_statfs,
	.show_options = ntfs_show_options,
	.shutdown = ntfs_shutdown,
	.sync_fs = ntfs_sync_fs,
	.write_inode = ntfs3_write_inode,
};

static struct inode *ntfs_export_get_inode(struct super_block *sb, u64 ino,
					   u32 generation)
{
	struct MFT_REF ref;
	struct inode *inode;

	ref.low = cpu_to_le32(ino);
#ifdef CONFIG_NTFS3_64BIT_CLUSTER
	ref.high = cpu_to_le16(ino >> 32);
#else
	ref.high = 0;
#endif
	ref.seq = cpu_to_le16(generation);

	inode = ntfs_iget5(sb, &ref, NULL);
	if (!IS_ERR(inode) && is_bad_inode(inode)) {
		iput(inode);
		inode = ERR_PTR(-ESTALE);
	}

	return inode;
}

static struct dentry *ntfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
					int fh_len, int fh_type)
{
	return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
				    ntfs_export_get_inode);
}

static struct dentry *ntfs_fh_to_parent(struct super_block *sb, struct fid *fid,
					int fh_len, int fh_type)
{
	return generic_fh_to_parent(sb, fid, fh_len, fh_type,
				    ntfs_export_get_inode);
}

/* TODO: == ntfs_sync_inode */
static int ntfs_nfs_commit_metadata(struct inode *inode)
{
	return _ni_write_inode(inode, 1);
}

static const struct export_operations ntfs_export_ops = {
	.encode_fh = generic_encode_ino32_fh,
	.fh_to_dentry = ntfs_fh_to_dentry,
	.fh_to_parent = ntfs_fh_to_parent,
	.get_parent = ntfs3_get_parent,
	.commit_metadata = ntfs_nfs_commit_metadata,
};

/*
 * format_size_gb - Return Gb,Mb to print with "%u.%02u Gb".
 */
static u32 format_size_gb(const u64 bytes, u32 *mb)
{
	/* Do simple right 30 bit shift of 64 bit value. */
	u64 kbytes = bytes >> 10;
	u32 kbytes32 = kbytes;

	*mb = (100 * (kbytes32 & 0xfffff) + 0x7ffff) >> 20;
	if (*mb >= 100)
		*mb = 99;

	return (kbytes32 >> 20) | (((u32)(kbytes >> 32)) << 12);
}

static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
{
	if (boot->sectors_per_clusters <= 0x80)
		return boot->sectors_per_clusters;
	if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
		return 1U << (-(s8)boot->sectors_per_clusters);
	return -EINVAL;
}

/*
 * ntfs_init_from_boot - Init internal info from on-disk boot sector.
 *
 * NTFS mount begins from boot - special formatted 512 bytes.
 * There are two boots: the first and the last 512 bytes of volume.
 * The content of boot is not changed during ntfs life.
 *
 * NOTE: ntfs.sys checks only first (primary) boot.
 * chkdsk checks both boots.
 */
static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
			       u64 dev_size, struct NTFS_BOOT **boot2)
{
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	int err;
	u32 mb, gb, boot_sector_size, sct_per_clst, record_size;
	u64 sectors, clusters, mlcn, mlcn2, dev_size0;
	struct NTFS_BOOT *boot;
	struct buffer_head *bh;
	struct MFT_REC *rec;
	u16 fn, ao;
	u8 cluster_bits;
	u32 boot_off = 0;
	sector_t boot_block = 0;
	const char *hint = "Primary boot";

	/* Save original dev_size. Used with alternative boot. */
	dev_size0 = dev_size;

	sbi->volume.blocks = dev_size >> PAGE_SHIFT;

read_boot:
	bh = ntfs_bread(sb, boot_block);
	if (!bh)
		return boot_block ? -EINVAL : -EIO;

	err = -EINVAL;

	/* Corrupted image; do not read OOB */
	if (bh->b_size - sizeof(*boot) < boot_off)
		goto out;

	boot = (struct NTFS_BOOT *)Add2Ptr(bh->b_data, boot_off);

	if (memcmp(boot->system_id, "NTFS    ", sizeof("NTFS    ") - 1)) {
		ntfs_err(sb, "%s signature is not NTFS.", hint);
		goto out;
	}

	/* 0x55AA is not mandaroty. Thanks Maxim Suhanov*/
	/*if (0x55 != boot->boot_magic[0] || 0xAA != boot->boot_magic[1])
	 *	goto out;
	 */

	boot_sector_size = ((u32)boot->bytes_per_sector[1] << 8) |
			   boot->bytes_per_sector[0];
	if (boot_sector_size < SECTOR_SIZE ||
	    !is_power_of_2(boot_sector_size)) {
		ntfs_err(sb, "%s: invalid bytes per sector %u.", hint,
			 boot_sector_size);
		goto out;
	}

	/* cluster size: 512, 1K, 2K, 4K, ... 2M */
	sct_per_clst = true_sectors_per_clst(boot);
	if ((int)sct_per_clst < 0 || !is_power_of_2(sct_per_clst)) {
		ntfs_err(sb, "%s: invalid sectors per cluster %u.", hint,
			 sct_per_clst);
		goto out;
	}

	sbi->cluster_size = boot_sector_size * sct_per_clst;
	sbi->cluster_bits = cluster_bits = blksize_bits(sbi->cluster_size);
	sbi->cluster_mask = sbi->cluster_size - 1;
	sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask;

	mlcn = le64_to_cpu(boot->mft_clst);
	mlcn2 = le64_to_cpu(boot->mft2_clst);
	sectors = le64_to_cpu(boot->sectors_per_volume);

	if (mlcn * sct_per_clst >= sectors || mlcn2 * sct_per_clst >= sectors) {
		ntfs_err(
			sb,
			"%s: start of MFT 0x%llx (0x%llx) is out of volume 0x%llx.",
			hint, mlcn, mlcn2, sectors);
		goto out;
	}

	if (boot->record_size >= 0) {
		record_size = (u32)boot->record_size << cluster_bits;
	} else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) {
		record_size = 1u << (-boot->record_size);
	} else {
		ntfs_err(sb, "%s: invalid record size %d.", hint,
			 boot->record_size);
		goto out;
	}

	sbi->record_size = record_size;
	sbi->record_bits = blksize_bits(record_size);
	sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes

	/* Check MFT record size. */
	if (record_size < SECTOR_SIZE || !is_power_of_2(record_size)) {
		ntfs_err(sb, "%s: invalid bytes per MFT record %u (%d).", hint,
			 record_size, boot->record_size);
		goto out;
	}

	if (record_size > MAXIMUM_BYTES_PER_MFT) {
		ntfs_err(sb, "Unsupported bytes per MFT record %u.",
			 record_size);
		goto out;
	}

	if (boot->index_size >= 0) {
		sbi->index_size = (u32)boot->index_size << cluster_bits;
	} else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) {
		sbi->index_size = 1u << (-boot->index_size);
	} else {
		ntfs_err(sb, "%s: invalid index size %d.", hint,
			 boot->index_size);
		goto out;
	}

	/* Check index record size. */
	if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) {
		ntfs_err(sb, "%s: invalid bytes per index %u(%d).", hint,
			 sbi->index_size, boot->index_size);
		goto out;
	}

	if (sbi->index_size > MAXIMUM_BYTES_PER_INDEX) {
		ntfs_err(sb, "%s: unsupported bytes per index %u.", hint,
			 sbi->index_size);
		goto out;
	}

	sbi->volume.size = sectors * boot_sector_size;

	gb = format_size_gb(sbi->volume.size + boot_sector_size, &mb);

	/*
	 * - Volume formatted and mounted with the same sector size.
	 * - Volume formatted 4K and mounted as 512.
	 * - Volume formatted 512 and mounted as 4K.
	 */
	if (boot_sector_size != sector_size) {
		ntfs_warn(
			sb,
			"Different NTFS sector size (%u) and media sector size (%u).",
			boot_sector_size, sector_size);
		dev_size += sector_size - 1;
	}

	sbi->mft.lbo = mlcn << cluster_bits;
	sbi->mft.lbo2 = mlcn2 << cluster_bits;

	/* Compare boot's cluster and sector. */
	if (sbi->cluster_size < boot_sector_size) {
		ntfs_err(sb, "%s: invalid bytes per cluster (%u).", hint,
			 sbi->cluster_size);
		goto out;
	}

	/* Compare boot's cluster and media sector. */
	if (sbi->cluster_size < sector_size) {
		/* No way to use ntfs_get_block in this case. */
		ntfs_err(
			sb,
			"Failed to mount 'cause NTFS's cluster size (%u) is less than media sector size (%u).",
			sbi->cluster_size, sector_size);
		goto out;
	}

	sbi->max_bytes_per_attr =
		record_size - ALIGN(MFTRECORD_FIXUP_OFFSET, 8) -
		ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) -
		ALIGN(sizeof(enum ATTR_TYPE), 8);

	sbi->volume.ser_num = le64_to_cpu(boot->serial_num);

	/* Warning if RAW volume. */
	if (dev_size < sbi->volume.size + boot_sector_size) {
		u32 mb0, gb0;

		gb0 = format_size_gb(dev_size, &mb0);
		ntfs_warn(
			sb,
			"RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only.",
			gb, mb, gb0, mb0);
		sb->s_flags |= SB_RDONLY;
	}

	clusters = sbi->volume.size >> cluster_bits;
#ifndef CONFIG_NTFS3_64BIT_CLUSTER
	/* 32 bits per cluster. */
	if (clusters >> 32) {
		ntfs_notice(
			sb,
			"NTFS %u.%02u Gb is too big to use 32 bits per cluster.",
			gb, mb);
		goto out;
	}
#elif BITS_PER_LONG < 64
#error "CONFIG_NTFS3_64BIT_CLUSTER incompatible in 32 bit OS"
#endif

	sbi->used.bitmap.nbits = clusters;

	rec = kzalloc(record_size, GFP_NOFS);
	if (!rec) {
		err = -ENOMEM;
		goto out;
	}

	sbi->new_rec = rec;
	rec->rhdr.sign = NTFS_FILE_SIGNATURE;
	rec->rhdr.fix_off = cpu_to_le16(MFTRECORD_FIXUP_OFFSET);
	fn = (sbi->record_size >> SECTOR_SHIFT) + 1;
	rec->rhdr.fix_num = cpu_to_le16(fn);
	ao = ALIGN(MFTRECORD_FIXUP_OFFSET + sizeof(short) * fn, 8);
	rec->attr_off = cpu_to_le16(ao);
	rec->used = cpu_to_le32(ao + ALIGN(sizeof(enum ATTR_TYPE), 8));
	rec->total = cpu_to_le32(sbi->record_size);
	((struct ATTRIB *)Add2Ptr(rec, ao))->type = ATTR_END;

	sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE));

	sbi->block_mask = sb->s_blocksize - 1;
	sbi->blocks_per_cluster = sbi->cluster_size >> sb->s_blocksize_bits;
	sbi->volume.blocks = sbi->volume.size >> sb->s_blocksize_bits;

	/* Maximum size for normal files. */
	sbi->maxbytes = (clusters << cluster_bits) - 1;

#ifdef CONFIG_NTFS3_64BIT_CLUSTER
	if (clusters >= (1ull << (64 - cluster_bits)))
		sbi->maxbytes = -1;
	sbi->maxbytes_sparse = -1;
	sb->s_maxbytes = MAX_LFS_FILESIZE;
#else
	/* Maximum size for sparse file. */
	sbi->maxbytes_sparse = (1ull << (cluster_bits + 32)) - 1;
	sb->s_maxbytes = 0xFFFFFFFFull << cluster_bits;
#endif

	/*
	 * Compute the MFT zone at two steps.
	 * It would be nice if we are able to allocate 1/8 of
	 * total clusters for MFT but not more then 512 MB.
	 */
	sbi->zone_max = min_t(CLST, 0x20000000 >> cluster_bits, clusters >> 3);

	err = 0;

	if (bh->b_blocknr && !sb_rdonly(sb)) {
		/*
	 	 * Alternative boot is ok but primary is not ok.
	 	 * Do not update primary boot here 'cause it may be faked boot.
	 	 * Let ntfs to be mounted and update boot later.
		 */
		*boot2 = kmemdup(boot, sizeof(*boot), GFP_NOFS | __GFP_NOWARN);
	}

out:
	brelse(bh);

	if (err == -EINVAL && !boot_block && dev_size0 > PAGE_SHIFT) {
		u32 block_size = min_t(u32, sector_size, PAGE_SIZE);
		u64 lbo = dev_size0 - sizeof(*boot);

		boot_block = lbo >> blksize_bits(block_size);
		boot_off = lbo & (block_size - 1);
		if (boot_block && block_size >= boot_off + sizeof(*boot)) {
			/*
			 * Try alternative boot (last sector)
			 */
			sb_set_blocksize(sb, block_size);
			hint = "Alternative boot";
			dev_size = dev_size0; /* restore original size. */
			goto read_boot;
		}
	}

	return err;
}

/*
 * ntfs_fill_super - Try to mount.
 */
static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
{
	int err;
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct block_device *bdev = sb->s_bdev;
	struct ntfs_mount_options *options;
	struct inode *inode;
	struct ntfs_inode *ni;
	size_t i, tt, bad_len, bad_frags;
	CLST vcn, lcn, len;
	struct ATTRIB *attr;
	const struct VOLUME_INFO *info;
	u32 done, bytes;
	struct ATTR_DEF_ENTRY *t;
	u16 *shared;
	struct MFT_REF ref;
	bool ro = sb_rdonly(sb);
	struct NTFS_BOOT *boot2 = NULL;

	ref.high = 0;

	sbi->sb = sb;
	sbi->options = options = fc->fs_private;
	fc->fs_private = NULL;
	sb->s_flags |= SB_NODIRATIME;
	sb->s_magic = 0x7366746e; // "ntfs"
	sb->s_op = &ntfs_sops;
	sb->s_export_op = &ntfs_export_ops;
	sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec
	sb->s_xattr = ntfs_xattr_handlers;
	sb->s_d_op = options->nocase ? &ntfs_dentry_ops : NULL;

	options->nls = ntfs_load_nls(options->nls_name);
	if (IS_ERR(options->nls)) {
		options->nls = NULL;
		errorf(fc, "Cannot load nls %s", options->nls_name);
		err = -EINVAL;
		goto out;
	}

	if (bdev_max_discard_sectors(bdev) && bdev_discard_granularity(bdev)) {
		sbi->discard_granularity = bdev_discard_granularity(bdev);
		sbi->discard_granularity_mask_inv =
			~(u64)(sbi->discard_granularity - 1);
	}

	/* Parse boot. */
	err = ntfs_init_from_boot(sb, bdev_logical_block_size(bdev),
				  bdev_nr_bytes(bdev), &boot2);
	if (err)
		goto out;

	/*
	 * Load $Volume. This should be done before $LogFile
	 * 'cause 'sbi->volume.ni' is used in 'ntfs_set_state'.
	 */
	ref.low = cpu_to_le32(MFT_REC_VOL);
	ref.seq = cpu_to_le16(MFT_REC_VOL);
	inode = ntfs_iget5(sb, &ref, &NAME_VOLUME);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $Volume (%d).", err);
		goto out;
	}

	ni = ntfs_i(inode);

	/* Load and save label (not necessary). */
	attr = ni_find_attr(ni, NULL, NULL, ATTR_LABEL, NULL, 0, NULL, NULL);

	if (!attr) {
		/* It is ok if no ATTR_LABEL */
	} else if (!attr->non_res && !is_attr_ext(attr)) {
		/* $AttrDef allows labels to be up to 128 symbols. */
		err = utf16s_to_utf8s(resident_data(attr),
				      le32_to_cpu(attr->res.data_size) >> 1,
				      UTF16_LITTLE_ENDIAN, sbi->volume.label,
				      sizeof(sbi->volume.label));
		if (err < 0)
			sbi->volume.label[0] = 0;
	} else {
		/* Should we break mounting here? */
		//err = -EINVAL;
		//goto put_inode_out;
	}

	attr = ni_find_attr(ni, attr, NULL, ATTR_VOL_INFO, NULL, 0, NULL, NULL);
	if (!attr || is_attr_ext(attr) ||
	    !(info = resident_data_ex(attr, SIZEOF_ATTRIBUTE_VOLUME_INFO))) {
		ntfs_err(sb, "$Volume is corrupted.");
		err = -EINVAL;
		goto put_inode_out;
	}

	sbi->volume.major_ver = info->major_ver;
	sbi->volume.minor_ver = info->minor_ver;
	sbi->volume.flags = info->flags;
	sbi->volume.ni = ni;
	if (info->flags & VOLUME_FLAG_DIRTY) {
		sbi->volume.real_dirty = true;
		ntfs_info(sb, "It is recommened to use chkdsk.");
	}

	/* Load $MFTMirr to estimate recs_mirr. */
	ref.low = cpu_to_le32(MFT_REC_MIRR);
	ref.seq = cpu_to_le16(MFT_REC_MIRR);
	inode = ntfs_iget5(sb, &ref, &NAME_MIRROR);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $MFTMirr (%d).", err);
		goto out;
	}

	sbi->mft.recs_mirr = ntfs_up_cluster(sbi, inode->i_size) >>
			     sbi->record_bits;

	iput(inode);

	/* Load LogFile to replay. */
	ref.low = cpu_to_le32(MFT_REC_LOG);
	ref.seq = cpu_to_le16(MFT_REC_LOG);
	inode = ntfs_iget5(sb, &ref, &NAME_LOGFILE);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load \x24LogFile (%d).", err);
		goto out;
	}

	ni = ntfs_i(inode);

	err = ntfs_loadlog_and_replay(ni, sbi);
	if (err)
		goto put_inode_out;

	iput(inode);

	if ((sbi->flags & NTFS_FLAGS_NEED_REPLAY) && !ro) {
		ntfs_warn(sb, "failed to replay log file. Can't mount rw!");
		err = -EINVAL;
		goto out;
	}

	if ((sbi->volume.flags & VOLUME_FLAG_DIRTY) && !ro && !options->force) {
		ntfs_warn(sb, "volume is dirty and \"force\" flag is not set!");
		err = -EINVAL;
		goto out;
	}

	/* Load $MFT. */
	ref.low = cpu_to_le32(MFT_REC_MFT);
	ref.seq = cpu_to_le16(1);

	inode = ntfs_iget5(sb, &ref, &NAME_MFT);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $MFT (%d).", err);
		goto out;
	}

	ni = ntfs_i(inode);

	sbi->mft.used = ni->i_valid >> sbi->record_bits;
	tt = inode->i_size >> sbi->record_bits;
	sbi->mft.next_free = MFT_REC_USER;

	err = wnd_init(&sbi->mft.bitmap, sb, tt);
	if (err)
		goto put_inode_out;

	err = ni_load_all_mi(ni);
	if (err) {
		ntfs_err(sb, "Failed to load $MFT's subrecords (%d).", err);
		goto put_inode_out;
	}

	sbi->mft.ni = ni;

	/* Load $Bitmap. */
	ref.low = cpu_to_le32(MFT_REC_BITMAP);
	ref.seq = cpu_to_le16(MFT_REC_BITMAP);
	inode = ntfs_iget5(sb, &ref, &NAME_BITMAP);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $Bitmap (%d).", err);
		goto out;
	}

#ifndef CONFIG_NTFS3_64BIT_CLUSTER
	if (inode->i_size >> 32) {
		err = -EINVAL;
		goto put_inode_out;
	}
#endif

	/* Check bitmap boundary. */
	tt = sbi->used.bitmap.nbits;
	if (inode->i_size < ntfs3_bitmap_size(tt)) {
		ntfs_err(sb, "$Bitmap is corrupted.");
		err = -EINVAL;
		goto put_inode_out;
	}

	err = wnd_init(&sbi->used.bitmap, sb, tt);
	if (err) {
		ntfs_err(sb, "Failed to initialize $Bitmap (%d).", err);
		goto put_inode_out;
	}

	iput(inode);

	/* Compute the MFT zone. */
	err = ntfs_refresh_zone(sbi);
	if (err) {
		ntfs_err(sb, "Failed to initialize MFT zone (%d).", err);
		goto out;
	}

	/* Load $BadClus. */
	ref.low = cpu_to_le32(MFT_REC_BADCLUST);
	ref.seq = cpu_to_le16(MFT_REC_BADCLUST);
	inode = ntfs_iget5(sb, &ref, &NAME_BADCLUS);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $BadClus (%d).", err);
		goto out;
	}

	ni = ntfs_i(inode);
	bad_len = bad_frags = 0;
	for (i = 0; run_get_entry(&ni->file.run, i, &vcn, &lcn, &len); i++) {
		if (lcn == SPARSE_LCN)
			continue;

		bad_len += len;
		bad_frags += 1;
		if (ro)
			continue;

		if (wnd_set_used_safe(&sbi->used.bitmap, lcn, len, &tt) || tt) {
			/* Bad blocks marked as free in bitmap. */
			ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
		}
	}
	if (bad_len) {
		/*
		 * Notice about bad blocks.
		 * In normal cases these blocks are marked as used in bitmap.
		 * And we never allocate space in it.
		 */
		ntfs_notice(sb,
			    "Volume contains %zu bad blocks in %zu fragments.",
			    bad_len, bad_frags);
	}
	iput(inode);

	/* Load $AttrDef. */
	ref.low = cpu_to_le32(MFT_REC_ATTR);
	ref.seq = cpu_to_le16(MFT_REC_ATTR);
	inode = ntfs_iget5(sb, &ref, &NAME_ATTRDEF);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $AttrDef (%d)", err);
		goto out;
	}

	/*
	 * Typical $AttrDef contains up to 20 entries.
	 * Check for extremely large/small size.
	 */
	if (inode->i_size < sizeof(struct ATTR_DEF_ENTRY) ||
	    inode->i_size > 100 * sizeof(struct ATTR_DEF_ENTRY)) {
		ntfs_err(sb, "Looks like $AttrDef is corrupted (size=%llu).",
			 inode->i_size);
		err = -EINVAL;
		goto put_inode_out;
	}

	bytes = inode->i_size;
	sbi->def_table = t = kvmalloc(bytes, GFP_KERNEL);
	if (!t) {
		err = -ENOMEM;
		goto put_inode_out;
	}

	/* Read the entire file. */
	err = inode_read_data(inode, sbi->def_table, bytes);
	if (err) {
		ntfs_err(sb, "Failed to read $AttrDef (%d).", err);
		goto put_inode_out;
	}

	if (ATTR_STD != t->type) {
		ntfs_err(sb, "$AttrDef is corrupted.");
		err = -EINVAL;
		goto put_inode_out;
	}

	t += 1;
	sbi->def_entries = 1;
	done = sizeof(struct ATTR_DEF_ENTRY);

	while (done + sizeof(struct ATTR_DEF_ENTRY) <= bytes) {
		u32 t32 = le32_to_cpu(t->type);
		u64 sz = le64_to_cpu(t->max_sz);

		if ((t32 & 0xF) || le32_to_cpu(t[-1].type) >= t32)
			break;

		if (t->type == ATTR_REPARSE)
			sbi->reparse.max_size = sz;
		else if (t->type == ATTR_EA)
			sbi->ea_max_size = sz;

		done += sizeof(struct ATTR_DEF_ENTRY);
		t += 1;
		sbi->def_entries += 1;
	}
	iput(inode);

	/* Load $UpCase. */
	ref.low = cpu_to_le32(MFT_REC_UPCASE);
	ref.seq = cpu_to_le16(MFT_REC_UPCASE);
	inode = ntfs_iget5(sb, &ref, &NAME_UPCASE);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load $UpCase (%d).", err);
		goto out;
	}

	if (inode->i_size != 0x10000 * sizeof(short)) {
		err = -EINVAL;
		ntfs_err(sb, "$UpCase is corrupted.");
		goto put_inode_out;
	}

	/* Read the entire file. */
	err = inode_read_data(inode, sbi->upcase, 0x10000 * sizeof(short));
	if (err) {
		ntfs_err(sb, "Failed to read $UpCase (%d).", err);
		goto put_inode_out;
	}

#ifdef __BIG_ENDIAN
	{
		u16 *dst = sbi->upcase;

		for (i = 0; i < 0x10000; i++)
			__swab16s(dst++);
	}
#endif

	shared = ntfs_set_shared(sbi->upcase, 0x10000 * sizeof(short));
	if (shared && sbi->upcase != shared) {
		kvfree(sbi->upcase);
		sbi->upcase = shared;
	}

	iput(inode);

	if (is_ntfs3(sbi)) {
		/* Load $Secure. */
		err = ntfs_security_init(sbi);
		if (err) {
			ntfs_err(sb, "Failed to initialize $Secure (%d).", err);
			goto out;
		}

		/* Load $Extend. */
		err = ntfs_extend_init(sbi);
		if (err) {
			ntfs_warn(sb, "Failed to initialize $Extend.");
			goto load_root;
		}

		/* Load $Extend/$Reparse. */
		err = ntfs_reparse_init(sbi);
		if (err) {
			ntfs_warn(sb, "Failed to initialize $Extend/$Reparse.");
			goto load_root;
		}

		/* Load $Extend/$ObjId. */
		err = ntfs_objid_init(sbi);
		if (err) {
			ntfs_warn(sb, "Failed to initialize $Extend/$ObjId.");
			goto load_root;
		}
	}

load_root:
	/* Load root. */
	ref.low = cpu_to_le32(MFT_REC_ROOT);
	ref.seq = cpu_to_le16(MFT_REC_ROOT);
	inode = ntfs_iget5(sb, &ref, &NAME_ROOT);
	if (IS_ERR(inode)) {
		err = PTR_ERR(inode);
		ntfs_err(sb, "Failed to load root (%d).", err);
		goto out;
	}

	/*
	 * Final check. Looks like this case should never occurs.
	 */
	if (!inode->i_op) {
		err = -EINVAL;
		ntfs_err(sb, "Failed to load root (%d).", err);
		goto put_inode_out;
	}

	sb->s_root = d_make_root(inode);
	if (!sb->s_root) {
		err = -ENOMEM;
		goto put_inode_out;
	}

	if (boot2) {
		/*
	 	 * Alternative boot is ok but primary is not ok.
	 	 * Volume is recognized as NTFS. Update primary boot.
		 */
		struct buffer_head *bh0 = sb_getblk(sb, 0);
		if (bh0) {
			if (buffer_locked(bh0))
				__wait_on_buffer(bh0);

			lock_buffer(bh0);
			memcpy(bh0->b_data, boot2, sizeof(*boot2));
			set_buffer_uptodate(bh0);
			mark_buffer_dirty(bh0);
			unlock_buffer(bh0);
			if (!sync_dirty_buffer(bh0))
				ntfs_warn(sb, "primary boot is updated");
			put_bh(bh0);
		}

		kfree(boot2);
	}

#ifdef CONFIG_PROC_FS
	/* Create /proc/fs/ntfs3/.. */
	if (proc_info_root) {
		struct proc_dir_entry *e = proc_mkdir(sb->s_id, proc_info_root);
		static_assert((S_IRUGO | S_IWUSR) == 0644);
		if (e) {
			proc_create_data("volinfo", S_IRUGO, e,
					 &ntfs3_volinfo_fops, sb);
			proc_create_data("label", S_IRUGO | S_IWUSR, e,
					 &ntfs3_label_fops, sb);
			sbi->procdir = e;
		}
	}
#endif

	if (is_legacy_ntfs(sb))
		sb->s_flags |= SB_RDONLY;
	return 0;

put_inode_out:
	iput(inode);
out:
	ntfs3_put_sbi(sbi);
	kfree(boot2);
	ntfs3_put_sbi(sbi);
	return err;
}

void ntfs_unmap_meta(struct super_block *sb, CLST lcn, CLST len)
{
	struct ntfs_sb_info *sbi = sb->s_fs_info;
	struct block_device *bdev = sb->s_bdev;
	sector_t devblock = (u64)lcn * sbi->blocks_per_cluster;
	unsigned long blocks = (u64)len * sbi->blocks_per_cluster;
	unsigned long cnt = 0;
	unsigned long limit = global_zone_page_state(NR_FREE_PAGES)
			      << (PAGE_SHIFT - sb->s_blocksize_bits);

	if (limit >= 0x2000)
		limit -= 0x1000;
	else if (limit < 32)
		limit = 32;
	else
		limit >>= 1;

	while (blocks--) {
		clean_bdev_aliases(bdev, devblock++, 1);
		if (cnt++ >= limit) {
			sync_blockdev(bdev);
			cnt = 0;
		}
	}
}

/*
 * ntfs_discard - Issue a discard request (trim for SSD).
 */
int ntfs_discard(struct ntfs_sb_info *sbi, CLST lcn, CLST len)
{
	int err;
	u64 lbo, bytes, start, end;
	struct super_block *sb;

	if (sbi->used.next_free_lcn == lcn + len)
		sbi->used.next_free_lcn = lcn;

	if (sbi->flags & NTFS_FLAGS_NODISCARD)
		return -EOPNOTSUPP;

	if (!sbi->options->discard)
		return -EOPNOTSUPP;

	lbo = (u64)lcn << sbi->cluster_bits;
	bytes = (u64)len << sbi->cluster_bits;

	/* Align up 'start' on discard_granularity. */
	start = (lbo + sbi->discard_granularity - 1) &
		sbi->discard_granularity_mask_inv;
	/* Align down 'end' on discard_granularity. */
	end = (lbo + bytes) & sbi->discard_granularity_mask_inv;

	sb = sbi->sb;
	if (start >= end)
		return 0;

	err = blkdev_issue_discard(sb->s_bdev, start >> 9, (end - start) >> 9,
				   GFP_NOFS);

	if (err == -EOPNOTSUPP)
		sbi->flags |= NTFS_FLAGS_NODISCARD;

	return err;
}

static int ntfs_fs_get_tree(struct fs_context *fc)
{
	return get_tree_bdev(fc, ntfs_fill_super);
}

/*
 * ntfs_fs_free - Free fs_context.
 *
 * Note that this will be called after fill_super and reconfigure
 * even when they pass. So they have to take pointers if they pass.
 */
static void ntfs_fs_free(struct fs_context *fc)
{
	struct ntfs_mount_options *opts = fc->fs_private;
	struct ntfs_sb_info *sbi = fc->s_fs_info;

	if (sbi) {
		ntfs3_put_sbi(sbi);
		ntfs3_free_sbi(sbi);
	}

	if (opts)
		put_mount_options(opts);
}

// clang-format off
static const struct fs_context_operations ntfs_context_ops = {
	.parse_param	= ntfs_fs_parse_param,
	.get_tree	= ntfs_fs_get_tree,
	.reconfigure	= ntfs_fs_reconfigure,
	.free		= ntfs_fs_free,
};
// clang-format on

/*
 * ntfs_init_fs_context - Initialize sbi and opts
 *
 * This will called when mount/remount. We will first initialize
 * options so that if remount we can use just that.
 */
static int __ntfs_init_fs_context(struct fs_context *fc)
{
	struct ntfs_mount_options *opts;
	struct ntfs_sb_info *sbi;

	opts = kzalloc(sizeof(struct ntfs_mount_options), GFP_NOFS);
	if (!opts)
		return -ENOMEM;

	/* Default options. */
	opts->fs_uid = current_uid();
	opts->fs_gid = current_gid();
	opts->fs_fmask_inv = ~current_umask();
	opts->fs_dmask_inv = ~current_umask();

	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE)
		goto ok;

	sbi = kzalloc(sizeof(struct ntfs_sb_info), GFP_NOFS);
	if (!sbi)
		goto free_opts;

	sbi->upcase = kvmalloc(0x10000 * sizeof(short), GFP_KERNEL);
	if (!sbi->upcase)
		goto free_sbi;

	ratelimit_state_init(&sbi->msg_ratelimit, DEFAULT_RATELIMIT_INTERVAL,
			     DEFAULT_RATELIMIT_BURST);

	mutex_init(&sbi->compress.mtx_lznt);
#ifdef CONFIG_NTFS3_LZX_XPRESS
	mutex_init(&sbi->compress.mtx_xpress);
	mutex_init(&sbi->compress.mtx_lzx);
#endif

	fc->s_fs_info = sbi;
ok:
	fc->fs_private = opts;
	fc->ops = &ntfs_context_ops;

	return 0;
free_sbi:
	kfree(sbi);
free_opts:
	kfree(opts);
	return -ENOMEM;
}

static int ntfs_init_fs_context(struct fs_context *fc)
{
	return __ntfs_init_fs_context(fc);
}

static void ntfs3_kill_sb(struct super_block *sb)
{
	struct ntfs_sb_info *sbi = sb->s_fs_info;

	kill_block_super(sb);

	if (sbi->options)
		put_mount_options(sbi->options);
	ntfs3_free_sbi(sbi);
}

// clang-format off
static struct file_system_type ntfs_fs_type = {
	.owner			= THIS_MODULE,
	.name			= "ntfs3",
	.init_fs_context	= ntfs_init_fs_context,
	.parameters		= ntfs_fs_parameters,
	.kill_sb		= ntfs3_kill_sb,
	.fs_flags		= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
};

#if IS_ENABLED(CONFIG_NTFS_FS)
static int ntfs_legacy_init_fs_context(struct fs_context *fc)
{
	int ret;

	ret = __ntfs_init_fs_context(fc);
	/* If ntfs3 is used as legacy ntfs enforce read-only mode. */
	fc->sb_flags |= SB_RDONLY;
	return ret;
}

static struct file_system_type ntfs_legacy_fs_type = {
	.owner			= THIS_MODULE,
	.name			= "ntfs",
	.init_fs_context	= ntfs_legacy_init_fs_context,
	.parameters		= ntfs_fs_parameters,
	.kill_sb		= ntfs3_kill_sb,
	.fs_flags		= FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
};
MODULE_ALIAS_FS("ntfs");

static inline void register_as_ntfs_legacy(void)
{
	int err = register_filesystem(&ntfs_legacy_fs_type);
	if (err)
		pr_warn("ntfs3: Failed to register legacy ntfs filesystem driver: %d\n", err);
}

static inline void unregister_as_ntfs_legacy(void)
{
	unregister_filesystem(&ntfs_legacy_fs_type);
}
bool is_legacy_ntfs(struct super_block *sb)
{
	return sb->s_type == &ntfs_legacy_fs_type;
}
#else
static inline void register_as_ntfs_legacy(void) {}
static inline void unregister_as_ntfs_legacy(void) {}
#endif

// clang-format on

static int __init init_ntfs_fs(void)
{
	int err;

	if (IS_ENABLED(CONFIG_NTFS3_FS_POSIX_ACL))
		pr_info("ntfs3: Enabled Linux POSIX ACLs support\n");
	if (IS_ENABLED(CONFIG_NTFS3_64BIT_CLUSTER))
		pr_notice(
			"ntfs3: Warning: Activated 64 bits per cluster. Windows does not support this\n");
	if (IS_ENABLED(CONFIG_NTFS3_LZX_XPRESS))
		pr_info("ntfs3: Read-only LZX/Xpress compression included\n");

#ifdef CONFIG_PROC_FS
	/* Create "/proc/fs/ntfs3" */
	proc_info_root = proc_mkdir("fs/ntfs3", NULL);
#endif

	err = ntfs3_init_bitmap();
	if (err)
		return err;

	ntfs_inode_cachep = kmem_cache_create(
		"ntfs_inode_cache", sizeof(struct ntfs_inode), 0,
		(SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT), init_once);
	if (!ntfs_inode_cachep) {
		err = -ENOMEM;
		goto out1;
	}

	register_as_ntfs_legacy();
	err = register_filesystem(&ntfs_fs_type);
	if (err)
		goto out;

	return 0;
out:
	kmem_cache_destroy(ntfs_inode_cachep);
out1:
	ntfs3_exit_bitmap();
	return err;
}

static void __exit exit_ntfs_fs(void)
{
	rcu_barrier();
	kmem_cache_destroy(ntfs_inode_cachep);
	unregister_filesystem(&ntfs_fs_type);
	unregister_as_ntfs_legacy();
	ntfs3_exit_bitmap();

#ifdef CONFIG_PROC_FS
	if (proc_info_root)
		remove_proc_entry("fs/ntfs3", NULL);
#endif
}

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ntfs3 read/write filesystem");
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
MODULE_INFO(behaviour, "Enabled Linux POSIX ACLs support");
#endif
#ifdef CONFIG_NTFS3_64BIT_CLUSTER
MODULE_INFO(
	cluster,
	"Warning: Activated 64 bits per cluster. Windows does not support this");
#endif
#ifdef CONFIG_NTFS3_LZX_XPRESS
MODULE_INFO(compression, "Read-only lzx/xpress compression included");
#endif

MODULE_AUTHOR("Konstantin Komarov");
MODULE_ALIAS_FS("ntfs3");

module_init(init_ntfs_fs);
module_exit(exit_ntfs_fs);
