LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-12-2006, 04:16 AM   #1
vishalbutte
Member
 
Registered: Dec 2005
Posts: 80

Rep: Reputation: 15
Question 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!!!
 
Old 01-12-2006, 10:56 PM   #2
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
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.
 
Old 01-13-2006, 06:29 AM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 01-13-2006, 06:57 AM   #4
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
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.
 
Old 01-13-2006, 07:34 AM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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.
 
Old 01-13-2006, 07:52 AM   #6
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
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.
 
Old 01-13-2006, 08:20 AM   #7
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
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
 
Old 01-13-2006, 08:38 AM   #8
paragn
Member
 
Registered: Jan 2006
Distribution: Red Hat EL5, Fedora 7
Posts: 259

Rep: Reputation: 30
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.
 
  


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
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
shell script + change shell && continue darkRoom Programming 6 02-25-2005 02:50 AM
Looking for addusesr&passwd shell script szklanka Programming 1 02-22-2005 08:37 PM
Shell Script with ssh & scp ErikJohnson Linux - Software 3 03-11-2004 04:53 PM
Shell Script with ssh & scp ErikJohnson Linux - Networking 1 03-11-2004 04:14 PM


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