Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the opposite of `mknod`?

I am learning to write character device drivers from the Kernel Module Programming Guide, and used mknod to create a node in /dev to talk to my driver.

However, I cannot find any obvious way to remove it, after checking the manpage and observing that rmnod is a non-existent command.

What is the correct way to reverse the effect of mknod, and safely remove the node created in /dev?

like image 811
merlin2011 Avatar asked Mar 18 '14 18:03

merlin2011


People also ask

How do I get rid of mknod?

Re: How to delete a device file created with mknod ? You need the "-k" option to rmsf in order to remove the device from the running kernel.

What does mknod?

The mknod command makes a directory entry and corresponding i-node for a special file. The first parameter is the name of the entry device. Select a name that is descriptive of the device. The mknod command has two forms that have different flags.

How do you use mknod commands?

The mknod command in Linux can be used to indicate the special files. These usually include disk, tape, or diskette. For that, all you need to do is pass the b flag. Running the mknod command with the b flag will display the block-oriented device files.


1 Answers

The correct command is just rm :)

A device node created by mknod is just a file that contains a device major and minor number. When you access that file the first time, Linux looks for a driver that advertises that major/minor and loads it. Your driver then handles all I/O with that file.

When you delete a device node, the usual Un*x file behavior aplies: Linux will wait until there are no more references to the file and then it will be deleted from disk.

Your driver doesn't really notice anything of this. Linux does not automatically unload modules. Your driver wil simply no longer receive requests do to anything. But it will be ready in case anybody recreates the device node.

like image 117
1000 Bites Avatar answered Oct 02 '22 10:10

1000 Bites