Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl2/lvm2/dist/libdm/ioctl Fix /var/run/dev.db depe...



details:   https://anonhg.NetBSD.org/src/rev/3947b841bb9a
branches:  trunk
changeset: 752946:3947b841bb9a
user:      haad <haad%NetBSD.org@localhost>
date:      Fri Mar 12 16:24:40 2010 +0000

description:
Fix /var/run/dev.db dependency by adding new get_dev_name routine which
converts raw device major:minor number to block device path. By reading
/dev and using stat to find block device major:minor numbers.

diffstat:

 external/gpl2/lvm2/dist/libdm/ioctl/libdm-nbsd-iface.c |  50 ++++++++++++++++-
 1 files changed, 45 insertions(+), 5 deletions(-)

diffs (77 lines):

diff -r 258caaffa40b -r 3947b841bb9a external/gpl2/lvm2/dist/libdm/ioctl/libdm-nbsd-iface.c
--- a/external/gpl2/lvm2/dist/libdm/ioctl/libdm-nbsd-iface.c    Fri Mar 12 15:12:12 2010 +0000
+++ b/external/gpl2/lvm2/dist/libdm/ioctl/libdm-nbsd-iface.c    Fri Mar 12 16:24:40 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: libdm-nbsd-iface.c,v 1.6 2009/12/09 00:15:51 haad Exp $        */
+/*      $NetBSD: libdm-nbsd-iface.c,v 1.7 2010/03/12 16:24:40 haad Exp $        */
 
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
@@ -358,6 +358,45 @@
        return 1;
 }
 
+static char *
+get_dev_name(char *d_name, uint32_t d_major, uint32_t d_minor)
+{
+       static char d_buf[MAXPATHLEN];
+       struct dirent *dire;
+       struct stat st;
+       DIR *dev_dir;
+
+       int err;
+       char *name;
+
+       dev_dir = opendir("/dev");
+
+       while ((dire = readdir(dev_dir)) != NULL) {
+
+               if (strstr(dire->d_name, d_name) == NULL)
+                       continue;
+
+               snprintf(d_buf, MAXPATHLEN, "/dev/%s", dire->d_name);
+
+               if ((err = stat(d_buf, &st)) < 0)
+                       printf("stat failed with %d", err);
+
+               if (st.st_mode & S_IFBLK){
+                       if ((major(st.st_rdev) == d_major) && (minor(st.st_rdev) == d_minor)) {
+                               strncpy(d_buf, dire->d_name, strlen(dire->d_name) + 1);
+                               name = d_buf;
+                               break;
+                       }
+               }
+
+               memset(d_buf, '0', sizeof(d_buf));
+       }
+
+       (void)closedir(dev_dir);
+
+       return name;
+}
+
 /*
  * @dev_major is major number of char device
  *
@@ -409,16 +448,17 @@
        dev = MKDEV(major,dev_minor);
 
        mode |= S_IFBLK;
-       
-       name = devname(dev,mode);
+
+       if ((name = devname(dev,mode)) == NULL)
+               name = get_dev_name(kd[i].d_name, major, dev_minor);
 
        r = snprintf(buf, (size_t) bufsize, "/dev/%s",name);
 
        free(kd);
-       
+
        if (r < 0 || r > bufsize - 1 || name == NULL)
                return 0;
-       
+
        return 1;
 }
 



Home | Main Index | Thread Index | Old Index