Пример #1
0
/*
 * Calculate the number of buffer credits needed to write multiple pages in
 * a single ext3 transaction. 
 *
 * Check ext3_writepage_trans_blocks() for detail
 *
 */
static int mlowerfs_ext3_credits_needed(struct inode *inode, __u64 len)
{
	struct super_block *sb = inode->i_sb;
	int _nblock = (int)(len >> sb->s_blocksize_bits); /* Any possible overflow? */
	int nblock = _nblock + 2; /* Two block or more */
	int nindirect = _nblock / EXT3_ADDR_PER_BLOCK(sb) + 2;
	int ndindirect = _nblock / (EXT3_ADDR_PER_BLOCK(sb) * EXT3_ADDR_PER_BLOCK(sb)) + 2;
	int nbitmaps = 1 + nblock + nindirect + ndindirect; /* tindirect */
	int ngdblocks = nbitmaps > EXT3_SB(sb)->s_gdb_count ? EXT3_SB(sb)->s_gdb_count : nbitmaps;
	int ngroups = nbitmaps > EXT3_SB(sb)->s_groups_count ? EXT3_SB(sb)->s_groups_count : nbitmaps;
	int needed = 2; /* inodes + superblock */
	int i = 0;

	if (mlowerfs_ext3_should_journal_data(inode)) {
		needed += nbitmaps;
	}

	needed += ngdblocks + ngroups;

#if defined(CONFIG_QUOTA)
	if (!IS_NOQUOTA(inode)) {
		for (i = 0; i < MAXQUOTAS; i++) {
			if (sb_has_quota_active(sb, i)) {
				needed += EXT3_SINGLEDATA_TRANS_BLOCKS;
			}
		}
	}
#endif
	return needed;
}
Пример #2
0
static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
{
	__u32 fmt;

	down_read(&sb_dqopt(sb)->dqptr_sem);
	if (!sb_has_quota_active(sb, type)) {
		up_read(&sb_dqopt(sb)->dqptr_sem);
		return -ESRCH;
	}
	fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
	up_read(&sb_dqopt(sb)->dqptr_sem);
	if (copy_to_user(addr, &fmt, sizeof(fmt)))
		return -EFAULT;
	return 0;
}
Пример #3
0
static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
{
	__u32 fmt;

	mutex_lock(&sb_dqopt(sb)->dqonoff_mutex);
	if (!sb_has_quota_active(sb, type)) {
		mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
		return -ESRCH;
	}
	fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
	mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
	if (copy_to_user(addr, &fmt, sizeof(fmt)))
		return -EFAULT;
	return 0;
}