我怎样才能更好地理解内核c编程代码

时间:2010-07-03 16:21:58

标签: 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_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 *);
};

如何更好地理解代码。任何教授指针的书,内核代码中的结构

4 个答案:

答案 0 :(得分:3)

除了事实,这是标准的C语法之外,你必须自己在内核代码中查找结构的定义。这并不难,一开始只是单调乏味。

这就是说,Linux Kernel Newbies对你来说可能是一个很好的起点。

答案 1 :(得分:2)

看看Corbet等人的书Linux Device Drivers。是的,看起来它不是你要求的,但实际上,你不能在不了解内核的情况下编写设备驱动程序,并且能够编写设备驱动程序就像大多数人应该去的那样。另外,请记住,虽然它是单片内核,但它是“模块化的”。你在上面的问题中所拥有的主要是文件系统的一部分,它可以或多或少地自己理解 - 就像其他子系统一样。

对于包含所有这些内容的核心内核,请查看Kernel Book。它还有其他来源的链接。还有另一个book,虽然非常过时,但Remy Card关于内核(2.2之前的内核)。从amazon.com获取该书,您可以看到相关的标题。

如果你真的想要正确地开始做一些小而易懂的事情。看一下MINIX和随附的textbook(Torvalds可能从这本书中学到了一些关于OS基础知识的东西)。

答案 2 :(得分:1)

另一本要查看的书是由核心内核开发人员之一Greg K-H撰写的Linux Kernel in a Nutshell。它既有书本形式(来自O'Reilly),也可以从作者那里免费下载。

答案 3 :(得分:1)

这是vtable的C版本。它允许您根据使用的文件系统调用不同的方法。 Google for vtable。