LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-27-2003, 11:13 AM   #1
dmaxj
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Rep: Reputation: 0
writing to proc module


Does anyone know how I can write a couple of integers to a file in the /proc folder???

I wrote a kernel module that does nothing, but show up in /proc. Now, I need to be able to write a couple of integers to the file I made in /proc...

I can also see my module when I 'cat /proc/modules'



Thanks

Last edited by dmaxj; 06-27-2003 at 11:14 AM.
 
Old 06-27-2003, 01:48 PM   #2
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
echo "1" > /proc/filename
 
Old 06-27-2003, 03:45 PM   #3
dmaxj
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
using c code

I am using c code to do this... So , now I am thinking 'how do I translate echo "1" > /proc/filename into something that my module and c compiler can understand...

Perhaps, kernel modules can use printk() ( similar to c standard out, printf() ) ???

Or maybe I can set up a file pointer???

Moses, what do you think?

Thanks
 
Old 06-28-2003, 01:02 AM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
These are just files. I think you should be able to open them as you would any file. Are you trying to write to the file with your module or from a userspace application?
Writing to the file with a userspace application would probably just mean opening the file for writing, writing to the file, closing the file. What your module does with that is different. . .
Messing with the file in your module is probably a little more complicated, but I don't really know as I haven't done any kernel hacking. It probably involves include/linux/proc_fs.h, though I would have to do a lot more research and coding to be sure.

Oh, you might also ask a moderator to move this thread to the programming forum where you may get much better help. . .

Last edited by moses; 06-28-2003 at 01:03 AM.
 
Old 06-28-2003, 10:30 AM   #5
dmaxj
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
correct

You are right. It does involve proc_fs.h. And I am unsure whether this has to be done from user space, but I think that the answer is yes.

Here is my code so far.

#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/proc_fs.h>
#define BUF_LEN 50

int read_my_clock( char *a, char **b, off_t c, int d, int e)
{
printk(KERN_ALERT, "\nread_my_clock\n") ;
/* this is the function that I write to read
the clock file info that I created in proc
*/
}

struct proc_dir_entry dc_clock_mod_file = {
0,
12,
"dc_clock_mod",
S_IFREG | S_IRUGO,
1,
0,
0,
BUF_LEN,
NULL,
read_my_clock,
NULL
};

int init_module()
{
return proc_register(&proc_root, &dc_clock_mod_file);
}

void cleanup_module()
{
proc_unregister(&proc_root, dc_clock_mod_file.low_ino) ;
}



This is nothing more than the skeleton. This code does create the module in the kernel.
 
Old 07-02-2003, 09:44 AM   #6
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
I'm running out of useful things to say -- I am not a kernel hacker, or really much of a programmer, I just hack things to make them work for me and I've never had to hack the kernel to make it work (well, once, but that had nothing to do with modules).
I suggest you request that a moderator move this post to the programming forum and ask for help there. There are some very good programmers who frequent LQ, and I'm sure you will get more useful help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial for writing cypher kernel module ta0kira Programming 7 06-19-2011 10:43 PM
Correlation between /proc/devices and /proc/modules ColinLadyka Linux - General 1 02-13-2006 05:25 PM
Problem with writing module mohsena Programming 3 10-16-2005 09:51 AM
How to read from /proc entry in another kernel module? linux_lover2005 Programming 0 01-14-2005 05:44 AM
Writing to "/dev/usb/hiddev*" and to "/proc/bus/usb/00B/00S" throw an arror EI stpg Programming 0 07-14-2004 05:44 AM


All times are GMT -5. The time now is 12:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration