inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. sync_filesystem(sb);
  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 void debugfs_evict_inode(struct inode *inode)
  213. {
  214. truncate_inode_pages_final(&inode->i_data);
  215. clear_inode(inode);
  216. if (S_ISLNK(inode->i_mode))
  217. kfree(inode->i_private);
  218. }
  219. static const struct super_operations debugfs_super_operations = {
  220. .statfs = simple_statfs,
  221. .remount_fs = debugfs_remount,
  222. .show_options = debugfs_show_options,
  223. .evict_inode = debugfs_evict_inode,
  224. };
  225. static int debug_fill_super(struct super_block *sb, void *data, int silent)
  226. {
  227. static struct tree_descr debug_files[] = {{""}};
  228. struct debugfs_fs_info *fsi;
  229. int err;
  230. save_mount_options(sb, data);
  231. fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL);
  232. sb->s_fs_info = fsi;
  233. if (!fsi) {
  234. err = -ENOMEM;
  235. goto fail;
  236. }
  237. err = debugfs_parse_options(data, &fsi->mount_opts);
  238. if (err)
  239. goto fail;
  240. err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
  241. if (err)
  242. goto fail;
  243. sb->s_op = &debugfs_super_operations;
  244. debugfs_apply_options(sb);
  245. return 0;
  246. fail:
  247. kfree(fsi);
  248. sb->s_fs_info = NULL;
  249. return err;
  250. }
  251. static struct dentry *debug_mount(struct file_system_type *fs_type,
  252. int flags, const char *dev_name,
  253. void *data)
  254. {
  255. return mount_single(fs_type, flags, data, debug_fill_super);
  256. }
  257. static struct file_system_type debug_fs_type = {
  258. .owner = THIS_MODULE,
  259. .name = "debugfs",
  260. .mount = debug_mount,
  261. .kill_sb = kill_litter_super,
  262. };
  263. MODULE_ALIAS_FS("debugfs");
  264. static struct dentry *__create_file(const char *name, umode_t mode,
  265. struct dentry *parent, void *data,
  266. const struct file_operations *fops)
  267. {
  268. struct dentry *dentry = NULL;
  269. int error;
  270. pr_debug("debugfs: creating file '%s'\n",name);
  271. error = simple_pin_fs(&debug_fs_type, &debugfs_mount,
  272. &debugfs_mount_count);
  273. if (error)
  274. goto exit;
  275. /* If the parent is not specified, we create it in the root.
  276. * We need the root dentry to do this, which is in the super
  277. * block. A pointer to that is in the struct vfsmount that we
  278. * have around.
  279. */
  280. if (!parent)
  281. parent = debugfs_mount->mnt_root;
  282. mutex_lock(&parent->d_inode->i_mutex);
  283. dentry = lookup_one_len(name, parent, strlen(name));
  284. if (!IS_ERR(dentry)) {
  285. switch (mode & S_IFMT) {
  286. case S_IFDIR:
  287. error = debugfs_mkdir(parent->d_inode, dentry, mode);
  288. break;
  289. case S_IFLNK:
  290. error = debugfs_link(parent->d_inode, dentry, mode,
  291. data);
  292. break;
  293. default:
  294. error = debugfs_create(parent->d_inode, dentry, mode,
  295. data, fops);
  296. break;
  297. }
  298. dput(dentry);
  299. } else
  300. error = PTR_ERR(dentry);
  301. mutex_unlock(&parent->d_inode->i_mutex);
  302. if (error) {
  303. dentry = NULL;
  304. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  305. }
  306. exit:
  307. return dentry;
  308. }
  309. /**
  310. * debugfs_create_file - create a file in the debugfs filesystem
  311. * @name: a pointer to a string containing the name of the file to create.
  312. * @mode: the permission that the file should have.
  313. * @parent: a pointer to the parent dentry for this file. This should be a
  314. * directory dentry if set. If this parameter is NULL, then the
  315. * file will be created in the root of the debugfs filesystem.
  316. * @data: a pointer to something that the caller will want to get to later
  317. * on. The inode.i_private pointer will point to this value on
  318. * the open() call.
  319. * @fops: a pointer to a struct file_operations that should be used for
  320. * this file.
  321. *
  322. * This is the basic "create a file" function for debugfs. It allows for a
  323. * wide range of flexibility in creating a file, or a directory (if you want
  324. * to create a directory, the debugfs_create_dir() function is
  325. * recommended to be used instead.)
  326. *
  327. * This function will return a pointer to a dentry if it succeeds. This
  328. * pointer must be passed to the debugfs_remove() function when the file is
  329. * to be removed (no automatic cleanup happens if your module is unloaded,
  330. * you are responsible here.) If an error occurs, %NULL will be returned.
  331. *
  332. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  333. * returned.
  334. */
  335. struct dentry *debugfs_create_file(const char *name, umode_t mode,
  336. struct dentry *parent, void *data,
  337. const struct file_operations *fops)
  338. {
  339. switch (mode & S_IFMT) {
  340. case S_IFREG:
  341. case 0:
  342. break;
  343. default:
  344. BUG();
  345. }
  346. return __create_file(name, mode, parent, data, fops);
  347. }
  348. EXPORT_SYMBOL_GPL(debugfs_create_file);
  349. /**
  350. * debugfs_create_dir - create a directory in the debugfs filesystem
  351. * @name: a pointer to a string containing the name of the directory to
  352. * create.
  353. * @parent: a pointer to the parent dentry for this file. This should be a
  354. * directory dentry if set. If this parameter is NULL, then the
  355. * directory will be created in the root of the debugfs filesystem.
  356. *
  357. * This function creates a directory in debugfs with the given name.
  358. *
  359. * This function will return a pointer to a dentry if it succeeds. This
  360. * pointer must be passed to the debugfs_remove() function when the file is
  361. * to be removed (no automatic cleanup happens if your module is unloaded,
  362. * you are responsible here.) If an error occurs, %NULL will be returned.
  363. *
  364. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  365. * returned.
  366. */
  367. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
  368. {
  369. return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
  370. parent, NULL, NULL);
  371. }
  372. EXPORT_SYMBOL_GPL(debugfs_create_dir);
  373. /**
  374. * debugfs_create_symlink- create a symbolic link in the debugfs filesystem
  375. * @name: a pointer to a string containing the name of the symbolic link to
  376. * create.
  377. * @parent: a pointer to the parent dentry for this symbolic link. This
  378. * should be a directory dentry if set. If this parameter is NULL,
  379. * then the symbolic link will be created in the root of the debugfs
  380. * filesystem.
  381. * @target: a pointer to a string containing the path to the target of the
  382. * symbolic link.
  383. *
  384. * This function creates a symbolic link with the given name in debugfs that
  385. * links to the given target path.
  386. *
  387. * This function will return a pointer to a dentry if it succeeds. This
  388. * pointer must be passed to the debugfs_remove() function when the symbolic
  389. * link is to be removed (no automatic cleanup happens if your module is
  390. * unloaded, you are responsible here.) If an error occurs, %NULL will be
  391. * returned.
  392. *
  393. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  394. * returned.
  395. */
  396. struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  397. const char *target)
  398. {
  399. struct dentry *result;
  400. char *link;
  401. link = kstrdup(target, GFP_KERNEL);
  402. if (!link)
  403. return NULL;
  404. result = __create_file(name, S_IFLNK | S_IRWXUGO, parent, link, NULL);
  405. if (!result)
  406. kfree(link);
  407. return result;
  408. }
  409. EXPORT_SYMBOL_GPL(debugfs_create_symlink);
  410. static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
  411. {
  412. int ret = 0;
  413. if (debugfs_positive(dentry)) {
  414. dget(dentry);
  415. if (S_ISDIR(dentry->d_inode->i_mode))
  416. ret = simple_rmdir(parent->d_inode, dentry);
  417. else
  418. simple_unlink(parent->d_inode, dentry);
  419. if (!ret)
  420. d_delete(dentry);
  421. dput(dentry);
  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, *parent;
  469. if (IS_ERR_OR_NULL(dentry))
  470. return;
  471. parent = dentry->d_parent;
  472. if (!parent || !parent->d_inode)
  473. return;
  474. parent = dentry;
  475. down:
  476. mutex_lock(&parent->d_inode->i_mutex);
  477. loop:
  478. /*
  479. * The parent->d_subdirs is protected by the d_lock. Outside that
  480. * lock, the child can be unlinked and set to be freed which can
  481. * use the d_u.d_child as the rcu head and corrupt this list.
  482. */
  483. spin_lock(&parent->d_lock);
  484. list_for_each_entry(child, &parent->d_subdirs, d_child) {
  485. if (!debugfs_positive(child))
  486. continue;
  487. /* perhaps simple_empty(child) makes more sense */
  488. if (!list_empty(&child->d_subdirs)) {
  489. spin_unlock(&parent->d_lock);
  490. mutex_unlock(&parent->d_inode->i_mutex);
  491. parent = child;
  492. goto down;
  493. }
  494. spin_unlock(&parent->d_lock);
  495. if (!__debugfs_remove(child, parent))
  496. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  497. /*
  498. * The parent->d_lock protects agaist child from unlinking
  499. * from d_subdirs. When releasing the parent->d_lock we can
  500. * no longer trust that the next pointer is valid.
  501. * Restart the loop. We'll skip this one with the
  502. * debugfs_positive() check.
  503. */
  504. goto loop;
  505. }
  506. spin_unlock(&parent->d_lock);
  507. mutex_unlock(&parent->d_inode->i_mutex);
  508. child = parent;
  509. parent = parent->d_parent;
  510. mutex_lock(&parent->d_inode->i_mutex);
  511. if (child != dentry)
  512. /* go up */
  513. goto loop;
  514. if (!__debugfs_remove(child, parent))
  515. simple_release_fs(&debugfs_mount, &debugfs_mount_count);
  516. mutex_unlock(&parent->d_inode->i_mutex);
  517. }
  518. EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
  519. /**
  520. * debugfs_rename - rename a file/directory in the debugfs filesystem
  521. * @old_dir: a pointer to the parent dentry for the renamed object. This
  522. * should be a directory dentry.
  523. * @old_dentry: dentry of an object to be renamed.
  524. * @new_dir: a pointer to the parent dentry where the object should be
  525. * moved. This should be a directory dentry.
  526. * @new_name: a pointer to a string containing the target name.
  527. *
  528. * This function renames a file/directory in debugfs. The target must not
  529. * exist for rename to succeed.
  530. *
  531. * This function will return a pointer to old_dentry (which is updated to
  532. * reflect renaming) if it succeeds. If an error occurs, %NULL will be
  533. * returned.
  534. *
  535. * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  536. * returned.
  537. */
  538. struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  539. struct dentry *new_dir, const char *new_name)
  540. {
  541. int error;
  542. struct dentry *dentry = NULL, *trap;
  543. struct name_snapshot old_name;
  544. trap = lock_rename(new_dir, old_dir);
  545. /* Source or destination directories don't exist? */
  546. if (!old_dir->d_inode || !new_dir->d_inode)
  547. goto exit;
  548. /* Source does not exist, cyclic rename, or mountpoint? */
  549. if (!old_dentry->d_inode || old_dentry == trap ||
  550. d_mountpoint(old_dentry))
  551. goto exit;
  552. dentry = lookup_one_len(new_name, new_dir, strlen(new_name));
  553. /* Lookup failed, cyclic rename or target exists? */
  554. if (IS_ERR(dentry) || dentry == trap || dentry->d_inode)
  555. goto exit;
  556. take_dentry_name_snapshot(&old_name, old_dentry);
  557. error = simple_rename(old_dir->d_inode, old_dentry, new_dir->d_inode,
  558. dentry);
  559. if (error) {
  560. release_dentry_name_snapshot(&old_name);
  561. goto exit;
  562. }
  563. d_move(old_dentry, dentry);
  564. fsnotify_move(old_dir->d_inode, new_dir->d_inode, old_name.name,
  565. S_ISDIR(old_dentry->d_inode->i_mode),
  566. NULL, old_dentry);
  567. release_dentry_name_snapshot(&old_name);
  568. unlock_rename(new_dir, old_dir);
  569. dput(dentry);
  570. return old_dentry;
  571. exit:
  572. if (dentry && !IS_ERR(dentry))
  573. dput(dentry);
  574. unlock_rename(new_dir, old_dir);
  575. return NULL;
  576. }
  577. EXPORT_SYMBOL_GPL(debugfs_rename);
  578. /**
  579. * debugfs_initialized - Tells whether debugfs has been registered
  580. */
  581. bool debugfs_initialized(void)
  582. {
  583. return debugfs_registered;
  584. }
  585. EXPORT_SYMBOL_GPL(debugfs_initialized);
  586. static struct kobject *debug_kobj;
  587. static int __init debugfs_init(void)
  588. {
  589. int retval;
  590. debug_kobj = kobject_create_and_add("debug", kernel_kobj);
  591. if (!debug_kobj)
  592. return -EINVAL;
  593. retval = register_filesystem(&debug_fs_type);
  594. if (retval)
  595. kobject_put(debug_kobj);
  596. else
  597. debugfs_registered = true;
  598. return retval;
  599. }
  600. core_initcall(debugfs_init);