Chinaunix首页 | 论坛 | 博客
  • 博客访问: 581193
  • 博文数量: 137
  • 博客积分: 4040
  • 博客等级: 上校
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-08 13:05
文章分类

全部博文(137)

文章存档

2011年(10)

2010年(23)

2009年(104)

分类: LINUX

2009-08-05 15:33:29

/*
 * linux/kernel/sys.c
 *
 * (C) 1991 Linus Torvalds
 */


#include <errno.h>

#include <linux/sched.h>
#include <linux/tty.h>
#include <linux/kernel.h>
#include <asm/segment.h>
#include <sys/times.h>
#include <sys/utsname.h>
//返回ENOSYS的函数,表明本系统版本还没有实现的函数

int sys_ftime()//返回时间日期

{
    return -ENOSYS;
}

int sys_break()//

{
    return -ENOSYS;
}

int sys_ptrace()//当前进程对子进程进行调试

{
    return -ENOSYS;
}

int sys_stty()//修改并打引终端行设置

{
    return -ENOSYS;
}

int sys_gtty()//取得终端行信息

{
    return -ENOSYS;
}

int sys_rename()//修改文件名

{
    return -ENOSYS;
}

int sys_prof()//程序执行时间区域。

{
    return -ENOSYS;
}

int sys_setregid(int rgid, int egid)//设置当前任务的实际以及有效组ID

{
    if (rgid>0) {
        if ((current->gid == rgid) ||
         suser())//是否为超级用户

            current->gid = rgid;
        else
            return(-EPERM);
    }
    if (egid>0) {
        if ((current->gid == egid) ||
         (current->egid == egid) ||
         (current->sgid == egid) ||
         suser())//是否为超级用户

            current->egid = egid;
        else
            return(-EPERM);
    }
    return 0;
}

int sys_setgid(int gid)//设置进程组号

{
    return(sys_setregid(gid, gid));
}

int sys_acct()//打开关闭进程记帐功能

{
    return -ENOSYS;
}

int sys_phys()//映射任意物理内存到进程的虚拟空间

{
    return -ENOSYS;
}

int sys_lock()//

{
    return -ENOSYS;
}

int sys_mpx()//

{
    return -ENOSYS;
}

int sys_ulimit()//

{
    return -ENOSYS;
}

int sys_time(long * tloc)//取当前时间,从1970年1月1日0点0分0秒开始

{
    int i;

    i = CURRENT_TIME;
    if (tloc) {
        verify_area(tloc,4);//验证内存容量

        put_fs_long(i,(unsigned long *)tloc);//存入数据 段tloc中

    }
    return i;
}

/*
 * Unprivileged users may change the real user id to the effective uid
 * or vice versa.
 */

int sys_setreuid(int ruid, int euid)//设置进程的实际以及有效的用户ID

{
    int old_ruid = current->uid;
    
    if (ruid>0) {
        if ((current->euid==ruid) ||
                    (old_ruid == ruid) ||
         suser())//超级用户

            current->uid = ruid;
        else
            return(-EPERM);
    }
    if (euid>0) {
        if ((old_ruid == euid) ||
                    (current->euid == euid) ||
         suser())//超级用户

            current->euid = euid;
        else {
            current->uid = old_ruid;
            return(-EPERM);
        }
    }
    return 0;
}

int sys_setuid(int uid)//设置用户ID

{
    return(sys_setreuid(uid, uid));
}

int sys_stime(long * tptr)//设置系统开机时间,参数tptr为从1970年1月1日0点0分0秒开始的时间值

{
    if (!suser())
        return -EPERM;
    startup_time = get_fs_long((unsigned long *)tptr) - jiffies/HZ;//当前时间值减去系统运行的时间值,也就是系统开机的霎时间值,其中HZ=100,为系统运行频率

    return 0;
}

int sys_times(struct tms * tbuf)//取得当前任务运行时间统计值

{
    if (tbuf) {
        verify_area(tbuf,sizeof *tbuf);
        put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime);//用户运行时间

        put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime);//内核运行时间

        put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime);//子进程用户运行时间

        put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime);//子进程内核运行时间

    }
    return jiffies;
}

int sys_brk(unsigned long end_data_seg)//修改数据段长度

{
    if (end_data_seg >= current->end_code &&
     end_data_seg < current->start_stack - 16384)
        current->brk = end_data_seg;
    return current->brk;
}

/*
 * This needs some heave checking ...
 * I just haven't get the stomach for it. I also don't fully
 * understand sessions/pgrp etc. Let somebody who does explain it.
 */

int sys_setpgid(int pid, int pgid)//设置进程组ID

{
    int i;

    if (!pid)
        pid = current->pid;
    if (!pgid)
        pgid = current->pid;
    for (i=0 ; i<NR_TASKS ; i++)
        if (task[i] && task[i]->pid==pid) {
            if (task[i]->leader)
                return -EPERM;
            if (task[i]->session != current->session)
                return -EPERM;
            task[i]->pgrp = pgid;
            return 0;
        }
    return -ESRCH;
}

int sys_getpgrp(void)//返回当前进程 的进程组号

{
    return current->pgrp;
}

int sys_setsid(void)//创建一个会 话

{
    if (current->leader && !suser())
        return -EPERM;
    current->leader = 1;
    current->session = current->pgrp = current->pid;//会话号==组号==进程号

    current->tty = -1;
    return current->pgrp;
}

int sys_uname(struct utsname * name)//取得系统相关信息

{
    static struct utsname thisname = {
        "linux .0","nodename","release ","version ","machine "
    };
    int i;

    if (!name) return -ERROR;
    verify_area(name,sizeof *name);//验证内存空间

    for(i=0;i<sizeof *name;i++)
        put_fs_byte(((char *) &thisname)[i],i+(char *) name);//将utsname 中的信息逐字节复制到用户缓冲区中

    return 0;
}

int sys_umask(int mask)//设置当前进程文件属性屏蔽码

{
    int old = current->umask;

    current->umask = mask & 0777;
    return (old);
}

int sys_newfuction(void)
{    

}

阅读(821) | 评论(0) | 转发(0) |
0

上一篇:fork.c

下一篇:vsprintf.c

给主人留下些什么吧!~~