#include <dirent.h>
#include <sys/stat.h>
+#include "c-ctype.h"
+
#include "daemon.h"
#include "actions.h"
struct dirent *d = readdir(dir);
if(NULL == d) break;
- 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) {
+ 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.
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);
return foreach_block_device(add_partitions);
}
-int
-do_mkfs (const char *fstype, const char *device)
+char *
+do_part_to_dev (const char *part)
{
- char *err;
- int r;
+ int err = 1;
+ size_t n = strlen (part);
- r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL);
- if (r == -1) {
- reply_with_error ("mkfs: %s", err);
- free (err);
- return -1;
+ while (n >= 1 && c_isdigit (part[n-1])) {
+ err = 0;
+ n--;
}
- free (err);
- return 0;
+ if (err) {
+ reply_with_error ("device name is not a partition");
+ return NULL;
+ }
+
+ char *r = strndup (part, n);
+ if (r == NULL) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
+
+ return r;
}