Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <linux/module.h> /* Needed by all modules */
  2. #include <linux/kernel.h> /* Needed for KERN_INFO */
  3. #include <linux/init.h> /* Needed for the macros */
  4. #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
  5. #include <linux/module.h> /* Specifically, a module */
  6. #include <linux/kernel.h> /* We're doing kernel work */
  7. #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
  8. #include <asm/uaccess.h> /* for copy_from_user */
  9. #include <linux/time.h> /* For the time */
  10.  
  11.  
  12.  
  13. #define iPROCFS_MAXSIZE 128
  14. #define iMESSAGE_STACK 64
  15.  
  16. #define acProcFileName "myclock"
  17.  
  18. /**
  19. * This structure hold information about the /proc file
  20. *
  21. */
  22. static struct proc_dir_entry *psFib_Proc_File;
  23.  
  24. /**
  25. * This structure hold information about the /proc file
  26. *
  27. */
  28.  
  29. int iFibWrite( struct file *psFile, const char *pcUserBuffer, unsigned long ulCount, void *pData)
  30. {
  31. printk(KERN_INFO "procfile_writes %s too /proc/%s\n", pcUserBuffer, acProcFileName);
  32. }
  33.  
  34. int iFibRead(char *pcBuffer, char **buffer_location,
  35. off_t iOffset, int iBufferLength, int *piEof, void *pData)
  36. {
  37. printk(KERN_INFO "procfile_read (/proc/%s) called\n", acProcFileName);
  38. struct timeval t;
  39. struct tm units;
  40. do_gettimeofday(&t);
  41. time_to_tm(t.tv_sec, 0, &units);
  42. return sprintf( pcBuffer, "The clock is: %d:%d:%d\n", units.tm_hour, units.tm_min, units.tm_sec);
  43.  
  44. }
  45.  
  46. int fib_start(void);
  47. void fib_end(void);
  48.  
  49. int fib_start(void)
  50. {
  51. psFib_Proc_File = create_proc_entry( acProcFileName, 0644, NULL);
  52.  
  53. if (psFib_Proc_File == NULL) {
  54. remove_proc_entry( acProcFileName, NULL);
  55. printk(KERN_ALERT "Error: Could not init /proc/%s\n",acProcFileName);
  56. return -ENOMEM;
  57. }
  58.  
  59. psFib_Proc_File->read_proc = iFibRead;
  60. psFib_Proc_File->write_proc = iFibWrite;
  61. psFib_Proc_File->mode = S_IFREG | S_IRUGO;
  62. psFib_Proc_File->uid = 0;
  63. psFib_Proc_File->gid = 0;
  64. psFib_Proc_File->size = 100;
  65.  
  66. printk(KERN_INFO "/proc/%s created\n", acProcFileName);
  67. return 0;
  68. }
  69.  
  70.  
  71.  
  72. void fib_end(void)
  73. {
  74. remove_proc_entry(acProcFileName, NULL);
  75. printk(KERN_INFO "/proc/%s removed\n", acProcFileName);
  76. }
  77.  
  78.  
  79. module_init(fib_start);
  80. module_exit(fib_end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement