- 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) {
- snprintf (buf, sizeof buf, "/dev/%s", d->d_name);
+ 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;