linux内核数据结构体,Linux内核数据结构体

struct file

{

union

{

struct list_head fu_list ;

struct rcu_head fu_rcuhead ;

}f_u ;

struct dentry *f_dentry ; /*与文件关联的目录入口(dentry)结构*/

struct vfsmount *f_vfsmnt ;

struct file_operations *f_op ;  /*和文件关联的操作*/

atomic_t f_count ;

unsigned int f_flags ; /*文件标志,如O_RDONLY,O_NONBLOCK,O_SYNC*/

mode_t f_mode ;  /*文件读/写模式,FMODE_READ和FMODE_WRITE*/

loff_t f_pos ;   /*当前读写位置*/

struct fown_struct f_owner ;

unsigned int f_uid,f_gid ;

struct file_ra_state f_ra ;

unsigned long f_version ;

void *f_security ;

/* tty 驱动需要,其他的驱动可能需要*/

void *private_data ;  /*文件私有数据*/

#ifdef CONFIG_EPOLL

/*被fs/eventpoll.c使用以便连接所有这个文件的钩子(hooks)*/

struct list_head f_ep_links ;

spinlock_t f_ep_lock ;

#endif

struct address_space *f_mapping ;

};

======================================================================

inode结构体

struct inode

{

...

umode_t i_mode ;/*inode的权限*/

uid_t i_uid ;   /*inode拥有者的id*/

gid_t i_gid ;   /*inode所属的群组id*/

dev_t i_rdev ;  /*如是设备文件,此字段将记录设备的设备号*/

loff_t i_size ; /*inode所代表的文件大小*/

struct timespec i_atime ;  /*inode最近一次的存取时间*/

struct timespec i_mtime ;  /*inode最近一次的修改时间*/

struct timespec i_ctime ;  /*inode的产生时间*/

unsigned long i_blksize ;  /*inode 在做I/O时的区块大小 */

unsigned long i_blocks ;   /*inode所使用的block数,一个block为512 byte */

struct block_device *i_bdev ;

/*若是块设备,为其对应的block_device结构体指针*/

struct cdev *i_cdev ;

/*若是字符设备,为其对应的cdev结构体指针*/

...

};

========================================================

kobject结构体

struct kobject

{

char *k_name ;

char name[KOBJ_NAME_LEN] ;  //对象名称

struct kref kref ;  //对象引用计数

struct list_head entry ; //用于挂接该kobject对象到kset链表

struct kobject *parent ; //指向父对象的指针

struct kset *kset ;      //所属kset的指针

struct kobj_type *ktype ; //指向对象类型描述符的指针

struct dentry *dentry ;   //sysfs文件系统中与该对象对应的文件节点入口

} ;

======================================================

kobj_type结构体

struct kobj_type

{

void (*release)(struct kobject *) ;//release 函数

struct sysfs_ops *sysfs_ops ;  //属性操作

struct attribute **default_attrs ;  //默认属性

};

=======================================================

sysfs_ops结构体

struct sysfs_ops

{

ssize_t (*show)(struct kobject *,struct attribute *,char *) ;

ssize_t (*store)(struct kobject *,struct attribute *,const char *,size_t) ;

};

=======================================================

kset结构体

struct kset

{

struct subsystem *subsys ; //所在的subsystem的指针

struct kobj_type *ktype ;  //指向该kset对象类型描述符的指针

struct list_head list ;    //用于连接该kset中所有kobject的链表头

spinlock_t  list_lock ;

struct kobject kobj ;      //嵌入的kobject

struct kset_uevent_ops *uevent_ops ; //事件操作集

};

=======================================================

kset_uevent_ops结构体

struct kset_uevent_ops

{

int (*filter)(struct kset *kset,struct kobject *kobj); //事件过滤

const char *(*name)(struct kset *kset,struct kobject *kobj) ;

int (*uevent)(struct kset *kset,struct kobject *kobj,char **envp,

int num_envp,char *buffer,int buffer_size) ;  //环境变量设置

};

=======================================================

subsystem结构体

struct subsystem

{

struct kset kset ; //内嵌的kset对象

struct rw_semaphore rwsem ;//互斥访问信号量

};

=======================================================

device结构体

struct device

