Solved

Syscall from module

Posted on 2001-07-17
8
242 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 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