0

I'm doing two system calls (linux 3.2). I've created these two system calls, and I have compiled the kernel. These two system calls need to write and read on a file. I'll modify two system calls, read and write to read this file. So this file need to be accessible for these four system calls (read, write and my two system calls). My question is, where and how I can create this file and how do I access it and modify it. I will use this file only for these system calls.

2
  • So, you want to read and write to a file inside a system call? Mar 6, 2013 at 0:25
  • Yes, the task of my system call is add one or partition(string which identify a partition) into a file. When the system call read/write are called they will verify if the partition is blocked or not (if the partition is on file), if the partition is blocked them read/write shouldn't be executed. Mar 6, 2013 at 2:30

2 Answers 2

2

This is actually a very good educational question - the answers hilighted here show where/why its an incredibly difficult and dangerous thing to do. However, the "solution" is easy if you, for example, have a user space daemon waiting for an event/signal/IO to indicate it should do the reading/writing for the kernel. This could be as simple as a /proc entry with some count/semaphore which the user space process reads/polls/select's on.

Solving this is a good practise to understand the trade offs in any/many solutions.

0

Reading or writing files inside the Linux kernel is considered "bad".

Add a system call that adds/removes a name in a list (not necessarily a Linux kernel List, but that's not a horrible idea either - could be an array, etc), and then use a user-mode program to set the names in the list from the file.

Next, I don't think it's that easy to tie a read/write system call to a partition. Might be easier to deal with that in open?

2
  • Thank you for your answer. I agree that dealing with open would be easier but my teacher specified to be read and write. My doubt is where I put this file and how I can access this file from my system calls. Mar 6, 2013 at 13:16
  • You shouldn't. If your teacher is asking you to do that, then he's asking you to do things in a way that is FAR from acceptable to the Linux community. It is not how you solve these problems. It is HIGHLY likely that sooner or later you will cause some sort of deadlock if you call other system calls (or the internal functions supporting such system calls) from a system call. Mar 6, 2013 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.