inode.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /* -*- linux-c -*- --------------------------------------------------------- *
  2. *
  3. * linux/fs/devpts/inode.c
  4. *
  5. * Copyright 1998-2004 H. Peter Anvin -- All Rights Reserved
  6. *
  7. * This file is part of the Linux kernel and is made available under
  8. * the terms of the GNU General Public License, version 2, or at your
  9. * option, any later version, incorporated herein by reference.
  10. *
  11. * ------------------------------------------------------------------------- */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/fs.h>
  16. #include <linux/sched.h>
  17. #include <linux/namei.h>
  18. #include <linux/slab.h>
  19. #include <linux/mount.h>
  20. #include <linux/tty.h>
  21. #include <linux/mutex.h>
  22. #include <linux/magic.h>
  23. #include <linux/idr.h>
  24. #include <linux/devpts_fs.h>
  25. #include <linux/parser.h>
  26. #include <linux/fsnotify.h>
  27. #include <linux/seq_file.h>
  28. #define DEVPTS_DEFAULT_MODE 0600
  29. /*
  30. * ptmx is a new node in /dev/pts and will be unused in legacy (single-
  31. * instance) mode. To prevent surprises in user space, set permissions of
  32. * ptmx to 0. Use 'chmod' or remount with '-o ptmxmode' to set meaningful
  33. * permissions.
  34. */
  35. #define DEVPTS_DEFAULT_PTMX_MODE 0000
  36. #define PTMX_MINOR 2
  37. /*
  38. * sysctl support for setting limits on the number of Unix98 ptys allocated.
  39. * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
  40. */
  41. static int pty_limit = NR_UNIX98_PTY_DEFAULT;
  42. static int pty_reserve = NR_UNIX98_PTY_RESERVE;
  43. static int pty_limit_min;
  44. static int pty_limit_max = INT_MAX;
  45. static int pty_count;
  46. static struct ctl_table pty_table[] = {
  47. {
  48. .procname = "max",
  49. .maxlen = sizeof(int),
  50. .mode = 0644,
  51. .data = &pty_limit,
  52. .proc_handler = proc_dointvec_minmax,
  53. .extra1 = &pty_limit_min,
  54. .extra2 = &pty_limit_max,
  55. }, {
  56. .procname = "reserve",
  57. .maxlen = sizeof(int),
  58. .mode = 0644,
  59. .data = &pty_reserve,
  60. .proc_handler = proc_dointvec_minmax,
  61. .extra1 = &pty_limit_min,
  62. .extra2 = &pty_limit_max,
  63. }, {
  64. .procname = "nr",
  65. .maxlen = sizeof(int),
  66. .mode = 0444,
  67. .data = &pty_count,
  68. .proc_handler = proc_dointvec,
  69. },
  70. {}
  71. };
  72. static struct ctl_table pty_kern_table[] = {
  73. {
  74. .procname = "pty",
  75. .mode = 0555,
  76. .child = pty_table,
  77. },
  78. {}
  79. };
  80. static struct ctl_table pty_root_table[] = {
  81. {
  82. .procname = "kernel",
  83. .mode = 0555,
  84. .child = pty_kern_table,
  85. },
  86. {}
  87. };
  88. static DEFINE_MUTEX(allocated_ptys_lock);
  89. static struct vfsmount *devpts_mnt;
  90. struct pts_mount_opts {
  91. int setuid;
  92. int setgid;
  93. kuid_t uid;
  94. kgid_t gid;
  95. umode_t mode;
  96. umode_t ptmxmode;
  97. int newinstance;
  98. int max;
  99. };
  100. enum {
  101. Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance, Opt_max,
  102. Opt_err
  103. };
  104. static const match_table_t tokens = {
  105. {Opt_uid, "uid=%u"},
  106. {Opt_gid, "gid=%u"},
  107. {Opt_mode, "mode=%o"},
  108. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  109. {Opt_ptmxmode, "ptmxmode=%o"},
  110. {Opt_newinstance, "newinstance"},
  111. {Opt_max, "max=%d"},
  112. #endif
  113. {Opt_err, NULL}
  114. };
  115. struct pts_fs_info {
  116. struct ida allocated_ptys;
  117. struct pts_mount_opts mount_opts;
  118. struct dentry *ptmx_dentry;
  119. };
  120. static inline struct pts_fs_info *DEVPTS_SB(struct super_block *sb)
  121. {
  122. return sb->s_fs_info;
  123. }
  124. static inline struct super_block *pts_sb_from_inode(struct inode *inode)
  125. {
  126. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  127. if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
  128. return inode->i_sb;
  129. #endif
  130. return devpts_mnt->mnt_sb;
  131. }
  132. #define PARSE_MOUNT 0
  133. #define PARSE_REMOUNT 1
  134. /*
  135. * parse_mount_options():
  136. * Set @opts to mount options specified in @data. If an option is not
  137. * specified in @data, set it to its default value. The exception is
  138. * 'newinstance' option which can only be set/cleared on a mount (i.e.
  139. * cannot be changed during remount).
  140. *
  141. * Note: @data may be NULL (in which case all options are set to default).
  142. */
  143. static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts)
  144. {
  145. char *p;
  146. kuid_t uid;
  147. kgid_t gid;
  148. opts->setuid = 0;
  149. opts->setgid = 0;
  150. opts->uid = GLOBAL_ROOT_UID;
  151. opts->gid = GLOBAL_ROOT_GID;
  152. opts->mode = DEVPTS_DEFAULT_MODE;
  153. opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
  154. opts->max = NR_UNIX98_PTY_MAX;
  155. /* newinstance makes sense only on initial mount */
  156. if (op == PARSE_MOUNT)
  157. opts->newinstance = 0;
  158. while ((p = strsep(&data, ",")) != NULL) {
  159. substring_t args[MAX_OPT_ARGS];
  160. int token;
  161. int option;
  162. if (!*p)
  163. continue;
  164. token = match_token(p, tokens, args);
  165. switch (token) {
  166. case Opt_uid:
  167. if (match_int(&args[0], &option))
  168. return -EINVAL;
  169. uid = make_kuid(current_user_ns(), option);
  170. if (!uid_valid(uid))
  171. return -EINVAL;
  172. opts->uid = uid;
  173. opts->setuid = 1;
  174. break;
  175. case Opt_gid:
  176. if (match_int(&args[0], &option))
  177. return -EINVAL;
  178. gid = make_kgid(current_user_ns(), option);
  179. if (!gid_valid(gid))
  180. return -EINVAL;
  181. opts->gid = gid;
  182. opts->setgid = 1;
  183. break;
  184. case Opt_mode:
  185. if (match_octal(&args[0], &option))
  186. return -EINVAL;
  187. opts->mode = option & S_IALLUGO;
  188. break;
  189. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  190. case Opt_ptmxmode:
  191. if (match_octal(&args[0], &option))
  192. return -EINVAL;
  193. opts->ptmxmode = option & S_IALLUGO;
  194. break;
  195. case Opt_newinstance:
  196. /* newinstance makes sense only on initial mount */
  197. if (op == PARSE_MOUNT)
  198. opts->newinstance = 1;
  199. break;
  200. case Opt_max:
  201. if (match_int(&args[0], &option) ||
  202. option < 0 || option > NR_UNIX98_PTY_MAX)
  203. return -EINVAL;
  204. opts->max = option;
  205. break;
  206. #endif
  207. default:
  208. pr_err("called with bogus options\n");
  209. return -EINVAL;
  210. }
  211. }
  212. return 0;
  213. }
  214. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  215. static int mknod_ptmx(struct super_block *sb)
  216. {
  217. int mode;
  218. int rc = -ENOMEM;
  219. struct dentry *dentry;
  220. struct inode *inode;
  221. struct dentry *root = sb->s_root;
  222. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  223. struct pts_mount_opts *opts = &fsi->mount_opts;
  224. kuid_t root_uid;
  225. kgid_t root_gid;
  226. root_uid = make_kuid(current_user_ns(), 0);
  227. root_gid = make_kgid(current_user_ns(), 0);
  228. if (!uid_valid(root_uid) || !gid_valid(root_gid))
  229. return -EINVAL;
  230. mutex_lock(&root->d_inode->i_mutex);
  231. /* If we have already created ptmx node, return */
  232. if (fsi->ptmx_dentry) {
  233. rc = 0;
  234. goto out;
  235. }
  236. dentry = d_alloc_name(root, "ptmx");
  237. if (!dentry) {
  238. pr_err("Unable to alloc dentry for ptmx node\n");
  239. goto out;
  240. }
  241. /*
  242. * Create a new 'ptmx' node in this mount of devpts.
  243. */
  244. inode = new_inode(sb);
  245. if (!inode) {
  246. pr_err("Unable to alloc inode for ptmx node\n");
  247. dput(dentry);
  248. goto out;
  249. }
  250. inode->i_ino = 2;
  251. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  252. mode = S_IFCHR|opts->ptmxmode;
  253. init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2));
  254. inode->i_uid = root_uid;
  255. inode->i_gid = root_gid;
  256. d_add(dentry, inode);
  257. fsi->ptmx_dentry = dentry;
  258. rc = 0;
  259. out:
  260. mutex_unlock(&root->d_inode->i_mutex);
  261. return rc;
  262. }
  263. static void update_ptmx_mode(struct pts_fs_info *fsi)
  264. {
  265. struct inode *inode;
  266. if (fsi->ptmx_dentry) {
  267. inode = fsi->ptmx_dentry->d_inode;
  268. inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode;
  269. }
  270. }
  271. #else
  272. static inline void update_ptmx_mode(struct pts_fs_info *fsi)
  273. {
  274. return;
  275. }
  276. #endif
  277. static int devpts_remount(struct super_block *sb, int *flags, char *data)
  278. {
  279. int err;
  280. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  281. struct pts_mount_opts *opts = &fsi->mount_opts;
  282. sync_filesystem(sb);
  283. err = parse_mount_options(data, PARSE_REMOUNT, opts);
  284. /*
  285. * parse_mount_options() restores options to default values
  286. * before parsing and may have changed ptmxmode. So, update the
  287. * mode in the inode too. Bogus options don't fail the remount,
  288. * so do this even on error return.
  289. */
  290. update_ptmx_mode(fsi);
  291. return err;
  292. }
  293. static int devpts_show_options(struct seq_file *seq, struct dentry *root)
  294. {
  295. struct pts_fs_info *fsi = DEVPTS_SB(root->d_sb);
  296. struct pts_mount_opts *opts = &fsi->mount_opts;
  297. if (opts->setuid)
  298. seq_printf(seq, ",uid=%u",
  299. from_kuid_munged(&init_user_ns, opts->uid));
  300. if (opts->setgid)
  301. seq_printf(seq, ",gid=%u",
  302. from_kgid_munged(&init_user_ns, opts->gid));
  303. seq_printf(seq, ",mode=%03o", opts->mode);
  304. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  305. seq_printf(seq, ",ptmxmode=%03o", opts->ptmxmode);
  306. if (opts->max < NR_UNIX98_PTY_MAX)
  307. seq_printf(seq, ",max=%d", opts->max);
  308. #endif
  309. return 0;
  310. }
  311. static const struct super_operations devpts_sops = {
  312. .statfs = simple_statfs,
  313. .remount_fs = devpts_remount,
  314. .show_options = devpts_show_options,
  315. };
  316. static void *new_pts_fs_info(void)
  317. {
  318. struct pts_fs_info *fsi;
  319. fsi = kzalloc(sizeof(struct pts_fs_info), GFP_KERNEL);
  320. if (!fsi)
  321. return NULL;
  322. ida_init(&fsi->allocated_ptys);
  323. fsi->mount_opts.mode = DEVPTS_DEFAULT_MODE;
  324. fsi->mount_opts.ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
  325. return fsi;
  326. }
  327. static int
  328. devpts_fill_super(struct super_block *s, void *data, int silent)
  329. {
  330. struct inode *inode;
  331. s->s_blocksize = 1024;
  332. s->s_blocksize_bits = 10;
  333. s->s_magic = DEVPTS_SUPER_MAGIC;
  334. s->s_op = &devpts_sops;
  335. s->s_time_gran = 1;
  336. s->s_fs_info = new_pts_fs_info();
  337. if (!s->s_fs_info)
  338. goto fail;
  339. inode = new_inode(s);
  340. if (!inode)
  341. goto fail;
  342. inode->i_ino = 1;
  343. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  344. inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
  345. inode->i_op = &simple_dir_inode_operations;
  346. inode->i_fop = &simple_dir_operations;
  347. set_nlink(inode, 2);
  348. s->s_root = d_make_root(inode);
  349. if (s->s_root)
  350. return 0;
  351. pr_err("get root dentry failed\n");
  352. fail:
  353. return -ENOMEM;
  354. }
  355. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  356. static int compare_init_pts_sb(struct super_block *s, void *p)
  357. {
  358. if (devpts_mnt)
  359. return devpts_mnt->mnt_sb == s;
  360. return 0;
  361. }
  362. /*
  363. * devpts_mount()
  364. *
  365. * If the '-o newinstance' mount option was specified, mount a new
  366. * (private) instance of devpts. PTYs created in this instance are
  367. * independent of the PTYs in other devpts instances.
  368. *
  369. * If the '-o newinstance' option was not specified, mount/remount the
  370. * initial kernel mount of devpts. This type of mount gives the
  371. * legacy, single-instance semantics.
  372. *
  373. * The 'newinstance' option is needed to support multiple namespace
  374. * semantics in devpts while preserving backward compatibility of the
  375. * current 'single-namespace' semantics. i.e all mounts of devpts
  376. * without the 'newinstance' mount option should bind to the initial
  377. * kernel mount, like mount_single().
  378. *
  379. * Mounts with 'newinstance' option create a new, private namespace.
  380. *
  381. * NOTE:
  382. *
  383. * For single-mount semantics, devpts cannot use mount_single(),
  384. * because mount_single()/sget() find and use the super-block from
  385. * the most recent mount of devpts. But that recent mount may be a
  386. * 'newinstance' mount and mount_single() would pick the newinstance
  387. * super-block instead of the initial super-block.
  388. */
  389. static struct dentry *devpts_mount(struct file_system_type *fs_type,
  390. int flags, const char *dev_name, void *data)
  391. {
  392. int error;
  393. struct pts_mount_opts opts;
  394. struct super_block *s;
  395. error = parse_mount_options(data, PARSE_MOUNT, &opts);
  396. if (error)
  397. return ERR_PTR(error);
  398. /* Require newinstance for all user namespace mounts to ensure
  399. * the mount options are not changed.
  400. */
  401. if ((current_user_ns() != &init_user_ns) && !opts.newinstance)
  402. return ERR_PTR(-EINVAL);
  403. if (opts.newinstance)
  404. s = sget(fs_type, NULL, set_anon_super, flags, NULL);
  405. else
  406. s = sget(fs_type, compare_init_pts_sb, set_anon_super, flags,
  407. NULL);
  408. if (IS_ERR(s))
  409. return ERR_CAST(s);
  410. if (!s->s_root) {
  411. error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
  412. if (error)
  413. goto out_undo_sget;
  414. s->s_flags |= MS_ACTIVE;
  415. }
  416. memcpy(&(DEVPTS_SB(s))->mount_opts, &opts, sizeof(opts));
  417. error = mknod_ptmx(s);
  418. if (error)
  419. goto out_undo_sget;
  420. return dget(s->s_root);
  421. out_undo_sget:
  422. deactivate_locked_super(s);
  423. return ERR_PTR(error);
  424. }
  425. #else
  426. /*
  427. * This supports only the legacy single-instance semantics (no
  428. * multiple-instance semantics)
  429. */
  430. static struct dentry *devpts_mount(struct file_system_type *fs_type, int flags,
  431. const char *dev_name, void *data)
  432. {
  433. return mount_single(fs_type, flags, data, devpts_fill_super);
  434. }
  435. #endif
  436. static void devpts_kill_sb(struct super_block *sb)
  437. {
  438. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  439. ida_destroy(&fsi->allocated_ptys);
  440. kfree(fsi);
  441. kill_litter_super(sb);
  442. }
  443. static struct file_system_type devpts_fs_type = {
  444. .name = "devpts",
  445. .mount = devpts_mount,
  446. .kill_sb = devpts_kill_sb,
  447. #ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
  448. .fs_flags = FS_USERNS_MOUNT | FS_USERNS_DEV_MOUNT,
  449. #endif
  450. };
  451. /*
  452. * The normal naming convention is simply /dev/pts/<number>; this conforms
  453. * to the System V naming convention
  454. */
  455. int devpts_new_index(struct inode *ptmx_inode)
  456. {
  457. struct super_block *sb = pts_sb_from_inode(ptmx_inode);
  458. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  459. int index;
  460. int ida_ret;
  461. retry:
  462. if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL))
  463. return -ENOMEM;
  464. mutex_lock(&allocated_ptys_lock);
  465. if (pty_count >= pty_limit -
  466. (fsi->mount_opts.newinstance ? pty_reserve : 0)) {
  467. mutex_unlock(&allocated_ptys_lock);
  468. return -ENOSPC;
  469. }
  470. ida_ret = ida_get_new(&fsi->allocated_ptys, &index);
  471. if (ida_ret < 0) {
  472. mutex_unlock(&allocated_ptys_lock);
  473. if (ida_ret == -EAGAIN)
  474. goto retry;
  475. return -EIO;
  476. }
  477. if (index >= fsi->mount_opts.max) {
  478. ida_remove(&fsi->allocated_ptys, index);
  479. mutex_unlock(&allocated_ptys_lock);
  480. return -ENOSPC;
  481. }
  482. pty_count++;
  483. mutex_unlock(&allocated_ptys_lock);
  484. return index;
  485. }
  486. void devpts_kill_index(struct inode *ptmx_inode, int idx)
  487. {
  488. struct super_block *sb = pts_sb_from_inode(ptmx_inode);
  489. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  490. mutex_lock(&allocated_ptys_lock);
  491. ida_remove(&fsi->allocated_ptys, idx);
  492. pty_count--;
  493. mutex_unlock(&allocated_ptys_lock);
  494. }
  495. /**
  496. * devpts_pty_new -- create a new inode in /dev/pts/
  497. * @ptmx_inode: inode of the master
  498. * @device: major+minor of the node to be created
  499. * @index: used as a name of the node
  500. * @priv: what's given back by devpts_get_priv
  501. *
  502. * The created inode is returned. Remove it from /dev/pts/ by devpts_pty_kill.
  503. */
  504. struct inode *devpts_pty_new(struct inode *ptmx_inode, dev_t device, int index,
  505. void *priv)
  506. {
  507. struct dentry *dentry;
  508. struct super_block *sb = pts_sb_from_inode(ptmx_inode);
  509. struct inode *inode;
  510. struct dentry *root = sb->s_root;
  511. struct pts_fs_info *fsi = DEVPTS_SB(sb);
  512. struct pts_mount_opts *opts = &fsi->mount_opts;
  513. char s[12];
  514. inode = new_inode(sb);
  515. if (!inode)
  516. return ERR_PTR(-ENOMEM);
  517. inode->i_ino = index + 3;
  518. inode->i_uid = opts->setuid ? opts->uid : current_fsuid();
  519. inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
  520. inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
  521. init_special_inode(inode, S_IFCHR|opts->mode, device);
  522. inode->i_private = priv;
  523. sprintf(s, "%d", index);
  524. mutex_lock(&root->d_inode->i_mutex);
  525. dentry = d_alloc_name(root, s);
  526. if (dentry) {
  527. d_add(dentry, inode);
  528. fsnotify_create(root->d_inode, dentry);
  529. } else {
  530. iput(inode);
  531. inode = ERR_PTR(-ENOMEM);
  532. }
  533. mutex_unlock(&root->d_inode->i_mutex);
  534. return inode;
  535. }
  536. /**
  537. * devpts_get_priv -- get private data for a slave
  538. * @pts_inode: inode of the slave
  539. *
  540. * Returns whatever was passed as priv in devpts_pty_new for a given inode.
  541. */
  542. void *devpts_get_priv(struct inode *pts_inode)
  543. {
  544. struct dentry *dentry;
  545. void *priv = NULL;
  546. BUG_ON(pts_inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
  547. /* Ensure dentry has not been deleted by devpts_pty_kill() */
  548. dentry = d_find_alias(pts_inode);
  549. if (!dentry)
  550. return NULL;
  551. if (pts_inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
  552. priv = pts_inode->i_private;
  553. dput(dentry);
  554. return priv;
  555. }
  556. /**
  557. * devpts_pty_kill -- remove inode form /dev/pts/
  558. * @inode: inode of the slave to be removed
  559. *
  560. * This is an inverse operation of devpts_pty_new.
  561. */
  562. void devpts_pty_kill(struct inode *inode)
  563. {
  564. struct super_block *sb = pts_sb_from_inode(inode);
  565. struct dentry *root = sb->s_root;
  566. struct dentry *dentry;
  567. BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
  568. mutex_lock(&root->d_inode->i_mutex);
  569. dentry = d_find_alias(inode);
  570. drop_nlink(inode);
  571. d_delete(dentry);
  572. dput(dentry); /* d_alloc_name() in devpts_pty_new() */
  573. dput(dentry); /* d_find_alias above */
  574. mutex_unlock(&root->d_inode->i_mutex);
  575. }
  576. static int __init init_devpts_fs(void)
  577. {
  578. int err = register_filesystem(&devpts_fs_type);
  579. struct ctl_table_header *table;
  580. if (!err) {
  581. table = register_sysctl_table(pty_root_table);
  582. devpts_mnt = kern_mount(&devpts_fs_type);
  583. if (IS_ERR(devpts_mnt)) {
  584. err = PTR_ERR(devpts_mnt);
  585. unregister_filesystem(&devpts_fs_type);
  586. unregister_sysctl_table(table);
  587. }
  588. }
  589. return err;
  590. }
  591. module_init(init_devpts_fs)