LinuxQuestions.org
Help answer threads with 0 replies.
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 12-04-2009, 10:20 AM   #1
sim0ne
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Rep: Reputation: 0
Trouble modifying fcntl.h


hello , i need to modify the kernel header fcntl.h (and other files but for now it's sufficient) . I must add a new variable to handle files.

/* BEGIN */

#define O_SESSION 040

/* END */

After i modified it i recompiled the kernel.
I started with my new kernel and tried to use the new variable in a c files .


/* BEGIN */
#include <fcntl.h>
#include...
.
.
main{

int fd
fd = open(argv[1], O_RDWR | O_SESSION);

/* END */



When i compile the c file , the answer is that the variable i defined (O_SESSION) is undeclared.

So what is my error?

Can anyone help me?

Thank you and sorry for my poor english.
 
Old 12-04-2009, 10:37 AM   #2
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
The syntax for open system call is ...

fd=-open(pathname,flags,modes);

you swapped the flags and modes. check that !

example

Code:
fdl=open("/etc/passwd",O_RDONLY);
fd2=open("local",O_RDWR);

Last edited by raju.mopidevi; 12-04-2009 at 10:38 AM.
 
Old 12-04-2009, 10:52 AM   #3
sim0ne
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by raju.mopidevi View Post
The syntax for open system call is ...

fd=-open(pathname,flags,modes);

you swapped the flags and modes. check that !

example

Code:
fdl=open("/etc/passwd",O_RDONLY);
fd2=open("local",O_RDWR);
If i change the code the problem it's the same . The system do not recognize the variable i define in the kernel header. If i write for example : fd2=open("local",O_SESSION) the compiler say me that O_SESSION is undeclared. I did some mistake modifing the kernel headers, but i do not understand what mistake!
 
Old 12-04-2009, 11:02 AM   #4
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
If it is only problem with header, but not with headers then compare with original source code.

download kernel source code archive.
 
Old 12-04-2009, 11:28 AM   #5
sim0ne
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Yes but if i want change a kernel header what is the way?
I think i must recompile the kernel if a change a kernel header. Is that right??
 
Old 12-04-2009, 11:38 AM   #6
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
if you want to change the kernel make a backup copy ! and then compile ....

compiling your kernel
this article may help you !
 
Old 12-04-2009, 01:40 PM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
When you compile programs, they refer to the kernel-headers or libc-headers which are packaged separately from the kernel sources.
You could explicitly point the sources at your modified headers in the kernel sources using -I/path/to/modified/files. But that is not really correct because the headers in the kernel sources are not sanitized for external use.
The libc-headers are sanitized headers which are used to compile your glibc version and it is these headers which are referred to by (nearly) all sources at compile time. You'll find these headers under /usr/include/asm, /usr/include/asm-generic and /usr/inlcude/linux.
 
Old 12-05-2009, 10:57 AM   #8
sim0ne
LQ Newbie
 
Registered: Dec 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gnashley View Post
When you compile programs, they refer to the kernel-headers or libc-headers which are packaged separately from the kernel sources.
You could explicitly point the sources at your modified headers in the kernel sources using -I/path/to/modified/files. But that is not really correct because the headers in the kernel sources are not sanitized for external use.
The libc-headers are sanitized headers which are used to compile your glibc version and it is these headers which are referred to by (nearly) all sources at compile time. You'll find these headers under /usr/include/asm, /usr/include/asm-generic and /usr/inlcude/linux.
So you are saying that when i compile file with gcc the headers it search are in "/usr/include/asm, /usr/include/asm-generic and /usr/inlcud/linux".

i see that in usr/include/asm there is the same header i need "fcntl.h" .
But that header is different from the header i modified and recompiled in my new kernel.
Do you suggest to overwrite that header with the one i modified in the kernel ?

thank you
 
Old 12-05-2009, 12:09 PM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
It would be better to modify that one -but keep a backup of the roiginal. These installed ehaders are the ones that define the functions for nearly all the software compiled on your system. That is why you should not upgrade them to match the kernel version you are running. Kernel-headers should only be upgraded when the glibc version is updated and the version of headers should, again, match those used to compile glibc with -not necessarily the version of the kernel you are running.
If the software you are compiling is a kernel module, then you should use the header from the kernel sources, but otherwsie use the installed one.
 
Old 12-05-2009, 01:13 PM   #10
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I think one would normally implement an ioctl within a file-system module rather than altering the fcntl header.
Kevin Barry
 
  


Reply


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
fcntl F_SETLKW on NFS kpj104 Linux - Kernel 0 05-12-2009 12:49 PM
Cannot find a file : fcntl.c ankit4u1 Red Hat 6 08-06-2007 06:15 PM
Do ioctl and fcntl affect pending data on a socket? Millenniumman Programming 2 07-03-2007 03:28 PM
fcntl I can not understand use level3 Programming 5 06-15-2006 03:15 AM
is a socket already opened? fcntl(); Thinking Programming 1 09-19-2005 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:16 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