debian/changelog: add missing section for 1.46.2-2
[e2fsprogs.git] / contrib / add_ext4_encrypt.c
blob133fe253fa7314b7040c2dc18130571344a1746d
1 /*
2 * Basic program to add ext4 encryption to a file system
4 * Copyright 2015, Google, Inc.
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <stdlib.h>
16 #include <time.h>
17 #include <sys/types.h>
18 #include <sys/time.h>
20 #include <ext2fs/ext2_fs.h>
21 #include <ext2fs/ext2fs.h>
23 int main (int argc, char *argv[])
25 errcode_t retval = 0;
26 ext2_filsys fs;
28 setbuf(stdout, NULL);
29 setbuf(stderr, NULL);
30 initialize_ext2_error_table();
32 if (argc != 2) {
33 fprintf(stderr, "%s: Usage <device|filesystem>\n", argv[0]);
34 exit(1);
37 retval = ext2fs_open(argv[1], EXT2_FLAG_RW, 0, 0,
38 unix_io_manager, &fs);
40 if (retval) {
41 com_err(argv[0], retval, "while trying to open '%s'",
42 argv[1]);
43 exit(1);
45 if (!ext2fs_has_feature_encrypt(fs->super)) {
46 ext2fs_set_feature_encrypt(fs->super);
47 fs->super->s_encrypt_algos[0] =
48 EXT4_ENCRYPTION_MODE_AES_256_XTS;
49 fs->super->s_encrypt_algos[1] =
50 EXT4_ENCRYPTION_MODE_AES_256_CTS;
51 ext2fs_mark_super_dirty(fs);
52 printf("Ext4 encryption enabled on %s\n", argv[1]);
53 } else
54 printf("Ext4 encryption already enabled on %s\n", argv[1]);
56 retval = ext2fs_close(fs);
57 if (retval) {
58 com_err(argv[0], retval, "while trying to close '%s'",
59 argv[1]);
60 exit(1);
62 return (0);