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

TOMOYO Linux Cross Reference
Linux/fs/bcachefs/checksum.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/bcachefs/checksum.h (Version linux-6.12-rc7) and /fs/bcachefs/checksum.h (Version linux-2.6.32.71)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 
  2 #ifndef _BCACHEFS_CHECKSUM_H                      
  3 #define _BCACHEFS_CHECKSUM_H                      
  4                                                   
  5 #include "bcachefs.h"                             
  6 #include "extents_types.h"                        
  7 #include "super-io.h"                             
  8                                                   
  9 #include <linux/crc64.h>                          
 10 #include <crypto/chacha.h>                        
 11                                                   
 12 static inline bool bch2_checksum_mergeable(uns    
 13 {                                                 
 14                                                   
 15         switch (type) {                           
 16         case BCH_CSUM_none:                       
 17         case BCH_CSUM_crc32c:                     
 18         case BCH_CSUM_crc64:                      
 19                 return true;                      
 20         default:                                  
 21                 return false;                     
 22         }                                         
 23 }                                                 
 24                                                   
 25 struct bch_csum bch2_checksum_merge(unsigned,     
 26                                     struct bch    
 27                                                   
 28 #define BCH_NONCE_EXTENT        cpu_to_le32(1     
 29 #define BCH_NONCE_BTREE         cpu_to_le32(2     
 30 #define BCH_NONCE_JOURNAL       cpu_to_le32(3     
 31 #define BCH_NONCE_PRIO          cpu_to_le32(4     
 32 #define BCH_NONCE_POLY          cpu_to_le32(1     
 33                                                   
 34 struct bch_csum bch2_checksum(struct bch_fs *,    
 35                              const void *, siz    
 36                                                   
 37 /*                                                
 38  * This is used for various on disk data struc    
 39  * jset: The checksum is _always_ the first fi    
 40  */                                               
 41 #define csum_vstruct(_c, _type, _nonce, _i)       
 42 ({                                                
 43         const void *_start = ((const void *) (    
 44                                                   
 45         bch2_checksum(_c, _type, _nonce, _star    
 46 })                                                
 47                                                   
 48 static inline void bch2_csum_to_text(struct pr    
 49                                      enum bch_    
 50                                      struct bc    
 51 {                                                 
 52         const u8 *p = (u8 *) &csum;               
 53         unsigned bytes = type < BCH_CSUM_NR ?     
 54                                                   
 55         for (unsigned i = 0; i < bytes; i++)      
 56                 prt_hex_byte(out, p[i]);          
 57 }                                                 
 58                                                   
 59 static inline void bch2_csum_err_msg(struct pr    
 60                                      enum bch_    
 61                                      struct bc    
 62                                      struct bc    
 63 {                                                 
 64         prt_str(out, "checksum error, type ");    
 65         bch2_prt_csum_type(out, type);            
 66         prt_str(out, ": got ");                   
 67         bch2_csum_to_text(out, type, got);        
 68         prt_str(out, " should be ");              
 69         bch2_csum_to_text(out, type, expected)    
 70 }                                                 
 71                                                   
 72 int bch2_chacha_encrypt_key(struct bch_key *,     
 73 int bch2_request_key(struct bch_sb *, struct b    
 74 #ifndef __KERNEL__                                
 75 int bch2_revoke_key(struct bch_sb *);             
 76 #endif                                            
 77                                                   
 78 int bch2_encrypt(struct bch_fs *, unsigned, st    
 79                  void *data, size_t);             
 80                                                   
 81 struct bch_csum bch2_checksum_bio(struct bch_f    
 82                                   struct nonce    
 83                                                   
 84 int bch2_rechecksum_bio(struct bch_fs *, struc    
 85                         struct bch_extent_crc_    
 86                         struct bch_extent_crc_    
 87                         struct bch_extent_crc_    
 88                         unsigned, unsigned, un    
 89                                                   
 90 int __bch2_encrypt_bio(struct bch_fs *, unsign    
 91                        struct nonce, struct bi    
 92                                                   
 93 static inline int bch2_encrypt_bio(struct bch_    
 94                                    struct nonc    
 95 {                                                 
 96         return bch2_csum_type_is_encryption(ty    
 97                 ? __bch2_encrypt_bio(c, type,     
 98                 : 0;                              
 99 }                                                 
100                                                   
101 extern const struct bch_sb_field_ops bch_sb_fi    
102                                                   
103 int bch2_decrypt_sb_key(struct bch_fs *, struc    
104                         struct bch_key *);        
105                                                   
106 int bch2_disable_encryption(struct bch_fs *);     
107 int bch2_enable_encryption(struct bch_fs *, bo    
108                                                   
109 void bch2_fs_encryption_exit(struct bch_fs *);    
110 int bch2_fs_encryption_init(struct bch_fs *);     
111                                                   
112 static inline enum bch_csum_type bch2_csum_opt    
113                                                   
114 {                                                 
115         switch (type) {                           
116         case BCH_CSUM_OPT_none:                   
117                 return BCH_CSUM_none;             
118         case BCH_CSUM_OPT_crc32c:                 
119                 return data ? BCH_CSUM_crc32c     
120         case BCH_CSUM_OPT_crc64:                  
121                 return data ? BCH_CSUM_crc64 :    
122         case BCH_CSUM_OPT_xxhash:                 
123                 return BCH_CSUM_xxhash;           
124         default:                                  
125                 BUG();                            
126         }                                         
127 }                                                 
128                                                   
129 static inline enum bch_csum_type bch2_data_che    
130                                                   
131 {                                                 
132         if (opts.nocow)                           
133                 return 0;                         
134                                                   
135         if (c->sb.encryption_type)                
136                 return c->opts.wide_macs          
137                         ? BCH_CSUM_chacha20_po    
138                         : BCH_CSUM_chacha20_po    
139                                                   
140         return bch2_csum_opt_to_type(opts.data    
141 }                                                 
142                                                   
143 static inline enum bch_csum_type bch2_meta_che    
144 {                                                 
145         if (c->sb.encryption_type)                
146                 return BCH_CSUM_chacha20_poly1    
147                                                   
148         return bch2_csum_opt_to_type(c->opts.m    
149 }                                                 
150                                                   
151 static inline bool bch2_checksum_type_valid(co    
152                                            uns    
153 {                                                 
154         if (type >= BCH_CSUM_NR)                  
155                 return false;                     
156                                                   
157         if (bch2_csum_type_is_encryption(type)    
158                 return false;                     
159                                                   
160         return true;                              
161 }                                                 
162                                                   
163 /* returns true if not equal */                   
164 static inline bool bch2_crc_cmp(struct bch_csu    
165 {                                                 
166         /*                                        
167          * XXX: need some way of preventing th    
168          * into a form that isn't constant tim    
169          */                                       
170         return ((l.lo ^ r.lo) | (l.hi ^ r.hi))    
171 }                                                 
172                                                   
173 /* for skipping ahead and encrypting/decryptin    
174 static inline struct nonce nonce_add(struct no    
175 {                                                 
176         EBUG_ON(offset & (CHACHA_BLOCK_SIZE -     
177                                                   
178         le32_add_cpu(&nonce.d[0], offset / CHA    
179         return nonce;                             
180 }                                                 
181                                                   
182 static inline struct nonce null_nonce(void)       
183 {                                                 
184         struct nonce ret;                         
185                                                   
186         memset(&ret, 0, sizeof(ret));             
187         return ret;                               
188 }                                                 
189                                                   
190 static inline struct nonce extent_nonce(struct    
191                                         struct    
192 {                                                 
193         unsigned compression_type = crc_is_com    
194                 ? crc.compression_type            
195                 : 0;                              
196         unsigned size = compression_type ? crc    
197         struct nonce nonce = (struct nonce) {{    
198                 [0] = cpu_to_le32(size << 22),    
199                 [1] = cpu_to_le32(version.lo),    
200                 [2] = cpu_to_le32(version.lo >    
201                 [3] = cpu_to_le32(version.hi|     
202                                   (compression    
203         }};                                       
204                                                   
205         return nonce_add(nonce, crc.nonce << 9    
206 }                                                 
207                                                   
208 static inline bool bch2_key_is_encrypted(struc    
209 {                                                 
210         return le64_to_cpu(key->magic) != BCH_    
211 }                                                 
212                                                   
213 static inline struct nonce __bch2_sb_key_nonce    
214 {                                                 
215         __le64 magic = __bch2_sb_magic(sb);       
216                                                   
217         return (struct nonce) {{                  
218                 [0] = 0,                          
219                 [1] = 0,                          
220                 [2] = ((__le32 *) &magic)[0],     
221                 [3] = ((__le32 *) &magic)[1],     
222         }};                                       
223 }                                                 
224                                                   
225 static inline struct nonce bch2_sb_key_nonce(s    
226 {                                                 
227         __le64 magic = bch2_sb_magic(c);          
228                                                   
229         return (struct nonce) {{                  
230                 [0] = 0,                          
231                 [1] = 0,                          
232                 [2] = ((__le32 *) &magic)[0],     
233                 [3] = ((__le32 *) &magic)[1],     
234         }};                                       
235 }                                                 
236                                                   
237 #endif /* _BCACHEFS_CHECKSUM_H */                 
238                                                   

~ [ 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