~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/ext4/bitmap.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 unsigned int ext4_count_free(char *bitmap, unsigned int numchars)
 15 {
 16         return numchars * BITS_PER_BYTE - memweight(bitmap, numchars);
 17 }
 18 
 19 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         __u32 hi;
 24         __u32 provided, calculated;
 25         struct ext4_sb_info *sbi = EXT4_SB(sb);
 26 
 27         if (!ext4_has_metadata_csum(sb))
 28                 return 1;
 29 
 30         provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
 31         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
 32         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END) {
 33                 hi = le16_to_cpu(gdp->bg_inode_bitmap_csum_hi);
 34                 provided |= (hi << 16);
 35         } else
 36                 calculated &= 0xFFFF;
 37 
 38         return provided == calculated;
 39 }
 40 
 41 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         __u32 csum;
 46         struct ext4_sb_info *sbi = EXT4_SB(sb);
 47 
 48         if (!ext4_has_metadata_csum(sb))
 49                 return;
 50 
 51         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
 52         gdp->bg_inode_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
 53         if (sbi->s_desc_size >= EXT4_BG_INODE_BITMAP_CSUM_HI_END)
 54                 gdp->bg_inode_bitmap_csum_hi = cpu_to_le16(csum >> 16);
 55 }
 56 
 57 int ext4_block_bitmap_csum_verify(struct super_block *sb,
 58                                   struct ext4_group_desc *gdp,
 59                                   struct buffer_head *bh)
 60 {
 61         __u32 hi;
 62         __u32 provided, calculated;
 63         struct ext4_sb_info *sbi = EXT4_SB(sb);
 64         int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
 65 
 66         if (!ext4_has_metadata_csum(sb))
 67                 return 1;
 68 
 69         provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
 70         calculated = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
 71         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END) {
 72                 hi = le16_to_cpu(gdp->bg_block_bitmap_csum_hi);
 73                 provided |= (hi << 16);
 74         } else
 75                 calculated &= 0xFFFF;
 76 
 77         return provided == calculated;
 78 }
 79 
 80 void ext4_block_bitmap_csum_set(struct super_block *sb,
 81                                 struct ext4_group_desc *gdp,
 82                                 struct buffer_head *bh)
 83 {
 84         int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
 85         __u32 csum;
 86         struct ext4_sb_info *sbi = EXT4_SB(sb);
 87 
 88         if (!ext4_has_metadata_csum(sb))
 89                 return;
 90 
 91         csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
 92         gdp->bg_block_bitmap_csum_lo = cpu_to_le16(csum & 0xFFFF);
 93         if (sbi->s_desc_size >= EXT4_BG_BLOCK_BITMAP_CSUM_HI_END)
 94                 gdp->bg_block_bitmap_csum_hi = cpu_to_le16(csum >> 16);
 95 }
 96 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php