Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
errno variable stores the error code. Remember to check it just after the call that fails.
0 you used id open (DEVICE_FILE_NAME, 0) means O_RDONLY. The example is O_RDWR. Which one is correct in your case? It depends on the device. O_RDONLY is safer, through and should work for all devices. One of the popular error codes in the situation like yours is that the file was not found, but you need to check it.
Another note: you can use perror to convert the code you get from errno to text message.
Check attributes of the file you created with 'mknod'. Make sure that you call open() from a process with privileges enough to access "/dev/your_file".
How to check source-code of mknod? That is, where can I find the source codes of mknod?
Uhh… mknod() is a kernel-level system call with a small libc wrapper. So basically, here’s the actual source code. If you want the wrapper, look in the glibc sources.
If you’re talking about mknod the utility, it is part of GNU coreutils.
Regarding your earlier question, did you find out why your call to open() fails? You could use perror() to print a diagnostic.
Certainly, one of the nice benefits of Linux is that you can see "the actual source-code of the operating system." So you can, if you choose, trace your open() call, all the way through the actual source-code of all of the software (kernel and otherwise) that ... resulted in the '-1' value that you received.
But you do need to recognize one of the important characteristics of that software: in the Unix-style environments, if (say) open() gives you a return-code such as "-1," it may not have any "additional information" to give you!
In the Microsoft Windows environments that you might be more familiar with, "extended error information" might be available ... that Unix-style environments simply do not offer.
But you do need to recognize one of the important characteristics of that software: in the Unix-style environments, if (say) open() gives you a return-code such as "-1," it may not have any "additional information" to give you!
Well, it must provide an errno interface to be POSIX-compliant. In fact, the POSIX notion of errno may be used in a similar manner to the returned value of GetLastError() (both are per-thread error codes, which should be accessed immediately after a suspected function fails because a subsequent, unrelated function may overwrite its value).
The only difference is that (IIRC) there are about 16000 WINAPI error codes, yet at most a couple hundred ones on a POSIX system (so with WINAPI, you might get more detailed information). Undoubtedly, WINAPI is much larger and monolithic than POSIX, so it must have to account for more errors.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.