添加新系统调用的问题
往内核里添加一个新的系统调用,功能是拷贝文件系统调用的代码为
asmlinkage int sys_copy(int source, int target)
{
int BUFFSIZE=8192;
int n;
char buf;
while ( (n = sys_read(source, buf, BUFFSIZE)) > 0)
if (sys_write(target, buf, n) != n)
return -1;
if (n < 0)
return -1;
return 1;
}
测试用的代码为
void
err_say(char* output)
{
printf("%s\n", output);
exit(1);
}
int
main(int argc, char* argv[])
{
int fd1,fd2;
int c;
if (argc!=3)
err_say("Usage:copy <source file> <target file>");
if ( (fd1 = open(argv, O_RDONLY) ) < 0)
err_say("Open source file error!");
if ( (fd2 = open(argv, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH) ) < 0)
err_say("Open target file error!");
c = copy(fd1, fd2);
if (c < 0)
err_say("File copy failed!\n");
else
printf("File copy success.\n");
close(fd1);
close(fd2);
exit(0);
}
结果测试时提示
Kernel panic:Aiee , killing interrupt handler!
In interrupt handler - not syncing
请问是什么地方出了问题?
页:
[1]