Solved

write to userspace files in kernel

Posted on 2001-08-16
3
247 Views
Last Modified: 2012-05-04
 I use kernel 2.4.2 ,add following code into
  ipchains_core.c, to record every packet :

  struct file *myfile;
  char log_file[100];
  char buf[100];
  ...
  strcpy(log_file,"/var/log/my.log");

  strcpy(buf,"This is a test!\n");
  ..
  myfile=filp_open(log_file,O_WRONLY|O_APPEND,0600);
  ...
  myfile->f_op->write(myfile,buf,strlen(buf),    \
                      &myfile- >f_pos);
  ...

  filp_close(myfile,NULL);
   
  ...
  when the new kernel go in work, code is called,
  this kernel breaks down at once!
  I don't know why this kernel breaks down,
  I need your help, please.

0
Comment
Question by:verybigcat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 200 total points
ID: 6399472
This is a very common error.  The "buf" parameter is an address in user space.   You're passing an address in kernel space, which as a user space address is rather arbitrary.

You have to use get_ds() and set_ds() to make the kernel address space the user address space while the write operation runs.

Because this is a frequent question on EE, I have an example program at <ftp://giraffe-data.com/pub/filewrite.c> that shows this.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9915941
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#6399472}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question