{

struct klist *klist_children ;   //设备列表中的孩子列表

struct klist_node knode_parent ; //兄弟节点

struct klist_node knode_driver ; //驱动结点

struct klist_node knode_bus ;    //总线结点

struct device *parent ;          //指向父设备

struct kobject kobj ;      //内嵌一个kobject对象

char bus_id[BUS_ID_SIZE] ; //总线上的位置

struct device_attribute uevent_attr ;

struct semaphore sem ;

struct bus_type *bus ;  //总线

struct device_driver *driver ;  //使用的驱动s

void *driver_data ;  //驱动私有数据

void *platform_data ;//平台特定的数据

void *firmware_data ;//固件特定的数据(如ACPI,BIOS数据)

struct dev_pm_info power ;

u64 *dma_mask ;  //dma掩码

u64 coherent_dma_mask ;

struct list_head dma_pools ;  //DMA缓冲池

struct dma_coherent_mem  *dma_mem;

void (*release)(struct device *dev) ;//释放设备方法

};

===================================================

device_driver结构体

struct device_driver

{

const char *name ;  //设备驱动程序的名称

struct bus_type *bus ;  //总线

struct completion unloaded ;

struct kobject kobj ;   //内嵌的kobject对象

struct klist klist_devices ;

struct klist_node knode_bus ;

struct module *owner ;

int (*probe)(struct device *dev) ;  //指向设备探测函数

int (*remove)(struct device *dev) ; //指向设备移除函数

void (*shutdown)(struct device *dev) ;

int (*suspend)(struct device *dev,pm_message_t state) ;

int (*resume)(struct device *dev) ;

};

====================================================

bus_type结构体

struct bus_type

{

const char *name ; //总线类型的名称

struct subsystem subsys ;  //与该总线相关的subsystem

struct kset drivers ; //所有与该总线相关的驱动程序集合

struct kset devices ; //所有挂接在该总线上的设备集合

struct klist klist_devices ;

struct klist klist_drivers ;

struct bus_attribute *bus_attrs ;//总线属性

struct device_attribute *dev_attrs ;//设备属性

struct driver_attribute *drv_attrs ;//驱动程序属性

int (*match)(struct device *dev,struct device_driver *drv) ;

int (*uevent)(struct device *dev,char **envp,

int num_envp,char *buffer,int buffer_size) ;  //事件

int (*probe)(struct device *dev) ;

int (*remove)(struct device *dev) ;

void (*shutdown)(struct device *dev) ;

int (*suspend)(struct device *dev,pm_message_t state) ;

int (*resume)(struct device *dev) ;

};

===================================================

class结构体

struct class

{

const char *name ; //类名

struct module *owner ;

struct subsystem subsys ;    //对应的subsystem

struct list_head children ;  //class_device链表

struct list_head interfaces ;//class_interface链表

struct semaphore sem ;  //children和interfaces链表锁

struct class_attribute *class_attrs ;  //类属性

struct class_device_attribute *class_dev_attrs ;  //类设备属性

int (*uevent)(struct class_device *dev,char **envp,

int num_envp,char *buffer,int buffer_size) ;  //事件

void (*release)(struct class_device *dev) ;

void (*class_release)(struct class *class) ;

};

============================================

class_device结构体

struct class_device

{

struct list_head node ;

struct kobject kobj ;  //内嵌的kobject

struct class *class ;  //所属的类

dev_t devt ;   //dev_t

struct class_device_attribute *devt_attr ;

struct class_device_attribute uevent_attr ;

struct device *dev ;  //如果存在,创建到 /sys/devices相应入口的符号链接

void (*release)(struct class_device *dev) ;

int (*uevent)(struct class_device *dev,char **envp,

int num_envp,char *buffer,int buffer_size) ;

char class_id[BUS_ID_LEN] ;  //类标识

};

===============================================

class_interface结构体

struct class_interface

{

struct list_head node ;

struct class *class ;  //对应的class

int (*add)(struct class_device *,struct class_interface *) ; //设备加入时触发

void (*remove)(struct class_device *,struct class_interface *) ;//设备移出时触发

};

================================================

总线属性

struct bus_attribute

{

struct attribute attr ;

ssize_t (*show)(struct bus_type *,char *buf) ;

ssize_t (*store)(struct bus_type *,const char *buf,size_t count) ;

};

=================================================

驱动属性

struct driver_attribute

{

struct attribute attr ;

ssize_t (*show)(struct device_driver *,char *buf) ;

ssize_t (*store)(struct device_driver *,const char *buf,size_t count) ;

};

==================================================

