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

TOMOYO Linux Cross Reference
Linux/fs/ntfs3/bitfunc.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 ] ~

Diff markup

Differences between /fs/ntfs3/bitfunc.c (Version linux-6.11.5) and /fs/ntfs3/bitfunc.c (Version linux-6.6.58)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  *                                                  3  *
  4  * Copyright (C) 2019-2021 Paragon Software Gm      4  * Copyright (C) 2019-2021 Paragon Software GmbH, All rights reserved.
  5  *                                                  5  *
  6  */                                                 6  */
  7                                                     7 
  8 #include <linux/types.h>                            8 #include <linux/types.h>
  9                                                     9 
 10 #include "ntfs_fs.h"                               10 #include "ntfs_fs.h"
 11                                                    11 
 12 #define BITS_IN_SIZE_T (sizeof(size_t) * 8)        12 #define BITS_IN_SIZE_T (sizeof(size_t) * 8)
 13                                                    13 
 14 /*                                                 14 /*
 15  * fill_mask[i] - first i bits are '1' , i = 0     15  * fill_mask[i] - first i bits are '1' , i = 0,1,2,3,4,5,6,7,8
 16  * fill_mask[i] = 0xFF >> (8-i)                    16  * fill_mask[i] = 0xFF >> (8-i)
 17  */                                                17  */
 18 static const u8 fill_mask[] = { 0x00, 0x01, 0x     18 static const u8 fill_mask[] = { 0x00, 0x01, 0x03, 0x07, 0x0F,
 19                                 0x1F, 0x3F, 0x     19                                 0x1F, 0x3F, 0x7F, 0xFF };
 20                                                    20 
 21 /*                                                 21 /*
 22  * zero_mask[i] - first i bits are '' , i = 0,     22  * zero_mask[i] - first i bits are '' , i = 0,1,2,3,4,5,6,7,8
 23  * zero_mask[i] = 0xFF << i                        23  * zero_mask[i] = 0xFF << i
 24  */                                                24  */
 25 static const u8 zero_mask[] = { 0xFF, 0xFE, 0x     25 static const u8 zero_mask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0,
 26                                 0xE0, 0xC0, 0x     26                                 0xE0, 0xC0, 0x80, 0x00 };
 27                                                    27 
 28 /*                                                 28 /*
 29  * are_bits_clear                                  29  * are_bits_clear
 30  *                                                 30  *
 31  * Return: True if all bits [bit, bit+nbits) a     31  * Return: True if all bits [bit, bit+nbits) are zeros "".
 32  */                                                32  */
 33 bool are_bits_clear(const void *lmap, size_t b     33 bool are_bits_clear(const void *lmap, size_t bit, size_t nbits)
 34 {                                                  34 {
 35         size_t pos = bit & 7;                      35         size_t pos = bit & 7;
 36         const u8 *map = (u8 *)lmap + (bit >> 3     36         const u8 *map = (u8 *)lmap + (bit >> 3);
 37                                                    37 
 38         if (pos) {                                 38         if (pos) {
 39                 if (8 - pos >= nbits)              39                 if (8 - pos >= nbits)
 40                         return !nbits || !(*ma     40                         return !nbits || !(*map & fill_mask[pos + nbits] &
 41                                            zer     41                                            zero_mask[pos]);
 42                                                    42 
 43                 if (*map++ & zero_mask[pos])       43                 if (*map++ & zero_mask[pos])
 44                         return false;              44                         return false;
 45                 nbits -= 8 - pos;                  45                 nbits -= 8 - pos;
 46         }                                          46         }
 47                                                    47 
 48         pos = ((size_t)map) & (sizeof(size_t)      48         pos = ((size_t)map) & (sizeof(size_t) - 1);
 49         if (pos) {                                 49         if (pos) {
 50                 pos = sizeof(size_t) - pos;        50                 pos = sizeof(size_t) - pos;
 51                 if (nbits >= pos * 8) {            51                 if (nbits >= pos * 8) {
 52                         for (nbits -= pos * 8;     52                         for (nbits -= pos * 8; pos; pos--, map++) {
 53                                 if (*map)          53                                 if (*map)
 54                                         return     54                                         return false;
 55                         }                          55                         }
 56                 }                                  56                 }
 57         }                                          57         }
 58                                                    58 
 59         for (pos = nbits / BITS_IN_SIZE_T; pos     59         for (pos = nbits / BITS_IN_SIZE_T; pos; pos--, map += sizeof(size_t)) {
 60                 if (*((size_t *)map))              60                 if (*((size_t *)map))
 61                         return false;              61                         return false;
 62         }                                          62         }
 63                                                    63 
 64         for (pos = (nbits % BITS_IN_SIZE_T) >>     64         for (pos = (nbits % BITS_IN_SIZE_T) >> 3; pos; pos--, map++) {
 65                 if (*map)                          65                 if (*map)
 66                         return false;              66                         return false;
 67         }                                          67         }
 68                                                    68 
 69         pos = nbits & 7;                           69         pos = nbits & 7;
 70         if (pos && (*map & fill_mask[pos]))        70         if (pos && (*map & fill_mask[pos]))
 71                 return false;                      71                 return false;
 72                                                    72 
 73         return true;                               73         return true;
 74 }                                                  74 }
 75                                                    75 
 76 /*                                                 76 /*
 77  * are_bits_set                                    77  * are_bits_set
 78  *                                                 78  *
 79  * Return: True if all bits [bit, bit+nbits) a     79  * Return: True if all bits [bit, bit+nbits) are ones "1".
 80  */                                                80  */
 81 bool are_bits_set(const void *lmap, size_t bit     81 bool are_bits_set(const void *lmap, size_t bit, size_t nbits)
 82 {                                                  82 {
 83         u8 mask;                                   83         u8 mask;
 84         size_t pos = bit & 7;                      84         size_t pos = bit & 7;
 85         const u8 *map = (u8 *)lmap + (bit >> 3     85         const u8 *map = (u8 *)lmap + (bit >> 3);
 86                                                    86 
 87         if (pos) {                                 87         if (pos) {
 88                 if (8 - pos >= nbits) {            88                 if (8 - pos >= nbits) {
 89                         mask = fill_mask[pos +     89                         mask = fill_mask[pos + nbits] & zero_mask[pos];
 90                         return !nbits || (*map     90                         return !nbits || (*map & mask) == mask;
 91                 }                                  91                 }
 92                                                    92 
 93                 mask = zero_mask[pos];             93                 mask = zero_mask[pos];
 94                 if ((*map++ & mask) != mask)       94                 if ((*map++ & mask) != mask)
 95                         return false;              95                         return false;
 96                 nbits -= 8 - pos;                  96                 nbits -= 8 - pos;
 97         }                                          97         }
 98                                                    98 
 99         pos = ((size_t)map) & (sizeof(size_t)      99         pos = ((size_t)map) & (sizeof(size_t) - 1);
100         if (pos) {                                100         if (pos) {
101                 pos = sizeof(size_t) - pos;       101                 pos = sizeof(size_t) - pos;
102                 if (nbits >= pos * 8) {           102                 if (nbits >= pos * 8) {
103                         for (nbits -= pos * 8;    103                         for (nbits -= pos * 8; pos; pos--, map++) {
104                                 if (*map != 0x    104                                 if (*map != 0xFF)
105                                         return    105                                         return false;
106                         }                         106                         }
107                 }                                 107                 }
108         }                                         108         }
109                                                   109 
110         for (pos = nbits / BITS_IN_SIZE_T; pos    110         for (pos = nbits / BITS_IN_SIZE_T; pos; pos--, map += sizeof(size_t)) {
111                 if (*((size_t *)map) != MINUS_    111                 if (*((size_t *)map) != MINUS_ONE_T)
112                         return false;             112                         return false;
113         }                                         113         }
114                                                   114 
115         for (pos = (nbits % BITS_IN_SIZE_T) >>    115         for (pos = (nbits % BITS_IN_SIZE_T) >> 3; pos; pos--, map++) {
116                 if (*map != 0xFF)                 116                 if (*map != 0xFF)
117                         return false;             117                         return false;
118         }                                         118         }
119                                                   119 
120         pos = nbits & 7;                          120         pos = nbits & 7;
121         if (pos) {                                121         if (pos) {
122                 mask = fill_mask[pos];            122                 mask = fill_mask[pos];
123                 if ((*map & mask) != mask)        123                 if ((*map & mask) != mask)
124                         return false;             124                         return false;
125         }                                         125         }
126                                                   126 
127         return true;                              127         return true;
128 }                                                 128 }
129                                                   129 

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