Solved

Syscall from module

Posted on 2001-07-17
8
239 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Debian 3 - initrd rebuild 3 69
understanding folder structure inside an rpm 2 60
check failing on yum update 5 29
Embeded Linux on Router 9 99
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now