类属性

struct class_attribute

{

struct attribute attr ;

ssize_t (*show)(struct class *,char *buf) ;

ssize_t (*store)(struct class *,const char *buf,size_t count) ;

};

===================================================

类设备属性

struct class_device_attribute

{

struct attribute attr ;

ssize_t (*show)(struct class_device *,char *buf) ;

ssize_t (*store)(struct clas_device *,const char *buf,size_t count) ;

};

===================================================

file_operations结构体

struct file_operations

{

struct module *owner ;

//拥有该结构的模块的指针,一般为THIS_MODULES

loff_t (*llseek)(struct file *,loff_t,int) ;

//用来修改文件当前的读写位置

ssize_t (*read)(struct file *,char __user *,size_t,loff_t *) ;

//从设备中同步读取数据

ssize_t (*aio_read)(struct kiocb *,char __user *,size_t,loff_t) ;

//初始化一个异步的读取数据

ssize_t (*write)(struct file *,const char __user *,size_t,loff_t) ;

//向设备发送数据

ssize_t (*aio_write)(struct kiocb *,const char __user*,size_t,loff_t) ;

//初始化一个异步的写入操作

int (*readdir)(struct file *,void *,filldir_t) ;

//仅用于读取目录,对于设备文件,该字段为NULL

unsigned int (*poll)(struct file *,struct poll_table_struct*) ;

//轮询函数,判断当前是否可以进行非阻塞的读取或写入

int (*ioctl)(struct inode *,struct file *,unsigned int,unsigned long) ;

//执行设备IO控制命令

long (*unlocked_ioctl)(struct file *,unsigned int,unsigned long) ;

//不使用BLK文件系统,将使用此种函数指针替代ioctl

long (*compat_ioctl)(struct file *,unsigned int,unsigned long) ;

//在64位系统上,32位的ioctl调用将使用此函数指针替代

int (*mmap)(struct file *,unsigned int,unsigned long) ;

//用于请求将设备内存映射到进程地址空间

int (*open)(struct inode *,struct file *) ;

//打开

int (*flush)(struct file *) ;

int (*release)(struct inode *,struct file *) ;

//关闭

int (*sync)(struct file *,struct dentry *,int datasync);

//刷新待处理的数据

int (*aio_fsync)(struct kiocb *,int datasync) ;

//异步fsync

int (*fasync)(int,struct file *,int) ;

//通知设备FASYNC标志发生变化

int (*lock)(struct file *,int,struct file_lock *) ;

ssize_t (*readv)(struct file *,const struct iovec*,unsigned long,loff_t *) ;

ssize_t (*writev)(struct file *,const struct iovec *,unsigned long,loff_t *) ;

//readv和writev:分散或聚集型的读写操作

ssize_t (*sendfile)(struct file *,lof_t *,size_t,read_actor_t,void*) ;

//通常为NULL

unsigned long (*get_unmapped_area)(struct file *,unsigned long,unsigned long,

unsigned long,unsigned long);

//在进程地址空间找到一个将底层设备中的内存段映射的位置

int (*check_flags)(int) ;

//允许模块检查传递给fcntl(F_SETEL...)通用的标志

int (*dir_notify)(struct file *filp,unsigned long arg) ;

//仅对文件系统有效,驱动程序不必实现

int (*flock)(struct file *,int ,struct file_lock *) ;

};

