fcntl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * linux/fs/fcntl.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. #include <linux/syscalls.h>
  7. #include <linux/init.h>
  8. #include <linux/mm.h>
  9. #include <linux/fs.h>
  10. #include <linux/file.h>
  11. #include <linux/fdtable.h>
  12. #include <linux/capability.h>
  13. #include <linux/dnotify.h>
  14. #include <linux/slab.h>
  15. #include <linux/module.h>
  16. #include <linux/pipe_fs_i.h>
  17. #include <linux/security.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/signal.h>
  20. #include <linux/rcupdate.h>
  21. #include <linux/pid_namespace.h>
  22. #include <linux/user_namespace.h>
  23. #include <asm/poll.h>
  24. #include <asm/siginfo.h>
  25. #include <asm/uaccess.h>
  26. #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
  27. static int setfl(int fd, struct file * filp, unsigned long arg)
  28. {
  29. struct inode * inode = file_inode(filp);
  30. int error = 0;
  31. /*
  32. * O_APPEND cannot be cleared if the file is marked as append-only
  33. * and the file is open for write.
  34. */
  35. if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode))
  36. return -EPERM;
  37. /* O_NOATIME can only be set by the owner or superuser */
  38. if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME))
  39. if (!inode_owner_or_capable(inode))
  40. return -EPERM;
  41. /* required for strict SunOS emulation */
  42. if (O_NONBLOCK != O_NDELAY)
  43. if (arg & O_NDELAY)
  44. arg |= O_NONBLOCK;
  45. if (arg & O_DIRECT) {
  46. if (!filp->f_mapping || !filp->f_mapping->a_ops ||
  47. !filp->f_mapping->a_ops->direct_IO)
  48. return -EINVAL;
  49. }
  50. if (filp->f_op->check_flags)
  51. error = filp->f_op->check_flags(arg);
  52. if (error)
  53. return error;
  54. /*
  55. * ->fasync() is responsible for setting the FASYNC bit.
  56. */
  57. if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op->fasync) {
  58. error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
  59. if (error < 0)
  60. goto out;
  61. if (error > 0)
  62. error = 0;
  63. }
  64. spin_lock(&filp->f_lock);
  65. filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
  66. spin_unlock(&filp->f_lock);
  67. out:
  68. return error;
  69. }
  70. static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
  71. int force)
  72. {
  73. write_lock_irq(&filp->f_owner.lock);
  74. if (force || !filp->f_owner.pid) {
  75. put_pid(filp->f_owner.pid);
  76. filp->f_owner.pid = get_pid(pid);
  77. filp->f_owner.pid_type = type;
  78. if (pid) {
  79. const struct cred *cred = current_cred();
  80. filp->f_owner.uid = cred->uid;
  81. filp->f_owner.euid = cred->euid;
  82. }
  83. }
  84. write_unlock_irq(&filp->f_owner.lock);
  85. }
  86. int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
  87. int force)
  88. {
  89. int err;
  90. err = security_file_set_fowner(filp);
  91. if (err)
  92. return err;
  93. f_modown(filp, pid, type, force);
  94. return 0;
  95. }
  96. EXPORT_SYMBOL(__f_setown);
  97. int f_setown(struct file *filp, unsigned long arg, int force)
  98. {
  99. enum pid_type type;
  100. struct pid *pid;
  101. int who = arg;
  102. int result;
  103. type = PIDTYPE_PID;
  104. if (who < 0) {
  105. type = PIDTYPE_PGID;
  106. who = -who;
  107. }
  108. rcu_read_lock();
  109. pid = find_vpid(who);
  110. result = __f_setown(filp, pid, type, force);
  111. rcu_read_unlock();
  112. return result;
  113. }
  114. EXPORT_SYMBOL(f_setown);
  115. void f_delown(struct file *filp)
  116. {
  117. f_modown(filp, NULL, PIDTYPE_PID, 1);
  118. }
  119. pid_t f_getown(struct file *filp)
  120. {
  121. pid_t pid;
  122. read_lock(&filp->f_owner.lock);
  123. pid = pid_vnr(filp->f_owner.pid);
  124. if (filp->f_owner.pid_type == PIDTYPE_PGID)
  125. pid = -pid;
  126. read_unlock(&filp->f_owner.lock);
  127. return pid;
  128. }
  129. static int f_setown_ex(struct file *filp, unsigned long arg)
  130. {
  131. struct f_owner_ex __user *owner_p = (void __user *)arg;
  132. struct f_owner_ex owner;
  133. struct pid *pid;
  134. int type;
  135. int ret;
  136. ret = copy_from_user(&owner, owner_p, sizeof(owner));
  137. if (ret)
  138. return -EFAULT;
  139. switch (owner.type) {
  140. case F_OWNER_TID:
  141. type = PIDTYPE_MAX;
  142. break;
  143. case F_OWNER_PID:
  144. type = PIDTYPE_PID;
  145. break;
  146. case F_OWNER_PGRP:
  147. type = PIDTYPE_PGID;
  148. break;
  149. default:
  150. return -EINVAL;
  151. }
  152. rcu_read_lock();
  153. pid = find_vpid(owner.pid);
  154. if (owner.pid && !pid)
  155. ret = -ESRCH;
  156. else
  157. ret = __f_setown(filp, pid, type, 1);
  158. rcu_read_unlock();
  159. return ret;
  160. }
  161. static int f_getown_ex(struct file *filp, unsigned long arg)
  162. {
  163. struct f_owner_ex __user *owner_p = (void __user *)arg;
  164. struct f_owner_ex owner;
  165. int ret = 0;
  166. read_lock(&filp->f_owner.lock);
  167. owner.pid = pid_vnr(filp->f_owner.pid);
  168. switch (filp->f_owner.pid_type) {
  169. case PIDTYPE_MAX:
  170. owner.type = F_OWNER_TID;
  171. break;
  172. case PIDTYPE_PID:
  173. owner.type = F_OWNER_PID;
  174. break;
  175. case PIDTYPE_PGID:
  176. owner.type = F_OWNER_PGRP;
  177. break;
  178. default:
  179. WARN_ON(1);
  180. ret = -EINVAL;
  181. break;
  182. }
  183. read_unlock(&filp->f_owner.lock);
  184. if (!ret) {
  185. ret = copy_to_user(owner_p, &owner, sizeof(owner));
  186. if (ret)
  187. ret = -EFAULT;
  188. }
  189. return ret;
  190. }
  191. #ifdef CONFIG_CHECKPOINT_RESTORE
  192. static int f_getowner_uids(struct file *filp, unsigned long arg)
  193. {
  194. struct user_namespace *user_ns = current_user_ns();
  195. uid_t __user *dst = (void __user *)arg;
  196. uid_t src[2];
  197. int err;
  198. read_lock(&filp->f_owner.lock);
  199. src[0] = from_kuid(user_ns, filp->f_owner.uid);
  200. src[1] = from_kuid(user_ns, filp->f_owner.euid);
  201. read_unlock(&filp->f_owner.lock);
  202. err = put_user(src[0], &dst[0]);
  203. err |= put_user(src[1], &dst[1]);
  204. return err;
  205. }
  206. #else
  207. static int f_getowner_uids(struct file *filp, unsigned long arg)
  208. {
  209. return -EINVAL;
  210. }
  211. #endif
  212. static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
  213. struct file *filp)
  214. {
  215. long err = -EINVAL;
  216. switch (cmd) {
  217. case F_DUPFD:
  218. err = f_dupfd(arg, filp, 0);
  219. break;
  220. case F_DUPFD_CLOEXEC:
  221. err = f_dupfd(arg, filp, O_CLOEXEC);
  222. break;
  223. case F_GETFD:
  224. err = get_close_on_exec(fd) ? FD_CLOEXEC : 0;
  225. break;
  226. case F_SETFD:
  227. err = 0;
  228. set_close_on_exec(fd, arg & FD_CLOEXEC);
  229. break;
  230. case F_GETFL:
  231. err = filp->f_flags;
  232. break;
  233. case F_SETFL:
  234. err = setfl(fd, filp, arg);
  235. break;
  236. case F_GETLK:
  237. err = fcntl_getlk(filp, (struct flock __user *) arg);
  238. break;
  239. case F_SETLK:
  240. case F_SETLKW:
  241. err = fcntl_setlk(fd, filp, cmd, (struct flock __user *) arg);
  242. break;
  243. case F_GETOWN:
  244. /*
  245. * XXX If f_owner is a process group, the
  246. * negative return value will get converted
  247. * into an error. Oops. If we keep the
  248. * current syscall conventions, the only way
  249. * to fix this will be in libc.
  250. */
  251. err = f_getown(filp);
  252. force_successful_syscall_return();
  253. break;
  254. case F_SETOWN:
  255. err = f_setown(filp, arg, 1);
  256. break;
  257. case F_GETOWN_EX:
  258. err = f_getown_ex(filp, arg);
  259. break;
  260. case F_SETOWN_EX:
  261. err = f_setown_ex(filp, arg);
  262. break;
  263. case F_GETOWNER_UIDS:
  264. err = f_getowner_uids(filp, arg);
  265. break;
  266. case F_GETSIG:
  267. err = filp->f_owner.signum;
  268. break;
  269. case F_SETSIG:
  270. /* arg == 0 restores default behaviour. */
  271. if (!valid_signal(arg)) {
  272. break;
  273. }
  274. err = 0;
  275. filp->f_owner.signum = arg;
  276. break;
  277. case F_GETLEASE:
  278. err = fcntl_getlease(filp);
  279. break;
  280. case F_SETLEASE:
  281. err = fcntl_setlease(fd, filp, arg);
  282. break;
  283. case F_NOTIFY:
  284. err = fcntl_dirnotify(fd, filp, arg);
  285. break;
  286. case F_SETPIPE_SZ:
  287. case F_GETPIPE_SZ:
  288. err = pipe_fcntl(filp, cmd, arg);
  289. break;
  290. default:
  291. break;
  292. }
  293. return err;
  294. }
  295. static int check_fcntl_cmd(unsigned cmd)
  296. {
  297. switch (cmd) {
  298. case F_DUPFD:
  299. case F_DUPFD_CLOEXEC:
  300. case F_GETFD:
  301. case F_SETFD:
  302. case F_GETFL:
  303. return 1;
  304. }
  305. return 0;
  306. }
  307. SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
  308. {
  309. struct fd f = fdget_raw(fd);
  310. long err = -EBADF;
  311. if (!f.file)
  312. goto out;
  313. if (unlikely(f.file->f_mode & FMODE_PATH)) {
  314. if (!check_fcntl_cmd(cmd))
  315. goto out1;
  316. }
  317. err = security_file_fcntl(f.file, cmd, arg);
  318. if (!err)
  319. err = do_fcntl(fd, cmd, arg, f.file);
  320. out1:
  321. fdput(f);
  322. out:
  323. return err;
  324. }
  325. #if BITS_PER_LONG == 32
  326. SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
  327. unsigned long, arg)
  328. {
  329. struct fd f = fdget_raw(fd);
  330. long err = -EBADF;
  331. if (!f.file)
  332. goto out;
  333. if (unlikely(f.file->f_mode & FMODE_PATH)) {
  334. if (!check_fcntl_cmd(cmd))
  335. goto out1;
  336. }
  337. err = security_file_fcntl(f.file, cmd, arg);
  338. if (err)
  339. goto out1;
  340. switch (cmd) {
  341. case F_GETLK64:
  342. err = fcntl_getlk64(f.file, (struct flock64 __user *) arg);
  343. break;
  344. case F_SETLK64:
  345. case F_SETLKW64:
  346. err = fcntl_setlk64(fd, f.file, cmd,
  347. (struct flock64 __user *) arg);
  348. break;
  349. default:
  350. err = do_fcntl(fd, cmd, arg, f.file);
  351. break;
  352. }
  353. out1:
  354. fdput(f);
  355. out:
  356. return err;
  357. }
  358. #endif
  359. /* Table to convert sigio signal codes into poll band bitmaps */
  360. static const long band_table[NSIGPOLL] = {
  361. POLLIN | POLLRDNORM, /* POLL_IN */
  362. POLLOUT | POLLWRNORM | POLLWRBAND, /* POLL_OUT */
  363. POLLIN | POLLRDNORM | POLLMSG, /* POLL_MSG */
  364. POLLERR, /* POLL_ERR */
  365. POLLPRI | POLLRDBAND, /* POLL_PRI */
  366. POLLHUP | POLLERR /* POLL_HUP */
  367. };
  368. static inline int sigio_perm(struct task_struct *p,
  369. struct fown_struct *fown, int sig)
  370. {
  371. const struct cred *cred;
  372. int ret;
  373. rcu_read_lock();
  374. cred = __task_cred(p);
  375. ret = ((uid_eq(fown->euid, GLOBAL_ROOT_UID) ||
  376. uid_eq(fown->euid, cred->suid) || uid_eq(fown->euid, cred->uid) ||
  377. uid_eq(fown->uid, cred->suid) || uid_eq(fown->uid, cred->uid)) &&
  378. !security_file_send_sigiotask(p, fown, sig));
  379. rcu_read_unlock();
  380. return ret;
  381. }
  382. static void send_sigio_to_task(struct task_struct *p,
  383. struct fown_struct *fown,
  384. int fd, int reason, int group)
  385. {
  386. /*
  387. * F_SETSIG can change ->signum lockless in parallel, make
  388. * sure we read it once and use the same value throughout.
  389. */
  390. int signum = ACCESS_ONCE(fown->signum);
  391. if (!sigio_perm(p, fown, signum))
  392. return;
  393. switch (signum) {
  394. siginfo_t si;
  395. default:
  396. /* Queue a rt signal with the appropriate fd as its
  397. value. We use SI_SIGIO as the source, not
  398. SI_KERNEL, since kernel signals always get
  399. delivered even if we can't queue. Failure to
  400. queue in this case _should_ be reported; we fall
  401. back to SIGIO in that case. --sct */
  402. si.si_signo = signum;
  403. si.si_errno = 0;
  404. si.si_code = reason;
  405. /* Make sure we are called with one of the POLL_*
  406. reasons, otherwise we could leak kernel stack into
  407. userspace. */
  408. BUG_ON((reason & __SI_MASK) != __SI_POLL);
  409. if (reason - POLL_IN >= NSIGPOLL)
  410. si.si_band = ~0L;
  411. else
  412. si.si_band = band_table[reason - POLL_IN];
  413. si.si_fd = fd;
  414. if (!do_send_sig_info(signum, &si, p, group))
  415. break;
  416. /* fall-through: fall back on the old plain SIGIO signal */
  417. case 0:
  418. do_send_sig_info(SIGIO, SEND_SIG_PRIV, p, group);
  419. }
  420. }
  421. void send_sigio(struct fown_struct *fown, int fd, int band)
  422. {
  423. struct task_struct *p;
  424. enum pid_type type;
  425. struct pid *pid;
  426. int group = 1;
  427. read_lock(&fown->lock);
  428. type = fown->pid_type;
  429. if (type == PIDTYPE_MAX) {
  430. group = 0;
  431. type = PIDTYPE_PID;
  432. }
  433. pid = fown->pid;
  434. if (!pid)
  435. goto out_unlock_fown;
  436. read_lock(&tasklist_lock);
  437. do_each_pid_task(pid, type, p) {
  438. send_sigio_to_task(p, fown, fd, band, group);
  439. } while_each_pid_task(pid, type, p);
  440. read_unlock(&tasklist_lock);
  441. out_unlock_fown:
  442. read_unlock(&fown->lock);
  443. }
  444. static void send_sigurg_to_task(struct task_struct *p,
  445. struct fown_struct *fown, int group)
  446. {
  447. if (sigio_perm(p, fown, SIGURG))
  448. do_send_sig_info(SIGURG, SEND_SIG_PRIV, p, group);
  449. }
  450. int send_sigurg(struct fown_struct *fown)
  451. {
  452. struct task_struct *p;
  453. enum pid_type type;
  454. struct pid *pid;
  455. int group = 1;
  456. int ret = 0;
  457. read_lock(&fown->lock);
  458. type = fown->pid_type;
  459. if (type == PIDTYPE_MAX) {
  460. group = 0;
  461. type = PIDTYPE_PID;
  462. }
  463. pid = fown->pid;
  464. if (!pid)
  465. goto out_unlock_fown;
  466. ret = 1;
  467. read_lock(&tasklist_lock);
  468. do_each_pid_task(pid, type, p) {
  469. send_sigurg_to_task(p, fown, group);
  470. } while_each_pid_task(pid, type, p);
  471. read_unlock(&tasklist_lock);
  472. out_unlock_fown:
  473. read_unlock(&fown->lock);
  474. return ret;
  475. }
  476. static DEFINE_SPINLOCK(fasync_lock);
  477. static struct kmem_cache *fasync_cache __read_mostly;
  478. static void fasync_free_rcu(struct rcu_head *head)
  479. {
  480. kmem_cache_free(fasync_cache,
  481. container_of(head, struct fasync_struct, fa_rcu));
  482. }
  483. /*
  484. * Remove a fasync entry. If successfully removed, return
  485. * positive and clear the FASYNC flag. If no entry exists,
  486. * do nothing and return 0.
  487. *
  488. * NOTE! It is very important that the FASYNC flag always
  489. * match the state "is the filp on a fasync list".
  490. *
  491. */
  492. int fasync_remove_entry(struct file *filp, struct fasync_struct **fapp)
  493. {
  494. struct fasync_struct *fa, **fp;
  495. int result = 0;
  496. spin_lock(&filp->f_lock);
  497. spin_lock(&fasync_lock);
  498. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  499. if (fa->fa_file != filp)
  500. continue;
  501. spin_lock_irq(&fa->fa_lock);
  502. fa->fa_file = NULL;
  503. spin_unlock_irq(&fa->fa_lock);
  504. *fp = fa->fa_next;
  505. call_rcu(&fa->fa_rcu, fasync_free_rcu);
  506. filp->f_flags &= ~FASYNC;
  507. result = 1;
  508. break;
  509. }
  510. spin_unlock(&fasync_lock);
  511. spin_unlock(&filp->f_lock);
  512. return result;
  513. }
  514. struct fasync_struct *fasync_alloc(void)
  515. {
  516. return kmem_cache_alloc(fasync_cache, GFP_KERNEL);
  517. }
  518. /*
  519. * NOTE! This can be used only for unused fasync entries:
  520. * entries that actually got inserted on the fasync list
  521. * need to be released by rcu - see fasync_remove_entry.
  522. */
  523. void fasync_free(struct fasync_struct *new)
  524. {
  525. kmem_cache_free(fasync_cache, new);
  526. }
  527. /*
  528. * Insert a new entry into the fasync list. Return the pointer to the
  529. * old one if we didn't use the new one.
  530. *
  531. * NOTE! It is very important that the FASYNC flag always
  532. * match the state "is the filp on a fasync list".
  533. */
  534. struct fasync_struct *fasync_insert_entry(int fd, struct file *filp, struct fasync_struct **fapp, struct fasync_struct *new)
  535. {
  536. struct fasync_struct *fa, **fp;
  537. spin_lock(&filp->f_lock);
  538. spin_lock(&fasync_lock);
  539. for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
  540. if (fa->fa_file != filp)
  541. continue;
  542. spin_lock_irq(&fa->fa_lock);
  543. fa->fa_fd = fd;
  544. spin_unlock_irq(&fa->fa_lock);
  545. goto out;
  546. }
  547. spin_lock_init(&new->fa_lock);
  548. new->magic = FASYNC_MAGIC;
  549. new->fa_file = filp;
  550. new->fa_fd = fd;
  551. new->fa_next = *fapp;
  552. rcu_assign_pointer(*fapp, new);
  553. filp->f_flags |= FASYNC;
  554. out:
  555. spin_unlock(&fasync_lock);
  556. spin_unlock(&filp->f_lock);
  557. return fa;
  558. }
  559. /*
  560. * Add a fasync entry. Return negative on error, positive if
  561. * added, and zero if did nothing but change an existing one.
  562. */
  563. static int fasync_add_entry(int fd, struct file *filp, struct fasync_struct **fapp)
  564. {
  565. struct fasync_struct *new;
  566. new = fasync_alloc();
  567. if (!new)
  568. return -ENOMEM;
  569. /*
  570. * fasync_insert_entry() returns the old (update) entry if
  571. * it existed.
  572. *
  573. * So free the (unused) new entry and return 0 to let the
  574. * caller know that we didn't add any new fasync entries.
  575. */
  576. if (fasync_insert_entry(fd, filp, fapp, new)) {
  577. fasync_free(new);
  578. return 0;
  579. }
  580. return 1;
  581. }
  582. /*
  583. * fasync_helper() is used by almost all character device drivers
  584. * to set up the fasync queue, and for regular files by the file
  585. * lease code. It returns negative on error, 0 if it did no changes
  586. * and positive if it added/deleted the entry.
  587. */
  588. int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fapp)
  589. {
  590. if (!on)
  591. return fasync_remove_entry(filp, fapp);
  592. return fasync_add_entry(fd, filp, fapp);
  593. }
  594. EXPORT_SYMBOL(fasync_helper);
  595. /*
  596. * rcu_read_lock() is held
  597. */
  598. static void kill_fasync_rcu(struct fasync_struct *fa, int sig, int band)
  599. {
  600. while (fa) {
  601. struct fown_struct *fown;
  602. unsigned long flags;
  603. if (fa->magic != FASYNC_MAGIC) {
  604. printk(KERN_ERR "kill_fasync: bad magic number in "
  605. "fasync_struct!\n");
  606. return;
  607. }
  608. spin_lock_irqsave(&fa->fa_lock, flags);
  609. if (fa->fa_file) {
  610. fown = &fa->fa_file->f_owner;
  611. /* Don't send SIGURG to processes which have not set a
  612. queued signum: SIGURG has its own default signalling
  613. mechanism. */
  614. if (!(sig == SIGURG && fown->signum == 0))
  615. send_sigio(fown, fa->fa_fd, band);
  616. }
  617. spin_unlock_irqrestore(&fa->fa_lock, flags);
  618. fa = rcu_dereference(fa->fa_next);
  619. }
  620. }
  621. void kill_fasync(struct fasync_struct **fp, int sig, int band)
  622. {
  623. /* First a quick test without locking: usually
  624. * the list is empty.
  625. */
  626. if (*fp) {
  627. rcu_read_lock();
  628. kill_fasync_rcu(rcu_dereference(*fp), sig, band);
  629. rcu_read_unlock();
  630. }
  631. }
  632. EXPORT_SYMBOL(kill_fasync);
  633. static int __init fcntl_init(void)
  634. {
  635. /*
  636. * Please add new bits here to ensure allocation uniqueness.
  637. * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY
  638. * is defined as O_NONBLOCK on some platforms and not on others.
  639. */
  640. BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
  641. O_RDONLY | O_WRONLY | O_RDWR |
  642. O_CREAT | O_EXCL | O_NOCTTY |
  643. O_TRUNC | O_APPEND | /* O_NONBLOCK | */
  644. __O_SYNC | O_DSYNC | FASYNC |
  645. O_DIRECT | O_LARGEFILE | O_DIRECTORY |
  646. O_NOFOLLOW | O_NOATIME | O_CLOEXEC |
  647. __FMODE_EXEC | O_PATH | __O_TMPFILE
  648. ));
  649. fasync_cache = kmem_cache_create("fasync_cache",
  650. sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL);
  651. return 0;
  652. }
  653. module_init(fcntl_init)