LDD3读书笔记(第10章 内核数据类型)

  • Post author:
  • Post category:其他
#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
    定义了当前体系结构的每页字节数和页偏移位数(4KB页为12,8KB页为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_emtry(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);
    遍历链表的便利宏。

版权声明:本文为hot_zcy2012原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。