2

I want to create a file in proc.c (kernel mode) and write something to it but the provided system call (open) is for user mode in user.h header and I can't include user.h in proc.c, Is there any other way to do this in proc.c?

Siavash
  • 308
  • 5
  • 17

2 Answers2

1

Use the code of the 'open' system call found in function sys_open() in sysfile.c, and assign the 'path' and 'omode' variables yourself.

(If you want to avoid code duplications, you can edit sys_open to call another function with the 'path', 'omode' variables, and use that function in your code in proc.c)

Yigal
  • 256
  • 3
  • 19
  • I have seen this (sys_open()), but just as you said I don't know how to use it and also I can not understand how open() function is related to it... please if it's possible give me a description and an example... – Siavash Dec 29 '15 at 10:17
  • When you use open(), a system call is made, and the kernel runs sys_open(). To use it you can copy the code of sys_open() to proc.c, and edit it to your needs – Yigal Dec 30 '15 at 08:50
  • but I think I should do something like open because sys_open() code depends a lot on other functions inside sys_file.c, Do you know how to do such thing? – Siavash Dec 30 '15 at 10:48
  • You can include sys_file.h (if there is such), or the files containing the methods you need - it is ok because they are all kernel – Yigal Dec 30 '15 at 10:56
  • So maybe you can include what sys_file.c is including (it is to better find only the needed ones among them) – Yigal Dec 30 '15 at 11:28
0

You should study the kernel file system. There you will see the relevant kernel functions.

Specifically You need the create, writei, iput functions. You will also need begin_trans and comnit_trans (since you are writing).

Morass
  • 323
  • 1
  • 5