Lines Matching refs:fs
41 (struct ext2_block_group *bg, const struct ext_filesystem *fs) in ext4fs_bg_free_inodes_inc() argument
44 if (fs->gdsize == 64) in ext4fs_bg_free_inodes_inc()
49 if (fs->gdsize == 64) in ext4fs_bg_free_inodes_inc()
54 (struct ext2_block_group *bg, const struct ext_filesystem *fs) in ext4fs_bg_free_blocks_inc() argument
57 if (fs->gdsize == 64) in ext4fs_bg_free_blocks_inc()
62 if (fs->gdsize == 64) in ext4fs_bg_free_blocks_inc()
70 struct ext_filesystem *fs = get_fs(); in ext4fs_update() local
75 (struct ext2_sblock *)fs->sb, (uint32_t)SUPERBLOCK_SIZE); in ext4fs_update()
78 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_update()
79 bgd = ext4fs_get_group_descriptor(fs, i); in ext4fs_update()
81 uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs); in ext4fs_update()
82 put_ext4(b_bitmap_blk * fs->blksz, in ext4fs_update()
83 fs->blk_bmaps[i], fs->blksz); in ext4fs_update()
87 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_update()
88 bgd = ext4fs_get_group_descriptor(fs, i); in ext4fs_update()
89 uint64_t i_bitmap_blk = ext4fs_bg_get_inode_id(bgd, fs); in ext4fs_update()
90 put_ext4(i_bitmap_blk * fs->blksz, in ext4fs_update()
91 fs->inode_bmaps[i], fs->blksz); in ext4fs_update()
95 put_ext4((uint64_t)((uint64_t)fs->gdtable_blkno * (uint64_t)fs->blksz), in ext4fs_update()
96 (struct ext2_block_group *)fs->gdtable, in ext4fs_update()
97 (fs->blksz * fs->no_blk_pergdt)); in ext4fs_update()
108 struct ext_filesystem *fs = get_fs(); in ext4fs_get_bgdtable() local
109 int gdsize_total = ROUND(fs->no_blkgrp * fs->gdsize, fs->blksz); in ext4fs_get_bgdtable()
110 fs->no_blk_pergdt = gdsize_total / fs->blksz; in ext4fs_get_bgdtable()
113 fs->gdtable = zalloc(gdsize_total); in ext4fs_get_bgdtable()
114 if (!fs->gdtable) in ext4fs_get_bgdtable()
117 status = ext4fs_devread((lbaint_t)fs->gdtable_blkno * fs->sect_perblk, in ext4fs_get_bgdtable()
118 0, fs->blksz * fs->no_blk_pergdt, fs->gdtable); in ext4fs_get_bgdtable()
122 if (ext4fs_log_gdt(fs->gdtable)) { in ext4fs_get_bgdtable()
129 free(fs->gdtable); in ext4fs_get_bgdtable()
130 fs->gdtable = NULL; in ext4fs_get_bgdtable()
144 struct ext_filesystem *fs = get_fs(); in delete_single_indirect_block() local
145 char *journal_buffer = zalloc(fs->blksz); in delete_single_indirect_block()
156 if (fs->blksz == 1024) { in delete_single_indirect_block()
161 ext4fs_reset_block_bmap(blknr, fs->blk_bmaps[bg_idx], bg_idx); in delete_single_indirect_block()
163 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_single_indirect_block()
164 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_single_indirect_block()
165 ext4fs_sb_free_blocks_inc(fs->sb); in delete_single_indirect_block()
168 uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs); in delete_single_indirect_block()
170 b_bitmap_blk * fs->sect_perblk, in delete_single_indirect_block()
171 0, fs->blksz, journal_buffer); in delete_single_indirect_block()
195 struct ext_filesystem *fs = get_fs(); in delete_double_indirect_block() local
196 char *journal_buffer = zalloc(fs->blksz); in delete_double_indirect_block()
203 di_buffer = zalloc(fs->blksz); in delete_double_indirect_block()
210 status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, in delete_double_indirect_block()
211 fs->blksz, (char *)di_buffer); in delete_double_indirect_block()
212 for (i = 0; i < fs->blksz / sizeof(int); i++) { in delete_double_indirect_block()
218 if (fs->blksz == 1024) { in delete_double_indirect_block()
224 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_double_indirect_block()
226 fs->blk_bmaps[bg_idx], bg_idx); in delete_double_indirect_block()
228 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_double_indirect_block()
229 ext4fs_sb_free_blocks_inc(fs->sb); in delete_double_indirect_block()
233 ext4fs_bg_get_block_id(bgd, fs); in delete_double_indirect_block()
235 * fs->sect_perblk, 0, in delete_double_indirect_block()
236 fs->blksz, in delete_double_indirect_block()
251 if (fs->blksz == 1024) { in delete_double_indirect_block()
257 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_double_indirect_block()
258 ext4fs_reset_block_bmap(blknr, fs->blk_bmaps[bg_idx], bg_idx); in delete_double_indirect_block()
259 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_double_indirect_block()
260 ext4fs_sb_free_blocks_inc(fs->sb); in delete_double_indirect_block()
263 uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs); in delete_double_indirect_block()
264 status = ext4fs_devread(b_bitmap_blk * fs->sect_perblk, in delete_double_indirect_block()
265 0, fs->blksz, journal_buffer); in delete_double_indirect_block()
294 struct ext_filesystem *fs = get_fs(); in delete_triple_indirect_block() local
295 char *journal_buffer = zalloc(fs->blksz); in delete_triple_indirect_block()
302 tigp_buffer = zalloc(fs->blksz); in delete_triple_indirect_block()
309 status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, in delete_triple_indirect_block()
310 fs->blksz, (char *)tigp_buffer); in delete_triple_indirect_block()
311 for (i = 0; i < fs->blksz / sizeof(int); i++) { in delete_triple_indirect_block()
316 tip_buffer = zalloc(fs->blksz); in delete_triple_indirect_block()
321 fs->sect_perblk, 0, fs->blksz, in delete_triple_indirect_block()
323 for (j = 0; j < fs->blksz / sizeof(int); j++) { in delete_triple_indirect_block()
327 if (fs->blksz == 1024) { in delete_triple_indirect_block()
334 fs->blk_bmaps[bg_idx], in delete_triple_indirect_block()
339 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_triple_indirect_block()
340 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_triple_indirect_block()
341 ext4fs_sb_free_blocks_inc(fs->sb); in delete_triple_indirect_block()
345 ext4fs_bg_get_block_id(bgd, fs); in delete_triple_indirect_block()
349 fs->sect_perblk, 0, in delete_triple_indirect_block()
350 fs->blksz, in delete_triple_indirect_block()
369 if (fs->blksz == 1024) { in delete_triple_indirect_block()
375 fs->blk_bmaps[bg_idx], bg_idx); in delete_triple_indirect_block()
379 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_triple_indirect_block()
380 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_triple_indirect_block()
381 ext4fs_sb_free_blocks_inc(fs->sb); in delete_triple_indirect_block()
385 ext4fs_bg_get_block_id(bgd, fs); in delete_triple_indirect_block()
386 memset(journal_buffer, '\0', fs->blksz); in delete_triple_indirect_block()
388 fs->sect_perblk, 0, in delete_triple_indirect_block()
389 fs->blksz, in delete_triple_indirect_block()
404 if (fs->blksz == 1024) { in delete_triple_indirect_block()
409 ext4fs_reset_block_bmap(blknr, fs->blk_bmaps[bg_idx], bg_idx); in delete_triple_indirect_block()
411 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in delete_triple_indirect_block()
412 ext4fs_bg_free_blocks_inc(bgd, fs); in delete_triple_indirect_block()
413 ext4fs_sb_free_blocks_inc(fs->sb); in delete_triple_indirect_block()
416 uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs); in delete_triple_indirect_block()
417 status = ext4fs_devread(b_bitmap_blk * fs->sect_perblk, in delete_triple_indirect_block()
418 0, fs->blksz, journal_buffer); in delete_triple_indirect_block()
455 struct ext_filesystem *fs = get_fs(); in ext4fs_delete_file() local
456 char *journal_buffer = zalloc(fs->blksz); in ext4fs_delete_file()
464 no_blocks = le32_to_cpu(inode.size) / fs->blksz; in ext4fs_delete_file()
465 if (le32_to_cpu(inode.size) % fs->blksz) in ext4fs_delete_file()
488 if (fs->blksz == 1024) { in ext4fs_delete_file()
493 ext4fs_reset_block_bmap(blknr, fs->blk_bmaps[bg_idx], in ext4fs_delete_file()
498 bgd = ext4fs_get_group_descriptor(fs, bg_idx); in ext4fs_delete_file()
499 ext4fs_bg_free_blocks_inc(bgd, fs); in ext4fs_delete_file()
500 ext4fs_sb_free_blocks_inc(fs->sb); in ext4fs_delete_file()
503 uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs); in ext4fs_delete_file()
504 status = ext4fs_devread(b_bitmap_blk * fs->sect_perblk, in ext4fs_delete_file()
505 0, fs->blksz, in ext4fs_delete_file()
517 inodes_per_block = fs->blksz / fs->inodesz; in ext4fs_delete_file()
523 bgd = ext4fs_get_group_descriptor(fs, ibmap_idx); in ext4fs_delete_file()
524 blkno = ext4fs_bg_get_inode_table_id(bgd, fs) + in ext4fs_delete_file()
528 blkoff = ((inodeno) % inodes_per_block) * fs->inodesz; in ext4fs_delete_file()
531 read_buffer = zalloc(fs->blksz); in ext4fs_delete_file()
535 status = ext4fs_devread((lbaint_t)blkno * fs->sect_perblk, in ext4fs_delete_file()
536 0, fs->blksz, read_buffer); in ext4fs_delete_file()
545 memset(inode_buffer, '\0', fs->inodesz); in ext4fs_delete_file()
553 ext4fs_reset_inode_bmap(inodeno, fs->inode_bmaps[ibmap_idx], ibmap_idx); in ext4fs_delete_file()
554 ext4fs_bg_free_inodes_inc(bgd, fs); in ext4fs_delete_file()
555 ext4fs_sb_free_inodes_inc(fs->sb); in ext4fs_delete_file()
557 memset(journal_buffer, '\0', fs->blksz); in ext4fs_delete_file()
558 status = ext4fs_devread(ext4fs_bg_get_inode_id(bgd, fs) * in ext4fs_delete_file()
559 fs->sect_perblk, 0, fs->blksz, journal_buffer); in ext4fs_delete_file()
562 if (ext4fs_log_journal(journal_buffer, ext4fs_bg_get_inode_id(bgd, fs))) in ext4fs_delete_file()
590 struct ext_filesystem *fs = get_fs(); in ext4fs_init() local
593 fs->blksz = EXT2_BLOCK_SIZE(ext4fs_root); in ext4fs_init()
594 fs->sect_perblk = fs->blksz >> fs->dev_desc->log2blksz; in ext4fs_init()
597 fs->sb = zalloc(SUPERBLOCK_SIZE); in ext4fs_init()
598 if (!fs->sb) in ext4fs_init()
600 if (!ext4_read_superblock((char *)fs->sb)) in ext4fs_init()
608 fs->no_blkgrp = (uint32_t)ext4fs_div_roundup( in ext4fs_init()
614 fs->gdtable_blkno = ((EXT2_MIN_BLOCK_SIZE == fs->blksz) + 1); in ext4fs_init()
621 fs->blk_bmaps = zalloc(fs->no_blkgrp * sizeof(char *)); in ext4fs_init()
622 if (!fs->blk_bmaps) in ext4fs_init()
624 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_init()
625 fs->blk_bmaps[i] = zalloc(fs->blksz); in ext4fs_init()
626 if (!fs->blk_bmaps[i]) in ext4fs_init()
630 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_init()
632 ext4fs_get_group_descriptor(fs, i); in ext4fs_init()
633 status = ext4fs_devread(ext4fs_bg_get_block_id(bgd, fs) * in ext4fs_init()
634 fs->sect_perblk, 0, in ext4fs_init()
635 fs->blksz, (char *)fs->blk_bmaps[i]); in ext4fs_init()
641 fs->inode_bmaps = zalloc(fs->no_blkgrp * sizeof(unsigned char *)); in ext4fs_init()
642 if (!fs->inode_bmaps) in ext4fs_init()
644 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_init()
645 fs->inode_bmaps[i] = zalloc(fs->blksz); in ext4fs_init()
646 if (!fs->inode_bmaps[i]) in ext4fs_init()
650 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_init()
652 ext4fs_get_group_descriptor(fs, i); in ext4fs_init()
653 status = ext4fs_devread(ext4fs_bg_get_inode_id(bgd, fs) * in ext4fs_init()
654 fs->sect_perblk, in ext4fs_init()
655 0, fs->blksz, in ext4fs_init()
656 (char *)fs->inode_bmaps[i]); in ext4fs_init()
667 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_init()
669 ext4fs_get_group_descriptor(fs, i); in ext4fs_init()
671 ext4fs_bg_get_free_blocks(bgd, fs); in ext4fs_init()
673 if (real_free_blocks != ext4fs_sb_get_free_blocks(fs->sb)) in ext4fs_init()
674 ext4fs_sb_set_free_blocks(fs->sb, real_free_blocks); in ext4fs_init()
689 struct ext_filesystem *fs = get_fs(); in ext4fs_deinit() local
693 char *temp_buff = zalloc(fs->blksz); in ext4fs_deinit()
699 ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0, fs->blksz, in ext4fs_deinit()
703 put_ext4((uint64_t) ((uint64_t)blknr * (uint64_t)fs->blksz), in ext4fs_deinit()
704 (struct journal_superblock_t *)temp_buff, fs->blksz); in ext4fs_deinit()
710 ext4_read_superblock((char *)fs->sb); in ext4fs_deinit()
711 new_feature_incompat = le32_to_cpu(fs->sb->feature_incompat); in ext4fs_deinit()
713 fs->sb->feature_incompat = cpu_to_le32(new_feature_incompat); in ext4fs_deinit()
715 (struct ext2_sblock *)fs->sb, (uint32_t)SUPERBLOCK_SIZE); in ext4fs_deinit()
716 free(fs->sb); in ext4fs_deinit()
717 fs->sb = NULL; in ext4fs_deinit()
719 if (fs->blk_bmaps) { in ext4fs_deinit()
720 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_deinit()
721 free(fs->blk_bmaps[i]); in ext4fs_deinit()
722 fs->blk_bmaps[i] = NULL; in ext4fs_deinit()
724 free(fs->blk_bmaps); in ext4fs_deinit()
725 fs->blk_bmaps = NULL; in ext4fs_deinit()
728 if (fs->inode_bmaps) { in ext4fs_deinit()
729 for (i = 0; i < fs->no_blkgrp; i++) { in ext4fs_deinit()
730 free(fs->inode_bmaps[i]); in ext4fs_deinit()
731 fs->inode_bmaps[i] = NULL; in ext4fs_deinit()
733 free(fs->inode_bmaps); in ext4fs_deinit()
734 fs->inode_bmaps = NULL; in ext4fs_deinit()
738 free(fs->gdtable); in ext4fs_deinit()
739 fs->gdtable = NULL; in ext4fs_deinit()
744 fs->first_pass_ibmap = 0; in ext4fs_deinit()
745 fs->first_pass_bbmap = 0; in ext4fs_deinit()
746 fs->curr_inode_no = 0; in ext4fs_deinit()
747 fs->curr_blkno = 0; in ext4fs_deinit()
760 struct ext_filesystem *fs = get_fs(); in ext4fs_write_file() local
761 int log2blksz = fs->dev_desc->log2blksz; in ext4fs_write_file()
773 blockcnt = ((len + pos) + fs->blksz - 1) / fs->blksz; in ext4fs_write_file()
775 for (i = pos / fs->blksz; i < blockcnt; i++) { in ext4fs_write_file()
777 int blockend = fs->blksz; in ext4fs_write_file()
819 memset(buf, 0, fs->blksz - skipfirst); in ext4fs_write_file()
821 buf += fs->blksz - skipfirst; in ext4fs_write_file()
855 struct ext_filesystem *fs = get_fs(); in ext4fs_write() local
859 g_parent_inode = zalloc(fs->inodesz); in ext4fs_write()
867 inodes_per_block = fs->blksz / fs->inodesz; in ext4fs_write()
882 fs->first_pass_bbmap = 0; in ext4fs_write()
883 fs->curr_blkno = 0; in ext4fs_write()
885 fs->first_pass_ibmap = 0; in ext4fs_write()
886 fs->curr_inode_no = 0; in ext4fs_write()
892 blks_reqd_for_file = lldiv(bytes_reqd_for_file, fs->blksz); in ext4fs_write()
893 if (do_div(bytes_reqd_for_file, fs->blksz) != 0) { in ext4fs_write()
899 if (le32_to_cpu(fs->sb->free_blocks) < blks_reqd_for_file) { in ext4fs_write()
908 inode_buffer = zalloc(fs->inodesz); in ext4fs_write()
924 file_inode->blockcnt = cpu_to_le32((blks_reqd_for_file * fs->blksz) >> in ext4fs_write()
925 fs->dev_desc->log2blksz); in ext4fs_write()
927 temp_ptr = zalloc(fs->blksz); in ext4fs_write()
932 bgd = ext4fs_get_group_descriptor(fs, ibmap_idx); in ext4fs_write()
933 itable_blkno = ext4fs_bg_get_inode_table_id(bgd, fs) + in ext4fs_write()
936 blkoff = (inodeno % inodes_per_block) * fs->inodesz; in ext4fs_write()
937 ext4fs_devread((lbaint_t)itable_blkno * fs->sect_perblk, 0, fs->blksz, in ext4fs_write()
942 memcpy(temp_ptr + blkoff, inode_buffer, fs->inodesz); in ext4fs_write()
953 bgd = ext4fs_get_group_descriptor(fs, ibmap_idx); in ext4fs_write()
954 parent_itable_blkno = ext4fs_bg_get_inode_table_id(bgd, fs) + in ext4fs_write()
957 blkoff = (parent_inodeno % inodes_per_block) * fs->inodesz; in ext4fs_write()
959 memset(temp_ptr, '\0', fs->blksz); in ext4fs_write()
960 ext4fs_devread((lbaint_t)parent_itable_blkno * fs->sect_perblk, in ext4fs_write()
961 0, fs->blksz, temp_ptr); in ext4fs_write()
965 memcpy(temp_ptr + blkoff, g_parent_inode, fs->inodesz); in ext4fs_write()
973 memcpy(temp_ptr + blkoff, g_parent_inode, fs->inodesz); in ext4fs_write()
981 fs->first_pass_bbmap = 0; in ext4fs_write()
982 fs->curr_blkno = 0; in ext4fs_write()
983 fs->first_pass_ibmap = 0; in ext4fs_write()
984 fs->curr_inode_no = 0; in ext4fs_write()