驱动开发第二步,入门,最常用的结构体了解。

 

  struct cdev {
   struct kobject kobj;          // 每个 cdev 都是一个 kobject
   struct module *owner;       // 指向实现驱动的模块
   const struct file_operations *ops;   // 操纵这个字符设备文件的方法
   struct list_head list;       // 与 cdev 对应的字符设备文件的 inode->i_devices 的链表头
   dev_t dev;                   // 起始设备编号
   unsigned int count;       // 设备范围号大小
};
 

struct kobject {

       const char             *name;

       struct list_head       entry;

       struct kobject         *parent;

       struct kset             *kset;

       struct kobj_type     *ktype;

       struct sysfs_dirent  *sd;

       struct kref             kref;

       unsigned int state_initialized:1;

       unsigned int state_in_sysfs:1;

       unsigned int state_add_uevent_sent:1;

       unsigned int state_remove_uevent_sent:1;

};

 

 

 

 

 

 

struct file_operations {

       struct module *owner;

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

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

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

       ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

       ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);

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

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

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

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

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

       int (*mmap) (struct file *, struct vm_area_struct *);

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

       int (*flush) (struct file *, fl_owner_t id);

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

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

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

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

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

       ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);

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

       int (*check_flags)(int);

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

       ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);

       ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);

       int (*setlease)(struct file *, long, struct file_lock **);

};

 

struct file {

       /*

        * fu_list becomes invalid after file_free is called and queued via

        * fu_rcuhead for RCU freeing

        */

       union {

              struct list_head       fu_list;

              struct rcu_head     fu_rcuhead;

       } f_u;

       struct path             f_path;

#define f_dentry     f_path.dentry

#define f_vfsmnt    f_path.mnt

       const struct file_operations    *f_op;

       atomic_long_t        f_count;

       unsigned int          f_flags;

       fmode_t                f_mode;

       loff_t                    f_pos;

       struct fown_struct f_owner;

       const struct cred    *f_cred;

       struct file_ra_state  f_ra;

 

       u64                f_version;

#ifdef CONFIG_SECURITY

       void               *f_security;

#endif

       /* needed for tty driver, and maybe others */

       void               *private_data;

 

#ifdef CONFIG_EPOLL

       /* Used by fs/eventpoll.c to link all the hooks to this file */

       struct list_head       f_ep_links;

       spinlock_t              f_ep_lock;

#endif /* #ifdef CONFIG_EPOLL */

       struct address_space     *f_mapping;

#ifdef CONFIG_DEBUG_WRITECOUNT

       unsigned long f_mnt_write_state;

#endif

};

 

 

 

 

struct inode {

       struct hlist_node     i_hash;

       struct list_head       i_list;

       struct list_head       i_sb_list;

       struct list_head       i_dentry;

       unsigned long         i_ino;

       atomic_t         i_count;

       unsigned int           i_nlink;

       uid_t                     i_uid;

       gid_t                     i_gid;

       dev_t                    i_rdev;

       u64                i_version;

       loff_t                    i_size;

#ifdef __NEED_I_SIZE_ORDERED

       seqcount_t             i_size_seqcount;

#endif

       struct timespec             i_atime;

       struct timespec             i_mtime;

       struct timespec             i_ctime;

       unsigned int           i_blkbits;

       blkcnt_t          i_blocks;

       unsigned short          i_bytes;

       umode_t                i_mode;

       spinlock_t              i_lock;     /* i_blocks, i_bytes, maybe i_size */

       struct mutex          i_mutex;

       struct rw_semaphore     i_alloc_sem;

       const struct inode_operations       *i_op;

       const struct file_operations    *i_fop;    /* former ->i_op->default_file_ops */

       struct super_block  *i_sb;

       struct file_lock       *i_flock;

       struct address_space     *i_mapping;

       struct address_space     i_data;

#ifdef CONFIG_QUOTA

       struct dquot           *i_dquot[MAXQUOTAS];

#endif

       struct list_head       i_devices;

       union {

              struct pipe_inode_info    *i_pipe;

              struct block_device       *i_bdev;

              struct cdev            *i_cdev;

       };

       int                  i_cindex;

 

       __u32                   i_generation;

 

#ifdef CONFIG_DNOTIFY

       unsigned long         i_dnotify_mask; /* Directory notify events */

       struct dnotify_struct      *i_dnotify; /* for directory notifications */

#endif

 

#ifdef CONFIG_INOTIFY

       struct list_head       inotify_watches; /* watches on this inode */

       struct mutex          inotify_mutex; /* protects the watches list */

#endif

 

       unsigned long         i_state;

       unsigned long         dirtied_when;  /* jiffies of first dirtying */

 

       unsigned int           i_flags;

 

       atomic_t         i_writecount;

#ifdef CONFIG_SECURITY

       void               *i_security;

#endif

       void               *i_private; /* fs or device private pointer */

};

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值