Solved

Syscall from module

Posted on 2001-07-17
8
246 Views
Last Modified: 2008-01-16
Hi

I want to be abe to write to a file from a driver module - loaded into the kernel ....

I tried this
char buffer[6]="sunny";

int fd = sys_open(filename, 1 , 0)
sys_write(fd, buffer, sizeof(buffer));

and nothing happens. "sunny" isnot written to filename

Can somebody plsssss helppppppppp --I am a novice kernel hacker on a deadline
0
Comment
Question by:sunny447492
[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
8 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6291297
// add
fsync(fd);
close(fd);
0
 

Author Comment

by:sunny447492
ID: 6295816
Nopes it didnt work
0
 
LVL 5

Expert Comment

by:bryanh
ID: 6316030
You don't mention a return code from sys_write(), and the code you show doesn't even get it.

One problem with your code is that the "buffer" argument to sys_write() is an address in the user address space, whereas your buffer is in the kernel address space.  You have to use get_ds() and set_ds() to set the user address space to the kernel address space while sys_write() runs.

Incidentally, people usually go in a layer lower than sys_open/sys_write and call filp_open() and file->f_op->write().  In fact, in my experience the sys_* system call handlers aren't exported for use by loadable kernel modules.
0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

Author Comment

by:sunny447492
ID: 6317473
Hi Bryanh,

Thanks for your reply. I had come across an article writtn by Rubini about using get_ds() and set_ds() and I even tried it but was not successful. Would you be able to provide a code snippet thats tested to do such a call -
? I can then give you the points :>

Thanks

Regards,

Sunny
0
 

Author Comment

by:sunny447492
ID: 6317571
Hi Bryanh,

Thanks for your reply. I had come across an article writtn by Rubini about using get_ds() and set_ds() and I even tried it but was not successful. Would you be able to provide a code snippet thats tested to do such a call -
? I can then give you the points :>

Thanks

Regards,

Sunny
0
 
LVL 5

Accepted Solution

by:
bryanh earned 200 total points
ID: 6318081
I've put an example program at ftp://giraffe-data.com/pub/filewrite.c  .  You can contact me at bryanh@giraffe-data.com.  This file is a loadable kernel module -- just compile it and insmod it to see it go.  It works for me.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9871635
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:#6318081}

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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