0

I'm working on kernel linux 2.6.34.14.

I added (in include/linux/fs.h) in struct file a pointer to a struct defined before, in this way:

struct session{
    char *session_buffer;
    loff_t session_dimension;
};

struct file {
struct session *sess_punt;

}

After that, I need to allocate my struct in open.c and do that in dentry_open (fs/open.c).

With this code I want to say: if there is a particular flag when open is called, then allocate the struct and the buffer in the struct.

if(f->f_flags & O_SESSION){
    f->sess_punt = kmalloc(sizeof(struct session), GFP_KERNEL);
    f->sess_punt -> session_buffer = kmalloc(MAX_BUFFER_SIZE, GFP_KERNEL);  
    //f->sess_punt -> session_dimension = 0;
}
else f->sess_punt = NULL;

The problem is the following:

I compile the new kernel and everything is fine. I try to entry in that kernel but I receive the message "kernel panic - not syncing: attempted to kill init".

Why?Where am I wrong?

  • Try checking for a valid pointer before using it, `f->sess_punt` –  Nov 30 '13 at 11:02
  • If I remove the rows with kmalloc, I can entry in that kernel and see with dmesg and some printk that else f->sess_punt = NULL; is performed without problems. – user1938352 Nov 30 '13 at 11:05
  • Because of course if I don't use a flag O_SESSION no one entry in that if. I don't understand why I can set the value to null but I can't set it to some other value. And why I have this error before use kmalloc, just when I try to entry in that kernel. – user1938352 Nov 30 '13 at 11:08
  • You get the error because the kernel tries to open /sbin and look for `init`? –  Dec 01 '13 at 15:13
  • Sorry but, what you mean by that? – user1938352 Dec 01 '13 at 16:41
  • Have you tried only removing the second kmalloc() line, or checking explicitly that f->sess_punt is a valid pointer when you do use O_SESSION? – Dan Fego Dec 05 '13 at 17:55

0 Answers0