如何更好地理解内核c编程代码

如何更好地理解内核c编程代码,c,linux-kernel,C,Linux Kernel,我在研究内核架构及其编程,以了解内核的概念。 我知道C语言编程,但是内核代码中提到的结构和指针让我难以理解。如下 int irq = regs.orig_eax & 0xff; asmlinkage int handle_IRQ_event(unsigned int irq, struct pt_regs *regs, struct irqaction *action) { struct super_operati

我在研究内核架构及其编程,以了解内核的概念。 我知道C语言编程,但是内核代码中提到的结构和指针让我难以理解。如下

int irq = regs.orig_eax & 0xff;


asmlinkage int handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
                                struct irqaction *action)
{



struct super_operations {
        struct inode *(*alloc_inode) (struct super_block *sb);
        void (*destroy_inode) (struct inode *);
        void (*read_inode) (struct inode *);
        void (*dirty_inode) (struct inode *);
        void (*write_inode) (struct inode *, int);
        void (*put_inode) (struct inode *);
        void (*drop_inode) (struct inode *);
        void (*delete_inode) (struct inode *);
        void (*put_super) (struct super_block *);
        void (*write_super) (struct super_block *);
        int (*sync_fs) (struct super_block *, int);
        void (*write_super_lockfs) (struct super_block *);
        void (*unlockfs) (struct super_block *);
        int (*statfs) (struct super_block *, struct statfs *);
        int (*remount_fs) (struct super_block *, int *, char *);
        void (*clear_inode) (struct inode *);
        void (*umount_begin) (struct super_block *);
        int (*show_options) (struct seq_file *, struct vfsmount *);
};

如何更好地理解代码。任何一本教指针和内核代码中的结构的书除了这是标准C语法之外,你还必须自己在内核代码中查找结构的定义。这并不难,只是开始时很乏味

这对你来说可能是一个很好的起点。

看看Corbet等人的书。是的,看起来这不是你想要的,但是,实际上,如果你不理解内核,你就不能编写设备驱动程序,并且能够编写设备驱动程序是大多数人应该做的。另外,请记住,虽然它是一个单片内核,但它是“模块化的”。您在上面的问题中看到的大部分都是文件系统的一部分,它们或多或少都是可以理解的,就像其他子系统一样

对于包含所有这些功能的核心内核,请查看。它还与其他来源有链接。Remy Card关于内核(2.2内核之前)的另一篇文章,虽然很过时。从amazon.com上你可以看到这本书的相关标题


如果你真的想正确地开始做一些小的和可以理解的事情。请看一看附带的(Torvalds可能从这本书中学到了一些操作系统基础知识)。

另一本书是由核心内核开发人员之一Greg K-H撰写的。它既有书籍形式(从O'Reilly)也有作者免费下载。

这是vtable的C版本。它允许您根据所使用的文件系统调用不同的方法。谷歌搜索vtable。

我可能错了,但这不是更好的解决堆栈溢出问题吗?呃,我想你是说Corbet。