Calling unlink() on a character driver should work just as Alan describes (provided that the character driver supports the unlink() method).  In the specific case that you ask about about, the /dev/mtdblock1 driver is a block driver.

The explanation is still correct, except that it is the block driver's unlink() method that is called.  And it is the block driver that must self destruct when the unlink() method is called.

The /dev/mtd1 is, I assume, a character driver that was instantiated via bchdev_register().  It should be unlinked first before the block driver.  The bchdev_unlink() method will teardown the /dev/mtd1 instance when it can.  Then the block driver can be unlinked.

On 11/18/2020 2:38 PM, Alan Carvalho de Assis wrote:
Hello Cate,

You can remove a driver by unlinking the device node and closing all
open references to the driver (provided that the driver properly
implements the unlink method.)

nsh> rm /dev/node is one way.

Calling unlink() is another.

What exactly are you willing to do? Could you please describe your use case?

BR,

Alan

On 11/18/20, Ecaterina FEDORENCO <ecaterina.fedore...@gmail.com> wrote:
Hello all,

I have a question regarding the device nodes from /dev folder.

The sequence I execute is the following:
         1. smart_initialize method - creates /dev/smart1d file

*mtd_part = mtd_partition(mtd, partoffset, (partsize >> 2) * 8);
smart_initialize(1, mtd_part, partname);*

*           mount("/dev/smart1d", "/mnt/smart", "smartfs", 0, NULL);*
         2. ftl_initialize and bchdev_register - create /dev/mtd1 and
/dev/mtdblock1






*mtd_part2 = mtd_partition(mtd, partoffset, (partsize>>2)*8);
  ftl_initialize(1, mtd_part2);              snprintf(blockname, 32,
"/dev/mtdblock%d", 1);             snprintf(charname, 32, "/dev/mtd%d",
1);             bchdev_register(blockname, charname, false);*
Is there a way to remove the device nodes(files) from /dev folder?

For the second step I found *int bchdev_unregister(FAR const char
*chardev),* which removes only */dev/mtd1 *node.
For the first step, *unregister_driver() *can be called to remove a device
driver, but I am not sure that these calls are sufficient.

Thank you,
Cate

Reply via email to