代码之家  ›  专栏  ›  技术社区  ›  Joh

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

  •  4
  • Joh  · 技术社区  · 16 年前

    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 回复  |  直到 16 年前
        1
  •  2
  •   Allen    16 年前

    看看这本书 Linux Device Drivers 是的,看起来这不是你想要的,但是,真的,如果你不理解内核,你就不能写一个设备驱动程序,而能够写一个设备驱动程序是大多数人应该做的。另外,请记住,虽然它是一个单片内核,但它是“模块化的”。您在上面的问题中遇到的大部分是文件系统的一部分内容,这些内容可以或多或少地单独理解——其他子系统也可以。

    对于将所有这些放在一起的核心内核,请看 Kernel Book . 它还与其他来源有联系。还有一个 book ,尽管非常过时,但由Remy Card介绍内核(2.2内核之前)。从亚马逊网站上你可以看到这本书的相关标题。

    如果你真的想正确的开始做一些小的和可以理解的事情。看一看 MINIX 以及随行人员 textbook (托瓦尔兹可能从这本书中学到了一些操作系统基础知识)。

        2
  •  3
  •   joschi    16 年前

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

    上面说, Linux Kernel Newbies 对你来说也许是个好的起点。

        3
  •  1
  •   tylerl    16 年前
        4
  •  1
  •   ninjalj    16 年前

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