Results 1 to 6 of 6
hi there,
i am working on a homework assignment of mine, and i need to write a module that tells us the system time in seconds and microseconds, and i ...
- 05-23-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 35
how can i write into a proc
hi there,
i am working on a homework assignment of mine, and i need to write a module that tells us the system time in seconds and microseconds, and i need a lil help, i am stuck in the part where i need to write into a proc file i created, i just dono how to do it, i searched everywhere for a function that may help me but to no avail, anyone here can help me please???
here is my current code
using do_gettimeofday i am able to obtain the current time, but i just dono how to write this time into /proc/rexorCode:#include <linux/init.h> #include <linux/module.h> #include <linux/proc_fs.h> #include <linux/kernel.h> #include <linux/time.h> #define PROCFS_NAME "rexor" static struct proc_dir_entry *proc_file; static int __init init(void) { struct timeval time; proc_file = create_proc_entry(PROCFS_NAME, 0, NULL); if(proc_file == NULL) { remove_proc_entry(PROCFS_NAME, NULL); printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); return -ENOMEM; } do_gettimeofday(&time); // printk(KERN_EMERG "%d.%d", time.tv_sec,time.tv_usec); proc_file->write_proc ; return 0; } static void __exit exit(void) { remove_proc_entry(PROCFS_NAME, NULL); } MODULE_LICENSE("GPL"); module_init(init); module_exit(exit);
thanks in advance
P.S: ITS MY FIRST POST YAYE :P, also i know rexor is a stupid name for a proc dictionary, i will change it later to currentTime or smth.
P.P.S: i dont want to make another post about this, so does anyone here know what callback_read does, cuz i think it may help me out in this problem
- 05-23-2009 #2
Hello,
this webpage should help you there.
Access the Linux kernel using the /proc filesystem
callback_read is supposed to be a callback function, i.e. it is up to you what is does.
You write this function as you want and it gets called when "something" specific happens.Debian GNU/Linux -- You know you want it.
- 05-23-2009 #3Just Joined!
- Join Date
- May 2009
- Posts
- 35
yea thank u but that is not what i ment
i am looking for a function similar to sprintf in C, isnt there a sprintk or smth?
EDIT: nvm i figured it out
- 05-23-2009 #4Just Joined!
- Join Date
- May 2009
- Posts
- 35
k i need help, i thought i figured it out, but i didnt
here is my current code
the problem is with sprintf, as i said i want currenttime to hold the current time in seconds and nanoseconds, but i am stuck, anyone could help me pleaseCode:#include <linux/init.h> #include <linux/module.h> #include <linux/proc_fs.h> #include <linux/kernel.h> #include <linux/time.h> MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("an LKM that gives the current system time"); MODULE_AUTHOR("sfsdfdsf"); #define PROCFS_NAME "currenttime" struct proc_dir_entry *proc_file; int init(void) { struct timeval time; proc_file = create_proc_entry(PROCFS_NAME, 0, NULL); if(proc_file == NULL) { remove_proc_entry(PROCFS_NAME, NULL); printk(KERN_ALERT "Error: Could not initialize /proc/%s\n", PROCFS_NAME); return -ENOMEM; } do_gettimeofday(&time); //sprintf(proc_file,"%d %d\n",time.tv_sec, time.tv_usec); return 0; } void exit(void) { remove_proc_entry(PROCFS_NAME, NULL); } module_init(init); module_exit(exit);
EDIT: well, it now works yaye
- 05-24-2009 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
You are using sprintf() to output to a structure. This is not valid. You can only sprintf() to a char array (buffer).
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-24-2009 #6Just Joined!
- Join Date
- May 2009
- Posts
- 35


Reply With Quote
