Add IS_DEVICE checks for all calls which take a device parameter.
[libguestfs.git] / daemon / ext2.c
index 99c12f0..4e1b398 100644 (file)
@@ -122,6 +122,8 @@ do_set_e2label (const char *device, const char *label)
   int r;
   char *err;
 
+  IS_DEVICE (device, -1);
+
   r = command (NULL, &err, "/sbin/e2label", device, label, NULL);
   if (r == -1) {
     reply_with_error ("e2label: %s", err);
@@ -139,6 +141,8 @@ do_get_e2label (const char *device)
   int r, len;
   char *out, *err;
 
+  IS_DEVICE (device, NULL);
+
   r = command (&out, &err, "/sbin/e2label", device, NULL);
   if (r == -1) {
     reply_with_error ("e2label: %s", err);
@@ -163,6 +167,8 @@ do_set_e2uuid (const char *device, const char *uuid)
   int r;
   char *err;
 
+  IS_DEVICE (device, -1);
+
   r = command (NULL, &err, "/sbin/tune2fs", "-U", uuid, device, NULL);
   if (r == -1) {
     reply_with_error ("tune2fs -U: %s", err);
@@ -180,6 +186,8 @@ do_get_e2uuid (const char *device)
   int r;
   char *out, *err, *p, *q;
 
+  IS_DEVICE (device, NULL);
+
   /* It's not so straightforward to get the volume UUID.  We have
    * to use tune2fs -l and then look for a particular string in
    * the output.
@@ -234,3 +242,41 @@ do_get_e2uuid (const char *device)
   free (out);
   return p;                    /* caller frees */
 }
+
+int
+do_resize2fs (const char *device)
+{
+  char *err;
+  int r;
+
+  IS_DEVICE (device, -1);
+
+  r = command (NULL, &err, "/sbin/resize2fs", device, NULL);
+  if (r == -1) {
+    reply_with_error ("resize2fs: %s", err);
+    free (err);
+    return -1;
+  }
+
+  free (err);
+  return 0;
+}
+
+int
+do_e2fsck_f (const char *device)
+{
+  char *err;
+  int r;
+
+  IS_DEVICE (device, -1);
+
+  r = command (NULL, &err, "/sbin/e2fsck", "-p", "-f", device, NULL);
+  if (r == -1) {
+    reply_with_error ("e2fsck: %s", err);
+    free (err);
+    return -1;
+  }
+
+  free (err);
+  return 0;
+}