Use Sys_Open from Kernel Level

Hi i am having some trouble using sys_open.At this point i am starting to think that i am doing something wrong with the arguments of the functions. An example of how i use it:

fd = sys_open("file.txt" , O_WRONLY | O_CREAT, 0);
sys_write(fd, "test\n", strlen("test\n"));
sys_fsync(fd);
sys_fdatasync(fd);
sys_close(fd);

fd value is a non negative integer (0) . Every single one of the functions returns 0 so i guess they are executed corectly.Except sys_write. Every time that i go to find the file after i write on it i can never find it any idea maybe something on my code is wrong?

10

1 Answer

The sys_ family of functions for Linux are considered deprecated now. However, for the purposes of this question, sys_open is a user-level function that calls the open syscall, which then calls the kernel level do_sys_open(), the latter two defined in fs/open.c. So to open files from within the kernel you should stick to kernel level functions and not user-level functions.

Here are some answers about opening files at the kernel level, some of which are deprecated as well, so be aware.

Your Answer

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

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest