This is my code to write to a file from kernel.(i know it is not a good idea to read and write directly from kernel but this is just a test).
static void write_startup_file(char *startstring)
{
mm_segment_t oldfs;
struct file *f;
loff_t pos=0;
f = filp_open("/bin/startupcheck",O_WRONLY|O_CREAT, 0644);
oldfs = get_fs();
set_fs (KERNEL_DS);
if(f)
{
vfs_write(f,startstring, strlen(startstring), &pos);
set_fs(oldfs);
filp_close(f, NULL);
}
else
printk(KERN_CRIT "Unable to open startfile...\n");
}
And i call it in another function ourVeryOwnFunction()
as
if(dbval==NULL) { write_startup_file("FAILED");}
Where dbval
is a value being read.But when i compile the kernel and run it( Im running it on vmware). The kernel panic i get is here
Clearly im doing something wrong. Looking for some help. Thanks.