This source file includes following definitions.
- file_ioctl
- sys_ioctl
1
2
3
4
5
6
7 #include <asm/segment.h>
8
9 #include <linux/sched.h>
10 #include <linux/mm.h>
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/termios.h>
15 #include <linux/fcntl.h>
16
17 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
18 {
19 int error;
20 int block;
21
22 switch (cmd) {
23 case FIBMAP:
24 if (filp->f_inode->i_op == NULL)
25 return -EBADF;
26 if (filp->f_inode->i_op->bmap == NULL)
27 return -EINVAL;
28 error = verify_area(VERIFY_WRITE,(void *) arg,4);
29 if (error)
30 return error;
31 block = get_fs_long((long *) arg);
32 block = filp->f_inode->i_op->bmap(filp->f_inode,block);
33 put_fs_long(block,(long *) arg);
34 return 0;
35 case FIGETBSZ:
36 if (filp->f_inode->i_sb == NULL)
37 return -EBADF;
38 error = verify_area(VERIFY_WRITE,(void *) arg,4);
39 if (error)
40 return error;
41 put_fs_long(filp->f_inode->i_sb->s_blocksize,
42 (long *) arg);
43 return 0;
44 case FIONREAD:
45 error = verify_area(VERIFY_WRITE,(void *) arg,sizeof(int));
46 if (error)
47 return error;
48 put_fs_long(filp->f_inode->i_size - filp->f_pos,
49 (int *) arg);
50 return 0;
51 }
52 if (filp->f_op && filp->f_op->ioctl)
53 return filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
54 return -EINVAL;
55 }
56
57
58 asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
59 {
60 struct file * filp;
61 int on;
62
63 if (fd >= NR_OPEN || !(filp = current->files->fd[fd]))
64 return -EBADF;
65 switch (cmd) {
66 case FIOCLEX:
67 FD_SET(fd, ¤t->files->close_on_exec);
68 return 0;
69
70 case FIONCLEX:
71 FD_CLR(fd, ¤t->files->close_on_exec);
72 return 0;
73
74 case FIONBIO:
75 on = get_user((unsigned int *) arg);
76 if (on)
77 filp->f_flags |= O_NONBLOCK;
78 else
79 filp->f_flags &= ~O_NONBLOCK;
80 return 0;
81
82 case FIOASYNC:
83
84 on = get_user ((unsigned int *) arg);
85 if (on)
86 filp->f_flags |= O_SYNC;
87 else
88 filp->f_flags &= ~O_SYNC;
89 return 0;
90
91 default:
92 if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
93 return file_ioctl(filp, cmd, arg);
94
95 if (filp->f_op && filp->f_op->ioctl)
96 return filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
97
98 return -EINVAL;
99 }
100 }