Solved

write to userspace files in kernel

Posted on 2001-08-16
3
246 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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