summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/pathnames.h1
-rw-r--r--shlibs/blkid/src/blkidP.h1
-rw-r--r--shlibs/blkid/src/devno.c38
3 files changed, 40 insertions, 0 deletions
diff --git a/include/pathnames.h b/include/pathnames.h
index f958a13bc..efe5c3bc8 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -74,6 +74,7 @@
#define _PATH_PROC_FILESYSTEMS "/proc/filesystems"
#define _PATH_PROC_MOUNTS "/proc/mounts"
#define _PATH_PROC_PARTITIONS "/proc/partitions"
+#define _PATH_PROC_DEVICES "/proc/devices"
#ifndef _PATH_MOUNTED
# ifdef MOUNTED /* deprecated */
diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index 64ebeee83..10c29776b 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -339,6 +339,7 @@ struct dir_list {
struct dir_list *next;
};
extern void blkid__scan_dir(char *, dev_t, struct dir_list **, char **);
+extern int blkid_driver_has_major(const char *drvname, int major);
/* lseek.c */
extern blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence);
diff --git a/shlibs/blkid/src/devno.c b/shlibs/blkid/src/devno.c
index c976228af..8518f9fd9 100644
--- a/shlibs/blkid/src/devno.c
+++ b/shlibs/blkid/src/devno.c
@@ -32,6 +32,7 @@
#endif
#include "blkidP.h"
+#include "pathnames.h"
char *blkid_strndup(const char *s, int length)
{
@@ -328,6 +329,43 @@ err:
return -1;
}
+/*
+ * Returns 1 if the @major number is associated with @drvname.
+ */
+int blkid_driver_has_major(const char *drvname, int major)
+{
+ FILE *f;
+ char buf[128];
+ int match = 0;
+
+ f = fopen(_PATH_PROC_DEVICES, "r");
+ if (!f)
+ return 0;
+
+ while (fgets(buf, sizeof(buf), f)) { /* skip to block dev section */
+ if (strncmp("Block devices:\n", buf, sizeof(buf)) == 0)
+ break;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ unsigned int maj;
+ char name[64];
+
+ if (sscanf(buf, "%u %64[^\n ]", &maj, name) != 2)
+ continue;
+
+ if (maj == major && strcmp(name, drvname) == 0) {
+ match = 1;
+ break;
+ }
+ }
+
+ fclose(f);
+
+ DBG(DEBUG_DEVNO, printf("major %d %s associated with '%s' driver\n",
+ major, match ? "is" : "is NOT", drvname));
+ return match;
+}
#ifdef TEST_PROGRAM
int main(int argc, char** argv)