【问题标题】:How can i better understand the kernel c programming code我怎样才能更好地理解内核 c 编程代码
【发布时间】:2011-03-11 16:42:53
【问题描述】:

我正在研究内核架构及其编程以了解有关内核的想法。 我知道 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 *);
};

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

【问题讨论】:

  • 我可能错了,但这在 Stack Overflow 上不是更好吗?

标签: c linux-kernel


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    如果您真的想正确地开始做一些小而易于理解的事情。看看MINIX 和随附的textbook(Torvalds 可能已经从这本书中学到了一些关于操作系统基础的知识)。

    【讨论】:

    • 呃,我想你是说 Corbet。
    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 2021-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多