inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * inode.c - part of debugfs, a tiny little debug file system
  3. *
  4. * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  5. * Copyright (C) 2004 IBM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * debugfs is for people to use instead of /proc or /sys.
  12. * See Documentation/DocBook/kernel-api for more details.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/fs.h>
  17. #include <linux/mount.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/init.h>
  20. #include <linux/kobject.h>
  21. #include <linux/namei.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/fsnotify.h>
  24. #include <linux/string.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/parser.h>
  27. #include <linux/magic.h>
  28. #include <linux/slab.h>
  29. #define DEBUGFS_DEFAULT_MODE 0700
  30. static struct vfsmount *debugfs_mount;
  31. static int debugfs_mount_count;
  32. static bool debugfs_registered;
  33. static struct inode *debugfs_get_inode(struct super_block *sb, umode_t mode, dev_t dev,
  34. void *data, const struct file_operations *fops)
  35. {
  36. struct inode *inode = new_inode(sb);
  37. if (inode) {
  38. inode->i_ino = get_next_ino();
  39. inode->i_mode = mode;
  40. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  41. switch (mode & S_IFMT) {
  42. default:
  43. init_special_inode(inode, mode, dev);
  44. break;
  45. case S_IFREG:
  46. inode->i_fop = fops ? fops : &debugfs_file_operations;
  47. inode->i_private = data;
  48. break;
  49. case S_IFLNK:
  50. inode->i_op = &debugfs_link_operations;
  51. inode->i_private = data;
  52. break;
  53. case S_IFDIR:
  54. inode->i_op = &simple_dir_inode_operations;
  55. inode->i_fop = &simple_dir_operations;
  56. inode->i_private = NULL;
  57. /* directory inodes start off with i_nlink == 2
  58. * (for "." entry) */
  59. inc_nlink(inode);
  60. break;
  61. }
  62. }
  63. return inode;
  64. }
  65. /* SMP-safe */
  66. static int debugfs_mknod(struct inode *dir, struct dentry *dentry,
  67. umode_t mode, dev_t dev, void *data,
  68. const struct file_operations *fops)
  69. {
  70. struct inode *inode;
  71. int error = -EPERM;
  72. if (dentry->d_inode)
  73. return -EEXIST;
  74. inode = debugfs_get_inode(dir->i_sb, mode, dev, data, fops);
  75. if (inode) {
  76. d_instantiate(dentry, inode);
  77. dget(dentry);
  78. error = 0;
  79. }
  80. return error;
  81. }
  82. static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  83. {
  84. int res;
  85. mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
  86. res = debugfs_mknod(dir, dentry, mode, 0, NULL, NULL);
  87. if (!res) {
  88. inc_nlink(dir);
  89. fsnotify_mkdir(dir, dentry);
  90. }
  91. return res;
  92. }
  93. static int debugfs_link(struct inode *dir, struct dentry *dentry, umode_t mode,
  94. void *data)
  95. {
  96. mode = (mode & S_IALLUGO) | S_IFLNK;
  97. return debugfs_mknod(dir, dentry, mode, 0, data, NULL);
  98. }
  99. static int debugfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
  100. void *data, const struct file_operations *fops)
  101. {
  102. int res;
  103. mode = (mode & S_IALLUGO) | S_IFREG;
  104. res = debugfs_mknod(dir, dentry, mode, 0, data, fops);
  105. if (!res)
  106. fsnotify_create(dir, dentry);
  107. return res;
  108. }
  109. static inline int debugfs_positive(struct dentry *dentry)
  110. {
  111. return dentry->d_inode && !d_unhashed(dentry);
  112. }
  113. struct debugfs_mount_opts {
  114. kuid_t uid;
  115. kgid_t gid;
  116. umode_t mode;
  117. };
  118. enum {
  119. Opt_uid,
  120. Opt_gid,
  121. Opt_mode,
  122. Opt_err
  123. };
  124. static const match_table_t tokens = {
  125. {Opt_uid, "uid=%u"},
  126. {Opt_gid, "gid=%u"},
  127. {Opt_mode, "mode=%o"},
  128. {Opt_err, NULL}
  129. };
  130. struct debugfs_fs_info {
  131. struct debugfs_mount_opts mount_opts;
  132. };
  133. static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts)
  134. {
  135. substring_t args[MAX_OPT_ARGS];
  136. int option;
  137. int token;
  138. kuid_t uid;
  139. kgid_t gid;
  140. char *p;
  141. opts->mode = DEBUGFS_DEFAULT_MODE;
  142. while ((p = strsep(&data, ",")) != NULL) {
  143. if (!*p)
  144. continue;
  145. token = match_token(p, tokens, args);
  146. switch (token) {
  147. case Opt_uid:
  148. if (match_int(&args[0], &option))
  149. return -EINVAL;
  150. uid = make_kuid(current_user_ns(), option);
  151. if (!uid_valid(uid))
  152. return -EINVAL;
  153. opts->uid = uid;
  154. break;
  155. case Opt_gid:
  156. if (match_octal(&args[0], &option))
  157. return -EINVAL;
  158. gid = make_kgid(current_user_ns(), option);
  159. if (!gid_valid(gid))
  160. return -EINVAL;
  161. opts->gid = gid;
  162. break;
  163. case Opt_mode:
  164. if (match_octal(&args[0], &option))
  165. return -EINVAL;
  166. opts->mode = option & S_IALLUGO;
  167. break;
  168. /*
  169. * We might like to report bad mount options here;
  170. * but traditionally debugfs has ignored all mount options
  171. */
  172. }
  173. }
  174. return 0;
  175. }
  176. static int debugfs_apply_options(struct super_block *sb)
  177. {
  178. struct debugfs_fs_info *fsi = sb->s_fs_info;
  179. struct inode *inode = sb->s_root->d_inode;
  180. struct debugfs_mount_opts *opts = &fsi->mount_opts;
  181. inode->i_mode &= ~S_IALLUGO;
  182. inode->i_mode |= opts->mode;
  183. inode->i_uid = opts->uid;
  184. inode->i_gid = opts->gid;
  185. return 0;
  186. }
  187. static int debugfs_remount(struct super_block *sb, int *flags, char *data)
  188. {
  189. int err;
  190. struct debugfs_fs_info *fsi = sb->s_fs_info;
  191. err = debugfs_parse_options(data, &fsi->mount_opts);
  192. if (err)
  193. goto fail;
  194. debugfs_apply_options(sb);
  195. fail:
  196. return err;
  197. }
  198. static int debugfs_show_options(struct seq_file *m, struct dentry *root)
  199. {
  200. struct debugfs_fs_info *fsi = root->d_sb->s_fs_info;
  201. struct debugfs_mount_opts *opts = &fsi->mount_opts;
  202. if (!uid_eq(opts->uid, GLOBAL_ROOT_UID))
  203. seq_printf(m, ",uid=%u",
  204. from_kuid_munged(&init_user_ns, opts->uid));
  205. if (!gid_eq(opts->gid, GLOBAL_ROOT_GID))
  206. seq_printf(m, ",gid=%u",
  207. from_kgid_munged(&init_user_ns, opts->gid));
  208. if (opts->mode != DEBUGFS_DEFAULT_MODE)
  209. seq_printf(m, ",mode=%o", opts->mode);
  210. return 0;
  211. }
  212. static const struct super_operations debugfs_super_operations = {
  213. .statfs = simple_statfs,
  214. .remount_fs = debugfs_remount,
  215. .show_options = debugfs_show_options,
  216. };
  217. static int debug_fill_super(struct super_block *sb, void *data, int silent)
  218. {
  219. static struct tree_descr debug_files[] = {{""}};
  220. struct debugfs_fs_info *fsi;
  221. int err;
  222. save_mount_options(sb, data);
  223. fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
  224. sb->s_fs_info = fsi;
  225. if (!fsi) {
  226. err = -ENOMEM;
  227. goto fail;
  228. }
  229. err = debugfs_parse_options(data, &fsi->mount_opts);
  230. if (err)
  231. goto fail;
  232. err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
  233. if (err)
  234. goto fail;
  235. sb->s_op = &debugfs_super_operations;
  236. debugfs_apply_options(sb);
  237. return 0;
  238. fail:
  239. kfree(fsi);
  240. sb->s_fs_info = NULL;
  241. return err;
  242. }
  243. static struct dentry *debug_mount(struct file_system_type *fs_type,
  244. int flags, const char *dev_name,
  245. void *data)
  246. {
  247. return mount_single(fs_type, flags, data, debug_fill_super);
  248. }
  249. static struct file_system_type debug_fs_type = {
  250. .owner = THIS_MODULE,
  251. .name = "debugfs",
  252. .mount = debug_mount,
  253. .kill_sb = kill_litter_super,
  254. };
  255. static struct dentry *__create_file(const char *name, umode_t mode,
  256. struct dentry *parent, void *data,
  257. const struct file_operations *fops)
  258. {
  259. struct dentry *dentry = NULL;
  260. int error;
  261. pr_debug("debugfs: creating file '%s'\n",name);
  262. error = simple_pin_fs(&debug_fs_type, &debugfs_mount,
  263. &debugfs_mount_count);
  264. if (error)
  265. goto exit;
  266. /* If the parent is not specified, we create it in the root.
  267. * We need the root dentry to do this, which is in the super
  268. * block. A pointer to that is in the struct vfsmount that we
  269. * have around.
  270. */
  271. if (!parent)
  272. parent = debugfs_mount->mnt_root;
  273. dentry = NULL;
  274. mutex_lock(&parent->d_inode->i_mutex);
  275. dentry = lookup_one_len(name, parent, strlen(name));
  276. if (!IS_ERR(dentry)) {
  277. switch (mode & S_IFMT) {
  278. case S_IFDIR:
  279. error = debugfs_mkdir(parent->d_inode, dentry, mode);
  280. break;
  281. case S_IFLNK:
  282. error = debugfs_link(parent->d_inode, dentry, mode,
  283. data);
  284. break;
  285. default:
  286. error = debugfs_create(parent->d_inode, dentry, mode,
  287. data, fops);
  288. break;
  289. }
  290. dput(dentry);
  291. } else
  292. error = PTR_ERR(dentry);
  293. mutex_unlock(&parent->d_inode->i_mutex);
  294. if (error) {
  295. dentry = NULL;
  296. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  297. }
  298. exit:
  299. return dentry;
  300. }
  301. /**
  302. * debugfs_create_file - create a file in the debugfs filesystem
  303. * @name: a pointer to a string containing the name of the file to create.
  304. * @mode: the permission that the file should have.
  305. * @parent: a pointer to the parent dentry for this file. This should be a
  306. * directory dentry if set. If this paramater is NULL, then the
  307. * file will be created in the root of the debugfs filesystem.
  308. * @data: a pointer to something that the caller will want to get to later
  309. * on. The inode.i_private pointer will point to this value on
  310. * the open() call.
  311. * @fops: a pointer to a struct file_operations that should be used for
  312. * this file.
  313. *
  314. * This is the basic "create a file" function for debugfs. It allows for a
  315. * wide range of flexibility in creating a file, or a directory (if you want
  316. * to create a directory, the debugfs_create_dir() function is
  317. * recommended to be used instead.)
  318. *
  319. * This function will return a pointer to a dentry if it succeeds. This
  320. * pointer must be passed to the debugfs_remove() function when the file is
  321. * to be removed (no automatic cleanup happens if your module is unloaded,
  322. * you are responsible here.) If an error occurs, %NULL will be returned.
  323. *
  324. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  325. * returned.
  326. */
  327. struct dentry *debugfs_create_file(const char *name, umode_t mode,
  328. struct dentry *parent, void *data,
  329. const struct file_operations *fops)
  330. {
  331. switch (mode & S_IFMT) {
  332. case S_IFREG:
  333. case 0:
  334. break;
  335. default:
  336. BUG();
  337. }
  338. return __create_file(name, mode, parent, data, fops);
  339. }
  340. EXPORT_SYMBOL_GPL(debugfs_create_file);
  341. /**
  342. * debugfs_create_dir - create a directory in the debugfs filesystem
  343. * @name: a pointer to a string containing the name of the directory to
  344. * create.
  345. * @parent: a pointer to the parent dentry for this file. This should be a
  346. * directory dentry if set. If this paramater is NULL, then the
  347. * directory will be created in the root of the debugfs filesystem.
  348. *
  349. * This function creates a directory in debugfs with the given name.
  350. *
  351. * This function will return a pointer to a dentry if it succeeds. This
  352. * pointer must be passed to the debugfs_remove() function when the file is
  353. * to be removed (no automatic cleanup happens if your module is unloaded,
  354. * you are responsible here.) If an error occurs, %NULL will be returned.
  355. *
  356. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  357. * returned.
  358. */
  359. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
  360. {
  361. return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
  362. parent, NULL, NULL);
  363. }
  364. EXPORT_SYMBOL_GPL(debugfs_create_dir);
  365. /**
  366. * debugfs_create_symlink- create a symbolic link in the debugfs filesystem
  367. * @name: a pointer to a string containing the name of the symbolic link to
  368. * create.
  369. * @parent: a pointer to the parent dentry for this symbolic link. This
  370. * should be a directory dentry if set. If this paramater is NULL,
  371. * then the symbolic link will be created in the root of the debugfs
  372. * filesystem.
  373. * @target: a pointer to a string containing the path to the target of the
  374. * symbolic link.
  375. *
  376. * This function creates a symbolic link with the given name in debugfs that
  377. * links to the given target path.
  378. *
  379. * This function will return a pointer to a dentry if it succeeds. This
  380. * pointer must be passed to the debugfs_remove() function when the symbolic
  381. * link is to be removed (no automatic cleanup happens if your module is
  382. * unloaded, you are responsible here.) If an error occurs, %NULL will be
  383. * returned.
  384. *
  385. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  386. * returned.
  387. */
  388. struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  389. const char *target)
  390. {
  391. struct dentry *result;
  392. char *link;
  393. link = kstrdup(target, GFP_KERNEL);
  394. if (!link)
  395. return NULL;
  396. result = __create_file(name, S_IFLNK | S_IRWXUGO, parent, link, NULL);
  397. if (!result)
  398. kfree(link);
  399. return result;
  400. }
  401. EXPORT_SYMBOL_GPL(debugfs_create_symlink);
  402. static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
  403. {
  404. int ret = 0;
  405. if (debugfs_positive(dentry)) {
  406. if (dentry->d_inode) {
  407. dget(dentry);
  408. switch (dentry->d_inode->i_mode & S_IFMT) {
  409. case S_IFDIR:
  410. ret = simple_rmdir(parent->d_inode, dentry);
  411. break;
  412. case S_IFLNK:
  413. kfree(dentry->d_inode->i_private);
  414. /* fall through */
  415. default:
  416. simple_unlink(parent->d_inode, dentry);
  417. break;
  418. }
  419. if (!ret)
  420. d_delete(dentry);
  421. dput(dentry);
  422. }
  423. }
  424. return ret;
  425. }
  426. /**
  427. * debugfs_remove - removes a file or directory from the debugfs filesystem
  428. * @dentry: a pointer to a the dentry of the file or directory to be
  429. * removed.
  430. *
  431. * This function removes a file or directory in debugfs that was previously
  432. * created with a call to another debugfs function (like
  433. * debugfs_create_file() or variants thereof.)
  434. *
  435. * This function is required to be called in order for the file to be
  436. * removed, no automatic cleanup of files will happen when a module is
  437. * removed, you are responsible here.
  438. */
  439. void debugfs_remove(struct dentry *dentry)
  440. {
  441. struct dentry *parent;
  442. int ret;
  443. if (IS_ERR_OR_NULL(dentry))
  444. return;
  445. parent = dentry->d_parent;
  446. if (!parent || !parent->d_inode)
  447. return;
  448. mutex_lock(&parent->d_inode->i_mutex);
  449. ret = __debugfs_remove(dentry, parent);
  450. mutex_unlock(&parent->d_inode->i_mutex);
  451. if (!ret)
  452. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  453. }
  454. EXPORT_SYMBOL_GPL(debugfs_remove);
  455. /**
  456. * debugfs_remove_recursive - recursively removes a directory
  457. * @dentry: a pointer to a the dentry of the directory to be removed.
  458. *
  459. * This function recursively removes a directory tree in debugfs that
  460. * was previously created with a call to another debugfs function
  461. * (like debugfs_create_file() or variants thereof.)
  462. *
  463. * This function is required to be called in order for the file to be
  464. * removed, no automatic cleanup of files will happen when a module is
  465. * removed, you are responsible here.
  466. */
  467. void debugfs_remove_recursive(struct dentry *dentry)
  468. {
  469. struct dentry *child;
  470. struct dentry *parent;
  471. if (IS_ERR_OR_NULL(dentry))
  472. return;
  473. parent = dentry->d_parent;
  474. if (!parent || !parent->d_inode)
  475. return;
  476. parent = dentry;
  477. mutex_lock(&parent->d_inode->i_mutex);
  478. while (1) {
  479. /*
  480. * When all dentries under "parent" has been removed,
  481. * walk up the tree until we reach our starting point.
  482. */
  483. if (list_empty(&parent->d_subdirs)) {
  484. mutex_unlock(&parent->d_inode->i_mutex);
  485. if (parent == dentry)
  486. break;
  487. parent = parent->d_parent;
  488. mutex_lock(&parent->d_inode->i_mutex);
  489. }
  490. child = list_entry(parent->d_subdirs.next, struct dentry,
  491. d_u.d_child);
  492. next_sibling:
  493. /*
  494. * If "child" isn't empty, walk down the tree and
  495. * remove all its descendants first.
  496. */
  497. if (!list_empty(&child->d_subdirs)) {
  498. mutex_unlock(&parent->d_inode->i_mutex);
  499. parent = child;
  500. mutex_lock(&parent->d_inode->i_mutex);
  501. continue;
  502. }
  503. __debugfs_remove(child, parent);
  504. if (parent->d_subdirs.next == &child->d_u.d_child) {
  505. /*
  506. * Try the next sibling.
  507. */
  508. if (child->d_u.d_child.next != &parent->d_subdirs) {
  509. child = list_entry(child->d_u.d_child.next,
  510. struct dentry,
  511. d_u.d_child);
  512. goto next_sibling;
  513. }
  514. /*
  515. * Avoid infinite loop if we fail to remove
  516. * one dentry.
  517. */
  518. mutex_unlock(&parent->d_inode->i_mutex);
  519. break;
  520. }
  521. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  522. }
  523. parent = dentry->d_parent;
  524. mutex_lock(&parent->d_inode->i_mutex);
  525. __debugfs_remove(dentry, parent);
  526. mutex_unlock(&parent->d_inode->i_mutex);
  527. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  528. }
  529. EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
  530. /**
  531. * debugfs_rename - rename a file/directory in the debugfs filesystem
  532. * @old_dir: a pointer to the parent dentry for the renamed object. This
  533. * should be a directory dentry.
  534. * @old_dentry: dentry of an object to be renamed.
  535. * @new_dir: a pointer to the parent dentry where the object should be
  536. * moved. This should be a directory dentry.
  537. * @new_name: a pointer to a string containing the target name.
  538. *
  539. * This function renames a file/directory in debugfs. The target must not
  540. * exist for rename to succeed.
  541. *
  542. * This function will return a pointer to old_dentry (which is updated to
  543. * reflect renaming) if it succeeds. If an error occurs, %NULL will be
  544. * returned.
  545. *
  546. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  547. * returned.
  548. */
  549. struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  550. struct dentry *new_dir, const char *new_name)
  551. {
  552. int error;
  553. struct dentry *dentry = NULL, *trap;
  554. const char *old_name;
  555. trap = lock_rename(new_dir, old_dir);
  556. /* Source or destination directories don't exist? */
  557. if (!old_dir->d_inode || !new_dir->d_inode)
  558. goto exit;
  559. /* Source does not exist, cyclic rename, or mountpoint? */
  560. if (!old_dentry->d_inode || old_dentry == trap ||
  561. d_mountpoint(old_dentry))
  562. goto exit;
  563. dentry = lookup_one_len(new_name, new_dir, strlen(new_name));
  564. /* Lookup failed, cyclic rename or target exists? */
  565. if (IS_ERR(dentry) || dentry == trap || dentry->d_inode)
  566. goto exit;
  567. old_name = fsnotify_oldname_init(old_dentry->d_name.name);
  568. error = simple_rename(old_dir->d_inode, old_dentry, new_dir->d_inode,
  569. dentry);
  570. if (error) {
  571. fsnotify_oldname_free(old_name);
  572. goto exit;
  573. }
  574. d_move(old_dentry, dentry);
  575. fsnotify_move(old_dir->d_inode, new_dir->d_inode, old_name,
  576. S_ISDIR(old_dentry->d_inode->i_mode),
  577. NULL, old_dentry);
  578. fsnotify_oldname_free(old_name);
  579. unlock_rename(new_dir, old_dir);
  580. dput(dentry);
  581. return old_dentry;
  582. exit:
  583. if (dentry && !IS_ERR(dentry))
  584. dput(dentry);
  585. unlock_rename(new_dir, old_dir);
  586. return NULL;
  587. }
  588. EXPORT_SYMBOL_GPL(debugfs_rename);
  589. /**
  590. * debugfs_initialized - Tells whether debugfs has been registered
  591. */
  592. bool debugfs_initialized(void)
  593. {
  594. return debugfs_registered;
  595. }
  596. EXPORT_SYMBOL_GPL(debugfs_initialized);
  597. static struct kobject *debug_kobj;
  598. static int __init debugfs_init(void)
  599. {
  600. int retval;
  601. debug_kobj = kobject_create_and_add("debug", kernel_kobj);
  602. if (!debug_kobj)
  603. return -EINVAL;
  604. retval = register_filesystem(&debug_fs_type);
  605. if (retval)
  606. kobject_put(debug_kobj);
  607. else
  608. debugfs_registered = true;
  609. return retval;
  610. }
  611. core_initcall(debugfs_init);