#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.
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);
char **ret = NULL;
int size = 0, alloc = 0;
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return NULL;
int r;
char *err;
- char prog[] = "/sbin/e2label";
+ char prog[] = "e2label";
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);
int r, len;
char *out, *err;
- char prog[] = "/sbin/e2label";
+ char prog[] = "e2label";
if (e2prog (prog) == -1)
return NULL;
int r;
char *err;
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return -1;
* to use tune2fs -l and then look for a particular string in
* the output.
*/
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return NULL;
char *err;
int r;
- char prog[] = "/sbin/resize2fs";
+ char prog[] = "resize2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/e2fsck";
+ char prog[] = "e2fsck";
if (e2prog (prog) == -1)
return -1;
- r = command (NULL, &err, prog, "-p", "-f", device, NULL);
- if (r == -1) {
+ /* 0 = no errors, 1 = errors corrected.
+ *
+ * >= 4 means uncorrected or other errors.
+ *
+ * 2, 3 means errors were corrected and we require a reboot. This is
+ * a difficult corner case.
+ */
+ r = commandr (NULL, &err, prog, "-p", "-f", device, NULL);
+ if (r == -1 || r >= 2) {
reply_with_error ("%s", err);
free (err);
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
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);
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
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);
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;