[systemd-devel] [PATCH] udev: Make builtin firmware to find in subdirectories

WaLyong Cho fyd0706 at gmail.com
Sun Jun 16 23:17:12 PDT 2013


From: WaLyong Cho <walyong.cho at samsung.com>

We can specify firmware path using "--with-firmware-path" configure
option.
In some of system, firmware can be located in subdirectories of the
firmware path.
If there are many firmware directories in below specified path then we
have to define those to "--with-firmware-path".
To avoid this, if builtin firmware could not find firmware in specified
directories then try to find firmware in subdirectories.

Signed-off-by: WaLyong Cho <walyong.cho at samsung.com>
---
 src/udev/udev-builtin-firmware.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/udev/udev-builtin-firmware.c b/src/udev/udev-builtin-firmware.c
index b80940b..fb43a37 100644
--- a/src/udev/udev-builtin-firmware.c
+++ b/src/udev/udev-builtin-firmware.c
@@ -74,6 +74,34 @@ exit:
         return ret;
 }
 
+static FILE* find_firmware(const char *path, const char *fwpath, const char *firmware)
+{
+        char searchpath[UTIL_PATH_SIZE];
+        FILE *fwfile = NULL;
+        DIR *srcdir;
+        struct dirent *dent;
+        struct stat statbuf;
+
+        srcdir = opendir(path);
+        while ((dent = readdir(srcdir)) != NULL) {
+                if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0)
+                        continue;
+                if (fstatat(dirfd(srcdir), dent->d_name, &statbuf, 0) < 0)
+                        continue;
+                if (S_ISDIR(statbuf.st_mode)) {
+                        strscpyl(fwpath, UTIL_PATH_SIZE, path, dent->d_name, "/", firmware, NULL);
+                        fwfile = fopen(fwpath, "re");
+                        if (fwfile == NULL) {
+                                strscpyl(searchpath, UTIL_PATH_SIZE, path, dent->d_name, "/", NULL);
+                                fwfile = find_firmware(searchpath, fwpath, firmware);
+                        }
+                        if (fwfile != NULL)
+                                return fwfile;
+                }
+        }
+        return NULL;
+}
+
 static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], bool test)
 {
         struct udev *udev = udev_device_get_udev(dev);
@@ -107,6 +135,11 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
                 fwfile = fopen(fwpath, "re");
                 if (fwfile != NULL)
                         break;
+                else {
+                        fwfile = find_firmware(searchpath[i], fwpath, firmware);
+                        if (fwfile != NULL)
+                                break;
+                }
         }
 
         strscpyl(loadpath, sizeof(loadpath), udev_device_get_syspath(dev), "/loading", NULL);
-- 
1.7.9.5



More information about the systemd-devel mailing list