4 * Copyright (C) 1991, 1992 Linus Torvalds
8 #include <linux/smp_lock.h>
9 #include <linux/file.h>
11 #include <asm/uaccess.h>
13 static int file_ioctl(struct file
*filp
,unsigned int cmd
,unsigned long arg
)
17 struct inode
* inode
= filp
->f_dentry
->d_inode
;
22 struct address_space
*mapping
= inode
->i_mapping
;
24 /* do we support this mess? */
25 if (!mapping
->a_ops
->bmap
)
27 if (!capable(CAP_SYS_RAWIO
))
29 if ((error
= get_user(block
, (int *) arg
)) != 0)
32 res
= mapping
->a_ops
->bmap(mapping
, block
);
33 return put_user(res
, (int *) arg
);
36 if (inode
->i_sb
== NULL
)
38 return put_user(inode
->i_sb
->s_blocksize
, (int *) arg
);
40 return put_user(inode
->i_size
- filp
->f_pos
, (int *) arg
);
42 if (filp
->f_op
&& filp
->f_op
->ioctl
)
43 return filp
->f_op
->ioctl(inode
, filp
, cmd
, arg
);
48 asmlinkage
long sys_ioctl(unsigned int fd
, unsigned int cmd
, unsigned long arg
)
52 int on
, error
= -EBADF
;
61 FD_SET(fd
, current
->files
->close_on_exec
);
65 FD_CLR(fd
, current
->files
->close_on_exec
);
69 if ((error
= get_user(on
, (int *)arg
)) != 0)
73 /* SunOS compatibility item. */
74 if(O_NONBLOCK
!= O_NDELAY
)
78 filp
->f_flags
|= flag
;
80 filp
->f_flags
&= ~flag
;
84 if ((error
= get_user(on
, (int *)arg
)) != 0)
86 flag
= on
? FASYNC
: 0;
88 /* Did FASYNC state change ? */
89 if ((flag
^ filp
->f_flags
) & FASYNC
) {
90 if (filp
->f_op
&& filp
->f_op
->fasync
)
91 error
= filp
->f_op
->fasync(fd
, filp
, on
);
98 filp
->f_flags
|= FASYNC
;
100 filp
->f_flags
&= ~FASYNC
;
105 if (S_ISREG(filp
->f_dentry
->d_inode
->i_mode
))
106 error
= file_ioctl(filp
, cmd
, arg
);
107 else if (filp
->f_op
&& filp
->f_op
->ioctl
)
108 error
= filp
->f_op
->ioctl(filp
->f_dentry
->d_inode
, filp
, cmd
, arg
);