mkinitrd unification across distributions
 help / color / mirror / Atom feed
From: Alan Jenkins <alan-jenkins-cCz0Lq7MMjm9FHfhHBbuYA@public.gmane.org>
To: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] dracut-gencmdline: use udevadm info to go from /dev/X to /sys/Y
Date: Thu, 29 Oct 2009 09:29:16 +0000	[thread overview]
Message-ID: <4AE9606C.1090008@tuffmail.co.uk> (raw)

Avoid some manual spelunking in sysfs.  This makes for slightly shorter
and simpler code.

diff --git a/dracut-gencmdline b/dracut-gencmdline
index 625546c..a4e2c3d 100755
--- a/dracut-gencmdline
+++ b/dracut-gencmdline
@@ -169,17 +169,20 @@ resolve_device_name() {
     echo "$1" 
 }
 
+finddevinsys() {
+    path=$(udevadm info --name "$1" --query=path 2>/dev/null)
+    if [ -n "$path" ]; then
+        echo "/sys/$path"
+        return 0
+    fi
+    return 1
+}
+
 finddevnoinsys() {
     majmin="$1"
     if [ -n "$majmin" ]; then
-        dev=$(for x in /sys/block/* ; do find $x/ -name dev ; done | while read device ; do \
-              echo "$majmin" | cmp -s $device && echo $device ; done)
-        if [ -n "$dev" ]; then
-            dev=${dev%%/dev}
-            dev=${dev%%/}
-            echo "$dev"
-            return 0
-        fi
+        finddevinsys "/dev/block/$majmin"
+        return $?
     fi
     return 1
 }
@@ -252,11 +255,10 @@ findstoragedriver () {
         return
     fi
 
-    local majmin=$(get_numeric_dev dec "$device")
-    local sysfs=$(finddevnoinsys "$majmin")
+    local sysfs=$(finddevinsys "$device")
 
     if [ -z "$sysfs" ]; then
-        #error "WARNING: $device major:minor $majmin not found, skipping"
+        #error "WARNING: $device not found in sysfs, skipping"
         return
     fi
 


             reply	other threads:[~2009-10-29  9:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-29  9:29 Alan Jenkins [this message]
     [not found] ` <4AE9606C.1090008-cCz0Lq7MMjm9FHfhHBbuYA@public.gmane.org>
2009-10-29 10:59   ` [PATCH] dracut-gencmdline: use udevadm info to go from /dev/X to /sys/Y Alan Jenkins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AE9606C.1090008@tuffmail.co.uk \
    --to=alan-jenkins-ccz0lq7mmjm9fhfhhbbuya@public.gmane.org \
    --cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox