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
Solved

write to userspace files in kernel

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why should double free() crash? 7 35
GUI development for Ubuntu 8 217
Identify Linux loader 67 181
improve Shell script 5 155
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 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