tags:

views:

107

answers:

4

I was studying the Kernel Architecture and its programming to get the idea about Kernel. I know C programming but the structures and pointers mentioned in kernel code are going over my head. Like below

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 *);
};

How can I better understand the code. Any book which teaches the pointers, structures like in kernel code

+2  A: 

Besides the fact, that this is standard C syntax, you'll have to lookup the definition of the structs in the kernel code yourself. It's not hard, it's just tedious in the beginning.

This said, Linux Kernel Newbies might be a good starting point for you.

joschi
thanks buddy , i will read the site
Mirage
+2  A: 

Take a look a the book Linux Device Drivers by Corbet et al. Yeah, it looks like it's not what you asked for but, really, you can't write a device driver without understanding the kernel and being able to write a device driver is about as far as most people should go. Also, keep in mind that while it is a monolithic kernel it is "modular". What you have in your question above is mostly part of the filesystem stuff which can be understood, more or less, on its own -- as can other subsystems.

For the core kernel which holds all of these together look at the Kernel Book. It also has links to other sources. There is another book, though very dated, by Remy Card about the kernel (pre 2.2 kernel). From the amazon.com for that book you can see related titles.

If you really want to begin correctly do it with something small and understandable. Take a look at MINIX and the accompanying textbook (Torvalds may have learned something about OS fundamentals from this very book).

Allen
Err, you mean Corbet, I think.
ninjalj
fixed. thank you.
Allen
A: 

Another book to have a look at is Linux Kernel in a Nutshell by Greg K-H, one of the core kernel developers. It's available both in book form (from O'Reilly) and as a free download from the author.

tylerl
A: 

That's the C version of a vtable. It allows you to call different methods depending on the filesystem in use. Google for vtable.

ninjalj