mlog_dump.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <linux/types.h>
  2. /* #include <linux/errno.h> */
  3. /* #include <linux/time.h> */
  4. /* #include <linux/kernel.h> */
  5. /* #include <linux/module.h> */
  6. #include <linux/wait.h>
  7. #include <linux/poll.h>
  8. #include <linux/init.h>
  9. #include <linux/fs.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/seq_file.h>
  12. #include "mlog_internal.h"
  13. #include "mlog_dump.h"
  14. static int mlog_open(struct inode *inode, struct file *file)
  15. {
  16. MLOG_PRINTK("[mlog] open %d\n", mlog_unread());
  17. mlog_doopen();
  18. return 0;
  19. }
  20. static int mlog_release(struct inode *inode, struct file *file)
  21. {
  22. MLOG_PRINTK("[mlog] release\n");
  23. return 0;
  24. }
  25. static ssize_t mlog_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  26. {
  27. if (file->f_flags & O_NONBLOCK) {
  28. if (!mlog_unread())
  29. return -EAGAIN;
  30. /* MLOG_PRINTK("[mlog] read (NonBlock) %d\n", count); */
  31. }
  32. return mlog_doread(buf, count);
  33. }
  34. static unsigned int mlog_poll(struct file *file, poll_table *wait)
  35. {
  36. /* MLOG_PRINTK("[mlog] poll\n"); */
  37. poll_wait(file, &mlog_wait, wait);
  38. if (mlog_unread())
  39. return POLLIN | POLLRDNORM;
  40. return 0;
  41. }
  42. static const struct file_operations proc_mlog_operations = {
  43. .read = mlog_read,
  44. .poll = mlog_poll,
  45. .open = mlog_open,
  46. .release = mlog_release,
  47. .llseek = generic_file_llseek,
  48. };
  49. static int mlog_fmt_proc_show(struct seq_file *m, void *v)
  50. {
  51. return mlog_print_fmt(m);
  52. }
  53. static int mlog_fmt_proc_open(struct inode *inode, struct file *file)
  54. {
  55. return single_open(file, mlog_fmt_proc_show, NULL);
  56. }
  57. static const struct file_operations mlog_fmt_proc_fops = {
  58. .open = mlog_fmt_proc_open,
  59. .read = seq_read,
  60. .llseek = seq_lseek,
  61. .release = single_release,
  62. };
  63. void mlog_init_procfs(void)
  64. {
  65. proc_create("mlog_fmt", 0, NULL, &mlog_fmt_proc_fops);
  66. proc_create("mlog", 0, NULL, &proc_mlog_operations);
  67. }