LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-03-2006, 02:48 AM   #1
mushudubi
LQ Newbie
 
Registered: Jan 2006
Posts: 1

Rep: Reputation: 0
unable to use sys_calls (like open etc.) in module code


Hi,
when trying to program kernel module I can't use sys_calls like open(), read() etc. in my code.
I include the following files:

#define __KERNEL_SYSCALLS__
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/smp_lock.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include <linux/string.h>
#include <linux/file.h>
#include <asm/uaccess.h>
#include <linux/proc_fs.h>
#include <asm/errno.h>
#include <asm/io.h>

my Makefile looks like this:

obj-m += my_code.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) cleans:

and when I do make the following warning is shown:
"warning: implicit declaration of function `open'"
--------------------------------------------------

How can I overcome this?
I am using FEDORA core 2.6.11

thanks.
 
Old 01-03-2006, 10:04 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
i think there might be a way to use userspace syscalls inside the kernel but it's wastefull
better to use internal functions like
Code:
#include < linux/fs.h>
struct file *fp;
fp = filp_open("/some/file", O_RDONLY, 0);
filp_close(fp, NULL);
how to figure it out is look in fs/open.c at sys_open() to see how it's implemented and there you find
Code:
struct file *f = filp_open(tmp, flags, mode);
there you go
couldn't be easier
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
First Post! Unable to compile source code J--Lew Linux - Newbie 5 08-16-2005 03:17 PM
Why is my socket unable to bind to the port in the C Code. mcp_achindra Programming 10 03-24-2004 08:34 AM
Open Firmware code for booting OS from SATA : sample code available somewhere ? drsparikh Linux - Hardware 0 03-12-2004 11:16 AM
Volume control is unable to run correctly. Unable to open audio device '/dev/mixer'. sevenreams Slackware 1 05-16-2003 07:29 PM
About Open source code anandc Linux - Newbie 3 03-13-2003 04:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration