Lines Matching refs:inode

110 static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd)
114 hfs_ext_build_key(fd->search_key, inode->i_ino, HFS_I(inode)->cached_start,
115 HFS_IS_RSRC(inode) ? HFS_FK_RSRC : HFS_FK_DATA);
117 if (HFS_I(inode)->flags & HFS_FLG_EXT_NEW) {
124 hfs_brec_insert(fd, HFS_I(inode)->cached_extents, sizeof(hfs_extent_rec));
125 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
129 hfs_bnode_write(fd->bnode, HFS_I(inode)->cached_extents, fd->entryoffset, fd->entrylength);
130 HFS_I(inode)->flags &= ~HFS_FLG_EXT_DIRTY;
135 int hfs_ext_write_extent(struct inode *inode)
140 if (HFS_I(inode)->flags & HFS_FLG_EXT_DIRTY) {
141 res = hfs_find_init(HFS_SB(inode->i_sb)->ext_tree, &fd);
144 res = __hfs_ext_write_extent(inode, &fd);
169 static inline int __hfs_ext_cache_extent(struct hfs_find_data *fd, struct inode *inode, u32 block)
173 if (HFS_I(inode)->flags & HFS_FLG_EXT_DIRTY) {
174 res = __hfs_ext_write_extent(inode, fd);
179 res = __hfs_ext_read_extent(fd, HFS_I(inode)->cached_extents, inode->i_ino,
180 block, HFS_IS_RSRC(inode) ? HFS_FK_RSRC : HFS_FK_DATA);
182 HFS_I(inode)->cached_start = be16_to_cpu(fd->key->ext.FABN);
183 HFS_I(inode)->cached_blocks = hfs_ext_block_count(HFS_I(inode)->cached_extents);
185 HFS_I(inode)->cached_start = HFS_I(inode)->cached_blocks = 0;
186 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
191 static int hfs_ext_read_extent(struct inode *inode, u16 block)
196 if (block >= HFS_I(inode)->cached_start &&
197 block < HFS_I(inode)->cached_start + HFS_I(inode)->cached_blocks)
200 res = hfs_find_init(HFS_SB(inode->i_sb)->ext_tree, &fd);
202 res = __hfs_ext_cache_extent(&fd, inode, block);
336 int hfs_get_block(struct inode *inode, sector_t block,
343 sb = inode->i_sb;
344 /* Convert inode block to disk allocation block */
347 if (block >= HFS_I(inode)->fs_blocks) {
350 if (block > HFS_I(inode)->fs_blocks)
352 if (ablock >= HFS_I(inode)->alloc_blocks) {
353 res = hfs_extend_file(inode);
360 if (ablock < HFS_I(inode)->first_blocks) {
361 dblock = hfs_ext_find_block(HFS_I(inode)->first_extents, ablock);
365 mutex_lock(&HFS_I(inode)->extents_lock);
366 res = hfs_ext_read_extent(inode, ablock);
368 dblock = hfs_ext_find_block(HFS_I(inode)->cached_extents,
369 ablock - HFS_I(inode)->cached_start);
371 mutex_unlock(&HFS_I(inode)->extents_lock);
374 mutex_unlock(&HFS_I(inode)->extents_lock);
383 HFS_I(inode)->phys_size += sb->s_blocksize;
384 HFS_I(inode)->fs_blocks++;
385 inode_add_bytes(inode, sb->s_blocksize);
386 mark_inode_dirty(inode);
391 int hfs_extend_file(struct inode *inode)
393 struct super_block *sb = inode->i_sb;
397 mutex_lock(&HFS_I(inode)->extents_lock);
398 if (HFS_I(inode)->alloc_blocks == HFS_I(inode)->first_blocks)
399 goal = hfs_ext_lastblock(HFS_I(inode)->first_extents);
401 res = hfs_ext_read_extent(inode, HFS_I(inode)->alloc_blocks);
404 goal = hfs_ext_lastblock(HFS_I(inode)->cached_extents);
407 len = HFS_I(inode)->clump_blocks;
414 hfs_dbg(EXTENT, "extend %lu: %u,%u\n", inode->i_ino, start, len);
415 if (HFS_I(inode)->alloc_blocks == HFS_I(inode)->first_blocks) {
416 if (!HFS_I(inode)->first_blocks) {
419 HFS_I(inode)->first_extents[0].block = cpu_to_be16(start);
420 HFS_I(inode)->first_extents[0].count = cpu_to_be16(len);
423 /* try to append to extents in inode */
424 res = hfs_add_extent(HFS_I(inode)->first_extents,
425 HFS_I(inode)->alloc_blocks,
431 hfs_dump_extent(HFS_I(inode)->first_extents);
432 HFS_I(inode)->first_blocks += len;
435 res = hfs_add_extent(HFS_I(inode)->cached_extents,
436 HFS_I(inode)->alloc_blocks -
437 HFS_I(inode)->cached_start,
440 hfs_dump_extent(HFS_I(inode)->cached_extents);
441 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY;
442 HFS_I(inode)->cached_blocks += len;
447 mutex_unlock(&HFS_I(inode)->extents_lock);
449 HFS_I(inode)->alloc_blocks += len;
450 mark_inode_dirty(inode);
451 if (inode->i_ino < HFS_FIRSTUSER_CNID)
460 res = hfs_ext_write_extent(inode);
464 memset(HFS_I(inode)->cached_extents, 0, sizeof(hfs_extent_rec));
465 HFS_I(inode)->cached_extents[0].block = cpu_to_be16(start);
466 HFS_I(inode)->cached_extents[0].count = cpu_to_be16(len);
467 hfs_dump_extent(HFS_I(inode)->cached_extents);
468 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW;
469 HFS_I(inode)->cached_start = HFS_I(inode)->alloc_blocks;
470 HFS_I(inode)->cached_blocks = len;
476 void hfs_file_truncate(struct inode *inode)
478 struct super_block *sb = inode->i_sb;
485 inode->i_ino, (long long)HFS_I(inode)->phys_size,
486 inode->i_size);
487 if (inode->i_size > HFS_I(inode)->phys_size) {
488 struct address_space *mapping = inode->i_mapping;
493 size = inode->i_size - 1;
501 inode->i_size = HFS_I(inode)->phys_size;
503 } else if (inode->i_size == HFS_I(inode)->phys_size)
505 size = inode->i_size + HFS_SB(sb)->alloc_blksz - 1;
507 alloc_cnt = HFS_I(inode)->alloc_blocks;
511 mutex_lock(&HFS_I(inode)->extents_lock);
514 mutex_unlock(&HFS_I(inode)->extents_lock);
519 if (alloc_cnt == HFS_I(inode)->first_blocks) {
520 hfs_free_extents(sb, HFS_I(inode)->first_extents,
522 hfs_dump_extent(HFS_I(inode)->first_extents);
523 HFS_I(inode)->first_blocks = blk_cnt;
526 res = __hfs_ext_cache_extent(&fd, inode, alloc_cnt);
529 start = HFS_I(inode)->cached_start;
530 hfs_free_extents(sb, HFS_I(inode)->cached_extents,
532 hfs_dump_extent(HFS_I(inode)->cached_extents);
534 HFS_I(inode)->flags |= HFS_FLG_EXT_DIRTY;
538 HFS_I(inode)->cached_start = HFS_I(inode)->cached_blocks = 0;
539 HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
543 mutex_unlock(&HFS_I(inode)->extents_lock);
545 HFS_I(inode)->alloc_blocks = blk_cnt;
547 HFS_I(inode)->phys_size = inode->i_size;
548 HFS_I(inode)->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
549 inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits);
550 mark_inode_dirty(inode);