LDD和scull相关各种结构体的故事(学习笔记 不定期更新)

LDD和各种结构体的故事

struct scull_dev     位置:scull/scull.h

struct scull_dev {
	struct scull_qset *data;  /* Pointer to first quantum set */
	int quantum;              /* the current quantum size */
	int qset;                 /* the current array size */
	unsigned long size;       /* amount of data stored here */
	unsigned int access_key;  /* used by sculluid and scullpriv */
	struct mutex mutex;     /* mutual exclusion semaphore     */
	struct cdev cdev;	  /* Char device structure		*/
};

struct mutex       
位置:/usr/src/linux-source/include/linux/

struct mutex {
        /* 1: unlocked, 0: locked, negative: locked, possible waiters */
        atomic_t                count;
        spinlock_t              wait_lock;
        struct list_head        wait_list;
#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
        struct task_struct      *owner;
#endif
#ifdef CONFIG_DEBUG_MUTEXES
        const char              *name;
        void                    *magic;
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
        struct lockdep_map      dep_map;
#endif
};

这个有点点长哇。。。

struct inode
   位置:/usr/src/linux-source/include/linux/fs.h

/*
 * Keep mostly read-only and often accessed (especially for
 * the RCU path lookup and 'stat' data) fields at the beginning
 * of the 'struct inode'
 */
struct inode {
        umode_t                 i_mode;
        unsigned short          i_opflags;
        kuid_t                  i_uid;
        kgid_t                  i_gid;
        unsigned int            i_flags;

#ifdef CONFIG_FS_POSIX_ACL
        struct posix_acl        *i_acl;
        struct posix_acl        *i_default_acl;
#endif

        const struct inode_operations   *i_op;
        struct super_block      *i_sb;
        struct address_space    *i_mapping;

#ifdef CONFIG_SECURITY
        void                    *i_security;
#endif

        /* Stat data, not accessed from path walking */
        unsigned long           i_ino;
        /*
         * Filesystems may only read i_nlink directly.  They shall use the
         * following functions for modification:
         *
         *    (set|clear|inc|drop)_nlink
         *    inode_(inc|dec)_link_count
         */
        union {
                const unsigned int i_nlink;
                unsigned int __i_nlink;
        };
        dev_t                   i_rdev;
        loff_t                  i_size;
        struct timespec         i_atime;
        struct timespec         i_mtime;
        struct timespec         i_ctime;
        spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
        unsigned short          i_bytes;
        unsigned int            i_blkbits;
        blkcnt_t                i_blocks;

#ifdef __NEED_I_SIZE_ORDERED
        seqcount_t              i_size_seqcount;
#endif

        /* Misc */

        unsigned long           i_state;
        struct mutex            i_mutex;

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

        struct hlist_node       i_hash;
        struct list_head        i_wb_list;      /* backing dev IO list */
        struct list_head        i_lru;          /* inode LRU list */
        struct list_head        i_sb_list;
        union {
                struct hlist_head       i_dentry;
                struct rcu_head         i_rcu;
        };
        u64                     i_version;
        atomic_t                i_count;
        atomic_t                i_dio_count;
        atomic_t                i_writecount;
        const struct file_operations    *i_fop; /* former ->i_op->default_file_ops */
        struct file_lock        *i_flock;
        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;
        };
        __u32                   i_generation;

#ifdef CONFIG_FSNOTIFY
        __u32                   i_fsnotify_mask; /* all events this inode cares about */
        struct hlist_head       i_fsnotify_marks;
#endif

#ifdef CONFIG_IMA
        atomic_t                i_readcount; /* struct files open RO */
#endif
        void                    *i_private; /* fs or device private pointer */
};

struct file     
位置:/usr/src/linux-source/include/linux/fs.h

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;

        /*
         * Protects f_ep_links, f_flags, f_pos vs i_size in lseek SEEK_CUR.
         * Must not be taken from IRQ context.
         */
        spinlock_t              f_lock;
#ifdef CONFIG_SMP
        int                     f_sb_list_cpu;
#endif
        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;
        struct list_head        f_tfile_llink;
#endif /* #ifdef CONFIG_EPOLL */
        struct address_space    *f_mapping;
#ifdef CONFIG_DEBUG_WRITECOUNT
        unsigned long f_mnt_write_state;
#endif
};

struct cdev      位置:/usr/src/linux-source/include/linux/cdev.h

struct cdev {
        struct kobject kobj;
        struct module *owner;
        const struct file_operations *ops;
        struct list_head list;
        dev_t dev;
        unsigned int count;
};

struct scull_qset                             位置:scull/scull.h

