QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 940|回复: 0

添加新系统调用的问题

[复制链接]
发表于 2005-4-15 17:26:54 | 显示全部楼层 |阅读模式
往内核里添加一个新的系统调用,功能是拷贝文件
系统调用的代码为
asmlinkage int sys_copy(int source, int target)
{
    int BUFFSIZE=8192;
    int n;
    char buf[BUFFSIZE];
   
    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[1], O_RDONLY) ) < 0)
        err_say("Open source file error!");
    if ( (fd2 = open(argv[2], 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

请问是什么地方出了问题?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-6-29 08:15 , Processed in 0.089823 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表