do_gettimeofday to get system time
Hello, I need to create a linux module that returns the values held in timespec struct when poked with cat. This also needs to use a /proc interface with the cat (so the input would be cat /proc/myModule). I have what should be working code I think but I may be missing something as I get the error "passing arg 1 of 'do_gettimeofday' from incompatible pointer type." Here is my Makefile: Code:
obj-m = moore.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Here is the full code for the program: Code:
#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/time.h> #define DRIVER_AUTHOR "Andrew Moore" #define DRIVER_DESC "Gets system time from timespec" #define procfs_name "moore" struct proc_dir_entry *Our_Proc_File; int procfile_read(char *buffer, char **buffer_location, off_t offset, int buffer_length, int *eof, void *data) { int ret; struct timespec ts; do_gettimeofday(&ts); printk(KERN_INFO "procfile_read (/proc/%s) called\n", procfs_name); if(offset>0) { ret=0; } else { ret=sprintf(buffer, "%ld\t%ld", ts.tv_sec, ts.tv_nsec); } return ret; } int init_module(void) { Our_Proc_File=create_proc_entry(procfs_name, 0644, NULL); if(Our_Proc_File == NULL) { remove_proc_entry(procfs_name, &proc_root); printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", procfs_name); return -ENOMEM; } Our_Proc_File->read_proc = procfile_read; Our_Proc_File->owner = THIS_MODULE; Our_Proc_File->mode = S_IFREG | S_IRUGO; Our_Proc_File->uid = 0; Our_Proc_File->gid = 0; Our_Proc_File->size = 37; printk(KERN_INFO "/proc/%s created\n", procfs_name); return 0; } void cleanup_module(void) { remove_proc_entry(procfs_name, &proc_root); printk(KERN_INFO "/proc/%s removed\n", procfs_name); } MODULE_LICENSE("GPL"); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); Does anyone see anything that is wrong? |
No comments:
Post a Comment