LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   C & kernel data structure & shell script (http://www.linuxquestions.org/questions/programming-9/c-and-kernel-data-structure-and-shell-script-402390/)

vishalbutte 01-12-2006 04:16 AM

C & kernel data structure & shell script
 
i want to save the absolute pathname of the file & its md5 hash into one file & while booting the linux kernel want to extract the pathname & its hash value into kernel data structure with same attributes.

So how can i do it?

if i use shell script to insert the contents into the file then how can i extract it into kernel data structure in 'C' program while booting the kernel?

thankx in advance!!!

paragn 01-12-2006 10:56 PM

Hi,
>want to save the absolute pathname of the file & its md5 hash into one file
ok do it by writing a C program that stores the absolute file name and its md5sum

>& while booting the linux kernel want to extract the pathname & its hash value into kernel data structure with same attributes.
so you have to write a system call that writes to data structure that must exist in kernel by modifying kernel and installing it.thus whenever system boots call your user C program that calls that kenrel function which writes to data structure in kernel

>So how can i do it?
write kernel source file that adds system call. exports that function call.use that function to write required attributes in kernel. thats it.

>if i use shell script to insert the contents into the file then how can i extract it into kernel data structure in 'C' program while booting the kernel?
i dont thing you need shell scritps to insert content in file. to extract kenrel data structure write read system call on that data structure.

jtshaw 01-13-2006 06:29 AM

Not to be nit picky.. but you should probably write a module that does this and not a system call (which would not be centralized). The reason being if you ever want to upgrade your kernel it is a lot easier to get a module to work with the new kernel then it is to re-patch the kernel with the changes you made for the system call. It is much easier to write something self contained that uses the standard write system call.

paragn 01-13-2006 06:57 AM

jtshaw,
vishalbutte want to maintain kernel data structure as soon as system boots up. so i dont seem any way at userspace to solve this problem with writing a module without using system call that write/read to kernel data structure. i know my solution is difflicult to implement.

jtshaw 01-13-2006 07:34 AM

What exactly is calling the system call? System calls by default are user space calls into the kernel, how does that not have the same issue?

It he module is statically compiled into the kernel you can absolutely get the same effect with a better division of code.

paragn 01-13-2006 07:52 AM

hi,
What i consider that to maintain a data structure that have 2 fields filename,its MD5 its needed to add structure header file in kernel then write kernel read/write functions to this structure and export this functions so that user C program can use that thing and by using data_read()/data_write() in user space can map to kernel internal functions by adding new system calls thats it. i did this stuff 2 years back successfully with maintaining big kernel data structure by writing dynamic strings to kenrel memory.

jtshaw 01-13-2006 08:20 AM

Pargn,

I'm not saying your method won't work. But the system call part of it can be replaced using a module. The module still gives you all the same access to kernel space structures and prevents you from having to maintain the syscall tables and from having to write a userspace library to call your system calls so that a userspace program can use them.

I've done similar things using both methods and in the long run adding system calls is much harder to maintain... plus you have about a 0% chance of ever getting your code actually into the kernel if you add a system call. All the kernel developers will tell you the same thing, adding system calls is a last resort action and you better have a very very good reason for doing so.

John

paragn 01-13-2006 08:38 AM

yes I agree what you said. even i preferred what i did was last way to acheive what i want to do at that time.i know its hard to implement syscall. but i thought its the only way here.


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