LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Trouble modifying fcntl.h (https://www.linuxquestions.org/questions/programming-9/trouble-modifying-fcntl-h-773473/)

sim0ne 12-04-2009 10:20 AM

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.

raju.mopidevi 12-04-2009 10:37 AM

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);


sim0ne 12-04-2009 10:52 AM

Quote:

Originally Posted by raju.mopidevi (Post 3779855)
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! :D

raju.mopidevi 12-04-2009 11:02 AM

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

download kernel source code archive.

sim0ne 12-04-2009 11:28 AM

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??

raju.mopidevi 12-04-2009 11:38 AM

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

compiling your kernel
this article may help you !

gnashley 12-04-2009 01:40 PM

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.

sim0ne 12-05-2009 10:57 AM

Quote:

Originally Posted by gnashley (Post 3780053)
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

gnashley 12-05-2009 12:09 PM

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.

ta0kira 12-05-2009 01:13 PM

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


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