13 #include <linux/capability.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
19 #include <linux/ptrace.h>
20 #include <linux/signal.h>
26 #include <asm/siginfo.h>
27 #include <asm/uaccess.h>
29 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
31 static int setfl(
int fd,
struct file * filp,
unsigned long arg)
59 if (filp->
f_op && filp->
f_op->check_flags)
60 error = filp->
f_op->check_flags(arg);
69 error = filp->
f_op->fasync(fd, filp, (arg & FASYNC) != 0);
77 spin_unlock(&filp->
f_lock);
87 if (force || !filp->
f_owner.pid) {
89 filp->
f_owner.pid = get_pid(pid);
110 f_modown(filp, pid, type, force);
150 static int f_setown_ex(
struct file *filp,
unsigned long arg)
162 switch (
owner.type) {
181 if (
owner.pid && !pid)
190 static int f_getown_ex(
struct file *filp,
unsigned long arg)
198 switch (filp->
f_owner.pid_type) {
226 #ifdef CONFIG_CHECKPOINT_RESTORE
227 static int f_getowner_uids(
struct file *filp,
unsigned long arg)
245 static int f_getowner_uids(
struct file *filp,
unsigned long arg)
251 static long do_fcntl(
int fd,
unsigned int cmd,
unsigned long arg,
274 err = setfl(fd, filp, arg);
298 err = f_getown_ex(filp, arg);
301 err = f_setown_ex(filp, arg);
304 err = f_getowner_uids(filp, arg);
311 if (!valid_signal(arg)) {
336 static int check_fcntl_cmd(
unsigned cmd)
351 struct fd f = fdget_raw(fd);
358 if (!check_fcntl_cmd(cmd))
364 err = do_fcntl(fd, cmd, arg, f.
file);
372 #if BITS_PER_LONG == 32
376 struct fd
f = fdget_raw(fd);
383 if (!check_fcntl_cmd(cmd))
393 err = fcntl_getlk64(f.
file, (
struct flock64 __user *) arg);
397 err = fcntl_setlk64(fd, f.
file, cmd,
398 (
struct flock64 __user *) arg);
401 err = do_fcntl(fd, cmd, arg, f.
file);
413 static const long band_table[
NSIGPOLL] = {
432 uid_eq(fown->
uid, cred->
suid) || uid_eq(fown->
uid, cred->
uid)) &&
438 static void send_sigio_to_task(
struct task_struct *p,
448 if (!sigio_perm(p, fown, signum))
470 si.si_band = band_table[reason -
POLL_IN];
497 goto out_unlock_fown;
501 send_sigio_to_task(p, fown, fd, band, group);
508 static void send_sigurg_to_task(
struct task_struct *p,
511 if (sigio_perm(p, fown,
SIGURG))
533 goto out_unlock_fown;
539 send_sigurg_to_task(p, fown, group);
571 spin_lock(&fasync_lock);
586 spin_unlock(&fasync_lock);
587 spin_unlock(&filp->
f_lock);
618 spin_lock(&fasync_lock);
633 new->fa_next = *fapp;
638 spin_unlock(&fasync_lock);
639 spin_unlock(&filp->
f_lock);
647 static int fasync_add_entry(
int fd,
struct file *filp,
struct fasync_struct **fapp)
680 return fasync_add_entry(fd, filp, fapp);
688 static void kill_fasync_rcu(
struct fasync_struct *
fa,
int sig,
int band)
708 spin_unlock_irqrestore(&fa->
fa_lock, flags);
726 static int __init fcntl_init(
void)