struct task_struct {

volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */

struct thread_info *thread_info;

atomic_t usage;

unsigned long flags; /* per process flags, defined below */

unsigned long ptrace;

int lock_depth;  /* BKL lock depth */

#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)

int oncpu;

#endif

int prio, static_prio;

struct list_head run_list;

prio_array_t *array;

unsigned short ioprio;

unsigned long sleep_avg;

unsigned long long timestamp, last_ran;

unsigned long long sched_time; /* sched_clock time spent running */

int activated;

unsigned long policy;

cpumask_t cpus_allowed;

unsigned int time_slice, first_time_slice;

#ifdef CONFIG_SCHEDSTATS

struct sched_info sched_info;

#endif

struct list_head tasks;

/*

* ptrace_list/ptrace_children forms the list of my children

* that were stolen by a ptracer.

*/

struct list_head ptrace_children;

struct list_head ptrace_list;

struct mm_struct *mm, *active_mm;

/* task state */

struct linux_binfmt *binfmt;

long exit_state;

int exit_code, exit_signal;

int pdeath_signal;  /*  The signal sent when the parent dies  */

/* ??? */

unsigned long personality;

unsigned did_exec:1;

pid_t pid;

pid_t tgid;

/*

* pointers to (original) parent process, youngest child, younger sibling,

* older sibling, respectively.  (p->father can be replaced with

* p->parent->pid)

*/

struct task_struct *real_parent; /* real parent process (when being debugged) */

struct task_struct *parent; /* parent process */

/*

* children/sibling forms the list of my children plus the

* tasks I'm ptracing.

*/

struct list_head children; /* list of my children */

struct list_head sibling; /* linkage in my parent's children list */

struct task_struct *group_leader; /* threadgroup leader */

/* PID/PID hash table linkage. */

struct pid pids[PIDTYPE_MAX];

struct completion *vfork_done;  /* for vfork() */

int __user *set_child_tid;  /* CLONE_CHILD_SETTID */

int __user *clear_child_tid;  /* CLONE_CHILD_CLEARTID */

unsigned long rt_priority;

cputime_t utime, stime;

unsigned long nvcsw, nivcsw; /* context switch counts */

struct timespec start_time;

/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */

unsigned long min_flt, maj_flt;

cputime_t it_prof_expires, it_virt_expires;

unsigned long long it_sched_expires;

struct list_head cpu_timers[3];

/* process credentials */

uid_t uid,euid,suid,fsuid;

gid_t gid,egid,sgid,fsgid;

struct group_info *group_info;

kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;

unsigned keep_capabilities:1;

struct user_struct *user;

#ifdef CONFIG_KEYS

struct key *thread_keyring; /* keyring private to this thread */

unsigned char jit_keyring; /* default keyring to attach requested keys to */

#endif

int oomkilladj; /* OOM kill score adjustment (bit shift). */

char comm[TASK_COMM_LEN]; /* executable name excluding path

- access with [gs]et_task_comm (which lock

it with task_lock())

- initialized normally by flush_old_exec */

/* file system info */

int link_count, total_link_count;

/* ipc stuff */

struct sysv_sem sysvsem;

/* CPU-specific state of this task */

struct thread_struct thread;

/* filesystem information */

struct fs_struct *fs;

/* open file information */

struct files_struct *files;

/* namespace */

struct namespace *namespace;

/* signal handlers */

struct signal_struct *signal;

struct sighand_struct *sighand;

sigset_t blocked, real_blocked;

struct sigpending pending;

unsigned long sas_ss_sp;

size_t sas_ss_size;

int (*notifier)(void *priv);

void *notifier_data;

sigset_t *notifier_mask;

void *security;

struct audit_context *audit_context;

seccomp_t seccomp;

/* Thread group tracking */

u32 parent_exec_id;

u32 self_exec_id;

/* Protection of (de-)allocation: mm, files, fs, tty, keyrings */

spinlock_t alloc_lock;

/* Protection of proc_dentry: nesting proc_lock, dcache_lock, write_lock_irq(&tasklist_lock); */

spinlock_t proc_lock;

/* journalling filesystem info */

void *journal_info;

/* VM state */

struct reclaim_state *reclaim_state;

struct dentry *proc_dentry;

struct backing_dev_info *backing_dev_info;

struct io_context *io_context;

unsigned long ptrace_message;

siginfo_t *last_siginfo; /* For ptrace use.  */

/*

* current io wait handle: wait queue entry to use for io waits

* If this thread is processing aio, this points at the waitqueue

* inside the currently handled kiocb. It may be NULL (i.e. default

* to a stack based synchronous wait) if its doing sync IO.

*/

wait_queue_t *io_wait;

/* i/o counters(bytes read/written, #syscalls */

u64 rchar, wchar, syscr, syscw;

#if defined(CONFIG_BSD_PROCESS_ACCT)

u64 acct_rss_mem1; /* accumulated rss usage */

u64 acct_vm_mem1; /* accumulated virtual memory usage */

clock_t acct_stimexpd; /* clock_t-converted stime since last update */

#endif

#ifdef CONFIG_NUMA

struct mempolicy *mempolicy;

short il_next;

#endif

#ifdef CONFIG_CPUSETS

struct cpuset *cpuset;

nodemask_t mems_allowed;

int cpuset_mems_generation;

#endif

atomic_t fs_excl; /* holding fs exclusive resources */

};

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值