Change to using ext2-based, cached supermin appliance.
[libguestfs.git] / daemon / devsparts.c
index b89682c..95e4a68 100644 (file)
@@ -40,7 +40,6 @@ foreach_block_device (block_dev_func_t func)
   int size = 0, alloc = 0;
 
   DIR *dir;
-  struct dirent *d;
   int err = 0;
 
   dir = opendir ("/sys/block");
@@ -49,15 +48,22 @@ foreach_block_device (block_dev_func_t func)
     return NULL;
   }
 
-  errno = 0;
-  while ((d = readdir (dir)) != NULL) {
-    if (strncmp (d->d_name, "sd", 2) == 0 ||
-        strncmp (d->d_name, "hd", 2) == 0 ||
-        strncmp (d->d_name, "vd", 2) == 0 ||
-        strncmp (d->d_name, "sr", 2) == 0) {
+  while(1) {
+    errno = 0;
+    struct dirent *d = readdir(dir);
+    if(NULL == d) break;
+
+    if (STREQLEN (d->d_name, "sd", 2) ||
+        STREQLEN (d->d_name, "hd", 2) ||
+        STREQLEN (d->d_name, "vd", 2) ||
+        STREQLEN (d->d_name, "sr", 2)) {
       char dev_path[256];
       snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
 
+      /* Ignore the root device. */
+      if (is_root_device (dev_path))
+        continue;
+
       /* RHBZ#514505: Some versions of qemu <= 0.10 add a
        * CD-ROM device even though we didn't request it.  Try to
        * detect this by seeing if the device contains media.
@@ -151,7 +157,7 @@ add_partitions(const char *device,
   errno = 0;
   struct dirent *d;
   while ((d = readdir (dir)) != NULL) {
-    if (strncmp (d->d_name, device, strlen (device)) == 0) {
+    if (STREQLEN (d->d_name, device, strlen (device))) {
       char part[256];
       snprintf (part, sizeof part, "/dev/%s", d->d_name);
 
@@ -184,22 +190,3 @@ do_list_partitions (void)
 {
   return foreach_block_device(add_partitions);
 }
-
-int
-do_mkfs (char *fstype, char *device)
-{
-  char *err;
-  int r;
-
-  IS_DEVICE (device, -1);
-
-  r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL);
-  if (r == -1) {
-    reply_with_error ("mkfs: %s", err);
-    free (err);
-    return -1;
-  }
-
-  free (err);
-  return 0;
-}