Lines Matching refs:inode
86 static void __hfsplus_ext_write_extent(struct inode *inode, struct hfs_find_data *fd) in __hfsplus_ext_write_extent() argument
90 hfsplus_ext_build_key(fd->search_key, inode->i_ino, HFSPLUS_I(inode).cached_start, in __hfsplus_ext_write_extent()
91 HFSPLUS_IS_RSRC(inode) ? HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA); in __hfsplus_ext_write_extent()
93 if (HFSPLUS_I(inode).flags & HFSPLUS_FLG_EXT_NEW) { in __hfsplus_ext_write_extent()
96 hfs_brec_insert(fd, HFSPLUS_I(inode).cached_extents, sizeof(hfsplus_extent_rec)); in __hfsplus_ext_write_extent()
97 HFSPLUS_I(inode).flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW); in __hfsplus_ext_write_extent()
101 hfs_bnode_write(fd->bnode, HFSPLUS_I(inode).cached_extents, fd->entryoffset, fd->entrylength); in __hfsplus_ext_write_extent()
102 HFSPLUS_I(inode).flags &= ~HFSPLUS_FLG_EXT_DIRTY; in __hfsplus_ext_write_extent()
106 void hfsplus_ext_write_extent(struct inode *inode) in hfsplus_ext_write_extent() argument
108 if (HFSPLUS_I(inode).flags & HFSPLUS_FLG_EXT_DIRTY) { in hfsplus_ext_write_extent()
111 hfs_find_init(HFSPLUS_SB(inode->i_sb).ext_tree, &fd); in hfsplus_ext_write_extent()
112 __hfsplus_ext_write_extent(inode, &fd); in hfsplus_ext_write_extent()
137 static inline int __hfsplus_ext_cache_extent(struct hfs_find_data *fd, struct inode *inode, u32 blo… in __hfsplus_ext_cache_extent() argument
141 if (HFSPLUS_I(inode).flags & HFSPLUS_FLG_EXT_DIRTY) in __hfsplus_ext_cache_extent()
142 __hfsplus_ext_write_extent(inode, fd); in __hfsplus_ext_cache_extent()
144 res = __hfsplus_ext_read_extent(fd, HFSPLUS_I(inode).cached_extents, inode->i_ino, in __hfsplus_ext_cache_extent()
145 block, HFSPLUS_IS_RSRC(inode) ? HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA); in __hfsplus_ext_cache_extent()
147 HFSPLUS_I(inode).cached_start = be32_to_cpu(fd->key->ext.start_block); in __hfsplus_ext_cache_extent()
148 HFSPLUS_I(inode).cached_blocks = hfsplus_ext_block_count(HFSPLUS_I(inode).cached_extents); in __hfsplus_ext_cache_extent()
150 HFSPLUS_I(inode).cached_start = HFSPLUS_I(inode).cached_blocks = 0; in __hfsplus_ext_cache_extent()
151 HFSPLUS_I(inode).flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW); in __hfsplus_ext_cache_extent()
156 static int hfsplus_ext_read_extent(struct inode *inode, u32 block) in hfsplus_ext_read_extent() argument
161 if (block >= HFSPLUS_I(inode).cached_start && in hfsplus_ext_read_extent()
162 block < HFSPLUS_I(inode).cached_start + HFSPLUS_I(inode).cached_blocks) in hfsplus_ext_read_extent()
165 hfs_find_init(HFSPLUS_SB(inode->i_sb).ext_tree, &fd); in hfsplus_ext_read_extent()
166 res = __hfsplus_ext_cache_extent(&fd, inode, block); in hfsplus_ext_read_extent()
172 int hfsplus_get_block(struct inode *inode, sector_t iblock, in hfsplus_get_block() argument
180 sb = inode->i_sb; in hfsplus_get_block()
186 if (iblock >= HFSPLUS_I(inode).fs_blocks) { in hfsplus_get_block()
187 if (iblock > HFSPLUS_I(inode).fs_blocks || !create) in hfsplus_get_block()
189 if (ablock >= HFSPLUS_I(inode).alloc_blocks) { in hfsplus_get_block()
190 res = hfsplus_file_extend(inode); in hfsplus_get_block()
197 if (ablock < HFSPLUS_I(inode).first_blocks) { in hfsplus_get_block()
198 dblock = hfsplus_ext_find_block(HFSPLUS_I(inode).first_extents, ablock); in hfsplus_get_block()
202 if (inode->i_ino == HFSPLUS_EXT_CNID) in hfsplus_get_block()
205 mutex_lock(&HFSPLUS_I(inode).extents_lock); in hfsplus_get_block()
206 res = hfsplus_ext_read_extent(inode, ablock); in hfsplus_get_block()
208 dblock = hfsplus_ext_find_block(HFSPLUS_I(inode).cached_extents, ablock - in hfsplus_get_block()
209 HFSPLUS_I(inode).cached_start); in hfsplus_get_block()
211 mutex_unlock(&HFSPLUS_I(inode).extents_lock); in hfsplus_get_block()
214 mutex_unlock(&HFSPLUS_I(inode).extents_lock); in hfsplus_get_block()
217 dprint(DBG_EXTENT, "get_block(%lu): %llu - %u\n", inode->i_ino, (long long)iblock, dblock); in hfsplus_get_block()
222 HFSPLUS_I(inode).phys_size += sb->s_blocksize; in hfsplus_get_block()
223 HFSPLUS_I(inode).fs_blocks++; in hfsplus_get_block()
224 inode_add_bytes(inode, sb->s_blocksize); in hfsplus_get_block()
225 mark_inode_dirty(inode); in hfsplus_get_block()
348 int hfsplus_file_extend(struct inode *inode) in hfsplus_file_extend() argument
350 struct super_block *sb = inode->i_sb; in hfsplus_file_extend()
361 mutex_lock(&HFSPLUS_I(inode).extents_lock); in hfsplus_file_extend()
362 if (HFSPLUS_I(inode).alloc_blocks == HFSPLUS_I(inode).first_blocks) in hfsplus_file_extend()
363 goal = hfsplus_ext_lastblock(HFSPLUS_I(inode).first_extents); in hfsplus_file_extend()
365 res = hfsplus_ext_read_extent(inode, HFSPLUS_I(inode).alloc_blocks); in hfsplus_file_extend()
368 goal = hfsplus_ext_lastblock(HFSPLUS_I(inode).cached_extents); in hfsplus_file_extend()
371 len = HFSPLUS_I(inode).clump_blocks; in hfsplus_file_extend()
381 dprint(DBG_EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len); in hfsplus_file_extend()
382 if (HFSPLUS_I(inode).alloc_blocks <= HFSPLUS_I(inode).first_blocks) { in hfsplus_file_extend()
383 if (!HFSPLUS_I(inode).first_blocks) { in hfsplus_file_extend()
386 HFSPLUS_I(inode).first_extents[0].start_block = cpu_to_be32(start); in hfsplus_file_extend()
387 HFSPLUS_I(inode).first_extents[0].block_count = cpu_to_be32(len); in hfsplus_file_extend()
391 res = hfsplus_add_extent(HFSPLUS_I(inode).first_extents, in hfsplus_file_extend()
392 HFSPLUS_I(inode).alloc_blocks, in hfsplus_file_extend()
398 hfsplus_dump_extent(HFSPLUS_I(inode).first_extents); in hfsplus_file_extend()
399 HFSPLUS_I(inode).first_blocks += len; in hfsplus_file_extend()
402 res = hfsplus_add_extent(HFSPLUS_I(inode).cached_extents, in hfsplus_file_extend()
403 HFSPLUS_I(inode).alloc_blocks - in hfsplus_file_extend()
404 HFSPLUS_I(inode).cached_start, in hfsplus_file_extend()
407 hfsplus_dump_extent(HFSPLUS_I(inode).cached_extents); in hfsplus_file_extend()
408 HFSPLUS_I(inode).flags |= HFSPLUS_FLG_EXT_DIRTY; in hfsplus_file_extend()
409 HFSPLUS_I(inode).cached_blocks += len; in hfsplus_file_extend()
414 mutex_unlock(&HFSPLUS_I(inode).extents_lock); in hfsplus_file_extend()
416 HFSPLUS_I(inode).alloc_blocks += len; in hfsplus_file_extend()
417 mark_inode_dirty(inode); in hfsplus_file_extend()
423 hfsplus_ext_write_extent(inode); in hfsplus_file_extend()
425 memset(HFSPLUS_I(inode).cached_extents, 0, sizeof(hfsplus_extent_rec)); in hfsplus_file_extend()
426 HFSPLUS_I(inode).cached_extents[0].start_block = cpu_to_be32(start); in hfsplus_file_extend()
427 HFSPLUS_I(inode).cached_extents[0].block_count = cpu_to_be32(len); in hfsplus_file_extend()
428 hfsplus_dump_extent(HFSPLUS_I(inode).cached_extents); in hfsplus_file_extend()
429 HFSPLUS_I(inode).flags |= HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW; in hfsplus_file_extend()
430 HFSPLUS_I(inode).cached_start = HFSPLUS_I(inode).alloc_blocks; in hfsplus_file_extend()
431 HFSPLUS_I(inode).cached_blocks = len; in hfsplus_file_extend()
437 void hfsplus_file_truncate(struct inode *inode) in hfsplus_file_truncate() argument
439 struct super_block *sb = inode->i_sb; in hfsplus_file_truncate()
444 dprint(DBG_INODE, "truncate: %lu, %Lu -> %Lu\n", inode->i_ino, in hfsplus_file_truncate()
445 (long long)HFSPLUS_I(inode).phys_size, inode->i_size); in hfsplus_file_truncate()
446 if (inode->i_size > HFSPLUS_I(inode).phys_size) { in hfsplus_file_truncate()
447 struct address_space *mapping = inode->i_mapping; in hfsplus_file_truncate()
450 u32 size = inode->i_size; in hfsplus_file_truncate()
461 mark_inode_dirty(inode); in hfsplus_file_truncate()
463 } else if (inode->i_size == HFSPLUS_I(inode).phys_size) in hfsplus_file_truncate()
466 blk_cnt = (inode->i_size + HFSPLUS_SB(sb).alloc_blksz - 1) >> HFSPLUS_SB(sb).alloc_blksz_shift; in hfsplus_file_truncate()
467 alloc_cnt = HFSPLUS_I(inode).alloc_blocks; in hfsplus_file_truncate()
471 mutex_lock(&HFSPLUS_I(inode).extents_lock); in hfsplus_file_truncate()
474 if (alloc_cnt == HFSPLUS_I(inode).first_blocks) { in hfsplus_file_truncate()
475 hfsplus_free_extents(sb, HFSPLUS_I(inode).first_extents, in hfsplus_file_truncate()
477 hfsplus_dump_extent(HFSPLUS_I(inode).first_extents); in hfsplus_file_truncate()
478 HFSPLUS_I(inode).first_blocks = blk_cnt; in hfsplus_file_truncate()
481 res = __hfsplus_ext_cache_extent(&fd, inode, alloc_cnt); in hfsplus_file_truncate()
484 start = HFSPLUS_I(inode).cached_start; in hfsplus_file_truncate()
485 hfsplus_free_extents(sb, HFSPLUS_I(inode).cached_extents, in hfsplus_file_truncate()
487 hfsplus_dump_extent(HFSPLUS_I(inode).cached_extents); in hfsplus_file_truncate()
489 HFSPLUS_I(inode).flags |= HFSPLUS_FLG_EXT_DIRTY; in hfsplus_file_truncate()
493 HFSPLUS_I(inode).cached_start = HFSPLUS_I(inode).cached_blocks = 0; in hfsplus_file_truncate()
494 HFSPLUS_I(inode).flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW); in hfsplus_file_truncate()
498 mutex_unlock(&HFSPLUS_I(inode).extents_lock); in hfsplus_file_truncate()
500 HFSPLUS_I(inode).alloc_blocks = blk_cnt; in hfsplus_file_truncate()
502 HFSPLUS_I(inode).phys_size = inode->i_size; in hfsplus_file_truncate()
503 HFSPLUS_I(inode).fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; in hfsplus_file_truncate()
504 inode_set_bytes(inode, HFSPLUS_I(inode).fs_blocks << sb->s_blocksize_bits); in hfsplus_file_truncate()
505 mark_inode_dirty(inode); in hfsplus_file_truncate()