Lines Matching refs:fs
33 void ext2fs_init_csum_seed(ext2_filsys fs) in ext2fs_init_csum_seed() argument
35 if (ext2fs_has_feature_csum_seed(fs->super)) in ext2fs_init_csum_seed()
36 fs->csum_seed = fs->super->s_checksum_seed; in ext2fs_init_csum_seed()
37 else if (ext2fs_has_feature_metadata_csum(fs->super) || in ext2fs_init_csum_seed()
38 ext2fs_has_feature_ea_inode(fs->super)) in ext2fs_init_csum_seed()
39 fs->csum_seed = ext2fs_crc32c_le(~0, fs->super->s_uuid, in ext2fs_init_csum_seed()
40 sizeof(fs->super->s_uuid)); in ext2fs_init_csum_seed()
43 static __u32 ext2fs_mmp_csum(ext2_filsys fs, struct mmp_struct *mmp) in ext2fs_mmp_csum() argument
47 return ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)mmp, offset); in ext2fs_mmp_csum()
50 int ext2fs_mmp_csum_verify(ext2_filsys fs, struct mmp_struct *mmp) in ext2fs_mmp_csum_verify() argument
54 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_mmp_csum_verify()
57 calculated = ext2fs_mmp_csum(fs, mmp); in ext2fs_mmp_csum_verify()
62 errcode_t ext2fs_mmp_csum_set(ext2_filsys fs, struct mmp_struct *mmp) in ext2fs_mmp_csum_set() argument
66 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_mmp_csum_set()
69 crc = ext2fs_mmp_csum(fs, mmp); in ext2fs_mmp_csum_set()
75 int ext2fs_verify_csum_type(ext2_filsys fs, struct ext2_super_block *sb) in ext2fs_verify_csum_type() argument
77 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_verify_csum_type()
83 static __u32 ext2fs_superblock_csum(ext2_filsys fs EXT2FS_ATTR((unused)), in ext2fs_superblock_csum()
92 int ext2fs_superblock_csum_verify(ext2_filsys fs, struct ext2_super_block *sb) in ext2fs_superblock_csum_verify() argument
96 if (fs->flags & EXT2_FLAG_SWAP_BYTES) in ext2fs_superblock_csum_verify()
101 if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, flag)) in ext2fs_superblock_csum_verify()
104 calculated = ext2fs_superblock_csum(fs, sb); in ext2fs_superblock_csum_verify()
110 errcode_t ext2fs_superblock_csum_set(ext2_filsys fs, in ext2fs_superblock_csum_set() argument
115 if (fs->flags & EXT2_FLAG_SWAP_BYTES) in ext2fs_superblock_csum_set()
120 if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, flag)) in ext2fs_superblock_csum_set()
123 crc = ext2fs_superblock_csum(fs, sb); in ext2fs_superblock_csum_set()
129 static errcode_t ext2fs_ext_attr_block_csum(ext2_filsys fs, in ext2fs_ext_attr_block_csum() argument
140 *crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&block, in ext2fs_ext_attr_block_csum()
142 *crc = ext2fs_crc32c_le(*crc, (unsigned char *)buf, fs->blocksize); in ext2fs_ext_attr_block_csum()
148 int ext2fs_ext_attr_block_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_ext_attr_block_csum_verify() argument
155 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_ext_attr_block_csum_verify()
158 retval = ext2fs_ext_attr_block_csum(fs, inum, block, hdr, &calculated); in ext2fs_ext_attr_block_csum_verify()
165 errcode_t ext2fs_ext_attr_block_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_ext_attr_block_csum_set() argument
172 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_ext_attr_block_csum_set()
175 retval = ext2fs_ext_attr_block_csum(fs, inum, block, hdr, &crc); in ext2fs_ext_attr_block_csum_set()
192 static errcode_t __get_dx_countlimit(ext2_filsys fs, in __get_dx_countlimit() argument
207 if (rec_len == fs->blocksize && translate(dirent->name_len) == 0) in __get_dx_countlimit()
212 if (rec_len != fs->blocksize - 12) in __get_dx_countlimit()
223 max_sane_entries = (fs->blocksize - count_offset) / in __get_dx_countlimit()
237 errcode_t ext2fs_get_dx_countlimit(ext2_filsys fs, in ext2fs_get_dx_countlimit() argument
242 return __get_dx_countlimit(fs, dirent, cc, offset, 0); in ext2fs_get_dx_countlimit()
245 void ext2fs_initialize_dirent_tail(ext2_filsys fs, in ext2fs_initialize_dirent_tail() argument
249 ext2fs_set_rec_len(fs, sizeof(struct ext2_dir_entry_tail), in ext2fs_initialize_dirent_tail()
254 static errcode_t __get_dirent_tail(ext2_filsys fs, in __get_dirent_tail() argument
267 top = EXT2_DIRENT_TAIL(dirent, fs->blocksize); in __get_dirent_tail()
291 int ext2fs_dirent_has_tail(ext2_filsys fs, struct ext2_dir_entry *dirent) in ext2fs_dirent_has_tail() argument
293 return __get_dirent_tail(fs, dirent, NULL, 0) == 0; in ext2fs_dirent_has_tail()
296 static errcode_t ext2fs_dirent_csum(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dirent_csum() argument
305 retval = ext2fs_read_inode(fs, inum, &inode); in ext2fs_dirent_csum()
311 *crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&inum, in ext2fs_dirent_csum()
319 int ext2fs_dirent_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dirent_csum_verify() argument
326 retval = __get_dirent_tail(fs, dirent, &t, 1); in ext2fs_dirent_csum_verify()
334 retval = ext2fs_dirent_csum(fs, inum, dirent, &calculated, in ext2fs_dirent_csum_verify()
341 static errcode_t ext2fs_dirent_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dirent_csum_set() argument
348 retval = __get_dirent_tail(fs, dirent, &t, 1); in ext2fs_dirent_csum_set()
353 retval = ext2fs_dirent_csum(fs, inum, dirent, &crc, in ext2fs_dirent_csum_set()
361 static errcode_t ext2fs_dx_csum(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dx_csum() argument
376 retval = ext2fs_read_inode(fs, inum, &inode); in ext2fs_dx_csum()
382 *crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&inum, in ext2fs_dx_csum()
393 static int ext2fs_dx_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dx_csum_verify() argument
402 retval = __get_dx_countlimit(fs, dirent, &c, &count_offset, 1); in ext2fs_dx_csum_verify()
408 fs->blocksize - sizeof(struct ext2_dx_tail)) in ext2fs_dx_csum_verify()
412 retval = ext2fs_dx_csum(fs, inum, dirent, &calculated, count_offset, in ext2fs_dx_csum_verify()
420 static errcode_t ext2fs_dx_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dx_csum_set() argument
429 retval = __get_dx_countlimit(fs, dirent, &c, &count_offset, 1); in ext2fs_dx_csum_set()
435 fs->blocksize - sizeof(struct ext2_dx_tail)) in ext2fs_dx_csum_set()
440 retval = ext2fs_dx_csum(fs, inum, dirent, &crc, count_offset, count, t); in ext2fs_dx_csum_set()
447 int ext2fs_dir_block_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dir_block_csum_verify() argument
450 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_dir_block_csum_verify()
453 if (__get_dirent_tail(fs, dirent, NULL, 1) == 0) in ext2fs_dir_block_csum_verify()
454 return ext2fs_dirent_csum_verify(fs, inum, dirent); in ext2fs_dir_block_csum_verify()
455 if (__get_dx_countlimit(fs, dirent, NULL, NULL, 1) == 0) in ext2fs_dir_block_csum_verify()
456 return ext2fs_dx_csum_verify(fs, inum, dirent); in ext2fs_dir_block_csum_verify()
461 errcode_t ext2fs_dir_block_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_dir_block_csum_set() argument
464 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_dir_block_csum_set()
467 if (__get_dirent_tail(fs, dirent, NULL, 1) == 0) in ext2fs_dir_block_csum_set()
468 return ext2fs_dirent_csum_set(fs, inum, dirent); in ext2fs_dir_block_csum_set()
469 if (__get_dx_countlimit(fs, dirent, NULL, NULL, 1) == 0) in ext2fs_dir_block_csum_set()
470 return ext2fs_dx_csum_set(fs, inum, dirent); in ext2fs_dir_block_csum_set()
472 if (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) in ext2fs_dir_block_csum_set()
486 static errcode_t ext2fs_extent_block_csum(ext2_filsys fs, ext2_ino_t inum, in ext2fs_extent_block_csum() argument
498 retval = ext2fs_read_inode(fs, inum, &inode); in ext2fs_extent_block_csum()
503 *crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&inum, in ext2fs_extent_block_csum()
511 int ext2fs_extent_block_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_extent_block_csum_verify() argument
522 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_extent_block_csum_verify()
526 retval = ext2fs_extent_block_csum(fs, inum, eh, &calculated); in ext2fs_extent_block_csum_verify()
533 errcode_t ext2fs_extent_block_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_extent_block_csum_set() argument
540 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_extent_block_csum_set()
547 retval = ext2fs_extent_block_csum(fs, inum, eh, &crc); in ext2fs_extent_block_csum_set()
554 int ext2fs_inode_bitmap_csum_verify(ext2_filsys fs, dgrp_t group, in ext2fs_inode_bitmap_csum_verify() argument
558 ext2fs_group_desc(fs, fs->group_desc, group); in ext2fs_inode_bitmap_csum_verify()
561 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_inode_bitmap_csum_verify()
564 calculated = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)bitmap, in ext2fs_inode_bitmap_csum_verify()
566 if (EXT2_DESC_SIZE(fs->super) >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) in ext2fs_inode_bitmap_csum_verify()
574 errcode_t ext2fs_inode_bitmap_csum_set(ext2_filsys fs, dgrp_t group, in ext2fs_inode_bitmap_csum_set() argument
579 ext2fs_group_desc(fs, fs->group_desc, group); in ext2fs_inode_bitmap_csum_set()
581 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_inode_bitmap_csum_set()
584 crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)bitmap, size); in ext2fs_inode_bitmap_csum_set()
586 if (EXT2_DESC_SIZE(fs->super) >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) in ext2fs_inode_bitmap_csum_set()
592 int ext2fs_block_bitmap_csum_verify(ext2_filsys fs, dgrp_t group, in ext2fs_block_bitmap_csum_verify() argument
596 ext2fs_group_desc(fs, fs->group_desc, group); in ext2fs_block_bitmap_csum_verify()
599 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_block_bitmap_csum_verify()
602 calculated = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)bitmap, in ext2fs_block_bitmap_csum_verify()
604 if (EXT2_DESC_SIZE(fs->super) >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) in ext2fs_block_bitmap_csum_verify()
612 errcode_t ext2fs_block_bitmap_csum_set(ext2_filsys fs, dgrp_t group, in ext2fs_block_bitmap_csum_set() argument
617 ext2fs_group_desc(fs, fs->group_desc, group); in ext2fs_block_bitmap_csum_set()
619 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_block_bitmap_csum_set()
622 crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)bitmap, size); in ext2fs_block_bitmap_csum_set()
624 if (EXT2_DESC_SIZE(fs->super) >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) in ext2fs_block_bitmap_csum_set()
630 static errcode_t ext2fs_inode_csum(ext2_filsys fs, ext2_ino_t inum, in ext2fs_inode_csum() argument
636 size_t size = EXT2_INODE_SIZE(fs->super); in ext2fs_inode_csum()
649 *crc = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&inum, in ext2fs_inode_csum()
660 int ext2fs_inode_csum_verify(ext2_filsys fs, ext2_ino_t inum, in ext2fs_inode_csum_verify() argument
668 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_inode_csum_verify()
671 has_hi = (EXT2_INODE_SIZE(fs->super) > EXT2_GOOD_OLD_INODE_SIZE && in ext2fs_inode_csum_verify()
675 retval = ext2fs_inode_csum(fs, inum, inode, &calculated, has_hi); in ext2fs_inode_csum_verify()
703 errcode_t ext2fs_inode_csum_set(ext2_filsys fs, ext2_ino_t inum, in ext2fs_inode_csum_set() argument
710 if (!ext2fs_has_feature_metadata_csum(fs->super)) in ext2fs_inode_csum_set()
713 has_hi = (EXT2_INODE_SIZE(fs->super) > EXT2_GOOD_OLD_INODE_SIZE && in ext2fs_inode_csum_set()
716 retval = ext2fs_inode_csum(fs, inum, inode, &crc, has_hi); in ext2fs_inode_csum_set()
725 __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) in ext2fs_group_desc_csum() argument
727 struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc, in ext2fs_group_desc_csum()
729 size_t offset, size = EXT2_DESC_SIZE(fs->super); in ext2fs_group_desc_csum()
741 ext2fs_swap_group_desc2(fs, (struct ext2_group_desc *) &swabdesc); in ext2fs_group_desc_csum()
746 if (ext2fs_has_feature_metadata_csum(fs->super)) { in ext2fs_group_desc_csum()
753 crc32 = ext2fs_crc32c_le(fs->csum_seed, (unsigned char *)&group, in ext2fs_group_desc_csum()
770 crc = ext2fs_crc16(~0, fs->super->s_uuid, in ext2fs_group_desc_csum()
771 sizeof(fs->super->s_uuid)); in ext2fs_group_desc_csum()
795 int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group) in ext2fs_group_desc_csum_verify() argument
797 if (ext2fs_has_group_desc_csum(fs) && in ext2fs_group_desc_csum_verify()
798 (ext2fs_bg_checksum(fs, group) != in ext2fs_group_desc_csum_verify()
799 ext2fs_group_desc_csum(fs, group))) in ext2fs_group_desc_csum_verify()
805 void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group) in ext2fs_group_desc_csum_set() argument
807 if (!ext2fs_has_group_desc_csum(fs)) in ext2fs_group_desc_csum_set()
812 ext2fs_bg_checksum_set(fs, group, ext2fs_group_desc_csum(fs, group)); in ext2fs_group_desc_csum_set()
832 errcode_t ext2fs_set_gdt_csum(ext2_filsys fs) in ext2fs_set_gdt_csum() argument
834 struct ext2_super_block *sb = fs->super; in ext2fs_set_gdt_csum()
838 if (!fs->inode_map) in ext2fs_set_gdt_csum()
841 if (!ext2fs_has_group_desc_csum(fs)) in ext2fs_set_gdt_csum()
844 for (i = 0; i < fs->group_desc_count; i++) { in ext2fs_set_gdt_csum()
845 __u32 old_csum = ext2fs_bg_checksum(fs, i); in ext2fs_set_gdt_csum()
846 __u32 old_unused = ext2fs_bg_itable_unused(fs, i); in ext2fs_set_gdt_csum()
847 __u32 old_flags = ext2fs_bg_flags(fs, i); in ext2fs_set_gdt_csum()
848 __u32 old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i); in ext2fs_set_gdt_csum()
849 __u32 old_free_blocks_count = ext2fs_bg_free_blocks_count(fs, i); in ext2fs_set_gdt_csum()
852 i != fs->group_desc_count - 1) in ext2fs_set_gdt_csum()
853 ext2fs_bg_flags_set(fs, i, EXT2_BG_BLOCK_UNINIT); in ext2fs_set_gdt_csum()
856 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); in ext2fs_set_gdt_csum()
857 ext2fs_bg_itable_unused_set(fs, i, sb->s_inodes_per_group); in ext2fs_set_gdt_csum()
861 find_last_inode_ingrp(fs->inode_map, in ext2fs_set_gdt_csum()
864 ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT); in ext2fs_set_gdt_csum()
865 ext2fs_bg_itable_unused_set(fs, i, unused); in ext2fs_set_gdt_csum()
868 ext2fs_group_desc_csum_set(fs, i); in ext2fs_set_gdt_csum()
869 if (old_flags != ext2fs_bg_flags(fs, i)) in ext2fs_set_gdt_csum()
871 if (old_unused != ext2fs_bg_itable_unused(fs, i)) in ext2fs_set_gdt_csum()
873 if (old_csum != ext2fs_bg_checksum(fs, i)) in ext2fs_set_gdt_csum()
877 ext2fs_mark_super_dirty(fs); in ext2fs_set_gdt_csum()
884 void print_csum(const char *msg, ext2_filsys fs, dgrp_t group) in print_csum() argument
888 struct ext2_group_desc *desc = ext2fs_group_desc(fs, fs->group_desc, in print_csum()
890 size_t size = EXT2_DESC_SIZE(fs->super); in print_csum()
891 struct ext2_super_block *sb = fs->super; in print_csum()
905 ext2fs_swap_group_desc2(fs, (struct ext2_group_desc *) &swabdesc); in print_csum()
913 crc1 = ext2fs_crc16(~0, sb->s_uuid, sizeof(fs->super->s_uuid)); in print_csum()
928 ext2fs_group_desc_csum(fs, group)); in print_csum()
938 ext2_filsys fs; in main() local
951 test_io_manager, &fs); in main()
957 memcpy(fs->super->s_uuid, sb_uuid, 16); in main()
958 fs->super->s_feature_ro_compat = EXT4_FEATURE_RO_COMPAT_GDT_CSUM; in main()
960 for (i=0; i < fs->group_desc_count; i++) { in main()
961 ext2fs_block_bitmap_loc_set(fs, i, 124); in main()
962 ext2fs_inode_bitmap_loc_set(fs, i, 125); in main()
963 ext2fs_inode_table_loc_set(fs, i, 126); in main()
964 ext2fs_bg_free_blocks_count_set(fs, i, 31119); in main()
965 ext2fs_bg_free_inodes_count_set(fs, i, 15701); in main()
966 ext2fs_bg_used_dirs_count_set(fs, i, 2); in main()
967 ext2fs_bg_flags_zap(fs, i); in main()
970 csum1 = ext2fs_group_desc_csum(fs, 0); in main()
971 print_csum("csum0000", fs, 0); in main()
977 csum2 = ext2fs_group_desc_csum(fs, 1); in main()
978 print_csum("csum0001", fs, 1); in main()
983 csum2 = ext2fs_group_desc_csum(fs, 2); in main()
984 print_csum("csumffff", fs, 2); in main()
989 ext2fs_bg_checksum_set(fs, 0, csum1); in main()
990 csum2 = ext2fs_group_desc_csum(fs, 0); in main()
991 print_csum("csum_set", fs, 0); in main()
996 if (!ext2fs_group_desc_csum_verify(fs, 0)) { in main()
1000 memset(fs->super->s_uuid, 0x30, sizeof(fs->super->s_uuid)); in main()
1001 print_csum("new_uuid", fs, 0); in main()
1002 if (ext2fs_group_desc_csum_verify(fs, 0) != 0) { in main()
1006 csum1 = ext2fs_group_desc_csum(fs, 0); in main()
1007 ext2fs_bg_checksum_set(fs, 0, csum1); in main()
1008 print_csum("csum_new", fs, 0); in main()
1009 ext2fs_bg_free_blocks_count_set(fs, 0, 1); in main()
1010 csum2 = ext2fs_group_desc_csum(fs, 0); in main()
1011 print_csum("csum_blk", fs, 0); in main()
1016 ext2fs_free(fs); in main()