Lines Matching refs:inode

110 static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd)  in __hfs_ext_write_extent()  argument
114 hfs_ext_build_key(fd->search_key, inode->i_ino, HFS_I(inode)->cached_start, in __hfs_ext_write_extent()
115 HFS_IS_RSRC(inode) ? HFS_FK_RSRC : HFS_FK_DATA); in __hfs_ext_write_extent()
117 if (HFS_I(inode)->flags & HFS_FLG_EXT_NEW) { in __hfs_ext_write_extent()
120 hfs_brec_insert(fd, HFS_I(inode)->cached_extents, sizeof(hfs_extent_rec)); in __hfs_ext_write_extent()
121 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW); in __hfs_ext_write_extent()
125 hfs_bnode_write(fd->bnode, HFS_I(inode)->cached_extents, fd->entryoffset, fd->entrylength); in __hfs_ext_write_extent()
126 HFS_I(inode)->flags &= ~HFS_FLG_EXT_DIRTY; in __hfs_ext_write_extent()
131 int hfs_ext_write_extent(struct inode *inode) in hfs_ext_write_extent() argument
136 if (HFS_I(inode)->flags & HFS_FLG_EXT_DIRTY) { in hfs_ext_write_extent()
137 res = hfs_find_init(HFS_SB(inode->i_sb)->ext_tree, &fd); in hfs_ext_write_extent()
140 res = __hfs_ext_write_extent(inode, &fd); in hfs_ext_write_extent()
165 static inline int __hfs_ext_cache_extent(struct hfs_find_data *fd, struct inode *inode, u32 block) in __hfs_ext_cache_extent() argument
169 if (HFS_I(inode)->flags & HFS_FLG_EXT_DIRTY) { in __hfs_ext_cache_extent()
170 res = __hfs_ext_write_extent(inode, fd); in __hfs_ext_cache_extent()
175 res = __hfs_ext_read_extent(fd, HFS_I(inode)->cached_extents, inode->i_ino, in __hfs_ext_cache_extent()
176 block, HFS_IS_RSRC(inode) ? HFS_FK_RSRC : HFS_FK_DATA); in __hfs_ext_cache_extent()
178 HFS_I(inode)->cached_start = be16_to_cpu(fd->key->ext.FABN); in __hfs_ext_cache_extent()
179 HFS_I(inode)->cached_blocks = hfs_ext_block_count(HFS_I(inode)->cached_extents); in __hfs_ext_cache_extent()
181 HFS_I(inode)->cached_start = HFS_I(inode)->cached_blocks = 0; in __hfs_ext_cache_extent()
182 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW); in __hfs_ext_cache_extent()
187 static int hfs_ext_read_extent(struct inode *inode, u16 block) in hfs_ext_read_extent() argument
192 if (block >= HFS_I(inode)->cached_start && in hfs_ext_read_extent()
193 block < HFS_I(inode)->cached_start + HFS_I(inode)->cached_blocks) in hfs_ext_read_extent()
196 res = hfs_find_init(HFS_SB(inode->i_sb)->ext_tree, &fd); in hfs_ext_read_extent()
198 res = __hfs_ext_cache_extent(&fd, inode, block); in hfs_ext_read_extent()
332 int hfs_get_block(struct inode *inode, sector_t block, in hfs_get_block() argument
339 sb = inode->i_sb; in hfs_get_block()
343 if (block >= HFS_I(inode)->fs_blocks) { in hfs_get_block()
344 if (block > HFS_I(inode)->fs_blocks || !create) in hfs_get_block()
346 if (ablock >= HFS_I(inode)->alloc_blocks) { in hfs_get_block()
347 res = hfs_extend_file(inode); in hfs_get_block()
354 if (ablock < HFS_I(inode)->first_blocks) { in hfs_get_block()
355 dblock = hfs_ext_find_block(HFS_I(inode)->first_extents, ablock); in hfs_get_block()
359 mutex_lock(&HFS_I(inode)->extents_lock); in hfs_get_block()
360 res = hfs_ext_read_extent(inode, ablock); in hfs_get_block()
362 dblock = hfs_ext_find_block(HFS_I(inode)->cached_extents, in hfs_get_block()
363 ablock - HFS_I(inode)->cached_start); in hfs_get_block()
365 mutex_unlock(&HFS_I(inode)->extents_lock); in hfs_get_block()
368 mutex_unlock(&HFS_I(inode)->extents_lock); in hfs_get_block()
377 HFS_I(inode)->phys_size += sb->s_blocksize; in hfs_get_block()
378 HFS_I(inode)->fs_blocks++; in hfs_get_block()
379 inode_add_bytes(inode, sb->s_blocksize); in hfs_get_block()
380 mark_inode_dirty(inode); in hfs_get_block()
385 int hfs_extend_file(struct inode *inode) in hfs_extend_file() argument
387 struct super_block *sb = inode->i_sb; in hfs_extend_file()
391 mutex_lock(&HFS_I(inode)->extents_lock); in hfs_extend_file()
392 if (HFS_I(inode)->alloc_blocks == HFS_I(inode)->first_blocks) in hfs_extend_file()
393 goal = hfs_ext_lastblock(HFS_I(inode)->first_extents); in hfs_extend_file()
395 res = hfs_ext_read_extent(inode, HFS_I(inode)->alloc_blocks); in hfs_extend_file()
398 goal = hfs_ext_lastblock(HFS_I(inode)->cached_extents); in hfs_extend_file()
401 len = HFS_I(inode)->clump_blocks; in hfs_extend_file()
408 hfs_dbg(EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len); in hfs_extend_file()
409 if (HFS_I(inode)->alloc_blocks == HFS_I(inode)->first_blocks) { in hfs_extend_file()
410 if (!HFS_I(inode)->first_blocks) { in hfs_extend_file()
413 HFS_I(inode)->first_extents[0].block = cpu_to_be16(start); in hfs_extend_file()
414 HFS_I(inode)->first_extents[0].count = cpu_to_be16(len); in hfs_extend_file()
418 res = hfs_add_extent(HFS_I(inode)->first_extents, in hfs_extend_file()
419 HFS_I(inode)->alloc_blocks, in hfs_extend_file()
425 hfs_dump_extent(HFS_I(inode)->first_extents); in hfs_extend_file()
426 HFS_I(inode)->first_blocks += len; in hfs_extend_file()
429 res = hfs_add_extent(HFS_I(inode)->cached_extents, in hfs_extend_file()
430 HFS_I(inode)->alloc_blocks - in hfs_extend_file()
431 HFS_I(inode)->cached_start, in hfs_extend_file()
434 hfs_dump_extent(HFS_I(inode)->cached_extents); in hfs_extend_file()
435 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY; in hfs_extend_file()
436 HFS_I(inode)->cached_blocks += len; in hfs_extend_file()
441 mutex_unlock(&HFS_I(inode)->extents_lock); in hfs_extend_file()
443 HFS_I(inode)->alloc_blocks += len; in hfs_extend_file()
444 mark_inode_dirty(inode); in hfs_extend_file()
445 if (inode->i_ino < HFS_FIRSTUSER_CNID) in hfs_extend_file()
454 res = hfs_ext_write_extent(inode); in hfs_extend_file()
458 memset(HFS_I(inode)->cached_extents, 0, sizeof(hfs_extent_rec)); in hfs_extend_file()
459 HFS_I(inode)->cached_extents[0].block = cpu_to_be16(start); in hfs_extend_file()
460 HFS_I(inode)->cached_extents[0].count = cpu_to_be16(len); in hfs_extend_file()
461 hfs_dump_extent(HFS_I(inode)->cached_extents); in hfs_extend_file()
462 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW; in hfs_extend_file()
463 HFS_I(inode)->cached_start = HFS_I(inode)->alloc_blocks; in hfs_extend_file()
464 HFS_I(inode)->cached_blocks = len; in hfs_extend_file()
470 void hfs_file_truncate(struct inode *inode) in hfs_file_truncate() argument
472 struct super_block *sb = inode->i_sb; in hfs_file_truncate()
479 inode->i_ino, (long long)HFS_I(inode)->phys_size, in hfs_file_truncate()
480 inode->i_size); in hfs_file_truncate()
481 if (inode->i_size > HFS_I(inode)->phys_size) { in hfs_file_truncate()
482 struct address_space *mapping = inode->i_mapping; in hfs_file_truncate()
487 size = inode->i_size - 1; in hfs_file_truncate()
495 inode->i_size = HFS_I(inode)->phys_size; in hfs_file_truncate()
497 } else if (inode->i_size == HFS_I(inode)->phys_size) in hfs_file_truncate()
499 size = inode->i_size + HFS_SB(sb)->alloc_blksz - 1; in hfs_file_truncate()
501 alloc_cnt = HFS_I(inode)->alloc_blocks; in hfs_file_truncate()
505 mutex_lock(&HFS_I(inode)->extents_lock); in hfs_file_truncate()
508 mutex_unlock(&HFS_I(inode)->extents_lock); in hfs_file_truncate()
513 if (alloc_cnt == HFS_I(inode)->first_blocks) { in hfs_file_truncate()
514 hfs_free_extents(sb, HFS_I(inode)->first_extents, in hfs_file_truncate()
516 hfs_dump_extent(HFS_I(inode)->first_extents); in hfs_file_truncate()
517 HFS_I(inode)->first_blocks = blk_cnt; in hfs_file_truncate()
520 res = __hfs_ext_cache_extent(&fd, inode, alloc_cnt); in hfs_file_truncate()
523 start = HFS_I(inode)->cached_start; in hfs_file_truncate()
524 hfs_free_extents(sb, HFS_I(inode)->cached_extents, in hfs_file_truncate()
526 hfs_dump_extent(HFS_I(inode)->cached_extents); in hfs_file_truncate()
528 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY; in hfs_file_truncate()
532 HFS_I(inode)->cached_start = HFS_I(inode)->cached_blocks = 0; in hfs_file_truncate()
533 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW); in hfs_file_truncate()
537 mutex_unlock(&HFS_I(inode)->extents_lock); in hfs_file_truncate()
539 HFS_I(inode)->alloc_blocks = blk_cnt; in hfs_file_truncate()
541 HFS_I(inode)->phys_size = inode->i_size; in hfs_file_truncate()
542 HFS_I(inode)->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits; in hfs_file_truncate()
543 inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits); in hfs_file_truncate()
544 mark_inode_dirty(inode); in hfs_file_truncate()