Thread: Linux Kernel Programming Help!!

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    12

    Exclamation Linux Kernel Programming Help!!

    Hello all! I am new to this forum and I had a question that I was hoping you guys might be able to help me out on!

    I am new to Operating Systems and Linux Programming and I embarked on a small project of creating a sample kernel module.

    Here is the code:
    Code:
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/list.h>
    #include <linux/types.h>
    
    struct birthday {
        int day;
        int month;
        int year;
        struct list_head list;
    }
    
    static LIST_HEAD(birthday_list);
    
    /* This function is called when the module is loaded. */
    int simple_init(void)
    {
           printk(KERN_INFO "Loading Module\n");
    
        struct birthday *person;
    
        person = kmalloc (sizeof(*person), GFP_KERNEL);
        person->day=2;
        person->month=8;
        person->year=1995;
        INIT_LIST_HEAD(&person->list);
    
        list_add_tail(&person->list, &birthday_list);
    
        struct birthday *ptr;
    
        list_for_each_entry(ptr, &birthday_list,list){
        /*on each iteration ptr points*/
        /*to the next birthday struct*/
        printk(KERN_INFO "day:%d, month:%d, year: %d\n",
        ptr->day,
        ptr->month,
        ptr->year);
        }
    
           return 0;
    }
    
    /* This function is called when the module is removed. */
    void simple_exit(void) {
        printk(KERN_INFO "Removing Module\n");
    
        struct birthday *ptr, *next;
    
        list_for_each_entry_safe(ptr,next,&birthday_list, list){
        /*on each iteration ptr points*/
        /*to the next birthday struct*/
        printk(KERN_INFO "day:%d, month:%d, year: %d\n",
        ptr->day,
        ptr->month,
        ptr->year);
        list_del(&ptr->list);
        kfree(ptr);
        }
    }
    
    /* Macros for registering module entry and exit points. */
    module_init( simple_init );
    module_exit( simple_exit );
    
    MODULE_LICENSE("GPL");
    MODULE_DESCRIPTION("Simple Module");
    MODULE_AUTHOR("SGG");
    You can tell pretty easily whats going on. The goal is to load struct birthday or get rid of it as necessary. However, when I tried to "make" this module I got these errors:

    error: (line 14) two or more data types in declaration specifiers
    error: (line 33,51) 'struct birthday' has no member named 'next'

    I have no idea what's wrong and I would really appreciate if you guys helped me debug my code. Thank you so much in advanced!

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    You're missing a semicolon after the closing brace of struct birthday
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    12
    Sweet! That was it! Thank you so much! Its funny how its the little things that drive you nuts!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux kernel
    By Annonymous in forum Linux Programming
    Replies: 15
    Last Post: 11-09-2011, 12:26 PM
  2. Linux kernel programming
    By Gnakul in forum Linux Programming
    Replies: 1
    Last Post: 10-21-2011, 07:38 AM
  3. Linux Kernel I/O C programming
    By inferno_gogo in forum C Programming
    Replies: 11
    Last Post: 02-18-2009, 04:44 PM
  4. linux kernel module programming
    By open_engg in forum Linux Programming
    Replies: 2
    Last Post: 08-05-2007, 04:41 PM
  5. linux kernel module programming
    By circuit in forum Linux Programming
    Replies: 10
    Last Post: 12-01-2004, 06:08 PM

Tags for this Thread