Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/fs/sysv/itree.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Handling of indirect blocks' trees.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  AV, Sep--Dec 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "sysv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) enum {DIRECT = 10, DEPTH = 4};	/* Have triple indirect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static inline void dirty_indirect(struct buffer_head *bh, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	mark_buffer_dirty_inode(bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	if (IS_SYNC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static int block_to_path(struct inode *inode, long block, int offsets[DEPTH])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	int ptrs_bits = sbi->s_ind_per_block_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	unsigned long	indirect_blocks = sbi->s_ind_per_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 			double_blocks = sbi->s_ind_per_block_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (block < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		printk("sysv_block_map: block < 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	} else if (block < DIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		offsets[n++] = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	} else if ( (block -= DIRECT) < indirect_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		offsets[n++] = DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		offsets[n++] = block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	} else if ((block -= indirect_blocks) < double_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		offsets[n++] = DIRECT+1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		offsets[n++] = block >> ptrs_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		offsets[n++] = block & (indirect_blocks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	} else if (((block -= double_blocks) >> (ptrs_bits * 2)) < indirect_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		offsets[n++] = DIRECT+2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		offsets[n++] = block >> (ptrs_bits * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		offsets[n++] = (block >> ptrs_bits) & (indirect_blocks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		offsets[n++] = block & (indirect_blocks - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		/* nothing */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static inline int block_to_cpu(struct sysv_sb_info *sbi, sysv_zone_t nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return sbi->s_block_base + fs32_to_cpu(sbi, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	sysv_zone_t     *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	sysv_zone_t     key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) } Indirect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static DEFINE_RWLOCK(pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static inline void add_chain(Indirect *p, struct buffer_head *bh, sysv_zone_t *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	p->key = *(p->p = v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	p->bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static inline int verify_chain(Indirect *from, Indirect *to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	while (from <= to && from->key == *from->p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		from++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return (from > to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static inline sysv_zone_t *block_end(struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return (sysv_zone_t*)((char*)bh->b_data + bh->b_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * Requires read_lock(&pointers_lock) or write_lock(&pointers_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static Indirect *get_branch(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			    int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			    int offsets[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			    Indirect chain[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			    int *err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	Indirect *p = chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	*err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	add_chain(chain, NULL, SYSV_I(inode)->i_data + *offsets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (!p->key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		goto no_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	while (--depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		int block = block_to_cpu(SYSV_SB(sb), p->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		bh = sb_bread(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if (!verify_chain(chain, p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			goto changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		add_chain(++p, bh, (sysv_zone_t*)bh->b_data + *++offsets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (!p->key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			goto no_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) changed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	*err = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	goto no_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	*err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) no_block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int alloc_branch(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			int *offsets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			Indirect *branch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	branch[0].key = sysv_new_block(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (branch[0].key) for (n = 1; n < num; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		int parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		/* Allocate the next block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		branch[n].key = sysv_new_block(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (!branch[n].key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		 * Get buffer_head for parent block, zero it out and set 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		 * the pointer to new one, then send parent to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		parent = block_to_cpu(SYSV_SB(inode->i_sb), branch[n-1].key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		bh = sb_getblk(inode->i_sb, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		memset(bh->b_data, 0, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		branch[n].bh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		branch[n].p = (sysv_zone_t*) bh->b_data + offsets[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		*branch[n].p = branch[n].key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		dirty_indirect(bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (n == num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	/* Allocation failed, free what we already allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (i = 1; i < n; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		bforget(branch[i].bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	for (i = 0; i < n; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		sysv_free_block(inode->i_sb, branch[i].key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline int splice_branch(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				Indirect chain[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				Indirect *where,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 				int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Verify that place we are splicing to is still there and vacant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	write_lock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (!verify_chain(chain, where-1) || *where->p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		goto changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	*where->p = where->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	write_unlock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/* had we spliced it onto indirect block? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (where->bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		dirty_indirect(where->bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (IS_SYNC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		sysv_sync_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) changed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	write_unlock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	for (i = 1; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		bforget(where[i].bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		sysv_free_block(inode->i_sb, where[i].key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_result, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	int err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	int offsets[DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	Indirect chain[DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	Indirect *partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int depth = block_to_path(inode, iblock, offsets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (depth == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) reread:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	read_lock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	partial = get_branch(inode, depth, offsets, chain, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	read_unlock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* Simplest case - block found, no allocation needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!partial) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) got_it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		map_bh(bh_result, sb, block_to_cpu(SYSV_SB(sb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					chain[depth-1].key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		/* Clean up and exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		partial = chain+depth-1; /* the whole chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/* Next simple case - plain lookup or failed read of indirect block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!create || err == -EIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		while (partial > chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			brelse(partial->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			partial--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	 * Indirect block might be removed by truncate while we were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * reading it. Handling of that case (forget what we've got and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * reread) is taken out of the main path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (err == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	left = (chain + depth) - partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	err = alloc_branch(inode, left, offsets+(partial-chain), partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (splice_branch(inode, chain, partial, left) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		goto changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	set_buffer_new(bh_result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	goto got_it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) changed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	while (partial > chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		brelse(partial->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		partial--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	goto reread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline int all_zeroes(sysv_zone_t *p, sysv_zone_t *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	while (p < q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		if (*p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static Indirect *find_shared(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				int offsets[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				Indirect chain[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				sysv_zone_t *top)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	Indirect *partial, *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	int k, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	*top = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	for (k = depth; k > 1 && !offsets[k-1]; k--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	write_lock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	partial = get_branch(inode, k, offsets, chain, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (!partial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		partial = chain + k-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 * If the branch acquired continuation since we've looked at it -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * fine, it should all survive and (new) top doesn't belong to us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (!partial->key && *partial->p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		write_unlock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		goto no_top;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	for (p=partial; p>chain && all_zeroes((sysv_zone_t*)p->bh->b_data,p->p); p--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * OK, we've found the last block that must survive. The rest of our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * branch should be detached before unlocking. However, if that rest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * of branch is all ours and does not grow immediately from the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 * it's easier to cheat and just decrement partial->p.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (p == chain + k - 1 && p > chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		p->p--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		*top = *p->p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		*p->p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	write_unlock(&pointers_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	while (partial > p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		brelse(partial->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		partial--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) no_top:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static inline void free_data(struct inode *inode, sysv_zone_t *p, sysv_zone_t *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	for ( ; p < q ; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		sysv_zone_t nr = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		if (nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			*p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			sysv_free_block(inode->i_sb, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static void free_branches(struct inode *inode, sysv_zone_t *p, sysv_zone_t *q, int depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (depth--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		for ( ; p < q ; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			int block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			sysv_zone_t nr = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			if (!nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			*p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			block = block_to_cpu(SYSV_SB(sb), nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			bh = sb_bread(sb, block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			free_branches(inode, (sysv_zone_t*)bh->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					block_end(bh), depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			bforget(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			sysv_free_block(sb, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		free_data(inode, p, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void sysv_truncate (struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	sysv_zone_t *i_data = SYSV_I(inode)->i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	int offsets[DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	Indirect chain[DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	Indirect *partial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	sysv_zone_t nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	long iblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	unsigned blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	    S_ISLNK(inode->i_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	blocksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	iblock = (inode->i_size + blocksize-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 					>> inode->i_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	block_truncate_page(inode->i_mapping, inode->i_size, get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	n = block_to_path(inode, iblock, offsets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (n == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		free_data(inode, i_data+offsets[0], i_data + DIRECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		goto do_indirects;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	partial = find_shared(inode, n, offsets, chain, &nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	/* Kill the top of shared branch (already detached) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		if (partial == chain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			dirty_indirect(partial->bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		free_branches(inode, &nr, &nr+1, (chain+n-1) - partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	/* Clear the ends of indirect blocks on the shared branch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	while (partial > chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		free_branches(inode, partial->p + 1, block_end(partial->bh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				(chain+n-1) - partial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		dirty_indirect(partial->bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		brelse (partial->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		partial--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) do_indirects:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	/* Kill the remaining (whole) subtrees (== subtrees deeper than...) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	while (n < DEPTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		nr = i_data[DIRECT + n - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		if (nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			i_data[DIRECT + n - 1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			free_branches(inode, &nr, &nr+1, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (IS_SYNC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		sysv_sync_inode (inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static unsigned sysv_nblocks(struct super_block *s, loff_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	struct sysv_sb_info *sbi = SYSV_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int ptrs_bits = sbi->s_ind_per_block_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	unsigned blocks, res, direct = DIRECT, i = DEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	blocks = (size + s->s_blocksize - 1) >> s->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	res = blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	while (--i && blocks > direct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		blocks = ((blocks - direct - 1) >> ptrs_bits) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		res += blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		direct = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	return blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int sysv_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		 u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct super_block *s = path->dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	generic_fillattr(d_inode(path->dentry), stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	stat->blocks = (s->s_blocksize / 512) * sysv_nblocks(s, stat->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	stat->blksize = s->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) static int sysv_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	return block_write_full_page(page,get_block,wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static int sysv_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	return block_read_full_page(page,get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int sysv_prepare_chunk(struct page *page, loff_t pos, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return __block_write_begin(page, pos, len, get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static void sysv_write_failed(struct address_space *mapping, loff_t to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (to > inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		truncate_pagecache(inode, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		sysv_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int sysv_write_begin(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			loff_t pos, unsigned len, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			struct page **pagep, void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	ret = block_write_begin(mapping, pos, len, flags, pagep, get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		sysv_write_failed(mapping, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static sector_t sysv_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	return generic_block_bmap(mapping,block,get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) const struct address_space_operations sysv_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	.readpage = sysv_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	.writepage = sysv_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	.write_begin = sysv_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	.write_end = generic_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	.bmap = sysv_bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) };