LDD3学习笔记(14):内核中的数据类型

来源:互联网 发布:ubuntu install ssh 编辑:程序博客网 时间:2024/06/14 23:00
 #include <linux/types.h>

typedef u8;

typedef u16;

typedef u32;

typedef u64;

保证是 8-, 16-, 32-位 和64-位 无符号整型值的类型对等的有符号类型也存在在用户空

你可用 __u8, __u16, 等等来引用这些类型.

#include <asm/page.h>

PAGE_SIZE

PAGE_SHIFT

给当前体系定义每页的字节数以及页偏移的位数对于 4 KB 页是 12, 8 KB 是 13 )的符号.

#include <asm/byteorder.h>

__LITTLE_ENDIAN

__BIG_ENDIAN 

这 个符号只有一个定义依赖体系.

#include <asm/byteorder.h>

u32 __cpu_to_le32 (u32);

u32 __le32_to_cpu (u32);

在已知字节序和处理器字节序之间转换的函数有超过 60 个这样的函数在 include/linux/

byteorder/ 中的各种文件有完整的列表和它们以何种方式定义.

#include <asm/unaligned.h>

get_unaligned(ptr);

put_unaligned(val, ptr);

一些体系需要使用这些宏保护不对齐的数据存取这些宏定义扩展成通常的指针解引用

那些允许你存取不对齐数据的体系.

#include <linux/err.h>

void *ERR_PTR(long error);

long PTR_ERR(const void *ptr);

long IS_ERR(const void *ptr);

允许错误码由返回指针值的函数返回.

#include <linux/list.h>

list_add(struct list_head *new, struct list_head *head);

list_add_tail(struct list_head *new, struct list_head *head);

list_del(struct list_head *entry);

list_del_init(struct list_head *entry);

list_empty(struct list_head *head);

list_entry(entry, type, member);

list_move(struct list_head *entry, struct list_head *head);

list_move_tail(struct list_head *entry, struct list_head *head);

list_splice(struct list_head *list, struct list_head *head);

操作环形双向链表的函数.

list_for_each(struct list_head *cursor, struct list_head *list)

list_for_each_prev(struct list_head *cursor, struct list_head *list)

list_for_each_safe(struct list_head *cursor, struct list_head *next, struct list_head *list)

list_for_each_entry(type *cursor, struct list_head *list, member)

list_for_each_entry_safe(type *cursor, type *next struct list_head *list, member)

方便的宏定义用在遍历链表上.

原创粉丝点击