summaryrefslogtreecommitdiffstats
path: root/contrib/add_ext4_encrypt.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
commit464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch)
tree6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /contrib/add_ext4_encrypt.c
parentInitial commit. (diff)
downloade2fsprogs-upstream.tar.xz
e2fsprogs-upstream.zip
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/add_ext4_encrypt.c')
-rw-r--r--contrib/add_ext4_encrypt.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/add_ext4_encrypt.c b/contrib/add_ext4_encrypt.c
new file mode 100644
index 0000000..133fe25
--- /dev/null
+++ b/contrib/add_ext4_encrypt.c
@@ -0,0 +1,64 @@
+/*
+ * Basic program to add ext4 encryption to a file system
+ *
+ * Copyright 2015, Google, Inc.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#include <ext2fs/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
+
+int main (int argc, char *argv[])
+{
+ errcode_t retval = 0;
+ ext2_filsys fs;
+
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
+ initialize_ext2_error_table();
+
+ if (argc != 2) {
+ fprintf(stderr, "%s: Usage <device|filesystem>\n", argv[0]);
+ exit(1);
+ }
+
+ retval = ext2fs_open(argv[1], EXT2_FLAG_RW, 0, 0,
+ unix_io_manager, &fs);
+
+ if (retval) {
+ com_err(argv[0], retval, "while trying to open '%s'",
+ argv[1]);
+ exit(1);
+ }
+ if (!ext2fs_has_feature_encrypt(fs->super)) {
+ ext2fs_set_feature_encrypt(fs->super);
+ fs->super->s_encrypt_algos[0] =
+ EXT4_ENCRYPTION_MODE_AES_256_XTS;
+ fs->super->s_encrypt_algos[1] =
+ EXT4_ENCRYPTION_MODE_AES_256_CTS;
+ ext2fs_mark_super_dirty(fs);
+ printf("Ext4 encryption enabled on %s\n", argv[1]);
+ } else
+ printf("Ext4 encryption already enabled on %s\n", argv[1]);
+
+ retval = ext2fs_close(fs);
+ if (retval) {
+ com_err(argv[0], retval, "while trying to close '%s'",
+ argv[1]);
+ exit(1);
+ }
+ return (0);
+}
+