X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fext2.c;h=7f9d2e02a0caea286871bf3823c81a4c35f7d414;hp=c90ee05c2d5af399f50fe2e70a49d64322c47636;hb=000f8059a53860ddf3319c1f54d4df5dcd6aa846;hpb=00a9ae7365e6bad258bcf079a18dcae94d0853ad diff --git a/daemon/ext2.c b/daemon/ext2.c index c90ee05..7f9d2e0 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -43,11 +44,11 @@ e2prog (char *name) p++; *p = '4'; - if (access (name, X_OK) == 0) + if (prog_exists (name)) return 0; *p = '2'; - if (access (name, X_OK) == 0) + if (prog_exists (name)) return 0; reply_with_error ("cannot find required program %s", name); @@ -63,7 +64,7 @@ do_tune2fs_l (const char *device) char **ret = NULL; int size = 0, alloc = 0; - char prog[] = "/sbin/tune2fs"; + char prog[] = "tune2fs"; if (e2prog (prog) == -1) return NULL; @@ -151,7 +152,7 @@ do_set_e2label (const char *device, const char *label) int r; char *err; - char prog[] = "/sbin/e2label"; + char prog[] = "e2label"; if (e2prog (prog) == -1) return -1; @@ -169,29 +170,7 @@ do_set_e2label (const char *device, const char *label) char * do_get_e2label (const char *device) { - int r, len; - char *out, *err; - - char prog[] = "/sbin/e2label"; - if (e2prog (prog) == -1) - return NULL; - - r = command (&out, &err, prog, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - return NULL; - } - - free (err); - - /* Remove any trailing \n from the label. */ - len = strlen (out); - if (len > 0 && out[len-1] == '\n') - out[len-1] = '\0'; - - return out; /* caller frees */ + return do_vfs_label (device); } int @@ -200,7 +179,7 @@ do_set_e2uuid (const char *device, const char *uuid) int r; char *err; - char prog[] = "/sbin/tune2fs"; + char prog[] = "tune2fs"; if (e2prog (prog) == -1) return -1; @@ -218,78 +197,55 @@ do_set_e2uuid (const char *device, const char *uuid) char * do_get_e2uuid (const char *device) { + return do_vfs_uuid (device); +} + +int +do_resize2fs (const char *device) +{ + char *err; int r; - char *out, *err, *p, *q; - /* 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. - */ - char prog[] = "/sbin/tune2fs"; + char prog[] = "resize2fs"; if (e2prog (prog) == -1) - return NULL; + return -1; - r = command (&out, &err, prog, "-l", device, NULL); + r = command (NULL, &err, prog, device, NULL); if (r == -1) { reply_with_error ("%s", err); - free (out); free (err); - return NULL; + return -1; } free (err); - - /* Look for /\nFilesystem UUID:\s+/ in the output. */ - p = strstr (out, "\nFilesystem UUID:"); - if (p == NULL) { - reply_with_error ("no Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - p += 17; - while (*p && c_isspace (*p)) - p++; - if (!*p) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - /* Now 'p' hopefully points to the start of the UUID. */ - q = p; - while (*q && (c_isxdigit (*q) || *q == '-')) - q++; - if (!*q) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - *q = '\0'; - - p = strdup (p); - if (!p) { - reply_with_perror ("strdup"); - free (out); - return NULL; - } - - free (out); - return p; /* caller frees */ + return 0; } int -do_resize2fs (const char *device) +do_resize2fs_size (const char *device, int64_t size) { char *err; int r; - char prog[] = "/sbin/resize2fs"; + char prog[] = "resize2fs"; if (e2prog (prog) == -1) return -1; - r = command (NULL, &err, prog, device, NULL); + /* resize2fs itself may impose additional limits. Since we are + * going to use the 'K' suffix however we can only work with whole + * kilobytes. + */ + if (size & 1023) { + reply_with_error ("%" PRIi64 ": size must be a round number of kilobytes", + size); + return -1; + } + size /= 1024; + + char buf[32]; + snprintf (buf, sizeof buf, "%" PRIi64 "K", size); + + r = command (NULL, &err, prog, device, buf, NULL); if (r == -1) { reply_with_error ("%s", err); free (err); @@ -306,7 +262,7 @@ do_e2fsck_f (const char *device) char *err; int r; - char prog[] = "/sbin/e2fsck"; + char prog[] = "e2fsck"; if (e2prog (prog) == -1) return -1; @@ -334,7 +290,7 @@ do_mke2journal (int blocksize, const char *device) char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1; @@ -360,7 +316,7 @@ do_mke2journal_L (int blocksize, const char *label, const char *device) char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1; @@ -387,7 +343,7 @@ do_mke2journal_U (int blocksize, const char *uuid, const char *device) char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1; @@ -415,7 +371,7 @@ do_mke2fs_J (const char *fstype, int blocksize, const char *device, char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1; @@ -446,7 +402,7 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device, char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1; @@ -477,7 +433,7 @@ do_mke2fs_JU (const char *fstype, int blocksize, const char *device, char *err; int r; - char prog[] = "/sbin/mke2fs"; + char prog[] = "mke2fs"; if (e2prog (prog) == -1) return -1;