fstools: media change detection (eg:sdcard) using kernel polling
authorMatthias Badaire <mbadaire@gmail.com>
Tue, 15 May 2018 22:07:37 +0000 (00:07 +0200)
committerJo-Philipp Wich <jo@mein.io>
Fri, 21 Jun 2019 12:17:22 +0000 (14:17 +0200)
Linux kernel has a polling mechanism that can be activated by changing
the parameter /sys/module/block/parameters/events_dfl_poll_msecs which
is deactivated by default or the /sys/block/[device]/events_poll_msecs
for one device.

This patch set the events_poll_msecs when a disk is inserted.
Once the media disk change event is sent by the kernel then we force a
re-read of the devices using /sbin/block info.

With this patch, insertion and ejection of sd card will automatically
generate partition devices in /dev.

Signed-off-by: Matthias Badaire <mbadaire@gmail.com>
[rewrap commit message, fix bashisms, fix non-matching condition,
 bump pkg release]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit cf8483cb4ffc99bf3f512bb134860ccc8c099abe)

package/system/fstools/Makefile
package/system/fstools/files/media-change.hotplug [new file with mode: 0644]

index 58be215f8f89bcef1f36a10ff525aaa6004b1807..60ccf09e1172c011d75e190749139ada4d5e9cca 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fstools
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/fstools.git
@@ -110,6 +110,7 @@ define Package/block-mount/install
        $(INSTALL_BIN) ./files/fstab.init $(1)/etc/init.d/fstab
        $(INSTALL_CONF) ./files/fstab.default $(1)/etc/uci-defaults/10-fstab
        $(INSTALL_CONF) ./files/mount.hotplug $(1)/etc/hotplug.d/block/10-mount
+       $(INSTALL_CONF) ./files/media-change.hotplug  $(1)/etc/hotplug.d/block/00-media-change
 
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/block $(1)/sbin/
        $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libblkid-tiny.so $(1)/lib/
diff --git a/package/system/fstools/files/media-change.hotplug b/package/system/fstools/files/media-change.hotplug
new file mode 100644 (file)
index 0000000..30fc3d5
--- /dev/null
@@ -0,0 +1,8 @@
+[ -n "$DISK_MEDIA_CHANGE" ] && /sbin/block info
+
+if [ "$ACTION" = "add" -a "$DEVTYPE" = "disk" ]; then
+       case "$DEVNAME" in
+               mtd*) : ;;
+               *) echo 2000 > /sys/block/$DEVNAME/events_poll_msecs ;;
+       esac
+fi