2 * Basic progam to add ext4 encryption to a file system
4 * Copyright 2015, Google, Inc.
7 * This file may be redistributed under the terms of the GNU Public
17 #include <sys/types.h>
20 #include <ext2fs/ext2_fs.h>
21 #include <ext2fs/ext2fs.h>
23 int main (int argc, char *argv[])
30 initialize_ext2_error_table();
33 fprintf(stderr, "%s: Usage <device|filesystem>\n", argv[0]);
37 retval = ext2fs_open(argv[1], EXT2_FLAG_RW, 0, 0,
38 unix_io_manager, &fs);
41 com_err(argv[0], retval, "while trying to open '%s'",
45 if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
46 EXT4_FEATURE_INCOMPAT_ENCRYPT)) {
47 fs->super->s_feature_incompat |= EXT4_FEATURE_INCOMPAT_ENCRYPT;
48 fs->super->s_encrypt_algos[0] =
49 EXT4_ENCRYPTION_MODE_AES_256_XTS;
50 fs->super->s_encrypt_algos[1] =
51 EXT4_ENCRYPTION_MODE_AES_256_CTS;
52 ext2fs_mark_super_dirty(fs);
53 printf("Ext4 encryption enabled on %s\n", argv[1]);
55 printf("Ext4 encryption already enabled on %s\n", argv[1]);
57 retval = ext2fs_close(fs);
59 com_err(argv[0], retval, "while trying to close '%s'",