LCOV - code coverage report
Current view: top level - fs/ext4 - bitmap.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsx @ Mon Jul 31 20:08:34 PDT 2023 Lines: 42 44 95.5 %
Date: 2023-07-31 20:08:34 Functions: 4 5 80.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  *  linux/fs/ext4/bitmap.c
       4             :  *
       5             :  * Copyright (C) 1992, 1993, 1994, 1995
       6             :  * Remy Card (card@masi.ibp.fr)
       7             :  * Laboratoire MASI - Institut Blaise Pascal
       8             :  * Universite Pierre et Marie Curie (Paris VI)
       9             :  */
      10             : 
      11             : #include <linux/buffer_head.h>
      12             : #include "ext4.h"
      13             : 
      14           0 : unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
      15             : {
      16           0 :         return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
      17             : }
      18             : 
      19        1181 : int ext4_inode_bitmap_csum_verify(struct super_block *sb,
      20             :                                   struct ext4_group_desc *gdp,
      21             :                                   struct buffer_head *bh, int sz)
      22             : {
      23        1181 :         __u32 hi;
      24        1181 :         __u32 provided, calculated;
      25        1181 :         struct ext4_sb_info *sbi = EXT4_SB(sb);
      26             : 
      27        1181 :         if (!ext4_has_metadata_csum(sb))
      28             :                 return 1;
      29             : 
      30        1176 :         provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
      31        1176 :         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
      32        1176 :         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
      33        1175 :                 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
      34        1175 :                 provided |= (hi << 16);
      35             :         } else
      36           1 :                 calculated &= 0xFFFF;
      37             : 
      38        1176 :         return provided == calculated;
      39             : }
      40             : 
      41     4833859 : void ext4_inode_bitmap_csum_set(struct super_block *sb,
      42             :                                 struct ext4_group_desc *gdp,
      43             :                                 struct buffer_head *bh, int sz)
      44             : {
      45     4833859 :         __u32 csum;
      46     4833859 :         struct ext4_sb_info *sbi = EXT4_SB(sb);
      47             : 
      48     4833859 :         if (!ext4_has_metadata_csum(sb))
      49             :                 return;
      50             : 
      51     4822799 :         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
      52     4842179 :         gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
      53     4842179 :         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
      54     4842585 :                 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
      55             : }
      56             : 
      57       70471 : int ext4_block_bitmap_csum_verify(struct super_block *sb,
      58             :                                   struct ext4_group_desc *gdp,
      59             :                                   struct buffer_head *bh)
      60             : {
      61       70471 :         __u32 hi;
      62       70471 :         __u32 provided, calculated;
      63       70471 :         struct ext4_sb_info *sbi = EXT4_SB(sb);
      64       70471 :         int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
      65             : 
      66       70471 :         if (!ext4_has_metadata_csum(sb))
      67             :                 return 1;
      68             : 
      69       70081 :         provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
      70       70081 :         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
      71       70081 :         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
      72       70077 :                 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
      73       70077 :                 provided |= (hi << 16);
      74             :         } else
      75           4 :                 calculated &= 0xFFFF;
      76             : 
      77       70081 :         return provided == calculated;
      78             : }
      79             : 
      80     6251313 : void ext4_block_bitmap_csum_set(struct super_block *sb,
      81             :                                 struct ext4_group_desc *gdp,
      82             :                                 struct buffer_head *bh)
      83             : {
      84     6251313 :         int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
      85     6251313 :         __u32 csum;
      86     6251313 :         struct ext4_sb_info *sbi = EXT4_SB(sb);
      87             : 
      88     6251313 :         if (!ext4_has_metadata_csum(sb))
      89             :                 return;
      90             : 
      91     6246652 :         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
      92     6246631 :         gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
      93     6246631 :         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
      94     6245850 :                 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);
      95             : }

Generated by: LCOV version 1.14