X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fext2.c;h=85ce316525b0a69c03ad66050d3726f89471433f;hb=65852011d8f5150c5c0bcbfeac90e2fd784905c5;hp=7f9d2e02a0caea286871bf3823c81a4c35f7d414;hpb=da4812ab6b44c29cb3cf181c7aa896420ecb8aa6;p=libguestfs.git diff --git a/daemon/ext2.c b/daemon/ext2.c index 7f9d2e0..85ce316 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -24,11 +24,14 @@ #include #include -#include "../src/guestfs_protocol.h" +#include "guestfs_protocol.h" #include "daemon.h" #include "c-ctype.h" #include "actions.h" +/* Confirmed this is true up to ext4 from the Linux sources. */ +#define EXT2_LABEL_MAX 16 + /* Choose which tools like mke2fs to use. For RHEL 5 (only) there * is a special set of tools which support ext2/3/4. eg. On RHEL 5, * mke2fs only supports ext2/3, but mke4fs supports ext2/3/4. @@ -156,6 +159,12 @@ do_set_e2label (const char *device, const char *label) if (e2prog (prog) == -1) return -1; + if (strlen (label) > EXT2_LABEL_MAX) { + reply_with_error ("%s: ext2 labels are limited to %d bytes", + label, EXT2_LABEL_MAX); + return -1; + } + r = command (NULL, &err, prog, device, label, NULL); if (r == -1) { reply_with_error ("%s", err); @@ -257,6 +266,27 @@ do_resize2fs_size (const char *device, int64_t size) } int +do_resize2fs_M (const char *device) +{ + char *err; + int r; + + char prog[] = "resize2fs"; + if (e2prog (prog) == -1) + return -1; + + r = command (NULL, &err, prog, "-M" , device, NULL); + if (r == -1) { + reply_with_error ("%s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int do_e2fsck_f (const char *device) { char *err; @@ -320,6 +350,12 @@ do_mke2journal_L (int blocksize, const char *label, const char *device) if (e2prog (prog) == -1) return -1; + if (strlen (label) > EXT2_LABEL_MAX) { + reply_with_error ("%s: ext2 labels are limited to %d bytes", + label, EXT2_LABEL_MAX); + return -1; + } + char blocksize_s[32]; snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); @@ -406,6 +442,12 @@ do_mke2fs_JL (const char *fstype, int blocksize, const char *device, if (e2prog (prog) == -1) return -1; + if (strlen (label) > EXT2_LABEL_MAX) { + reply_with_error ("%s: ext2 labels are limited to %d bytes", + label, EXT2_LABEL_MAX); + return -1; + } + char blocksize_s[32]; snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);