55 fnum1 = key1->
ext.FNum;
56 fnum2 = key2->
ext.FNum;
59 if (key1->
ext.FkType != key2->
ext.FkType)
60 return key1->
ext.FkType < key2->
ext.FkType ? -1 : 1;
62 block1 = key1->
ext.FABN;
63 block2 = key2->
ext.FABN;
79 for (i = 0; i < 3; ext++, i++) {
89 static int hfs_ext_block_count(
struct hfs_extent *ext)
94 for (i = 0; i < 3; ext++, i++)
104 for (i = 0; i < 2; ext--, i++)
136 __hfs_ext_write_extent(inode, &fd);
146 hfs_ext_build_key(fd->
search_key, cnid, block, type);
149 if (res && res != -
ENOENT)
160 static inline int __hfs_ext_cache_extent(
struct hfs_find_data *fd,
struct inode *inode,
u32 block)
165 __hfs_ext_write_extent(inode, fd);
167 res = __hfs_ext_read_extent(fd,
HFS_I(inode)->cached_extents, inode->
i_ino,
171 HFS_I(inode)->cached_blocks = hfs_ext_block_count(
HFS_I(inode)->cached_extents);
173 HFS_I(inode)->cached_start =
HFS_I(inode)->cached_blocks = 0;
179 static int hfs_ext_read_extent(
struct inode *inode,
u16 block)
184 if (block >=
HFS_I(inode)->cached_start &&
185 block <
HFS_I(inode)->cached_start +
HFS_I(inode)->cached_blocks)
189 res = __hfs_ext_cache_extent(&fd, inode, block);
194 static void hfs_dump_extent(
struct hfs_extent *extent)
199 for (i = 0; i < 3; i++)
211 hfs_dump_extent(extent);
212 for (i = 0; i < 3; extent++, i++) {
214 if (offset == count) {
216 if (alloc_block != start + count) {
222 block_count +=
count;
225 }
else if (offset < count)
239 hfs_dump_extent(extent);
240 for (i = 0; i < 3; extent++, i++) {
244 else if (offset < count)
253 if (count <= block_nr) {
287 total_blocks /=
HFS_SB(sb)->alloc_blksz;
292 for (i = 0; i < 3; extent++, i++)
295 res = hfs_free_extents(sb, extent, blocks, blocks);
298 if (total_blocks == blocks)
303 res = __hfs_ext_read_extent(&fd, extent, cnid, total_blocks, type);
307 hfs_free_extents(sb, extent, total_blocks - start, total_blocks);
309 total_blocks =
start;
310 }
while (total_blocks > blocks);
320 struct buffer_head *bh_result,
int create)
328 ablock = (
u32)block /
HFS_SB(sb)->fs_div;
330 if (block >=
HFS_I(inode)->fs_blocks) {
333 if (ablock >=
HFS_I(inode)->alloc_blocks) {
341 if (ablock <
HFS_I(inode)->first_blocks) {
342 dblock = hfs_ext_find_block(
HFS_I(inode)->first_extents, ablock);
347 res = hfs_ext_read_extent(inode, ablock);
349 dblock = hfs_ext_find_block(
HFS_I(inode)->cached_extents,
350 ablock -
HFS_I(inode)->cached_start);
358 map_bh(bh_result, sb,
HFS_SB(sb)->fs_start +
359 dblock *
HFS_SB(sb)->fs_div +
363 set_buffer_new(bh_result);
365 HFS_I(inode)->fs_blocks++;
367 mark_inode_dirty(inode);
379 if (
HFS_I(inode)->alloc_blocks ==
HFS_I(inode)->first_blocks)
380 goal = hfs_ext_lastblock(
HFS_I(inode)->first_extents);
382 res = hfs_ext_read_extent(inode,
HFS_I(inode)->alloc_blocks);
385 goal = hfs_ext_lastblock(
HFS_I(inode)->cached_extents);
388 len =
HFS_I(inode)->clump_blocks;
396 if (
HFS_I(inode)->alloc_blocks ==
HFS_I(inode)->first_blocks) {
397 if (!
HFS_I(inode)->first_blocks) {
405 res = hfs_add_extent(
HFS_I(inode)->first_extents,
406 HFS_I(inode)->alloc_blocks,
412 hfs_dump_extent(
HFS_I(inode)->first_extents);
413 HFS_I(inode)->first_blocks += len;
416 res = hfs_add_extent(
HFS_I(inode)->cached_extents,
417 HFS_I(inode)->alloc_blocks -
418 HFS_I(inode)->cached_start,
421 hfs_dump_extent(
HFS_I(inode)->cached_extents);
423 HFS_I(inode)->cached_blocks += len;
424 }
else if (res == -
ENOSPC)
430 HFS_I(inode)->alloc_blocks += len;
431 mark_inode_dirty(inode);
446 hfs_dump_extent(
HFS_I(inode)->cached_extents);
448 HFS_I(inode)->cached_start =
HFS_I(inode)->alloc_blocks;
449 HFS_I(inode)->cached_blocks = len;
464 (
long long)
HFS_I(inode)->phys_size, inode->
i_size);
482 }
else if (inode->
i_size ==
HFS_I(inode)->phys_size)
485 blk_cnt = size /
HFS_SB(sb)->alloc_blksz;
486 alloc_cnt =
HFS_I(inode)->alloc_blocks;
487 if (blk_cnt == alloc_cnt)
493 if (alloc_cnt ==
HFS_I(inode)->first_blocks) {
494 hfs_free_extents(sb,
HFS_I(inode)->first_extents,
495 alloc_cnt, alloc_cnt - blk_cnt);
496 hfs_dump_extent(
HFS_I(inode)->first_extents);
500 res = __hfs_ext_cache_extent(&fd, inode, alloc_cnt);
503 start =
HFS_I(inode)->cached_start;
504 hfs_free_extents(sb,
HFS_I(inode)->cached_extents,
505 alloc_cnt - start, alloc_cnt - blk_cnt);
506 hfs_dump_extent(
HFS_I(inode)->cached_extents);
507 if (blk_cnt > start) {
512 HFS_I(inode)->cached_start =
HFS_I(inode)->cached_blocks = 0;
524 mark_inode_dirty(inode);