使用宏DECLARE_BITMAP来声明位图,该宏定义如下: // file: include/linux/types.h#define DECLARE_BITMAP(name,bits) \unsignedlongname[BITS_TO_LONGS(bits)] 该宏接收 2 个参数: name- 位图名称 bits- 位图中比特位的数量 由于我们使用unsigned long数组来表示位图,所以需要将比特位数量转换成数组的元素数量。
unsignedlongmy_bitmap[8] 第二种方法,是使用DECLARE_BITMAP宏,它定义于include/linux/types.h头文件: #defineDECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] 我们可以看到DECLARE_BITMAP宏使用两个参数: name- 位图名称; bits- 位图中位数; 并且只是使用BITS_TO_LONGS(bits)元素展开...
unsigned long my_bitmap[8] 第二种方式,采用DECLARE_BITMAP宏,此宏位于头文件include/linux/types.h中: #define DECLARE_BITMAP(name,bits) unsigned long name[BITS_TO_LONGS(bits)] DECLARE_BITMAP宏有两个参数: name – 位图名字; bits – 位图中比特总数目 并且扩展元素大小为BITS_TO_LONGS(bits)、类...
declare_bitmap(bitmap_name, bits_count); 其中bitmap_name是指定位图的名称,bits_count是指定位图中位的数量。通过这种方式,可以在程序中方便地创建和管理位图。 在实际应用中,declare_bitmap可以用于各种用途,如管理文件系统中的空闲块、管理进程的状态等。通过声明一个declare_bitmap变量,可以在程序中操作位图,...
内核定义了一系列的宏和函数来对DECLARE_BITMAP定义的位图进行操作,它们分别位于bitmap.h和bitmap.c中。这些宏和函数的操作思想是一致的。 1 /arch/arm/include/asm/types.h2#define BITS_PER_LONG 3234 include/linux/bitmap.h5static inlinevoid bitmap_zero(unsignedlong *dst,intnbits)6{7if (nbits <=BI...
DECLARE_BITMAP宏有两个参数: name – 位图名字; bits – 位图中比特总数目 并且扩展元素大小为BITS_TO_LONGS(bits)、类型unsigned long的数组,而BITS_TO_LONGS宏将位转换为long类型,或者说计算出bits中包含多少byte元素: #define BITS_PER_BYTE 8
因此,例如 DECLARE_BITMAP(my_bitmap, 64) 将产生: >>> (((64) + (64) - 1) / (64)) 1 与: unsigned long my_bitmap[1]; 在能够声明一个位数组之后,我们便可以使用它了。 体系结构特定的位操作 我们已经看了上面提及的一对源文件和头文件,它们提供了位数组操作的 API。其中重要且广泛使用的位...
typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; extern nodemask_t node_states[NR_NODE_STATES]; 节点的状态可通过以下掩码表示: enum node_states { N_POSSIBLE, /* The node could become online at some point */ N_ONLINE, /* The node is online */ N_NORMAL_MEMORY, /...
/** * DOC: declare bitmap * The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used * to declare an array named 'name' of just enough unsigned longs to * contain all bit positions from 0 to 'bits' - 1. *//* * Allocation and deallocation of bitmap....
/** * DOC: declare bitmap * The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used * to declare an array named 'name' of just enough unsigned longs to * contain all bit positions from 0 to 'bits' - 1. *//* * Allocation and deallocation of bitmap....