OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [ioctl.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/fs/ioctl.c
3
 *
4
 *  Copyright (C) 1991, 1992  Linus Torvalds
5
 */
6
 
7
#include <asm/segment.h>
8
 
9
#include <linux/sched.h>
10
#include <linux/mm.h>
11
#include <linux/file.h>
12
#include <linux/errno.h>
13
#include <linux/string.h>
14
#include <linux/stat.h>
15
#include <linux/termios.h>
16
#include <linux/fcntl.h> /* for f_flags values */
17
 
18
static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
19
{
20
        int error;
21
        int block;
22
 
23
        switch (cmd) {
24
                case FIBMAP:
25
                        if (filp->f_inode->i_op == NULL)
26
                                return -EBADF;
27
                        if (filp->f_inode->i_op->bmap == NULL)
28
                                return -EINVAL;
29
                        error = verify_area(VERIFY_WRITE,(void *) arg,4);
30
                        if (error)
31
                                return error;
32
                        block = get_fs_long((long *) arg);
33
                        block = filp->f_inode->i_op->bmap(filp->f_inode,block);
34
                        put_fs_long(block,(long *) arg);
35
                        return 0;
36
                case FIGETBSZ:
37
                        if (filp->f_inode->i_sb == NULL)
38
                                return -EBADF;
39
                        error = verify_area(VERIFY_WRITE,(void *) arg,4);
40
                        if (error)
41
                                return error;
42
                        put_fs_long(filp->f_inode->i_sb->s_blocksize,
43
                            (long *) arg);
44
                        return 0;
45
                case FIONREAD:
46
                        error = verify_area(VERIFY_WRITE,(void *) arg,sizeof(int));
47
                        if (error)
48
                                return error;
49
                        put_fs_long(filp->f_inode->i_size - filp->f_pos,
50
                            (int *) arg);
51
                        return 0;
52
        }
53
        if (filp->f_op && filp->f_op->ioctl)
54
                return filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
55
        return -ENOTTY;
56
}
57
 
58
 
59
asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
60
{
61
        struct file * filp;
62
        int on;
63
        int retval = 0;
64
 
65
        filp = fget(fd);
66
 
67
        if(filp==NULL)
68
                return -EBADF;
69
 
70
        switch (cmd) {
71
                case FIOCLEX:
72
                        FD_SET(fd, &current->files->close_on_exec);
73
                        break;
74
 
75
                case FIONCLEX:
76
                        FD_CLR(fd, &current->files->close_on_exec);
77
                        break;
78
 
79
                case FIONBIO:
80
                        retval = verify_area(VERIFY_READ, (unsigned int *)arg,
81
                                sizeof(unsigned int));
82
                        if(!retval)
83
                        {
84
                                on = get_user((unsigned int *) arg);
85
                                if (on)
86
                                        filp->f_flags |= O_NONBLOCK;
87
                                else
88
                                        filp->f_flags &= ~O_NONBLOCK;
89
                        }
90
                        break;
91
 
92
                case FIOASYNC: /* O_SYNC is not yet implemented,
93
                                  but it's here for completeness. */
94
                        retval = verify_area(VERIFY_READ, (unsigned int *)arg,
95
                                sizeof(unsigned int));
96
                        if(!retval)
97
                        {
98
                                on = get_user ((unsigned int *) arg);
99
                                if (on)
100
                                        filp->f_flags |= O_SYNC;
101
                                else
102
                                        filp->f_flags &= ~O_SYNC;
103
                        }
104
                        break;
105
 
106
                default:
107
                        if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
108
                                retval = file_ioctl(filp, cmd, arg);
109
                        else if (filp->f_op && filp->f_op->ioctl)
110
                                retval = filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
111
                        else
112
                                retval = -ENOTTY;
113
        }
114
        fput(filp, filp->f_inode);
115
        return retval;
116
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.