Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/affs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  (c) 1996  Hans-Joachim Widmaier - Rewritten
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  (C) 1993  Ray Burr - Modified for Amiga FFS filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  (C) 1992  Eric Youngdale Modified for ISO 9660 filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  (C) 1991  Linus Torvalds - minix filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "affs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int affs_statfs(struct dentry *dentry, struct kstatfs *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static int affs_show_options(struct seq_file *m, struct dentry *root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static int affs_remount (struct super_block *sb, int *flags, char *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) affs_commit_super(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct affs_sb_info *sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct buffer_head *bh = sbi->s_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct affs_root_tail *tail = AFFS_ROOT_TAIL(sb, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	affs_secs_to_datestamp(ktime_get_real_seconds(), &tail->disk_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	affs_fix_checksum(sb, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) affs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct affs_sb_info *sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	pr_debug("%s()\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	cancel_delayed_work_sync(&sbi->sb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) affs_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	affs_commit_super(sb, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void flush_superblock(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct affs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	sbi = container_of(work, struct affs_sb_info, sb_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	sb = sbi->sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	spin_lock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	sbi->work_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	spin_unlock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	affs_commit_super(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) void affs_mark_sb_dirty(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct affs_sb_info *sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	       return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	spin_lock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!sbi->work_queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	       delay = msecs_to_jiffies(dirty_writeback_interval * 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	       queue_delayed_work(system_long_wq, &sbi->sb_work, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	       sbi->work_queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	spin_unlock(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static struct kmem_cache * affs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static struct inode *affs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct affs_inode_info *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	i = kmem_cache_alloc(affs_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	inode_set_iversion(&i->vfs_inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	i->i_lc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	i->i_ext_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	i->i_pa_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return &i->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void affs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct affs_inode_info *ei = (struct affs_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	mutex_init(&ei->i_link_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	mutex_init(&ei->i_ext_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	affs_inode_cachep = kmem_cache_create("affs_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					     sizeof(struct affs_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					     0, (SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 						SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 					     init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (affs_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	kmem_cache_destroy(affs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static const struct super_operations affs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.alloc_inode	= affs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.free_inode	= affs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.write_inode	= affs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	.evict_inode	= affs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	.put_super	= affs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	.sync_fs	= affs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.statfs		= affs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.remount_fs	= affs_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.show_options	= affs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	Opt_bs, Opt_mode, Opt_mufs, Opt_notruncate, Opt_prefix, Opt_protect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	Opt_reserved, Opt_root, Opt_setgid, Opt_setuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	Opt_verbose, Opt_volume, Opt_ignore, Opt_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	{Opt_bs, "bs=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	{Opt_mode, "mode=%o"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	{Opt_mufs, "mufs"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	{Opt_notruncate, "nofilenametruncate"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	{Opt_prefix, "prefix=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	{Opt_protect, "protect"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	{Opt_reserved, "reserved=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	{Opt_root, "root=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	{Opt_setgid, "setgid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	{Opt_setuid, "setuid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	{Opt_verbose, "verbose"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	{Opt_volume, "volume=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	{Opt_ignore, "grpquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	{Opt_ignore, "noquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	{Opt_ignore, "quota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	{Opt_ignore, "usrquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	{Opt_err, NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) parse_options(char *options, kuid_t *uid, kgid_t *gid, int *mode, int *reserved, s32 *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		int *blocksize, char **prefix, char *volume, unsigned long *mount_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/* Fill in defaults */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	*uid        = current_uid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	*gid        = current_gid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	*reserved   = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	*root       = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	*blocksize  = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	volume[0]   = ':';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	volume[1]   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	*mount_opts = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		int token, n, option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		case Opt_bs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			if (match_int(&args[0], &n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			if (n != 512 && n != 1024 && n != 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			    && n != 4096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 				pr_warn("Invalid blocksize (512, 1024, 2048, 4096 allowed)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			*blocksize = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		case Opt_mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			if (match_octal(&args[0], &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			*mode = option & 0777;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			affs_set_opt(*mount_opts, SF_SETMODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		case Opt_mufs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			affs_set_opt(*mount_opts, SF_MUFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		case Opt_notruncate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			affs_set_opt(*mount_opts, SF_NO_TRUNCATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		case Opt_prefix:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			kfree(*prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			*prefix = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			if (!*prefix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			affs_set_opt(*mount_opts, SF_PREFIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		case Opt_protect:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			affs_set_opt(*mount_opts, SF_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		case Opt_reserved:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			if (match_int(&args[0], reserved))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		case Opt_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			if (match_int(&args[0], root))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		case Opt_setgid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			if (match_int(&args[0], &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			*gid = make_kgid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			if (!gid_valid(*gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			affs_set_opt(*mount_opts, SF_SETGID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		case Opt_setuid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			if (match_int(&args[0], &option))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			*uid = make_kuid(current_user_ns(), option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			if (!uid_valid(*uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			affs_set_opt(*mount_opts, SF_SETUID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		case Opt_verbose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			affs_set_opt(*mount_opts, SF_VERBOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		case Opt_volume: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			char *vol = match_strdup(&args[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			if (!vol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			strlcpy(volume, vol, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			kfree(vol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		case Opt_ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		 	/* Silently ignore the quota options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			pr_warn("Unrecognized mount option \"%s\" or missing value\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int affs_show_options(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	struct super_block *sb = root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct affs_sb_info *sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		seq_printf(m, ",bs=%lu", sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (affs_test_opt(sbi->s_flags, SF_SETMODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		seq_printf(m, ",mode=%o", sbi->s_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (affs_test_opt(sbi->s_flags, SF_MUFS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		seq_puts(m, ",mufs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (affs_test_opt(sbi->s_flags, SF_NO_TRUNCATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		seq_puts(m, ",nofilenametruncate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (affs_test_opt(sbi->s_flags, SF_PREFIX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		seq_printf(m, ",prefix=%s", sbi->s_prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (affs_test_opt(sbi->s_flags, SF_IMMUTABLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		seq_puts(m, ",protect");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (sbi->s_reserved != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		seq_printf(m, ",reserved=%u", sbi->s_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (sbi->s_root_block != (sbi->s_reserved + sbi->s_partition_size - 1) / 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		seq_printf(m, ",root=%u", sbi->s_root_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (affs_test_opt(sbi->s_flags, SF_SETGID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		seq_printf(m, ",setgid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			   from_kgid_munged(&init_user_ns, sbi->s_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (affs_test_opt(sbi->s_flags, SF_SETUID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		seq_printf(m, ",setuid=%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			   from_kuid_munged(&init_user_ns, sbi->s_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (affs_test_opt(sbi->s_flags, SF_VERBOSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		seq_puts(m, ",verbose");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	if (sbi->s_volume[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		seq_printf(m, ",volume=%s", sbi->s_volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* This function definitely needs to be split up. Some fine day I'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * hopefully have the guts to do so. Until then: sorry for the mess.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int affs_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	struct affs_sb_info	*sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct buffer_head	*root_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct buffer_head	*boot_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct inode		*root_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	s32			 root_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	int			 size, blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	u32			 chksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	int			 num_bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	int			 i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	kuid_t			 uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	kgid_t			 gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	int			 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	unsigned long		 mount_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	int			 tmp_flags;	/* fix remount prototype... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	u8			 sig[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	int			 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	pr_debug("read_super(%s)\n", data ? (const char *)data : "no options");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	sb->s_magic             = AFFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	sb->s_op                = &affs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	sb->s_flags |= SB_NODIRATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	sb->s_time_gran = NSEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	sb->s_time_min = sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	sb->s_time_max = 86400LL * U32_MAX + 86400 + sb->s_time_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	sbi = kzalloc(sizeof(struct affs_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	sbi->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	mutex_init(&sbi->s_bmlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	spin_lock_init(&sbi->symlink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	spin_lock_init(&sbi->work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	INIT_DELAYED_WORK(&sbi->sb_work, flush_superblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!parse_options(data,&uid,&gid,&i,&reserved,&root_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				&blocksize,&sbi->s_prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				sbi->s_volume, &mount_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		pr_err("Error parsing options\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	/* N.B. after this point s_prefix must be released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	sbi->s_flags   = mount_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	sbi->s_mode    = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	sbi->s_uid     = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	sbi->s_gid     = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	sbi->s_reserved= reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	/* Get the size of the device in 512-byte blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	 * If we later see that the partition uses bigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	 * blocks, we will have to change it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	size = i_size_read(sb->s_bdev->bd_inode) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	pr_debug("initial blocksize=%d, #blocks=%d\n", 512, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	affs_set_blocksize(sb, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	/* Try to find root block. Its location depends on the block size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	i = bdev_logical_block_size(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	j = PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	if (blocksize > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		i = j = blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		size = size / (blocksize / 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	for (blocksize = i; blocksize <= j; blocksize <<= 1, size >>= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		sbi->s_root_block = root_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		if (root_block < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			sbi->s_root_block = (reserved + size - 1) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		pr_debug("setting blocksize to %d\n", blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		affs_set_blocksize(sb, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		sbi->s_partition_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		/* The root block location that was calculated above is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		 * correct if the partition size is an odd number of 512-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		 * byte blocks, which will be rounded down to a number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		 * 1024-byte blocks, and if there were an even number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		 * reserved blocks. Ideally, all partition checkers should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		 * report the real number of blocks of the real blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		 * but since this just cannot be done, we have to try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		 * find the root block anyways. In the above case, it is one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		 * block behind the calculated one. So we check this one, too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		for (num_bm = 0; num_bm < 2; num_bm++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			pr_debug("Dev %s, trying root=%u, bs=%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				"size=%d, reserved=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 				sb->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 				sbi->s_root_block + num_bm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				blocksize, size, reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			root_bh = affs_bread(sb, sbi->s_root_block + num_bm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			if (!root_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 			if (!affs_checksum_block(sb, root_bh) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			    be32_to_cpu(AFFS_ROOT_HEAD(root_bh)->ptype) == T_SHORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			    be32_to_cpu(AFFS_ROOT_TAIL(sb, root_bh)->stype) == ST_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 				sbi->s_hashsize    = blocksize / 4 - 56;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				sbi->s_root_block += num_bm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				goto got_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			affs_brelse(root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			root_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		pr_err("No valid root block on device %s\n", sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	/* N.B. after this point bh must be released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) got_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	/* Keep super block in cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	sbi->s_root_bh = root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	root_block = sbi->s_root_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	/* Find out which kind of FS we have */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	boot_bh = sb_bread(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!boot_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		pr_err("Cannot read boot block\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	memcpy(sig, boot_bh->b_data, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	brelse(boot_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	chksum = be32_to_cpu(*(__be32 *)sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	/* Dircache filesystems are compatible with non-dircache ones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	 * when reading. As long as they aren't supported, writing is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 * not recommended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	if ((chksum == FS_DCFFS || chksum == MUFS_DCFFS || chksum == FS_DCOFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	     || chksum == MUFS_DCOFS) && !sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		pr_notice("Dircache FS - mounting %s read only\n", sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	switch (chksum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	case MUFS_FS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	case MUFS_INTLFFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	case MUFS_DCFFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		affs_set_opt(sbi->s_flags, SF_MUFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	case FS_INTLFFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	case FS_DCFFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		affs_set_opt(sbi->s_flags, SF_INTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	case MUFS_FFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		affs_set_opt(sbi->s_flags, SF_MUFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	case FS_FFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	case MUFS_OFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		affs_set_opt(sbi->s_flags, SF_MUFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	case FS_OFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		affs_set_opt(sbi->s_flags, SF_OFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		sb->s_flags |= SB_NOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	case MUFS_DCOFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	case MUFS_INTLOFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		affs_set_opt(sbi->s_flags, SF_MUFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	case FS_DCOFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	case FS_INTLOFS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		affs_set_opt(sbi->s_flags, SF_INTL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		affs_set_opt(sbi->s_flags, SF_OFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		sb->s_flags |= SB_NOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		pr_err("Unknown filesystem on device %s: %08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		       sb->s_id, chksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	if (affs_test_opt(mount_flags, SF_VERBOSE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		u8 len = AFFS_ROOT_TAIL(sb, root_bh)->disk_name[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		pr_notice("Mounting volume \"%.*s\": Type=%.3s\\%c, Blocksize=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 			len > 31 ? 31 : len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			AFFS_ROOT_TAIL(sb, root_bh)->disk_name + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 			sig, sig[3] + '0', blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	sb->s_flags |= SB_NODEV | SB_NOSUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	sbi->s_data_blksize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	if (affs_test_opt(sbi->s_flags, SF_OFS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		sbi->s_data_blksize -= 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	tmp_flags = sb->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	ret = affs_init_bitmap(sb, &tmp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	sb->s_flags = tmp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	/* set up enough so that it can read an inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	root_inode = affs_iget(sb, root_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	if (IS_ERR(root_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		return PTR_ERR(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	if (affs_test_opt(AFFS_SB(sb)->s_flags, SF_INTL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		sb->s_d_op = &affs_intl_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		sb->s_d_op = &affs_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	sb->s_root = d_make_root(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	if (!sb->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		pr_err("AFFS: Get root inode failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	sb->s_export_op = &affs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	pr_debug("s_flags=%lX\n", sb->s_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) affs_remount(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	struct affs_sb_info	*sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	int			 blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	kuid_t			 uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	kgid_t			 gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	int			 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	int			 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	int			 root_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	unsigned long		 mount_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	int			 res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	char			 volume[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	char			*prefix = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	pr_debug("%s(flags=0x%x,opts=\"%s\")\n", __func__, *flags, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	*flags |= SB_NODIRATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	memcpy(volume, sbi->s_volume, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 			   &blocksize, &prefix, volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 			   &mount_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 		kfree(prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	flush_delayed_work(&sbi->sb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	sbi->s_flags = mount_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	sbi->s_mode  = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	sbi->s_uid   = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	sbi->s_gid   = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	/* protect against readers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	spin_lock(&sbi->symlink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (prefix) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		kfree(sbi->s_prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		sbi->s_prefix = prefix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	memcpy(sbi->s_volume, volume, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	spin_unlock(&sbi->symlink_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if (*flags & SB_RDONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		affs_free_bitmap(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		res = affs_init_bitmap(sb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) affs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	int		 free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	u64		 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	pr_debug("%s() partsize=%d, reserved=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		 __func__, AFFS_SB(sb)->s_partition_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		 AFFS_SB(sb)->s_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	free          = affs_count_free_blocks(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	buf->f_type    = AFFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	buf->f_bsize   = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	buf->f_blocks  = AFFS_SB(sb)->s_partition_size - AFFS_SB(sb)->s_reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	buf->f_bfree   = free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	buf->f_bavail  = free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	buf->f_fsid    = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	buf->f_namelen = AFFSNAMEMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static struct dentry *affs_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	return mount_bdev(fs_type, flags, dev_name, data, affs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static void affs_kill_sb(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	struct affs_sb_info *sbi = AFFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	kill_block_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	if (sbi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		affs_free_bitmap(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		affs_brelse(sbi->s_root_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		kfree(sbi->s_prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 		mutex_destroy(&sbi->s_bmlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) static struct file_system_type affs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	.name		= "affs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	.mount		= affs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	.kill_sb	= affs_kill_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	.fs_flags	= FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) MODULE_ALIAS_FS("affs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) static int __init init_affs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	int err = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	err = register_filesystem(&affs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) static void __exit exit_affs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	unregister_filesystem(&affs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) MODULE_DESCRIPTION("Amiga filesystem support for Linux");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) module_init(init_affs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) module_exit(exit_affs_fs)