xref: /OK3568_Linux_fs/kernel/fs/omfs/file.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * OMFS (as used by RIO Karma) file operations.
4*4882a593Smuzhiyun  * Copyright (C) 2005 Bob Copeland <me@bobcopeland.com>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/module.h>
8*4882a593Smuzhiyun #include <linux/fs.h>
9*4882a593Smuzhiyun #include <linux/buffer_head.h>
10*4882a593Smuzhiyun #include <linux/mpage.h>
11*4882a593Smuzhiyun #include "omfs.h"
12*4882a593Smuzhiyun 
omfs_max_extents(struct omfs_sb_info * sbi,int offset)13*4882a593Smuzhiyun static u32 omfs_max_extents(struct omfs_sb_info *sbi, int offset)
14*4882a593Smuzhiyun {
15*4882a593Smuzhiyun 	return (sbi->s_sys_blocksize - offset -
16*4882a593Smuzhiyun 		sizeof(struct omfs_extent)) /
17*4882a593Smuzhiyun 		sizeof(struct omfs_extent_entry) + 1;
18*4882a593Smuzhiyun }
19*4882a593Smuzhiyun 
omfs_make_empty_table(struct buffer_head * bh,int offset)20*4882a593Smuzhiyun void omfs_make_empty_table(struct buffer_head *bh, int offset)
21*4882a593Smuzhiyun {
22*4882a593Smuzhiyun 	struct omfs_extent *oe = (struct omfs_extent *) &bh->b_data[offset];
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun 	oe->e_next = ~cpu_to_be64(0ULL);
25*4882a593Smuzhiyun 	oe->e_extent_count = cpu_to_be32(1),
26*4882a593Smuzhiyun 	oe->e_fill = cpu_to_be32(0x22),
27*4882a593Smuzhiyun 	oe->e_entry.e_cluster = ~cpu_to_be64(0ULL);
28*4882a593Smuzhiyun 	oe->e_entry.e_blocks = ~cpu_to_be64(0ULL);
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
omfs_shrink_inode(struct inode * inode)31*4882a593Smuzhiyun int omfs_shrink_inode(struct inode *inode)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
34*4882a593Smuzhiyun 	struct omfs_extent *oe;
35*4882a593Smuzhiyun 	struct omfs_extent_entry *entry;
36*4882a593Smuzhiyun 	struct buffer_head *bh;
37*4882a593Smuzhiyun 	u64 next, last;
38*4882a593Smuzhiyun 	u32 extent_count;
39*4882a593Smuzhiyun 	u32 max_extents;
40*4882a593Smuzhiyun 	int ret;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	/* traverse extent table, freeing each entry that is greater
43*4882a593Smuzhiyun 	 * than inode->i_size;
44*4882a593Smuzhiyun 	 */
45*4882a593Smuzhiyun 	next = inode->i_ino;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	/* only support truncate -> 0 for now */
48*4882a593Smuzhiyun 	ret = -EIO;
49*4882a593Smuzhiyun 	if (inode->i_size != 0)
50*4882a593Smuzhiyun 		goto out;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	bh = omfs_bread(inode->i_sb, next);
53*4882a593Smuzhiyun 	if (!bh)
54*4882a593Smuzhiyun 		goto out;
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	oe = (struct omfs_extent *)(&bh->b_data[OMFS_EXTENT_START]);
57*4882a593Smuzhiyun 	max_extents = omfs_max_extents(sbi, OMFS_EXTENT_START);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	for (;;) {
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 		if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next))
62*4882a593Smuzhiyun 			goto out_brelse;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 		extent_count = be32_to_cpu(oe->e_extent_count);
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 		if (extent_count > max_extents)
67*4882a593Smuzhiyun 			goto out_brelse;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 		last = next;
70*4882a593Smuzhiyun 		next = be64_to_cpu(oe->e_next);
71*4882a593Smuzhiyun 		entry = &oe->e_entry;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 		/* ignore last entry as it is the terminator */
74*4882a593Smuzhiyun 		for (; extent_count > 1; extent_count--) {
75*4882a593Smuzhiyun 			u64 start, count;
76*4882a593Smuzhiyun 			start = be64_to_cpu(entry->e_cluster);
77*4882a593Smuzhiyun 			count = be64_to_cpu(entry->e_blocks);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 			omfs_clear_range(inode->i_sb, start, (int) count);
80*4882a593Smuzhiyun 			entry++;
81*4882a593Smuzhiyun 		}
82*4882a593Smuzhiyun 		omfs_make_empty_table(bh, (char *) oe - bh->b_data);
83*4882a593Smuzhiyun 		mark_buffer_dirty(bh);
84*4882a593Smuzhiyun 		brelse(bh);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 		if (last != inode->i_ino)
87*4882a593Smuzhiyun 			omfs_clear_range(inode->i_sb, last, sbi->s_mirrors);
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 		if (next == ~0)
90*4882a593Smuzhiyun 			break;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 		bh = omfs_bread(inode->i_sb, next);
93*4882a593Smuzhiyun 		if (!bh)
94*4882a593Smuzhiyun 			goto out;
95*4882a593Smuzhiyun 		oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]);
96*4882a593Smuzhiyun 		max_extents = omfs_max_extents(sbi, OMFS_EXTENT_CONT);
97*4882a593Smuzhiyun 	}
98*4882a593Smuzhiyun 	ret = 0;
99*4882a593Smuzhiyun out:
100*4882a593Smuzhiyun 	return ret;
101*4882a593Smuzhiyun out_brelse:
102*4882a593Smuzhiyun 	brelse(bh);
103*4882a593Smuzhiyun 	return ret;
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun 
omfs_truncate(struct inode * inode)106*4882a593Smuzhiyun static void omfs_truncate(struct inode *inode)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun 	omfs_shrink_inode(inode);
109*4882a593Smuzhiyun 	mark_inode_dirty(inode);
110*4882a593Smuzhiyun }
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /*
113*4882a593Smuzhiyun  * Add new blocks to the current extent, or create new entries/continuations
114*4882a593Smuzhiyun  * as necessary.
115*4882a593Smuzhiyun  */
omfs_grow_extent(struct inode * inode,struct omfs_extent * oe,u64 * ret_block)116*4882a593Smuzhiyun static int omfs_grow_extent(struct inode *inode, struct omfs_extent *oe,
117*4882a593Smuzhiyun 			u64 *ret_block)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	struct omfs_extent_entry *terminator;
120*4882a593Smuzhiyun 	struct omfs_extent_entry *entry = &oe->e_entry;
121*4882a593Smuzhiyun 	struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
122*4882a593Smuzhiyun 	u32 extent_count = be32_to_cpu(oe->e_extent_count);
123*4882a593Smuzhiyun 	u64 new_block = 0;
124*4882a593Smuzhiyun 	u32 max_count;
125*4882a593Smuzhiyun 	int new_count;
126*4882a593Smuzhiyun 	int ret = 0;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	/* reached the end of the extent table with no blocks mapped.
129*4882a593Smuzhiyun 	 * there are three possibilities for adding: grow last extent,
130*4882a593Smuzhiyun 	 * add a new extent to the current extent table, and add a
131*4882a593Smuzhiyun 	 * continuation inode.  in last two cases need an allocator for
132*4882a593Smuzhiyun 	 * sbi->s_cluster_size
133*4882a593Smuzhiyun 	 */
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	/* TODO: handle holes */
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	/* should always have a terminator */
138*4882a593Smuzhiyun 	if (extent_count < 1)
139*4882a593Smuzhiyun 		return -EIO;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	/* trivially grow current extent, if next block is not taken */
142*4882a593Smuzhiyun 	terminator = entry + extent_count - 1;
143*4882a593Smuzhiyun 	if (extent_count > 1) {
144*4882a593Smuzhiyun 		entry = terminator-1;
145*4882a593Smuzhiyun 		new_block = be64_to_cpu(entry->e_cluster) +
146*4882a593Smuzhiyun 			be64_to_cpu(entry->e_blocks);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 		if (omfs_allocate_block(inode->i_sb, new_block)) {
149*4882a593Smuzhiyun 			be64_add_cpu(&entry->e_blocks, 1);
150*4882a593Smuzhiyun 			terminator->e_blocks = ~(cpu_to_be64(
151*4882a593Smuzhiyun 				be64_to_cpu(~terminator->e_blocks) + 1));
152*4882a593Smuzhiyun 			goto out;
153*4882a593Smuzhiyun 		}
154*4882a593Smuzhiyun 	}
155*4882a593Smuzhiyun 	max_count = omfs_max_extents(sbi, OMFS_EXTENT_START);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	/* TODO: add a continuation block here */
158*4882a593Smuzhiyun 	if (be32_to_cpu(oe->e_extent_count) > max_count-1)
159*4882a593Smuzhiyun 		return -EIO;
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun 	/* try to allocate a new cluster */
162*4882a593Smuzhiyun 	ret = omfs_allocate_range(inode->i_sb, 1, sbi->s_clustersize,
163*4882a593Smuzhiyun 		&new_block, &new_count);
164*4882a593Smuzhiyun 	if (ret)
165*4882a593Smuzhiyun 		goto out_fail;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	/* copy terminator down an entry */
168*4882a593Smuzhiyun 	entry = terminator;
169*4882a593Smuzhiyun 	terminator++;
170*4882a593Smuzhiyun 	memcpy(terminator, entry, sizeof(struct omfs_extent_entry));
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	entry->e_cluster = cpu_to_be64(new_block);
173*4882a593Smuzhiyun 	entry->e_blocks = cpu_to_be64((u64) new_count);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	terminator->e_blocks = ~(cpu_to_be64(
176*4882a593Smuzhiyun 		be64_to_cpu(~terminator->e_blocks) + (u64) new_count));
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun 	/* write in new entry */
179*4882a593Smuzhiyun 	be32_add_cpu(&oe->e_extent_count, 1);
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun out:
182*4882a593Smuzhiyun 	*ret_block = new_block;
183*4882a593Smuzhiyun out_fail:
184*4882a593Smuzhiyun 	return ret;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun /*
188*4882a593Smuzhiyun  * Scans across the directory table for a given file block number.
189*4882a593Smuzhiyun  * If block not found, return 0.
190*4882a593Smuzhiyun  */
find_block(struct inode * inode,struct omfs_extent_entry * ent,sector_t block,int count,int * left)191*4882a593Smuzhiyun static sector_t find_block(struct inode *inode, struct omfs_extent_entry *ent,
192*4882a593Smuzhiyun 			sector_t block, int count, int *left)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun 	/* count > 1 because of terminator */
195*4882a593Smuzhiyun 	sector_t searched = 0;
196*4882a593Smuzhiyun 	for (; count > 1; count--) {
197*4882a593Smuzhiyun 		int numblocks = clus_to_blk(OMFS_SB(inode->i_sb),
198*4882a593Smuzhiyun 			be64_to_cpu(ent->e_blocks));
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 		if (block >= searched  &&
201*4882a593Smuzhiyun 		    block < searched + numblocks) {
202*4882a593Smuzhiyun 			/*
203*4882a593Smuzhiyun 			 * found it at cluster + (block - searched)
204*4882a593Smuzhiyun 			 * numblocks - (block - searched) is remainder
205*4882a593Smuzhiyun 			 */
206*4882a593Smuzhiyun 			*left = numblocks - (block - searched);
207*4882a593Smuzhiyun 			return clus_to_blk(OMFS_SB(inode->i_sb),
208*4882a593Smuzhiyun 				be64_to_cpu(ent->e_cluster)) +
209*4882a593Smuzhiyun 				block - searched;
210*4882a593Smuzhiyun 		}
211*4882a593Smuzhiyun 		searched += numblocks;
212*4882a593Smuzhiyun 		ent++;
213*4882a593Smuzhiyun 	}
214*4882a593Smuzhiyun 	return 0;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun 
omfs_get_block(struct inode * inode,sector_t block,struct buffer_head * bh_result,int create)217*4882a593Smuzhiyun static int omfs_get_block(struct inode *inode, sector_t block,
218*4882a593Smuzhiyun 			  struct buffer_head *bh_result, int create)
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun 	struct buffer_head *bh;
221*4882a593Smuzhiyun 	sector_t next, offset;
222*4882a593Smuzhiyun 	int ret;
223*4882a593Smuzhiyun 	u64 new_block;
224*4882a593Smuzhiyun 	u32 max_extents;
225*4882a593Smuzhiyun 	int extent_count;
226*4882a593Smuzhiyun 	struct omfs_extent *oe;
227*4882a593Smuzhiyun 	struct omfs_extent_entry *entry;
228*4882a593Smuzhiyun 	struct omfs_sb_info *sbi = OMFS_SB(inode->i_sb);
229*4882a593Smuzhiyun 	int max_blocks = bh_result->b_size >> inode->i_blkbits;
230*4882a593Smuzhiyun 	int remain;
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	ret = -EIO;
233*4882a593Smuzhiyun 	bh = omfs_bread(inode->i_sb, inode->i_ino);
234*4882a593Smuzhiyun 	if (!bh)
235*4882a593Smuzhiyun 		goto out;
236*4882a593Smuzhiyun 
237*4882a593Smuzhiyun 	oe = (struct omfs_extent *)(&bh->b_data[OMFS_EXTENT_START]);
238*4882a593Smuzhiyun 	max_extents = omfs_max_extents(sbi, OMFS_EXTENT_START);
239*4882a593Smuzhiyun 	next = inode->i_ino;
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 	for (;;) {
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 		if (omfs_is_bad(sbi, (struct omfs_header *) bh->b_data, next))
244*4882a593Smuzhiyun 			goto out_brelse;
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 		extent_count = be32_to_cpu(oe->e_extent_count);
247*4882a593Smuzhiyun 		next = be64_to_cpu(oe->e_next);
248*4882a593Smuzhiyun 		entry = &oe->e_entry;
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun 		if (extent_count > max_extents)
251*4882a593Smuzhiyun 			goto out_brelse;
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 		offset = find_block(inode, entry, block, extent_count, &remain);
254*4882a593Smuzhiyun 		if (offset > 0) {
255*4882a593Smuzhiyun 			ret = 0;
256*4882a593Smuzhiyun 			map_bh(bh_result, inode->i_sb, offset);
257*4882a593Smuzhiyun 			if (remain > max_blocks)
258*4882a593Smuzhiyun 				remain = max_blocks;
259*4882a593Smuzhiyun 			bh_result->b_size = (remain << inode->i_blkbits);
260*4882a593Smuzhiyun 			goto out_brelse;
261*4882a593Smuzhiyun 		}
262*4882a593Smuzhiyun 		if (next == ~0)
263*4882a593Smuzhiyun 			break;
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 		brelse(bh);
266*4882a593Smuzhiyun 		bh = omfs_bread(inode->i_sb, next);
267*4882a593Smuzhiyun 		if (!bh)
268*4882a593Smuzhiyun 			goto out;
269*4882a593Smuzhiyun 		oe = (struct omfs_extent *) (&bh->b_data[OMFS_EXTENT_CONT]);
270*4882a593Smuzhiyun 		max_extents = omfs_max_extents(sbi, OMFS_EXTENT_CONT);
271*4882a593Smuzhiyun 	}
272*4882a593Smuzhiyun 	if (create) {
273*4882a593Smuzhiyun 		ret = omfs_grow_extent(inode, oe, &new_block);
274*4882a593Smuzhiyun 		if (ret == 0) {
275*4882a593Smuzhiyun 			mark_buffer_dirty(bh);
276*4882a593Smuzhiyun 			mark_inode_dirty(inode);
277*4882a593Smuzhiyun 			map_bh(bh_result, inode->i_sb,
278*4882a593Smuzhiyun 					clus_to_blk(sbi, new_block));
279*4882a593Smuzhiyun 		}
280*4882a593Smuzhiyun 	}
281*4882a593Smuzhiyun out_brelse:
282*4882a593Smuzhiyun 	brelse(bh);
283*4882a593Smuzhiyun out:
284*4882a593Smuzhiyun 	return ret;
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun 
omfs_readpage(struct file * file,struct page * page)287*4882a593Smuzhiyun static int omfs_readpage(struct file *file, struct page *page)
288*4882a593Smuzhiyun {
289*4882a593Smuzhiyun 	return block_read_full_page(page, omfs_get_block);
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun 
omfs_readahead(struct readahead_control * rac)292*4882a593Smuzhiyun static void omfs_readahead(struct readahead_control *rac)
293*4882a593Smuzhiyun {
294*4882a593Smuzhiyun 	mpage_readahead(rac, omfs_get_block);
295*4882a593Smuzhiyun }
296*4882a593Smuzhiyun 
omfs_writepage(struct page * page,struct writeback_control * wbc)297*4882a593Smuzhiyun static int omfs_writepage(struct page *page, struct writeback_control *wbc)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun 	return block_write_full_page(page, omfs_get_block, wbc);
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun static int
omfs_writepages(struct address_space * mapping,struct writeback_control * wbc)303*4882a593Smuzhiyun omfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun 	return mpage_writepages(mapping, wbc, omfs_get_block);
306*4882a593Smuzhiyun }
307*4882a593Smuzhiyun 
omfs_write_failed(struct address_space * mapping,loff_t to)308*4882a593Smuzhiyun static void omfs_write_failed(struct address_space *mapping, loff_t to)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun 	struct inode *inode = mapping->host;
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	if (to > inode->i_size) {
313*4882a593Smuzhiyun 		truncate_pagecache(inode, inode->i_size);
314*4882a593Smuzhiyun 		omfs_truncate(inode);
315*4882a593Smuzhiyun 	}
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun 
omfs_write_begin(struct file * file,struct address_space * mapping,loff_t pos,unsigned len,unsigned flags,struct page ** pagep,void ** fsdata)318*4882a593Smuzhiyun static int omfs_write_begin(struct file *file, struct address_space *mapping,
319*4882a593Smuzhiyun 			loff_t pos, unsigned len, unsigned flags,
320*4882a593Smuzhiyun 			struct page **pagep, void **fsdata)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun 	int ret;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	ret = block_write_begin(mapping, pos, len, flags, pagep,
325*4882a593Smuzhiyun 				omfs_get_block);
326*4882a593Smuzhiyun 	if (unlikely(ret))
327*4882a593Smuzhiyun 		omfs_write_failed(mapping, pos + len);
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 	return ret;
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun 
omfs_bmap(struct address_space * mapping,sector_t block)332*4882a593Smuzhiyun static sector_t omfs_bmap(struct address_space *mapping, sector_t block)
333*4882a593Smuzhiyun {
334*4882a593Smuzhiyun 	return generic_block_bmap(mapping, block, omfs_get_block);
335*4882a593Smuzhiyun }
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun const struct file_operations omfs_file_operations = {
338*4882a593Smuzhiyun 	.llseek = generic_file_llseek,
339*4882a593Smuzhiyun 	.read_iter = generic_file_read_iter,
340*4882a593Smuzhiyun 	.write_iter = generic_file_write_iter,
341*4882a593Smuzhiyun 	.mmap = generic_file_mmap,
342*4882a593Smuzhiyun 	.fsync = generic_file_fsync,
343*4882a593Smuzhiyun 	.splice_read = generic_file_splice_read,
344*4882a593Smuzhiyun };
345*4882a593Smuzhiyun 
omfs_setattr(struct dentry * dentry,struct iattr * attr)346*4882a593Smuzhiyun static int omfs_setattr(struct dentry *dentry, struct iattr *attr)
347*4882a593Smuzhiyun {
348*4882a593Smuzhiyun 	struct inode *inode = d_inode(dentry);
349*4882a593Smuzhiyun 	int error;
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	error = setattr_prepare(dentry, attr);
352*4882a593Smuzhiyun 	if (error)
353*4882a593Smuzhiyun 		return error;
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun 	if ((attr->ia_valid & ATTR_SIZE) &&
356*4882a593Smuzhiyun 	    attr->ia_size != i_size_read(inode)) {
357*4882a593Smuzhiyun 		error = inode_newsize_ok(inode, attr->ia_size);
358*4882a593Smuzhiyun 		if (error)
359*4882a593Smuzhiyun 			return error;
360*4882a593Smuzhiyun 		truncate_setsize(inode, attr->ia_size);
361*4882a593Smuzhiyun 		omfs_truncate(inode);
362*4882a593Smuzhiyun 	}
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun 	setattr_copy(inode, attr);
365*4882a593Smuzhiyun 	mark_inode_dirty(inode);
366*4882a593Smuzhiyun 	return 0;
367*4882a593Smuzhiyun }
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun const struct inode_operations omfs_file_inops = {
370*4882a593Smuzhiyun 	.setattr = omfs_setattr,
371*4882a593Smuzhiyun };
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun const struct address_space_operations omfs_aops = {
374*4882a593Smuzhiyun 	.readpage = omfs_readpage,
375*4882a593Smuzhiyun 	.readahead = omfs_readahead,
376*4882a593Smuzhiyun 	.writepage = omfs_writepage,
377*4882a593Smuzhiyun 	.writepages = omfs_writepages,
378*4882a593Smuzhiyun 	.write_begin = omfs_write_begin,
379*4882a593Smuzhiyun 	.write_end = generic_write_end,
380*4882a593Smuzhiyun 	.bmap = omfs_bmap,
381*4882a593Smuzhiyun };
382*4882a593Smuzhiyun 
383