I'm having some problems with this system call and probably with kmalloc.
Well , basically I'm building a system call , and this system call and the kernel are compiled without a problem. But when I call my system call , the shell shows a lot of message and then the computer crash.
I think the problem is with the kmalloc , because when I remove the kmalloc and other code that envolves the kmalloc the system call works perfectly.
For example: bloqueados = kmalloc(sizeof(struct bloqueio),GFP_ATOMIC);
Just to add : Maybe it's ocurring a deadlock , but I don't know accuratelly.
Thank you.
This is the code :
#include <linux/linkage.h>
#include <linux/io_block_unblock.h>
//#include <linux/printk.h>
#include <linux/kernel.h>
#include <linux/unistd.h>
#include <linux/stddef.h>
#include <linux/slab.h>
#include <linux/gfp.h>
#include <linux/unistd.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/mount.h>
#include <linux/genhd.h>
#include <linux/device.h>
struct bloqueio *bloqueados;
EXPORT_SYMBOLL(bloqueados);
asmlinkage long sys_io_block(const char __user *particao, const char __user *arquivo){
int id_inode;
struct file *arq;
char *part;
struct bloqueio *tmp;
arq = filp_open(arquivo,O_CREAT, S_IRWXU);
printk(KERN_EMERG "\nstruct file criado para o arquivo %s",arquivo);
id_inode = arq->f_path.dentry->d_inode->i_ino;
printk(KERN_EMERG "\nO inode do arquivo %s e %d",arquivo, id_inode);
//part = arq->f_path.mnt->mnt_sb->s_bdev->bd_part->__dev.init_name;
//printk(KERN_EMERG "\nA particao a qual o arquivo se encontra e %s",part);
if(bloqueados == NULL){
bloqueados = kmalloc(sizeof(struct bloqueio),GFP_ATOMIC);//<--------------
if(!bloqueados){
printk(KERN_EMERG "\n Erro ao alocar memoria");
return 0;
}
bloqueados->inode = id_inode;
bloqueados->tipo = 0;
bloqueados->prox = NULL;
}
else
{
tmp = kmalloc(sizeof(struct bloqueio), GFP_ATOMIC);//<--------------------
if(!bloqueados){
printk(KERN_EMERG "\n Erro ao alocar memoria");
return 0;
}
tmp->inode = id_inode;
tmp->tipo = 0;
tmp->prox = bloqueados->prox;
bloqueados->prox = tmp;
}
return 1;
}
Just to add , this is the struct bloqueio.
extern int contem(const char *arquivo);
struct bloqueio{
int inode;
int tipo; // 0 -> arquivo 1 -> partição
struct bloqueio *prox;
};
extern struct bloqueio *bloqueados;