struct scull_qset {
	void **data;
	struct scull_qset *next;
};

LDD和scull相关各种结构体的故事(学习笔记 不定期更新)

时间: 2024-08-26 00:02:29

LDD和scull相关各种结构体的故事(学习笔记 不定期更新)的相关文章

关于结构体字节对齐的笔记

1,空结构体的字节大小为:1: 2,含有static成员的结构体:sizeof 只算存栈中分配的空间大小,static成员存储在全局数据区内,故 static 成员变量不计算在内. 3,在默认对齐方式中,每种类型的存储开始地址是 能被该类型大小整除的地址.故:每次计算都假设结构体开始地址是 0: 4,遇到成员是结构体变量的:将此结构体变量当做一个数据类型,但是: 注意: 千万不能把此结构体的 sizeof 当做该变量的类型大小 也不能直接将此结构体拆解开 解法: 此结构体成员变量的类型大小 理解

结构体指针的学习

#include <stdio.h>struct Point{  /* 定义结构体 */double x;double y;double z;};int main(){    struct Point a={100,100,0}; /* 对点A进行初始化 */    struct Point b;    struct Point *c;    c=&b; /* 将b的地址给c */    (*c).x=a.x; /* 对c所代表的地址进行赋值,实质上是对b进行赋值 */    (*c)

关于结构体类型的学习

1. 定义结构体类型时,最后的分号一定不能忘: struct st { int num; int s; //分号不能少 }; 2. 关于结构体成员的获取: int main(void) { struct st a[3]; int i=0; scanf("%d",a); //输入a[0].num的值 scanf("%d",&a->s); //a.s的值 scanf("%d",(a+1)); //a[1].num scanf("

Java 第五章 循环结构(二)学习笔记

1.for语法: for(1参数初始化,2,条件,3,参数叠加){ 4.循环操作 } 2.break:改变程序的控制流,多用于循环中,结合条件机构和分支结构一起使用. 作用,跳出整个循环: continue:只能用于循环中,跳过循环中剩下的语句,去执行下次循环. 作用:结合当前循环,进入下一下循环: 3.while for它俩的区别是: whlie :先判断在执行. do-while:先执行在判断. for:先判断在执行 使用场景为:确认循环次数的时候. 4.使用循环步骤: 确认循环条件和循环体

Oracle相关的个人学习记录,不定期更新

存储过程基本语法 http://www.cnblogs.com/hero4china/articles/base_rule_oracle_procedure.html 存储过程基本写法 http://www.linuxidc.com/Linux/2013-11/93196.htm 存储过程简单例子 http://www.cnblogs.com/yueers/p/5710446.html 注意点: 存储结构创建 CREATE (OR REPLACE) PROCEDURE 存储结构名(需要输入的参数

c#中枚举,结构,数组的学习笔记

enum 枚举使用方法:enum <typename> : <underlyingtype> { value1 = <actualval1>, value2 = <actualval2>, ……, valuen = <actualvaln> }示例enum orientation : byte { north =1, south=2, east=3, west=4 }struct 结构使用方法:struct <typename> {

Introduction the naive“scull” 《linux设备驱动》 学习笔记

Introduction the naive "scull" 首先,什么是scull? scull (Simple Character Utility for Loading Localities). scull is a char driver that acts on a memory area as though it were a device. 和第一个C程序Hello world一样,他什么都不能干,却能很好的阐释怎么一步步进阶的去写驱动 blog的最后,我会给出这对于sc

结构体概括

结构体也属于构造类型.结构体比数组更加灵活,可以存放不同类型的变量 结构体是由若干组成员组成的,成员既可以是基本数据类型.又可以是构造类型,比如数组 结构体属于自定义数据类型 1.结构体声明: struct 结构体名 { 类型说明符  成员名; -; 类型说明符  成员名; };  //注意此处分号不能少. 结构体是自定义类型,结构体变量是由结构体类型修饰的变量. 定义结构体变量 struct 结构体名 变量名 = {初值} ; 结构体成员访问 结构体成员的表示形式 结构体变量,成员 typed

C语言经典---结构体

结构体也属于构造类型.结构体比数组更加灵活,可以存放不同类型的变量 结构体是由若干组成员组成的,成员既可以是基本数据类型.又可以是构造类型,比如数组 结构体属于自定义数据类型 1.结构体声明: struct 结构体名 { 类型说明符  成员名; -; 类型说明符  成员名; };  //注意此处分号不能少. 结构体是自定义类型,结构体变量是由结构体类型修饰的变量. 定义结构体变量 struct 结构体名 变量名 = {初值} ; 结构体成员访问 结构体成员的表示形式 结构体变量,成员 typed