inode.c 16 KB

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