[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] Add cdroms and other non-partition based devices to blkid database (#485060)



Hi,

On 11/09/2009 01:58 PM, Martin Sivak wrote:
---
  loader2/driverdisk.c |   24 ++++++++++++++++++++++++
  1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/loader2/driverdisk.c b/loader2/driverdisk.c
index eca8605..298c896 100644
--- a/loader2/driverdisk.c
+++ b/loader2/driverdisk.c
@@ -23,6 +23,8 @@
  #include<string.h>
  #include<sys/stat.h>
  #include<unistd.h>
+#include<sys/types.h>
+#include<dirent.h>

  #include<blkid/blkid.h>

@@ -591,6 +593,8 @@ struct ddlist* findDriverDiskByLabel(void)
      char *ddLabel = "OEMDRV";
      struct ddlist *ddDevice = NULL;
      blkid_cache bCache;
+    struct dirent *direntry;
+    DIR *sysblock;

      int res;
      blkid_dev_iterate bIter;
@@ -600,6 +604,26 @@ struct ddlist* findDriverDiskByLabel(void)
  	logMessage(ERROR, _("Cannot initialize cache instance for blkid"));
  	return NULL;
      }
+
+    /* List all block devices from /sys/block and add them to blkid db
+     * libblkid should be doing that, so lets consider this as a workaround */
+    sysblock = opendir("/sys/block");
+    if(sysblock){
+      while((direntry = readdir(sysblock))!=NULL){
+	/* add only h(d?), s(d?), z(fcp) devices */

scsi cdroms are scd? not sd?, also zfcp attached storage shows up as
regular scsi devices (sd? scd?), so no need to check for those (my bad).

+	if(direntry->d_name[0]!='h'&&
+	   direntry->d_name[0]!='s'&&
+	   direntry->d_name[0]!='z') continue;
+
+	char *devname = asprintf("/dev/%s", direntry->d_name);

This not how asprintf works.

+	if(devname){

You should check asprintf return != -1, when properly using asprintf
(so passing in the address of devnam as first arg) devname will not get
touched on error, so its not guaranteed to be NULL (unless you init it
as such).

+	  blkid_get_dev(bCache, devname, BLKID_DEV_NORMAL);
+	  free(devname);
+	}
+      }
+      closedir(sysblock);
+    }
+

Regards,

Hans


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]