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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Trivial changes by Alan Cox to add the LFS fixes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Trivial Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Rights granted to Hans Reiser to redistribute under other terms providing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * he accepts all liability including but not limited to patent, fitness
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * for purpose, and direct or indirect claims arising from failure to perform.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * NO WARRANTY
^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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "reiserfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/init.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/backing-dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) struct file_system_type reiserfs_fs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) int is_reiserfs_3_5(struct reiserfs_super_block *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 			strlen(reiserfs_3_5_magic_string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) int is_reiserfs_3_6(struct reiserfs_super_block *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 			strlen(reiserfs_3_6_magic_string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) int is_reiserfs_jr(struct reiserfs_super_block *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 			strlen(reiserfs_jr_magic_string));
^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 is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		is_reiserfs_jr(rs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static int reiserfs_remount(struct super_block *s, int *flags, char *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static int reiserfs_sync_fs(struct super_block *s, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	 * Writeback quota in non-journalled quota case - journalled quota has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	 * no dirty dquots
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	dquot_writeback_dquots(s, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	if (!journal_begin(&th, s, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		if (!journal_end_sync(&th))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 			reiserfs_flush_old_commits(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static void flush_old_commits(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	struct reiserfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	struct super_block *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	sbi = container_of(work, struct reiserfs_sb_info, old_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	s = sbi->s_journal->j_work_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	 * We need s_umount for protecting quota writeback. We have to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	 * trylock as reiserfs_cancel_old_flush() may be waiting for this work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	 * to complete with s_umount held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	if (!down_read_trylock(&s->s_umount)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 		/* Requeue work if we are not cancelling it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 		spin_lock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		if (sbi->work_queued == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 			queue_delayed_work(system_long_wq, &sbi->old_work, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 		spin_unlock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	spin_lock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	/* Avoid clobbering the cancel state... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	if (sbi->work_queued == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		sbi->work_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	spin_unlock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	reiserfs_sync_fs(s, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	up_read(&s->s_umount);
^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) void reiserfs_schedule_old_flush(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	struct reiserfs_sb_info *sbi = REISERFS_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	 * Avoid scheduling flush when sb is being shut down. It can race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	 * with journal shutdown and free still queued delayed work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	if (sb_rdonly(s) || !(s->s_flags & SB_ACTIVE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	spin_lock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	if (!sbi->work_queued) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		delay = msecs_to_jiffies(dirty_writeback_interval * 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		queue_delayed_work(system_long_wq, &sbi->old_work, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		sbi->work_queued = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	spin_unlock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) void reiserfs_cancel_old_flush(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	struct reiserfs_sb_info *sbi = REISERFS_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	spin_lock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	/* Make sure no new flushes will be queued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	sbi->work_queued = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	spin_unlock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static int reiserfs_freeze(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	reiserfs_cancel_old_flush(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	if (!sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		int err = journal_begin(&th, s, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 			reiserfs_block_writes(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 			reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 						     1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 			journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			reiserfs_block_writes(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 			journal_end_sync(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static int reiserfs_unfreeze(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	struct reiserfs_sb_info *sbi = REISERFS_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	reiserfs_allow_writes(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	spin_lock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	/* Allow old_work to run again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	sbi->work_queued = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	spin_unlock(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) extern const struct in_core_key MAX_IN_CORE_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)  * this is used to delete "save link" when there are no items of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)  * file it points to. It can either happen if unlink is completed but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)  * "save unlink" removal, or if file has both unlink and truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  * pending and as unlink completes first (because key of "save link"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  * protecting unlink is bigger that a key lf "save link" which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  * protects truncate), so there left no items to make truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  * completion on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) static int remove_save_link_only(struct super_block *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 				 struct reiserfs_key *key, int oid_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	/* we are going to do one balancing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	reiserfs_delete_solid_item(&th, NULL, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	if (oid_free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		/* removals are protected by direct items */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	return journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) static int reiserfs_quota_on_mount(struct super_block *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  * Look for uncompleted unlinks and truncates and complete them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  * Called with superblock write locked.  If quotas are enabled, we have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  * release/retake lest we call dquot_quota_on_mount(), proceed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  * schedule_on_each_cpu() in invalidate_bdev() and deadlock waiting for the per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  * cpu worklets to complete flush_async_commits() that in turn wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  * superblock write lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static int finish_unfinished(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	INITIALIZE_PATH(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	struct cpu_key max_cpu_key, obj_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	struct reiserfs_key save_link_key, last_inode_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	struct item_head *ih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	int item_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	char *item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	int done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	int truncate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	int ms_active_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	int quota_enabled[REISERFS_MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/* compose key to look for "save" links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	max_cpu_key.version = KEY_FORMAT_3_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	max_cpu_key.on_disk_key.k_dir_id = ~0U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	max_cpu_key.on_disk_key.k_objectid = ~0U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	set_cpu_key_k_offset(&max_cpu_key, ~0U);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	max_cpu_key.key_length = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	memset(&last_inode_key, 0, sizeof(last_inode_key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	/* Needed for iput() to work correctly and not trash data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	if (s->s_flags & SB_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		ms_active_set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		ms_active_set = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		s->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	/* Turn on quotas so that they are updated correctly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		quota_enabled[i] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		if (REISERFS_SB(s)->s_qf_names[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			if (sb_has_quota_active(s, i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 				quota_enabled[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 			reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			ret = reiserfs_quota_on_mount(s, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 				reiserfs_warning(s, "reiserfs-2500",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 						 "cannot turn on journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 						 "quota: error %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	REISERFS_SB(s)->s_is_unlinked_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	while (!retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		retval = search_item(s, &max_cpu_key, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		if (retval != ITEM_NOT_FOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			reiserfs_error(s, "vs-2140",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				       "search_by_key returned %d", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		bh = get_last_bh(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		item_pos = get_item_pos(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		if (item_pos != B_NR_ITEMS(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			reiserfs_warning(s, "vs-2060",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 					 "wrong position found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		item_pos--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		ih = item_head(bh, item_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			/* there are no "save" links anymore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		save_link_key = ih->ih_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		if (is_indirect_le_ih(ih))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			truncate = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			truncate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		/* reiserfs_iget needs k_dirid and k_objectid only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		item = ih_item_body(bh, ih);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		obj_key.on_disk_key.k_objectid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		    le32_to_cpu(ih->ih_key.k_objectid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		obj_key.on_disk_key.k_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		obj_key.on_disk_key.k_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		pathrelse(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		inode = reiserfs_iget(s, &obj_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 		if (IS_ERR_OR_NULL(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 			 * the unlink almost completed, it just did not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 			 * manage to remove "save" link and release objectid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 			reiserfs_warning(s, "vs-2180", "iget failed for %K",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 					 &obj_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 			retval = remove_save_link_only(s, &save_link_key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		if (!truncate && inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 			/* file is not unlinked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			reiserfs_warning(s, "vs-2185",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 					 "file %K is not unlinked",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 					 &obj_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			retval = remove_save_link_only(s, &save_link_key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		depth = reiserfs_write_unlock_nested(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		reiserfs_write_lock_nested(inode->i_sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		if (truncate && S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			 * We got a truncate request for a dir which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			 * is impossible.  The only imaginable way is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			 * execute unfinished truncate request then boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 			 * into old kernel, remove the file and create dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			 * with the same key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			reiserfs_warning(s, "green-2101",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 					 "impossible truncate on a "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 					 "directory %k. Please report",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 					 INODE_PKEY(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			retval = remove_save_link_only(s, &save_link_key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			truncate = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 			iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		if (truncate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 			REISERFS_I(inode)->i_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			    i_link_saved_truncate_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			 * not completed truncate found. New size was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			 * committed together with "save" link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 			reiserfs_info(s, "Truncating %k to %lld ..",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 				      INODE_PKEY(inode), inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			/* don't update modification time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			reiserfs_truncate_file(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 			retval = remove_save_link(inode, truncate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			/* not completed unlink (rmdir) found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 			if (memcmp(&last_inode_key, INODE_PKEY(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 					sizeof(last_inode_key))){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 				last_inode_key = *INODE_PKEY(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 				/* removal gets completed in iput */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 				reiserfs_warning(s, "super-2189", "Dead loop "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 						 "in finish_unfinished "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 						 "detected, just remove "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 						 "save link\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				retval = remove_save_link_only(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 							&save_link_key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		printk("done\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		done++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	REISERFS_SB(s)->s_is_unlinked_ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* Turn quotas off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		if (sb_dqopt(s)->files[i] && quota_enabled[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			dquot_quota_off(s, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	if (ms_active_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		/* Restore the flag back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		s->s_flags &= ~SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	pathrelse(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 			      "Completed\n", done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  * to protect file being unlinked from getting lost we "safe" link files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)  * being unlinked. This link will be deleted in the same transaction with last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  * item of file. mounting the filesystem we scan all these links and remove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  * files which almost got lost
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) void add_save_link(struct reiserfs_transaction_handle *th,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		   struct inode *inode, int truncate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	INITIALIZE_PATH(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	struct cpu_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	struct item_head ih;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	__le32 link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	BUG_ON(!th->t_trans_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	/* file can only get one "save link" of each kind */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	RFALSE(truncate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	       (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	       "saved link already exists for truncated inode %lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	       (long)inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	RFALSE(!truncate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	       (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	       "saved link already exists for unlinked inode %lx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	       (long)inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	/* setup key of "save" link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	key.version = KEY_FORMAT_3_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	key.on_disk_key.k_objectid = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	if (!truncate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		/* unlink, rmdir, rename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		set_cpu_key_k_type(&key, TYPE_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		/* item head of "safe" link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		make_le_item_head(&ih, &key, key.version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 				  1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 				  4 /*length */ , 0xffff /*free space */ );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		/* truncate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			reiserfs_warning(inode->i_sb, "green-2102",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 					 "Adding a truncate savelink for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 					 "a directory %k! Please report",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 					 INODE_PKEY(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		set_cpu_key_k_offset(&key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		set_cpu_key_k_type(&key, TYPE_INDIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		/* item head of "safe" link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 				  4 /*length */ , 0 /*free space */ );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	key.key_length = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	/* look for its place in the tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	retval = search_item(inode->i_sb, &key, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	if (retval != ITEM_NOT_FOUND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		if (retval != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			reiserfs_error(inode->i_sb, "vs-2100",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				       "search_by_key (%K) returned %d", &key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				       retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		pathrelse(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	/* body of "save" link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	link = INODE_PKEY(inode)->k_dir_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	/* put "save" link into tree, don't charge quota to anyone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	retval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	    reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		if (retval != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			reiserfs_error(inode->i_sb, "vs-2120",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 				       "insert_item returned %d", retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		if (truncate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			REISERFS_I(inode)->i_flags |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			    i_link_saved_truncate_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) /* this opens transaction unlike add_save_link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) int remove_save_link(struct inode *inode, int truncate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	struct reiserfs_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	/* we are going to do one balancing only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	/* setup key of "save" link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	key.k_objectid = INODE_PKEY(inode)->k_objectid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	if (!truncate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		/* unlink, rmdir, rename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		set_le_key_k_offset(KEY_FORMAT_3_5, &key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 				    1 + inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		/* truncate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	if ((truncate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	     (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	    (!truncate &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	     (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		/* don't take quota bytes from anywhere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		reiserfs_delete_solid_item(&th, NULL, &key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	if (!truncate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		reiserfs_release_objectid(&th, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	return journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) static void reiserfs_kill_sb(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	if (REISERFS_SB(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		reiserfs_proc_info_done(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		 * Force any pending inode evictions to occur now. Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		 * inodes to be removed that have extended attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		 * associated with them need to clean them up before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		 * we can release the extended attribute root dentries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		 * shrink_dcache_for_umount will BUG if we don't release
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		 * those before it's called so ->put_super is too late.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		shrink_dcache_sb(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		dput(REISERFS_SB(s)->xattr_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 		REISERFS_SB(s)->xattr_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		dput(REISERFS_SB(s)->priv_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		REISERFS_SB(s)->priv_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	kill_block_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) static int reiserfs_quota_off(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) static void reiserfs_quota_off_umount(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	for (type = 0; type < REISERFS_MAXQUOTAS; type++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		reiserfs_quota_off(s, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) static inline void reiserfs_quota_off_umount(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) static void reiserfs_put_super(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	th.t_trans_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	reiserfs_quota_off_umount(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	 * change file system state to current state if it was mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 * with read-write permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	if (!sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		if (!journal_begin(&th, s, 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 			reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 						     1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 					    REISERFS_SB(s)->s_mount_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	 * note, journal_release checks for readonly mount, and can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 * decide not to do a journal_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	journal_release(&th, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	reiserfs_free_bitmap_cache(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	brelse(SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	print_statistics(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	if (REISERFS_SB(s)->reserved_blocks != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		reiserfs_warning(s, "green-2005", "reserved blocks left %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 				 REISERFS_SB(s)->reserved_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	mutex_destroy(&REISERFS_SB(s)->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	destroy_workqueue(REISERFS_SB(s)->commit_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	kfree(REISERFS_SB(s)->s_jdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	kfree(s->s_fs_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	s->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) static struct kmem_cache *reiserfs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) static struct inode *reiserfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	struct reiserfs_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	ei = kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	atomic_set(&ei->openers, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	mutex_init(&ei->tailpack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	return &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) static void reiserfs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	INIT_LIST_HEAD(&ei->i_prealloc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 						  sizeof(struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 							 reiserfs_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 						  0, (SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 						      SLAB_MEM_SPREAD|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 						      SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 						  init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	if (reiserfs_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	 * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	 * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	kmem_cache_destroy(reiserfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) /* we don't mark inodes dirty, we just log them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) static void reiserfs_dirty_inode(struct inode *inode, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	if (sb_rdonly(inode->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		reiserfs_warning(inode->i_sb, "clm-6006",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 				 "writing inode %lu on readonly FS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 				 inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	reiserfs_write_lock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	 * this is really only used for atime updates, so they don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	 * to be included in O_SYNC or fsync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	err = journal_begin(&th, inode->i_sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	reiserfs_update_sd(&th, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	reiserfs_write_unlock(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) static int reiserfs_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	struct super_block *s = root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	struct reiserfs_journal *journal = SB_JOURNAL(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	long opts = REISERFS_SB(s)->s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (opts & (1 << REISERFS_LARGETAIL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		seq_puts(seq, ",tails=on");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	else if (!(opts & (1 << REISERFS_SMALLTAIL)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		seq_puts(seq, ",notail");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	/* tails=small is default so we don't show it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	if (!(opts & (1 << REISERFS_BARRIER_FLUSH)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		seq_puts(seq, ",barrier=none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	/* barrier=flush is default so we don't show it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	if (opts & (1 << REISERFS_ERROR_CONTINUE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		seq_puts(seq, ",errors=continue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	else if (opts & (1 << REISERFS_ERROR_PANIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		seq_puts(seq, ",errors=panic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	/* errors=ro is default so we don't show it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (opts & (1 << REISERFS_DATA_LOG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		seq_puts(seq, ",data=journal");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	else if (opts & (1 << REISERFS_DATA_WRITEBACK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		seq_puts(seq, ",data=writeback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	/* data=ordered is default so we don't show it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	if (opts & (1 << REISERFS_ATTRS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		seq_puts(seq, ",attrs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	if (opts & (1 << REISERFS_XATTRS_USER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		seq_puts(seq, ",user_xattr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (opts & (1 << REISERFS_EXPOSE_PRIVROOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		seq_puts(seq, ",expose_privroot");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	if (opts & (1 << REISERFS_POSIXACL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		seq_puts(seq, ",acl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	if (REISERFS_SB(s)->s_jdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		seq_show_option(seq, "jdev", REISERFS_SB(s)->s_jdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	if (journal->j_max_commit_age != journal->j_default_max_commit_age)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		seq_printf(seq, ",commit=%d", journal->j_max_commit_age);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	if (REISERFS_SB(s)->s_qf_names[USRQUOTA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		seq_show_option(seq, "usrjquota",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 				REISERFS_SB(s)->s_qf_names[USRQUOTA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	else if (opts & (1 << REISERFS_USRQUOTA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		seq_puts(seq, ",usrquota");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (REISERFS_SB(s)->s_qf_names[GRPQUOTA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		seq_show_option(seq, "grpjquota",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 				REISERFS_SB(s)->s_qf_names[GRPQUOTA]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	else if (opts & (1 << REISERFS_GRPQUOTA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		seq_puts(seq, ",grpquota");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	if (REISERFS_SB(s)->s_jquota_fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_OLD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			seq_puts(seq, ",jqfmt=vfsold");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		else if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_V0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			seq_puts(seq, ",jqfmt=vfsv0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	/* Block allocator options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	if (opts & (1 << REISERFS_NO_BORDER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		seq_puts(seq, ",block-allocator=noborder");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	if (opts & (1 << REISERFS_NO_UNHASHED_RELOCATION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		seq_puts(seq, ",block-allocator=no_unhashed_relocation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	if (opts & (1 << REISERFS_HASHED_RELOCATION))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		seq_puts(seq, ",block-allocator=hashed_relocation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	if (opts & (1 << REISERFS_TEST4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		seq_puts(seq, ",block-allocator=test4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	show_alloc_options(seq, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 				    size_t, loff_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 				   loff_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) static struct dquot **reiserfs_get_dquots(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	return REISERFS_I(inode)->i_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) static const struct super_operations reiserfs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	.alloc_inode = reiserfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	.free_inode = reiserfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	.write_inode = reiserfs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	.dirty_inode = reiserfs_dirty_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	.evict_inode = reiserfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	.put_super = reiserfs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	.sync_fs = reiserfs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	.freeze_fs = reiserfs_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	.unfreeze_fs = reiserfs_unfreeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	.statfs = reiserfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	.remount_fs = reiserfs_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	.show_options = reiserfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	.quota_read = reiserfs_quota_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	.quota_write = reiserfs_quota_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	.get_dquots = reiserfs_get_dquots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) static int reiserfs_write_dquot(struct dquot *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) static int reiserfs_acquire_dquot(struct dquot *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) static int reiserfs_release_dquot(struct dquot *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) static int reiserfs_mark_dquot_dirty(struct dquot *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) static int reiserfs_write_info(struct super_block *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) static int reiserfs_quota_on(struct super_block *, int, int, const struct path *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) static const struct dquot_operations reiserfs_quota_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	.write_dquot = reiserfs_write_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	.acquire_dquot = reiserfs_acquire_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	.release_dquot = reiserfs_release_dquot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	.mark_dirty = reiserfs_mark_dquot_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	.write_info = reiserfs_write_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	.alloc_dquot	= dquot_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	.destroy_dquot	= dquot_destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	.get_next_id	= dquot_get_next_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) static const struct quotactl_ops reiserfs_qctl_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	.quota_on = reiserfs_quota_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	.quota_off = reiserfs_quota_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	.quota_sync = dquot_quota_sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	.get_state = dquot_get_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	.set_info = dquot_set_dqinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	.get_dqblk = dquot_get_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	.set_dqblk = dquot_set_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) static const struct export_operations reiserfs_export_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	.encode_fh = reiserfs_encode_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	.fh_to_dentry = reiserfs_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	.fh_to_parent = reiserfs_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	.get_parent = reiserfs_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  * this struct is used in reiserfs_getopt () for containing the value for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  * those mount options that have values rather than being toggles.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	char *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	 * bitmask which is to set on mount_options bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	 * when this value is found, 0 is no bits are to be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	int setmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	 * bitmask which is to clear on mount_options bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	 * when this value is found, 0 is no bits are to be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	 * This is applied BEFORE setmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	int clrmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) } arg_desc_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) /* Set this bit in arg_required to allow empty arguments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) #define REISERFS_OPT_ALLOWEMPTY 31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)  * this struct is used in reiserfs_getopt() for describing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)  * set of reiserfs mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	char *option_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	/* 0 if argument is not required, not 0 otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	int arg_required;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	/* list of values accepted by an option */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	const arg_desc_t *values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	 * bitmask which is to set on mount_options bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	 * when this value is found, 0 is no bits are to be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	int setmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	 * bitmask which is to clear on mount_options bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	 * when this value is found, 0 is no bits are to be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	 * This is applied BEFORE setmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	int clrmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) } opt_desc_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) /* possible values for -o data= */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) static const arg_desc_t logging_mode[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	{"ordered", 1 << REISERFS_DATA_ORDERED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	{"journal", 1 << REISERFS_DATA_LOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	{"writeback", 1 << REISERFS_DATA_WRITEBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	 (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	{.value = NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) /* possible values for -o barrier= */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) static const arg_desc_t barrier_mode[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	{"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	{"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	{.value = NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938)  * possible values for "-o block-allocator=" and bits which are to be set in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939)  * s_mount_opt of reiserfs specific part of in-core super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) static const arg_desc_t balloc[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	{"noborder", 1 << REISERFS_NO_BORDER, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	{"border", 0, 1 << REISERFS_NO_BORDER},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	{"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	{"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	{"test4", 1 << REISERFS_TEST4, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	{"notest4", 0, 1 << REISERFS_TEST4},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	{NULL, 0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) static const arg_desc_t tails[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	{"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	{"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	{"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	{NULL, 0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static const arg_desc_t error_actions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	{"panic", 1 << REISERFS_ERROR_PANIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	 (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	{"ro-remount", 1 << REISERFS_ERROR_RO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	{"continue", 1 << REISERFS_ERROR_CONTINUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	 (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	{NULL, 0, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)  * proceed only one option from a list *cur - string containing of mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972)  * options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)  * opts - array of options which are accepted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)  * opt_arg - if option is found and requires an argument and if it is specifed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975)  * in the input - pointer to the argument is stored here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)  * bit_flags - if option requires to set a certain bit - it is set here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  * return -1 if unknown option is found, opt->arg_required otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			   char **opt_arg, unsigned long *bit_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	 * foo=bar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	 * ^   ^  ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	 * |   |  +-- option_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	 * |   +-- arg_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	 * +-- option_start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	const opt_desc_t *opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	const arg_desc_t *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	p = *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	/* assume argument cannot contain commas */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	*cur = strchr(p, ',');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	if (*cur) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		*(*cur) = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		(*cur)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	if (!strncmp(p, "alloc=", 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		 * Ugly special case, probably we should redo options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		 * parser so that it can understand several arguments for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		 * some options, also so that it can fill several bitfields
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		 * with option values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		if (reiserfs_parse_alloc_options(s, p + 6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	/* for every option in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	for (opt = opts; opt->option_name; opt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			if (bit_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 				if (opt->clrmask ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 				    (1 << REISERFS_UNSUPPORTED_OPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 					reiserfs_warning(s, "super-6500",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 							 "%s not supported.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 							 p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 					*bit_flags &= ~opt->clrmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				if (opt->setmask ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 				    (1 << REISERFS_UNSUPPORTED_OPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 					reiserfs_warning(s, "super-6501",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 							 "%s not supported.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 							 p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 					*bit_flags |= opt->setmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (!opt->option_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		reiserfs_warning(s, "super-6502",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 				 "unknown mount option \"%s\"", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	p += strlen(opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	switch (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	case '=':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		if (!opt->arg_required) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			reiserfs_warning(s, "super-6503",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 					 "the option \"%s\" does not "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 					 "require an argument\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 					 opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		if (opt->arg_required) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 			reiserfs_warning(s, "super-6504",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 					 "the option \"%s\" requires an "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 					 "argument\n", opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		reiserfs_warning(s, "super-6505",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 				 "head of option \"%s\" is only correct\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 				 opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	 * move to the argument, or to next option if argument is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	 * required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	if (opt->arg_required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	    && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	    && !strlen(p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		/* this catches "option=," if not allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		reiserfs_warning(s, "super-6506",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 				 "empty argument for \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				 opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	if (!opt->values) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		/* *=NULLopt_arg contains pointer to argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		*opt_arg = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	/* values possible for this option are listed in opt->values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	for (arg = opt->values; arg->value; arg++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		if (!strcmp(p, arg->value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			if (bit_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 				*bit_flags &= ~arg->clrmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 				*bit_flags |= arg->setmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 			return opt->arg_required;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	reiserfs_warning(s, "super-6506",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 			 "bad value \"%s\" for option \"%s\"\n", p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 			 opt->option_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) /* returns 0 if something is wrong in option string, 1 - otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) static int reiserfs_parse_options(struct super_block *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 				  /* string given via mount's -o */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 				  char *options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 				  /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 				   * after the parsing phase, contains the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 				   * collection of bitflags defining what
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 				   * mount options were selected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 				   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 				  unsigned long *mount_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 				  /* strtol-ed from NNN of resize=NNN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 				  unsigned long *blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 				  char **jdev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 				  unsigned int *commit_max_age,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 				  char **qf_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 				  unsigned int *qfmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	int c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	char *arg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	char *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	opt_desc_t opts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		 * Compatibility stuff, so that -o notail for old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		 * setups still work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		{"tails",.arg_required = 't',.values = tails},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		{"notail",.clrmask =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		{"conv",.setmask = 1 << REISERFS_CONVERT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		{"attrs",.setmask = 1 << REISERFS_ATTRS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		{"noattrs",.clrmask = 1 << REISERFS_ATTRS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		{"expose_privroot", .setmask = 1 << REISERFS_EXPOSE_PRIVROOT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) #ifdef CONFIG_REISERFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		{"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 		{"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		{"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		{"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) #ifdef CONFIG_REISERFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		{"acl",.setmask = 1 << REISERFS_POSIXACL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		{"noacl",.clrmask = 1 << REISERFS_POSIXACL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		{"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 		{"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		{.option_name = "nolog"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		{"replayonly",.setmask = 1 << REPLAYONLY},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		{"block-allocator",.arg_required = 'a',.values = balloc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		{"data",.arg_required = 'd',.values = logging_mode},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		{"barrier",.arg_required = 'b',.values = barrier_mode},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 		{"resize",.arg_required = 'r',.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 		{"jdev",.arg_required = 'j',.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		{"nolargeio",.arg_required = 'w',.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		{"commit",.arg_required = 'c',.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 		{"usrquota",.setmask = 1 << REISERFS_USRQUOTA},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		{"grpquota",.setmask = 1 << REISERFS_GRPQUOTA},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		{"noquota",.clrmask = 1 << REISERFS_USRQUOTA | 1 << REISERFS_GRPQUOTA},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		{"errors",.arg_required = 'e',.values = error_actions},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		{"usrjquota",.arg_required =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		{"grpjquota",.arg_required =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		{"jqfmt",.arg_required = 'f',.values = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		{.option_name = NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	*blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (!options || !*options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		 * use default configuration: create tails, journaling on, no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 		 * conversion to newest format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	for (pos = options; pos;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 		if (c == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 			/* wrong option is given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		if (c == 'r') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 			char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 			/* "resize=NNN" or "resize=auto" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			if (!strcmp(arg, "auto")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 				/* From JFS code, to auto-get the size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 				*blocks =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 				    i_size_read(s->s_bdev->bd_inode) >> s->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 				    s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 				*blocks = simple_strtoul(arg, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 				if (*p != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 					/* NNN does not look like a number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 					reiserfs_warning(s, "super-6507",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 							 "bad value %s for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 							 "-oresize\n", arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 		if (c == 'c') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 			char *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 			unsigned long val = simple_strtoul(arg, &p, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 			/* commit=NNN (time in seconds) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 			if (*p != '\0' || val >= (unsigned int)-1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 				reiserfs_warning(s, "super-6508",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 						 "bad value %s for -ocommit\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 						 arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 			*commit_max_age = (unsigned int)val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		if (c == 'w') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 			reiserfs_warning(s, "super-6509", "nolargeio option "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 					 "is no longer supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 		if (c == 'j') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 			if (arg && *arg && jdev_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 				/* Hm, already assigned? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 				if (*jdev_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 					reiserfs_warning(s, "super-6510",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 							 "journal device was "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 							 "already specified to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 							 "be %s", *jdev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 				*jdev_name = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		if (c == 'u' || c == 'g') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 			int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 			if (sb_any_quota_loaded(s) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 			    (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 				reiserfs_warning(s, "super-6511",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 						 "cannot change journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 						 "quota options when quota "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 						 "turned on.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 			if (qf_names[qtype] !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 			    REISERFS_SB(s)->s_qf_names[qtype])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 				kfree(qf_names[qtype]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 			qf_names[qtype] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 			if (*arg) {	/* Some filename specified? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 				if (REISERFS_SB(s)->s_qf_names[qtype]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 				    && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 					      arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 					reiserfs_warning(s, "super-6512",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 							 "%s quota file "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 							 "already specified.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 							 QTYPE2NAME(qtype));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 				if (strchr(arg, '/')) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 					reiserfs_warning(s, "super-6513",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 							 "quotafile must be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 							 "on filesystem root.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 				qf_names[qtype] = kstrdup(arg, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 				if (!qf_names[qtype]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 					reiserfs_warning(s, "reiserfs-2502",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 							 "not enough memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 							 "for storing "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 							 "quotafile name.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 					return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 				if (qtype == USRQUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 					*mount_options |= 1 << REISERFS_USRQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 					*mount_options |= 1 << REISERFS_GRPQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 				if (qtype == USRQUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 					*mount_options &= ~(1 << REISERFS_USRQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 					*mount_options &= ~(1 << REISERFS_GRPQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		if (c == 'f') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 			if (!strcmp(arg, "vfsold"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 				*qfmt = QFMT_VFS_OLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 			else if (!strcmp(arg, "vfsv0"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 				*qfmt = QFMT_VFS_V0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 			else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 				reiserfs_warning(s, "super-6514",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 						 "unknown quota format "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 						 "specified.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 			if (sb_any_quota_loaded(s) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 			    *qfmt != REISERFS_SB(s)->s_jquota_fmt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 				reiserfs_warning(s, "super-6515",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 						 "cannot change journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 						 "quota options when quota "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 						 "turned on.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		if (c == 'u' || c == 'g' || c == 'f') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 			reiserfs_warning(s, "reiserfs-2503", "journaled "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 					 "quota options not supported.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	    && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		reiserfs_warning(s, "super-6515",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 				 "journaled quota format not specified.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	if ((!(*mount_options & (1 << REISERFS_USRQUOTA)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	       sb_has_quota_loaded(s, USRQUOTA)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	    (!(*mount_options & (1 << REISERFS_GRPQUOTA)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	       sb_has_quota_loaded(s, GRPQUOTA))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		reiserfs_warning(s, "super-6516", "quota options must "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 				 "be present when quota is turned on.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) static void switch_data_mode(struct super_block *s, unsigned long mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 					 (1 << REISERFS_DATA_ORDERED) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 					 (1 << REISERFS_DATA_WRITEBACK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	REISERFS_SB(s)->s_mount_opt |= (1 << mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) static void handle_data_mode(struct super_block *s, unsigned long mount_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	if (mount_options & (1 << REISERFS_DATA_LOG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 		if (!reiserfs_data_log(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 			switch_data_mode(s, REISERFS_DATA_LOG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			reiserfs_info(s, "switching to journaled data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	} else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 		if (!reiserfs_data_ordered(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 			switch_data_mode(s, REISERFS_DATA_ORDERED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			reiserfs_info(s, "switching to ordered data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	} else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		if (!reiserfs_data_writeback(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 			switch_data_mode(s, REISERFS_DATA_WRITEBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			reiserfs_info(s, "switching to writeback data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static void handle_barrier_mode(struct super_block *s, unsigned long bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	int flush = (1 << REISERFS_BARRIER_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	int none = (1 << REISERFS_BARRIER_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	int all_barrier = flush | none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	if (bits & all_barrier) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 		if (bits & flush) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 			REISERFS_SB(s)->s_mount_opt |= flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 			printk("reiserfs: enabling write barrier flush mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		} else if (bits & none) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 			REISERFS_SB(s)->s_mount_opt |= none;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 			printk("reiserfs: write barriers turned off\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) static void handle_attrs(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	if (reiserfs_attrs(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		if (old_format_only(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 			reiserfs_warning(s, "super-6517", "cannot support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 					 "attributes on 3.5.x disk format");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 			REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			reiserfs_warning(s, "super-6518", "cannot support "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 					 "attributes until flag is set in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 					 "super-block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 			REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) static void handle_quota_files(struct super_block *s, char **qf_names,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 			       unsigned int *qfmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			kfree(REISERFS_SB(s)->s_qf_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		REISERFS_SB(s)->s_qf_names[i] = qf_names[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	if (*qfmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 		REISERFS_SB(s)->s_jquota_fmt = *qfmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	struct reiserfs_super_block *rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	unsigned long blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	unsigned long safe_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	unsigned int commit_max_age = (unsigned int)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	struct reiserfs_journal *journal = SB_JOURNAL(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	char *new_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	char *qf_names[REISERFS_MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 	unsigned int qfmt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	new_opts = kstrdup(arg, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	if (arg && !new_opts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	sync_filesystem(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	memcpy(qf_names, REISERFS_SB(s)->s_qf_names, sizeof(qf_names));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	rs = SB_DISK_SUPER_BLOCK(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	if (!reiserfs_parse_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	    (s, arg, &mount_options, &blocks, NULL, &commit_max_age,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	    qf_names, &qfmt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 		for (i = 0; i < REISERFS_MAXQUOTAS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 			if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 				kfree(qf_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 		goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	handle_quota_files(s, qf_names, &qfmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	handle_attrs(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	/* Add options that are safe here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	safe_mask |= 1 << REISERFS_SMALLTAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	safe_mask |= 1 << REISERFS_LARGETAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	safe_mask |= 1 << REISERFS_NO_BORDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	safe_mask |= 1 << REISERFS_TEST4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	safe_mask |= 1 << REISERFS_ATTRS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	safe_mask |= 1 << REISERFS_XATTRS_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	safe_mask |= 1 << REISERFS_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	safe_mask |= 1 << REISERFS_BARRIER_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	safe_mask |= 1 << REISERFS_ERROR_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	safe_mask |= 1 << REISERFS_ERROR_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	safe_mask |= 1 << REISERFS_USRQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	safe_mask |= 1 << REISERFS_GRPQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	 * Update the bitmask, taking care to keep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	 * the bits we're not allowed to change here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	REISERFS_SB(s)->s_mount_opt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	    (REISERFS_SB(s)->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	     s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		journal->j_max_commit_age = commit_max_age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		journal->j_max_trans_age = commit_max_age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	} else if (commit_max_age == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 		/* 0 means restore defaults. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		journal->j_max_commit_age = journal->j_default_max_commit_age;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	if (blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		err = reiserfs_resize(s, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		if (err != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 			goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	if (*mount_flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 		reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		reiserfs_xattr_init(s, *mount_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		/* remount read-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		if (sb_rdonly(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 			/* it is read-only already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 			goto out_ok_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 		err = dquot_suspend(s, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 			goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 		/* try to remount file system with read-only permissions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		if (sb_umount_state(rs) == REISERFS_VALID_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 		    || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 			goto out_ok_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 		reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		err = journal_begin(&th, s, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 			goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 		/* Mounting a rw partition read-only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 		reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 		set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 		journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		/* remount read-write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		if (!sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 			reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 			reiserfs_xattr_init(s, *mount_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 			goto out_ok_unlocked;	/* We are read-write already */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 		if (reiserfs_is_journal_aborted(journal)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 			err = journal->j_errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 			goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 		handle_data_mode(s, mount_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 		handle_barrier_mode(s, mount_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 		/* now it is safe to call journal_begin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		s->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		err = journal_begin(&th, s, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		/* Mount a partition which is read-only, read-write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 		REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		s->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		set_sb_umount_state(rs, REISERFS_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		if (!old_format_only(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 			set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		/* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 		journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 		REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	/* this will force a full flush of all journal lists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	SB_JOURNAL(s)->j_must_wait = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	err = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		goto out_err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	if (!(*mount_flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		dquot_resume(s, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		finish_unfinished(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 		reiserfs_xattr_init(s, *mount_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) out_ok_unlocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) out_err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	kfree(new_opts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) static int read_super_block(struct super_block *s, int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	struct reiserfs_super_block *rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	int fs_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	bh = sb_bread(s, offset / s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		reiserfs_warning(s, "sh-2006",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 				 "bread failed (dev %s, block %lu, size %lu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 				 s->s_id, offset / s->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 				 s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	rs = (struct reiserfs_super_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	if (!is_any_reiserfs_magic_string(rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	 * ok, reiserfs signature (old or new) found in at the given offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	fs_blocksize = sb_blocksize(rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	sb_set_blocksize(s, fs_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	bh = sb_bread(s, offset / s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 		reiserfs_warning(s, "sh-2007",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 				 "bread failed (dev %s, block %lu, size %lu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 				 s->s_id, offset / s->s_blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 				 s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	rs = (struct reiserfs_super_block *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	if (sb_blocksize(rs) != s->s_blocksize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 		reiserfs_warning(s, "sh-2011", "can't find a reiserfs "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 				 "filesystem on (dev %s, block %llu, size %lu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 				 s->s_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 				 (unsigned long long)bh->b_blocknr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 				 s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		reiserfs_warning(s, "super-6519", "Unfinished reiserfsck "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 				 "--rebuild-tree run detected. Please run\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 				 "reiserfsck --rebuild-tree and wait for a "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 				 "completion. If that fails\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 				 "get newer reiserfsprogs package");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	SB_BUFFER_WITH_SB(s) = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	SB_DISK_SUPER_BLOCK(s) = rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	 * magic is of non-standard journal filesystem, look at s_version to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	 * find which format is in use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	if (is_reiserfs_jr(rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		if (sb_version(rs) == REISERFS_VERSION_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			reiserfs_info(s, "found reiserfs format \"3.6\""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 				      " with non-standard journal\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 		else if (sb_version(rs) == REISERFS_VERSION_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 			reiserfs_info(s, "found reiserfs format \"3.5\""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 				      " with non-standard journal\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			reiserfs_warning(s, "sh-2012", "found unknown "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 					 "format \"%u\" of reiserfs with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 					 "non-standard magic", sb_version(rs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		 * s_version of standard format may contain incorrect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		 * information, so we just look at the magic string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		reiserfs_info(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 			      "found reiserfs format \"%s\" with standard journal\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			      is_reiserfs_3_5(rs) ? "3.5" : "3.6");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	s->s_op = &reiserfs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	s->s_export_op = &reiserfs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	s->s_qcop = &reiserfs_qctl_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	s->dq_op = &reiserfs_quota_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	s->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	 * new format is limited by the 32 bit wide i_blocks field, want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	 * be one full block below that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	s->s_maxbytes = (512LL << 32) - s->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) /* after journal replay, reread all bitmap and super blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) static int reread_meta_blocks(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	ll_rw_block(REQ_OP_READ, 0, 1, &SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	wait_on_buffer(SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 		reiserfs_warning(s, "reiserfs-2504", "error reading the super");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) /* hash detection stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)  * if root directory is empty - we set default - Yura's - hash and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)  * warn about it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)  * FIXME: we look for only one name in a directory. If tea and yura
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)  * both have the same value - we ask user to send report to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)  * mailing list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) static __u32 find_hash_out(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	struct cpu_key key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	INITIALIZE_PATH(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	struct reiserfs_dir_entry de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	struct reiserfs_de_head *deh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	__u32 hash = DEFAULT_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	__u32 deh_hashval, teahash, r5hash, yurahash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	inode = d_inode(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	retval = search_by_entry_key(s, &key, &path, &de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	if (retval == IO_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		pathrelse(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 		return UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	if (retval == NAME_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 		de.de_entry_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	set_de_name_and_namelen(&de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	deh = de.de_deh + de.de_entry_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	if (deh_offset(deh) == DOT_DOT_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		/* allow override in this case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		if (reiserfs_rupasov_hash(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 			hash = YURA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		reiserfs_info(s, "FS seems to be empty, autodetect is using the default hash\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	deh_hashval = GET_HASH_VALUE(deh_offset(deh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	if ((teahash == r5hash && deh_hashval == r5hash) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	    (teahash == yurahash && deh_hashval == yurahash) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	    (r5hash == yurahash && deh_hashval == yurahash)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		reiserfs_warning(s, "reiserfs-2506",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 				 "Unable to automatically detect hash "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 				 "function. Please mount with -o "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 				 "hash={tea,rupasov,r5}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 		hash = UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	if (deh_hashval == yurahash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 		hash = YURA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	else if (deh_hashval == teahash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		hash = TEA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	else if (deh_hashval == r5hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		hash = R5_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 		reiserfs_warning(s, "reiserfs-2506",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 				 "Unrecognised hash function");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 		hash = UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	pathrelse(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	return hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) /* finds out which hash names are sorted with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) static int what_hash(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	__u32 code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	 * reiserfs_hash_detect() == true if any of the hash mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	 * were used.  We must check them to make sure the user isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	 * using a bad hash value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	if (code == UNSET_HASH || reiserfs_hash_detect(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		code = find_hash_out(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		 * detection has found the hash, and we must check against the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		 * mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 		if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 			reiserfs_warning(s, "reiserfs-2507",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 					 "Error, %s hash detected, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 					 "unable to force rupasov hash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 					 reiserfs_hashname(code));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 			code = UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		} else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 			reiserfs_warning(s, "reiserfs-2508",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 					 "Error, %s hash detected, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 					 "unable to force tea hash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 					 reiserfs_hashname(code));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 			code = UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 		} else if (reiserfs_r5_hash(s) && code != R5_HASH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 			reiserfs_warning(s, "reiserfs-2509",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 					 "Error, %s hash detected, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 					 "unable to force r5 hash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 					 reiserfs_hashname(code));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 			code = UNSET_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		 * find_hash_out was not called or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 		 * could not determine the hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 		if (reiserfs_rupasov_hash(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 			code = YURA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 		} else if (reiserfs_tea_hash(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 			code = TEA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		} else if (reiserfs_r5_hash(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 			code = R5_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	 * if we are mounted RW, and we have a new valid hash code, update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	 * the super
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	if (code != UNSET_HASH &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	    !sb_rdonly(s) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	    code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	return code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) /* return pointer to appropriate function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) static hashf_t hash_function(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 	switch (what_hash(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 	case TEA_HASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 		reiserfs_info(s, "Using tea hash to sort names\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 		return keyed_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	case YURA_HASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		reiserfs_info(s, "Using rupasov hash to sort names\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 		return yura_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	case R5_HASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 		reiserfs_info(s, "Using r5 hash to sort names\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 		return r5_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) /* this is used to set up correct value for old partitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) static int function2code(hashf_t func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	if (func == keyed_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 		return TEA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	if (func == yura_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		return YURA_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	if (func == r5_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 		return R5_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	BUG();			/* should never happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) #define SWARN(silent, s, id, ...)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	if (!(silent))				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		reiserfs_warning(s, id, __VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	struct inode *root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	int old_format = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	unsigned long blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 	unsigned int commit_max_age = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	int jinit_done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	struct reiserfs_iget_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	struct reiserfs_super_block *rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	char *jdev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	struct reiserfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	int errval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	char *qf_names[REISERFS_MAXQUOTAS] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	unsigned int qfmt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	s->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	/* Set default values for options: non-aggressive tails, RO on errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 	sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	/* no preallocation minimum, be smart in reiserfs_file_write instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 	sbi->s_alloc_options.preallocmin = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	/* Preallocate by 16 blocks (17-1) at once */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	sbi->s_alloc_options.preallocsize = 17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	/* setup default block allocator options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	reiserfs_init_alloc_options(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	spin_lock_init(&sbi->old_work_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	INIT_DELAYED_WORK(&sbi->old_work, flush_old_commits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	mutex_init(&sbi->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	sbi->lock_depth = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	sbi->commit_wq = alloc_workqueue("reiserfs/%s", WQ_MEM_RECLAIM, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 					 s->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	if (!sbi->commit_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		SWARN(silent, s, "", "Cannot allocate commit workqueue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		errval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	jdev_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	if (reiserfs_parse_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	    (s, (char *)data, &sbi->s_mount_opt, &blocks, &jdev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 	     &commit_max_age, qf_names, &qfmt) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	if (jdev_name && jdev_name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 		sbi->s_jdev = kstrdup(jdev_name, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		if (!sbi->s_jdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 			SWARN(silent, s, "", "Cannot allocate memory for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 				"journal device name");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 			goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 	handle_quota_files(s, qf_names, &qfmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	if (blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		SWARN(silent, s, "jmacd-7", "resize option for remount only");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	 * try old format (undistributed bitmap, super block in 8-th 1k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	 * block of a device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		old_format = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 	 * try new format (64-th 1k block), which can contain reiserfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	 * super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		SWARN(silent, s, "sh-2021", "can not find reiserfs on %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 		      s->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	s->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 	s->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 	rs = SB_DISK_SUPER_BLOCK(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	 * Let's do basic sanity check to verify that underlying device is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	 * smaller than the filesystem. If the check fails then abort and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	 * scream, because bad stuff will happen otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	if (s->s_bdev && s->s_bdev->bd_inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	    && i_size_read(s->s_bdev->bd_inode) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 	    sb_block_count(rs) * sb_blocksize(rs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		SWARN(silent, s, "", "Filesystem cannot be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 		      "mounted because it is bigger than the device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 		SWARN(silent, s, "", "You may need to run fsck "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		      "or increase size of your LVM partition");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 		SWARN(silent, s, "", "Or may be you forgot to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 		      "reboot after fdisk when it told you to");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	sbi->s_mount_state = SB_REISERFS_STATE(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 	sbi->s_mount_state = REISERFS_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	if ((errval = reiserfs_init_bitmap_cache(s))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		SWARN(silent, s, "jmacd-8", "unable to read bitmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	errval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) #ifdef CONFIG_REISERFS_CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	SWARN(silent, s, "", "CONFIG_REISERFS_CHECK is set ON");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	SWARN(silent, s, "", "- it is slow mode for debugging.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	/* make data=ordered the default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	    !reiserfs_data_writeback(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 		sbi->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 	if (reiserfs_data_log(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 		reiserfs_info(s, "using journaled data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 	} else if (reiserfs_data_ordered(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 		reiserfs_info(s, "using ordered data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		reiserfs_info(s, "using writeback data mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	if (reiserfs_barrier_flush(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 		printk("reiserfs: using flush barriers\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	if (journal_init(s, jdev_name, old_format, commit_max_age)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 		SWARN(silent, s, "sh-2022",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 		      "unable to initialize journal space");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		 * once this is set, journal_release must be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		 * if we error out of the mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 		jinit_done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	if (reread_meta_blocks(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 		SWARN(silent, s, "jmacd-9",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 		      "unable to reread meta blocks after journal init");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	if (replay_only(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	s->s_xattr = reiserfs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	if (bdev_read_only(s->s_bdev) && !sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 		SWARN(silent, s, "clm-7000",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 		      "Detected readonly device, marking FS readonly");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		s->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	args.objectid = REISERFS_ROOT_OBJECTID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	root_inode =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	    iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 			 reiserfs_init_locked_inode, (void *)&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	if (!root_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		SWARN(silent, s, "jmacd-10", "get root inode failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 		goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	 * This path assumed to be called with the BKL in the old times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 	 * Now we have inherited the big reiserfs lock from it and many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	 * reiserfs helpers called in the mount path and elsewhere require
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	 * this lock to be held even if it's not always necessary. Let's be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 	 * conservative and hold it early. The window can be reduced after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	 * careful review of the code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	if (root_inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 		reiserfs_read_locked_inode(root_inode, &args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 		unlock_new_inode(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	if (!S_ISDIR(root_inode->i_mode) || !inode_get_bytes(root_inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	    !root_inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 		SWARN(silent, s, "", "corrupt root inode, run fsck");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 		iput(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 		errval = -EUCLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	s->s_root = d_make_root(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	if (!s->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	/* define and initialize hash function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	sbi->s_hash_function = hash_function(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	if (sbi->s_hash_function == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		dput(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 		s->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	if (is_reiserfs_3_5(rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 	    || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		set_bit(REISERFS_3_5, &sbi->s_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	else if (old_format)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 		set_bit(REISERFS_OLD_FORMAT, &sbi->s_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 		set_bit(REISERFS_3_6, &sbi->s_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	if (!sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		errval = journal_begin(&th, s, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 		if (errval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 			dput(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 			s->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 		reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 		set_sb_umount_state(rs, REISERFS_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 		set_sb_fs_state(rs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 		 * Clear out s_bmap_nr if it would wrap. We can handle this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		 * case, but older revisions can't. This will cause the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 		 * file system to fail mount on those older implementations,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 		 * avoiding corruption. -jeffm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		    sb_bmap_nr(rs) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 			reiserfs_warning(s, "super-2030", "This file system "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 					"claims to use %u bitmap blocks in "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 					"its super block, but requires %u. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 					"Clearing to zero.", sb_bmap_nr(rs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 					reiserfs_bmap_count(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 			set_sb_bmap_nr(rs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		if (old_format_only(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 			 * filesystem of format 3.5 either with standard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 			 * or non-standard journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 			if (convert_reiserfs(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 				/* and -o conv is given */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 				if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 					reiserfs_info(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 						      "converting 3.5 filesystem to the 3.6 format");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 				if (is_reiserfs_3_5(rs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 					 * put magic string of 3.6 format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 					 * 2.2 will not be able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 					 * mount this filesystem anymore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 					memcpy(rs->s_v1.s_magic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 					       reiserfs_3_6_magic_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 					       sizeof
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 					       (reiserfs_3_6_magic_string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 				set_sb_version(rs, REISERFS_VERSION_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 				reiserfs_convert_objectid_map_v1(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 				set_bit(REISERFS_3_6, &sbi->s_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 				clear_bit(REISERFS_3_5, &sbi->s_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 			} else if (!silent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 				reiserfs_info(s, "using 3.5.x disk format\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 			set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 		journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		errval = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		if (errval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 			dput(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 			s->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		if ((errval = reiserfs_lookup_privroot(s)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		    (errval = reiserfs_xattr_init(s, s->s_flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			dput(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 			s->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 			goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 		 * look for files which were to be removed in previous session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 		finish_unfinished(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		if (old_format_only(s) && !silent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 			reiserfs_info(s, "using 3.5.x disk format\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 		reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 		if ((errval = reiserfs_lookup_privroot(s)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		    (errval = reiserfs_xattr_init(s, s->s_flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 			dput(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 			s->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 			goto error_unlocked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 		reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	 * mark hash in super block: it could be unset. overwrite should be ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	handle_attrs(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	reiserfs_proc_info_init(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	init_waitqueue_head(&(sbi->s_wait));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	spin_lock_init(&sbi->bitmap_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	return (0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) error_unlocked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	/* kill the commit thread, free journal ram */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	if (jinit_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 		reiserfs_write_lock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 		journal_release_error(NULL, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		reiserfs_write_unlock(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	if (sbi->commit_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		destroy_workqueue(sbi->commit_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	reiserfs_cancel_old_flush(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	reiserfs_free_bitmap_cache(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	if (SB_BUFFER_WITH_SB(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 		brelse(SB_BUFFER_WITH_SB(s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		for (j = 0; j < REISERFS_MAXQUOTAS; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 			kfree(qf_names[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	kfree(sbi->s_jdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	s->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	return errval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 	struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 	buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 	buf->f_bfree = sb_free_blocks(rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	buf->f_bavail = buf->f_bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 	buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	buf->f_bsize = dentry->d_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 	/* changed to accommodate gcc folks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	buf->f_type = REISERFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 	buf->f_fsid.val[0] = (u32)crc32_le(0, rs->s_uuid, sizeof(rs->s_uuid)/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 	buf->f_fsid.val[1] = (u32)crc32_le(0, rs->s_uuid + sizeof(rs->s_uuid)/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 				sizeof(rs->s_uuid)/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) static int reiserfs_write_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	reiserfs_write_lock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 	ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	    journal_begin(&th, dquot->dq_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 			  REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 	depth = reiserfs_write_unlock_nested(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 	ret = dquot_commit(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	reiserfs_write_lock_nested(dquot->dq_sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	err = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	if (!ret && err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	reiserfs_write_unlock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) static int reiserfs_acquire_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 	int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	reiserfs_write_lock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	    journal_begin(&th, dquot->dq_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 			  REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	depth = reiserfs_write_unlock_nested(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 	ret = dquot_acquire(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	reiserfs_write_lock_nested(dquot->dq_sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 	err = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 	if (!ret && err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 	reiserfs_write_unlock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) static int reiserfs_release_dquot(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	reiserfs_write_lock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	ret =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	    journal_begin(&th, dquot->dq_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 			  REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	reiserfs_write_unlock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 		/* Release dquot anyway to avoid endless cycle in dqput() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 		dquot_release(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	ret = dquot_release(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	reiserfs_write_lock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 	err = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 	if (!ret && err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	reiserfs_write_unlock(dquot->dq_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 	/* Are we journaling quotas? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	    REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 		dquot_mark_dquot_dirty(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 		return reiserfs_write_dquot(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 		return dquot_mark_dquot_dirty(dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) static int reiserfs_write_info(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	int depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	/* Data block + inode block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 	reiserfs_write_lock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 	ret = journal_begin(&th, sb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	depth = reiserfs_write_unlock_nested(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 	ret = dquot_commit_info(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	reiserfs_write_lock_nested(sb, depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	err = journal_end(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	if (!ret && err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)  * Turn on quotas during mount time - we need to find the quota file and such...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) static int reiserfs_quota_on_mount(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	return dquot_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 					REISERFS_SB(sb)->s_jquota_fmt, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392)  * Standard function to be called on quota_on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 			     const struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	struct reiserfs_transaction_handle th;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 	int opt = type == USRQUOTA ? REISERFS_USRQUOTA : REISERFS_GRPQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	reiserfs_write_lock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	if (!(REISERFS_SB(sb)->s_mount_opt & (1 << opt))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 	/* Quotafile not on the same filesystem? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	if (path->dentry->d_sb != sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 		err = -EXDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 	 * We must not pack tails for quota files on reiserfs for quota
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	 * IO to work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 		err = reiserfs_unpack(inode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 			reiserfs_warning(sb, "super-6520",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 				"Unpacking tail of quota file failed"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 				" (%d). Cannot turn on quotas.", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	/* Journaling quota? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	if (REISERFS_SB(sb)->s_qf_names[type]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 		/* Quotafile not of fs root? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 		if (path->dentry->d_parent != sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 			reiserfs_warning(sb, "super-6521",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 				 "Quota file not on filesystem root. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 				 "Journalled quota will not work.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 	 * When we journal data on quota file, we have to flush journal to see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	 * all updates to the file when we bypass pagecache...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	if (reiserfs_file_data_log(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 		/* Just start temporary transaction and finish it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 		err = journal_begin(&th, sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 		err = journal_end_sync(&th);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 	reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	err = dquot_quota_on(sb, type, format_id, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 		inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 		REISERFS_I(inode)->i_attrs |= REISERFS_IMMUTABLE_FL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 					      REISERFS_NOATIME_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 		inode_set_flags(inode, S_IMMUTABLE | S_NOATIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 				S_IMMUTABLE | S_NOATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 		inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) static int reiserfs_quota_off(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	if (!inode || !igrab(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	err = dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	REISERFS_I(inode)->i_attrs &= ~(REISERFS_IMMUTABLE_FL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 					REISERFS_NOATIME_FL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	inode_set_flags(inode, 0, S_IMMUTABLE | S_NOATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	return dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)  * Read data from quotafile - avoid pagecache and such because we cannot afford
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)  * acquiring the locks... As quota files are never truncated and quota code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496)  * itself serializes the operations (and no one else should touch the files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)  * we don't have to be afraid of races
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 				   size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 	unsigned long blk = off >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 	int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 	size_t toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	struct buffer_head tmp_bh, *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	loff_t i_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 	if (off > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 	if (off + len > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		len = i_size - off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	toread = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 	while (toread > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 		tocopy =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 		    sb->s_blocksize - offset <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		    toread ? sb->s_blocksize - offset : toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 		tmp_bh.b_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 		 * Quota files are without tails so we can safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 		 * use this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 		reiserfs_write_lock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 		err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 		if (!buffer_mapped(&tmp_bh))	/* A hole? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 			memset(data, 0, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 			bh = sb_bread(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 			if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 				return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 			memcpy(data, bh->b_data + offset, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 			brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 		toread -= tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 		data += tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		blk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)  * Write to quotafile (we know the transaction is already started and has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)  * enough credits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 				    const char *data, size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 	struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	unsigned long blk = off >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 	int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 	int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	size_t towrite = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 	struct buffer_head tmp_bh, *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 	if (!current->journal_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 		printk(KERN_WARNING "reiserfs: Quota write (off=%llu, len=%llu) cancelled because transaction is not started.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 			(unsigned long long)off, (unsigned long long)len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 	while (towrite > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 		tocopy = sb->s_blocksize - offset < towrite ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 		    sb->s_blocksize - offset : towrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 		tmp_bh.b_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		reiserfs_write_lock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 		err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 		if (offset || tocopy != sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 			bh = sb_bread(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 			bh = sb_getblk(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 		if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 			err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 		memcpy(bh->b_data + offset, data, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 		flush_dcache_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 		reiserfs_write_lock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 		reiserfs_prepare_for_journal(sb, bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 		journal_mark_dirty(current->journal_info, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 		if (!journal_quota)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 			reiserfs_add_ordered_list(inode, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 		reiserfs_write_unlock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 		brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		towrite -= tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 		data += tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 		blk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 	if (len == towrite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	if (inode->i_size < off + len - towrite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		i_size_write(inode, off + len - towrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 	inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 	return len - towrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) static struct dentry *get_super_block(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 			   int flags, const char *dev_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 			   void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	return mount_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) static int __init init_reiserfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 	ret = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 	reiserfs_proc_info_global_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 	ret = register_filesystem(&reiserfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 	reiserfs_proc_info_global_done();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) static void __exit exit_reiserfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 	reiserfs_proc_info_global_done();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 	unregister_filesystem(&reiserfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 	destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) struct file_system_type reiserfs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 	.name = "reiserfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 	.mount = get_super_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	.kill_sb = reiserfs_kill_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 	.fs_flags = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) MODULE_ALIAS_FS("reiserfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) MODULE_DESCRIPTION("ReiserFS journaled filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) module_init(init_reiserfs_fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) module_exit(exit_reiserfs_fs);