Problem creating a new system call

Saurabh Desai (sdesai@ecs.fullerton.edu)
Sat, 11 Oct 1997 09:51:40 -0700 (PDT)


thanks for your reply, friends.
Actually I am sorry for the MISTYPE.

#include <linux/unistd.h>
_syscall2 (int, bdflush, int, mode, int, nr_hints)
^^^^^^^
I never meant to type bdflush. Instead it should have been "prefetch".
That is what is in my code.
_syscall2 (int, prefetch, int, mode, int, nr_hints)
^^^^^^^^
Thanks again.
saurabh desai
<sdesai@ecs.fullerton.edu>

**************** SYSTEM CALL code **********************************
int PREFETCH = 0; /* this is a global variable */

int initialize (int nr_hints)
{
printk ("prefetch routine to be initialized\n");

if (PREFETCH == 1)
return 0;
PREFETCH = 1;
return 1;
}

int terminate ()
{
PREFETCH = 0;
return 1;
}

asmlinkage int sys_prefetch (int mode, int nr_hints)
{
printk ("prefetch system call called\n");

if (mode >= 0)
return initialize (nr_hints);
else
return terminate ();
}
**************** SYSTEM CALL code END**********************************

I included this code in /usr/src/linux/fs/buffer.c
I then added the following line to arch/i386/kernel/entry.S

.long SYMBOL_NAME (sys_prefetch)
and changed
.space (NR_syscalls - 163)*4
to
.space (NR_syscalls - 164)*4

I then added the following line to include/asm/unistd.h
#define __NR_prefetch 164

To execute the sys_prefetch system call, I wrote a prefetch.c file with
the following code.

************************code to call sys_prefetch*****************
#include <linux/unistd.h>
_syscall2 (int, bdflush, int, mode, int, nr_hints)

void main()
{
(few declarations and statements)
return_value = prefetch(1, 100); /* initialize */
printf ("%d", return_value);
}
******************************************************************
This code compiles and runs but always returns a -1 value and does not
even print the messages on the screen that I inserted using printk() in the
system call code in buffer.c

Since the messages are not getting printed, I have no way to know if
the system call is getting called AT ALL !!!

Thanks for reading it. If you have any insights into the problem, please
let me know.

Thanks again.
saurabh desai
<sdesai@ecs.fullerton.edu>