Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-20-2016, 09:08 AM   #1
Registered: Dec 2008
Posts: 39

Rep: Reputation: 1
using mknod to create a device file.

Hi All,

Here i am using below sample code to create a character device file.
mknod returns success but when i do ls -ltr at "/home/xxxx/" i donot see any file there with temp_dev.

Any thing i am missing here to understand?.

 1#include <stdio.h>
 2#include <sys/types.h>
 3#include <sys/stat.h>
 4#include <fcntl.h>
 5#include <unistd.h>
 6#include <string.h>
 7#include <error.h>
 9int main()
11    dev_t dev;
12    int status;
13    int errno;
15    if (status = mknod("/home/xxxx/temp_dev",S_IRUSR|S_IWUSR|S_IFCHR, dev))
16    {
17        printf("%s \n", strerror(errno));
18        sleep(30);
19    }
20    return 0;
Old 09-20-2016, 06:23 PM   #2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,844

Rep: Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477Reputation: 1477
It isn't going to work.

The mknod uses the contents of dev to determine how to create the file. Very likely, the contents of dev are 0, which isn't used.

The mknod system call is really not used to create devices in linux. The /dev/xxxx entries are created when a driver is loaded, and the driver registers with the kernel to allocate a device/unit value, which is only presented for legacy use - the kernel itself doesn't use them anymore as the directory entry in /dev (a devtmpfs filesystem) directly connects to the driver internal structures for access.

Linux also doesn't really distinguish a difference between block and character devices, though for historical compatibility, the bits are still set.

One of the other things is that only root could create a device. The only non-root devices allowed are sockets (not created via mknod) and fifo files (you don't use mknod to create those - you use mkfifo (a library function, not system call).
Old 09-21-2016, 03:42 AM   #3
Registered: Dec 2008
Posts: 39

Original Poster
Rep: Reputation: 1
Thanks Pollard for the info.


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
mknod: does the creation of a block device write data into the device? stf92 Slackware 7 11-20-2013 12:54 PM
[SOLVED] How do we create Device Node Directory using Mknod command jendeavor Linux - Hardware 4 11-05-2012 01:12 AM
device node created using mknod dissapear after reboot minike Slackware 2 12-13-2006 06:12 PM
Device drivers : How to insmod and mknod through an application program? shendeswanand Linux - Newbie 0 02-08-2006 12:28 PM
Create /dev in chroot jail - mknod question The_JinJ Linux - General 1 12-14-2005 04:49 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration