What's wrong with this really simple function?
From: Mohamed El Dawy
Date: Sun Nov 27 2005 - 13:57:14 EST
Hi,
I have created this 5-liner system call, which basically opens a
file, write "Hello World" to it, and then returns. That's all.
Now, when I actually call it, it creates the file successfully but
writes nothing to it. The file is created and is only zero bytes. So,
either write didn't write, or close didn't close. Any help would be
greatly appreciated.
#define SUCCESS 0
#define CANT_OPEN_FILE 1
#define YOU_ARE_NOT_ROOT 3
#define OTHER_STUPID_ERROR 4
asmlinkage long sys_dump(char * filename)
{
int fd;
if(!capable(CAP_SYS_ADMIN))
return YOU_ARE_NOT_ROOT;
fd=sys_open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRWXU);
if(fd==-1)
return CANT_OPEN_FILE;
if(sys_write(fd,"Hello World From inside the kernel!",35)==0)
{
sys_close(fd);
return OTHER_STUPID_ERROR;
}
sys_close(fd);
return SUCCESS;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/