[Toybox] [PATCH] mdev: Follow symbolic links in /sys

Marius Adaskevicius marius.a at fods.com
Thu Nov 15 22:08:31 PST 2018


The current code does not follow symbolic links when iterating over /sys 
entries
for block devices when run with -s flag. As a result, mdev rules are never
executed, for example, for USB flash drive partitions.

On i.MX6 board with 4.9.11 kernel:

/sys/block/sda -> 
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda
/sys/block/sda/sda1 -> 
/sys/devices/soc0/soc/2100000.aips-bus/2184200.usb/ci_hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1

As a workaround, USB flash drive has to be reinserted so that mdev rules are
executed in response to kernel hotplug events. The issue can be fixed by
adding a flag to follow symbolic links so that partition entries could be
processed as well.

---
  toys/pending/mdev.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c
index 0493f1a..b80efea 100644
--- a/toys/pending/mdev.c
+++ b/toys/pending/mdev.c
@@ -280,7 +280,7 @@ static int callback(struct dirtree *node)
    // Circa 2.6.25 the entries more than 2 deep are all either redundant
    // (mouse#, event#) or unnamed (every usb_* entry is called "device").

-  return (node->parent && node->parent->parent) ? 0 : DIRTREE_RECURSE;
+  return (node->parent && node->parent->parent) ? 0 : (DIRTREE_RECURSE 
| DIRTREE_SYMFOLLOW);
  }

  void mdev_main(void)
-- 
2.7.4




More information about the Toybox mailing list