Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <linux/module.h> /* Needed by all modules */
- #include <linux/kernel.h> /* Needed for KERN_INFO */
- #include <linux/init.h> /* Needed for the macros */
- #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
- #include <linux/module.h> /* Specifically, a module */
- #include <linux/kernel.h> /* We're doing kernel work */
- #include <linux/proc_fs.h> /* Necessary because we use the proc fs */
- #include <asm/uaccess.h> /* for copy_from_user */
- #include <linux/time.h> /* For the time */
- #define iPROCFS_MAXSIZE 128
- #define iMESSAGE_STACK 64
- #define acProcFileName "myclock"
- /**
- * This structure hold information about the /proc file
- *
- */
- static struct proc_dir_entry *psFib_Proc_File;
- /**
- * This structure hold information about the /proc file
- *
- */
- int iFibWrite( struct file *psFile, const char *pcUserBuffer, unsigned long ulCount, void *pData)
- {
- printk(KERN_INFO "procfile_writes %s too /proc/%s\n", pcUserBuffer, acProcFileName);
- }
- int iFibRead(char *pcBuffer, char **buffer_location,
- off_t iOffset, int iBufferLength, int *piEof, void *pData)
- {
- printk(KERN_INFO "procfile_read (/proc/%s) called\n", acProcFileName);
- struct timeval t;
- struct tm units;
- do_gettimeofday(&t);
- time_to_tm(t.tv_sec, 0, &units);
- return sprintf( pcBuffer, "The clock is: %d:%d:%d\n", units.tm_hour, units.tm_min, units.tm_sec);
- }
- int fib_start(void);
- void fib_end(void);
- int fib_start(void)
- {
- psFib_Proc_File = create_proc_entry( acProcFileName, 0644, NULL);
- if (psFib_Proc_File == NULL) {
- remove_proc_entry( acProcFileName, NULL);
- printk(KERN_ALERT "Error: Could not init /proc/%s\n",acProcFileName);
- return -ENOMEM;
- }
- psFib_Proc_File->read_proc = iFibRead;
- psFib_Proc_File->write_proc = iFibWrite;
- psFib_Proc_File->mode = S_IFREG | S_IRUGO;
- psFib_Proc_File->uid = 0;
- psFib_Proc_File->gid = 0;
- psFib_Proc_File->size = 100;
- printk(KERN_INFO "/proc/%s created\n", acProcFileName);
- return 0;
- }
- void fib_end(void)
- {
- remove_proc_entry(acProcFileName, NULL);
- printk(KERN_INFO "/proc/%s removed\n", acProcFileName);
- }
- module_init(fib_start);
- module_exit(fib_end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement