LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-17-2007, 10:38 PM   #1
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
Question Cannot use copy_to_user inside the open() sys call routine


When I use the open() system call, this is mapped to a file operation structure defined in my driver module. (i.e. my_fops.open = myOpen())

In my myOpen function, it has some defined error codes specifically returned by some of my functions inside the myOpen(). My scenario is, when an error occurs in these functions, I need to bring the error code to the user space, and the way that I think to do that is by using the copy_to_user command. But as a usual use of copy_to_user, it needs to have a pointer to a user space address, and it must be passed to the system call via the system call arguments. Apparently the open() system call does not have a place for arguments such as this.

So can I still use the copy_to_user function inside the open() system call routine? If not, is there any other way of exporting my data to the user space inside open()/close() routine?
 
Old 05-18-2007, 01:43 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,158

Rep: Reputation: 328Reputation: 328Reputation: 328Reputation: 328
If you just need to return an error code, why not simply return it from the syscall using the normal return? Generally in the kernel syscalls return the negative of the error code (which gets translated back positive in user space).
 
Old 05-18-2007, 10:01 AM   #3
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Original Poster
Rep: Reputation: 41
ah I have some my own defined error codes in the opening functions of my module. for example, when it can return -5 which stands for module not yet initialize, or -3 for module already opened, or -1 module invalid parameters. I need these customize error codes to be exported to the user space
 
Old 05-25-2007, 04:19 AM   #4
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Original Poster
Rep: Reputation: 41
Does someone knows a way to copy data inside the open function(mapped to open syscall in user space) in kernel space to user space?
 
Old 05-26-2007, 10:09 AM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by archieval
Does someone knows a way to copy data inside the open function(mapped to open syscall in user space) in kernel space to user space?
You’d need something (i.e., a userspace address) to which to copy. If you are using a system call, the “standard practice” (as mentioned before) is to return the negative errno corresponding when you have an error (e.g., “return -EINVAL;”).

You can get a list of error numbers from asm/errno.h (try here and here for most of them).
 
  


Reply

Tags
kernel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
question about select sys call xatzipol Programming 1 10-30-2005 10:22 AM
Write sys call failing ppy Programming 1 11-05-2004 09:57 AM
Any sys call to list all users ? dileepkk Linux - General 5 07-06-2004 07:04 PM
Kill sys call eshwar_ind Programming 4 05-07-2004 12:41 PM
any sys call to get ip address of NIC jmdey Linux - General 2 05-30-2002 04:09 PM


All times are GMT -5. The time now is 07:44 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration