inode.c 18 KB

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