public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* What's wrong with this really simple function?
@ 2005-11-27 18:57 Mohamed El Dawy
  2005-11-28  7:55 ` Juergen Quade
  0 siblings, 1 reply; 5+ messages in thread
From: Mohamed El Dawy @ 2005-11-27 18:57 UTC (permalink / raw)
  To: linux-kernel

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;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-28 13:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <5dCs1-7zM-853@gated-at.bofh.it>
2005-11-28  1:01 ` What's wrong with this really simple function? Robert Hancock
2005-11-27 18:57 Mohamed El Dawy
2005-11-28  7:55 ` Juergen Quade
2005-11-28 12:46   ` Nikita Danilov
2005-11-28 13:09     ` linux-os (Dick Johnson)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox