diff options
author | Richard Weinberger <richard@nod.at> | 2016-10-19 23:24:47 +0200 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2016-12-12 23:07:38 +0100 |
commit | e021986ee4119e487febb9a5f077ec77dff85865 (patch) | |
tree | afce15fde0bd515e82f2463c74fffbe63f54dd5d /fs/ubifs/sb.c | |
parent | d63d61c16972c667d770f713c21aa04e2c0489d2 (diff) | |
download | op-kernel-dev-e021986ee4119e487febb9a5f077ec77dff85865.zip op-kernel-dev-e021986ee4119e487febb9a5f077ec77dff85865.tar.gz |
ubifs: Implement UBIFS_FLG_ENCRYPTION
This feature flag indicates that the filesystem contains encrypted
files.
Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'fs/ubifs/sb.c')
-rw-r--r-- | fs/ubifs/sb.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index 4a2b4c3..54cef70 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c @@ -622,6 +622,16 @@ int ubifs_read_superblock(struct ubifs_info *c) c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT); c->space_fixup = !!(sup_flags & UBIFS_FLG_SPACE_FIXUP); c->double_hash = !!(sup_flags & UBIFS_FLG_DOUBLE_HASH); + c->encrypted = !!(sup_flags & UBIFS_FLG_ENCRYPTION); + +#ifndef CONFIG_UBIFS_FS_ENCRYPTION + if (c->encrypted) { + ubifs_err(c, "file system contains encrypted files but UBIFS" + " was built without crypto support."); + err = -EINVAL; + goto out; + } +#endif /* Automatically increase file system size to the maximum size */ c->old_leb_cnt = c->leb_cnt; @@ -809,3 +819,33 @@ int ubifs_fixup_free_space(struct ubifs_info *c) ubifs_msg(c, "free space fixup complete"); return err; } + +int ubifs_enable_encryption(struct ubifs_info *c) +{ + int err; + struct ubifs_sb_node *sup; + + if (c->encrypted) + return 0; + + if (c->ro_mount || c->ro_media) + return -EROFS; + + if (c->fmt_version < 5) { + ubifs_err(c, "on-flash format version 5 is needed for encryption"); + return -EINVAL; + } + + sup = ubifs_read_sb_node(c); + if (IS_ERR(sup)) + return PTR_ERR(sup); + + sup->flags |= cpu_to_le32(UBIFS_FLG_ENCRYPTION); + + err = ubifs_write_sb_node(c, sup); + if (!err) + c->encrypted = 1; + kfree(sup); + + return err; +} |