system/corennnnn
Revision | eac3e1b8af0e2e7cc57ea5a166a7766c21ba5046 (tree) |
---|---|
Time | 2016-07-20 18:01:29 |
Author | Chuanxiao Dong <chuanxiao.dong@inte...> |
Commiter | Chih-Wei Huang |
fs_mgr: fix encryptable=footer support
If the userdata partition has the encryptable=footer fstab option,
fs_mgr must leave room for the crypt footer.
Upstream: https://android-review.googlesource.com/206992
Change-Id: Id07818c5d93aafc27577f72fb0a780f26db51b16
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-23540
Reviewed-on: https://android.intel.com:443/479471
@@ -577,6 +577,7 @@ int fs_mgr_mount_all(struct fstab *fstab) | ||
577 | 577 | |
578 | 578 | /* mount(2) returned an error, handle the encryptable/formattable case */ |
579 | 579 | bool wiped = partition_wiped(fstab->recs[top_idx].blk_device); |
580 | + bool crypt_footer = false; | |
580 | 581 | if (mret && mount_errno != EBUSY && mount_errno != EACCES && |
581 | 582 | fs_mgr_is_formattable(&fstab->recs[top_idx]) && wiped) { |
582 | 583 | /* top_idx and attempted_idx point at the same partition, but sometimes |
@@ -597,8 +598,11 @@ int fs_mgr_mount_all(struct fstab *fstab) | ||
597 | 598 | ERROR("%s(): %s wouldn't open (%s)\n", __func__, |
598 | 599 | fstab->recs[top_idx].key_loc, strerror(errno)); |
599 | 600 | } |
601 | + } else if (fs_mgr_is_encryptable(&fstab->recs[top_idx]) && | |
602 | + !strcmp(fstab->recs[top_idx].key_loc, KEY_IN_FOOTER)) { | |
603 | + crypt_footer = true; | |
600 | 604 | } |
601 | - if (fs_mgr_do_format(&fstab->recs[top_idx]) == 0) { | |
605 | + if (fs_mgr_do_format(&fstab->recs[top_idx], crypt_footer) == 0) { | |
602 | 606 | /* Let's replay the mount actions. */ |
603 | 607 | i = top_idx - 1; |
604 | 608 | continue; |
@@ -27,11 +27,12 @@ | ||
27 | 27 | #include "ext4.h" |
28 | 28 | #include "make_ext4fs.h" |
29 | 29 | #include "fs_mgr_priv.h" |
30 | +#include "cryptfs.h" | |
30 | 31 | |
31 | 32 | extern struct fs_info info; /* magic global from ext4_utils */ |
32 | 33 | extern void reset_ext4fs_info(); |
33 | 34 | |
34 | -static int format_ext4(char *fs_blkdev, char *fs_mnt_point) | |
35 | +static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer) | |
35 | 36 | { |
36 | 37 | unsigned int nr_sec; |
37 | 38 | int fd, rc = 0; |
@@ -50,6 +51,9 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point) | ||
50 | 51 | /* Format the partition using the calculated length */ |
51 | 52 | reset_ext4fs_info(); |
52 | 53 | info.len = ((off64_t)nr_sec * 512); |
54 | + if (crypt_footer) { | |
55 | + info.len -= CRYPT_FOOTER_OFFSET; | |
56 | + } | |
53 | 57 | |
54 | 58 | /* Use make_ext4fs_internal to avoid wiping an already-wiped partition. */ |
55 | 59 | rc = make_ext4fs_internal(fd, NULL, NULL, fs_mnt_point, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL); |
@@ -101,7 +105,7 @@ static int format_f2fs(char *fs_blkdev) | ||
101 | 105 | return rc; |
102 | 106 | } |
103 | 107 | |
104 | -int fs_mgr_do_format(struct fstab_rec *fstab) | |
108 | +int fs_mgr_do_format(struct fstab_rec *fstab, bool crypt_footer) | |
105 | 109 | { |
106 | 110 | int rc = -EINVAL; |
107 | 111 |
@@ -110,7 +114,7 @@ int fs_mgr_do_format(struct fstab_rec *fstab) | ||
110 | 114 | if (!strncmp(fstab->fs_type, "f2fs", 4)) { |
111 | 115 | rc = format_f2fs(fstab->blk_device); |
112 | 116 | } else if (!strncmp(fstab->fs_type, "ext4", 4)) { |
113 | - rc = format_ext4(fstab->blk_device, fstab->mount_point); | |
117 | + rc = format_ext4(fstab->blk_device, fstab->mount_point, crypt_footer); | |
114 | 118 | } else { |
115 | 119 | ERROR("File system type '%s' is not supported\n", fstab->fs_type); |
116 | 120 | } |
@@ -18,6 +18,7 @@ | ||
18 | 18 | #define __CORE_FS_MGR_H |
19 | 19 | |
20 | 20 | #include <stdint.h> |
21 | +#include <stdbool.h> | |
21 | 22 | #include <linux/dm-ioctl.h> |
22 | 23 | |
23 | 24 | // Magic number at start of verity metadata |
@@ -107,7 +108,7 @@ int fs_mgr_is_notrim(struct fstab_rec *fstab); | ||
107 | 108 | int fs_mgr_is_formattable(struct fstab_rec *fstab); |
108 | 109 | int fs_mgr_swapon_all(struct fstab *fstab); |
109 | 110 | |
110 | -int fs_mgr_do_format(struct fstab_rec *fstab); | |
111 | +int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer); | |
111 | 112 | |
112 | 113 | #ifdef __cplusplus |
113 | 114 | } |