aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-09-07 08:36:41 -0400
committerRichard Weinberger <richard@nod.at>2018-10-23 07:48:56 -0400
commitb5b1f08369222394540fb4b3b947fe26a2557d1d (patch)
tree58b94ec0ca6804ea7006f0fc1ed89d04b9559b94
parent625700ccb5069ec81d15aae3b47282ecc59d63b5 (diff)
ubifs: Create hash for default LPT
During creation of the default filesystem on an empty flash the default LPT is created. With this patch a hash over the default LPT is calculated which can be added to the default filesystems master node. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r--fs/ubifs/lpt.c21
-rw-r--r--fs/ubifs/sb.c3
-rw-r--r--fs/ubifs/ubifs.h2
3 files changed, 23 insertions, 3 deletions
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index ee18305a6152..d1d5e96350dd 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -604,11 +604,12 @@ static int calc_pnode_num_from_parent(const struct ubifs_info *c,
604 * @lpt_first: LEB number of first LPT LEB 604 * @lpt_first: LEB number of first LPT LEB
605 * @lpt_lebs: number of LEBs for LPT is passed and returned here 605 * @lpt_lebs: number of LEBs for LPT is passed and returned here
606 * @big_lpt: use big LPT model is passed and returned here 606 * @big_lpt: use big LPT model is passed and returned here
607 * @hash: hash of the LPT is returned here
607 * 608 *
608 * This function returns %0 on success and a negative error code on failure. 609 * This function returns %0 on success and a negative error code on failure.
609 */ 610 */
610int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, 611int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
611 int *lpt_lebs, int *big_lpt) 612 int *lpt_lebs, int *big_lpt, u8 *hash)
612{ 613{
613 int lnum, err = 0, node_sz, iopos, i, j, cnt, len, alen, row; 614 int lnum, err = 0, node_sz, iopos, i, j, cnt, len, alen, row;
614 int blnum, boffs, bsz, bcnt; 615 int blnum, boffs, bsz, bcnt;
@@ -617,6 +618,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
617 void *buf = NULL, *p; 618 void *buf = NULL, *p;
618 struct ubifs_lpt_lprops *ltab = NULL; 619 struct ubifs_lpt_lprops *ltab = NULL;
619 int *lsave = NULL; 620 int *lsave = NULL;
621 struct shash_desc *desc;
620 622
621 err = calc_dflt_lpt_geom(c, main_lebs, big_lpt); 623 err = calc_dflt_lpt_geom(c, main_lebs, big_lpt);
622 if (err) 624 if (err)
@@ -630,6 +632,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
630 /* Needed by 'ubifs_pack_lsave()' */ 632 /* Needed by 'ubifs_pack_lsave()' */
631 c->main_first = c->leb_cnt - *main_lebs; 633 c->main_first = c->leb_cnt - *main_lebs;
632 634
635 desc = ubifs_hash_get_desc(c);
636 if (IS_ERR(desc))
637 return PTR_ERR(desc);
638
633 lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_KERNEL); 639 lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_KERNEL);
634 pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL); 640 pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
635 nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL); 641 nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
@@ -677,6 +683,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
677 683
678 /* Add first pnode */ 684 /* Add first pnode */
679 ubifs_pack_pnode(c, p, pnode); 685 ubifs_pack_pnode(c, p, pnode);
686 err = ubifs_shash_update(c, desc, p, c->pnode_sz);
687 if (err)
688 goto out;
689
680 p += c->pnode_sz; 690 p += c->pnode_sz;
681 len = c->pnode_sz; 691 len = c->pnode_sz;
682 pnode->num += 1; 692 pnode->num += 1;
@@ -711,6 +721,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
711 len = 0; 721 len = 0;
712 } 722 }
713 ubifs_pack_pnode(c, p, pnode); 723 ubifs_pack_pnode(c, p, pnode);
724 err = ubifs_shash_update(c, desc, p, c->pnode_sz);
725 if (err)
726 goto out;
727
714 p += c->pnode_sz; 728 p += c->pnode_sz;
715 len += c->pnode_sz; 729 len += c->pnode_sz;
716 /* 730 /*
@@ -830,6 +844,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
830 if (err) 844 if (err)
831 goto out; 845 goto out;
832 846
847 err = ubifs_shash_final(c, desc, hash);
848 if (err)
849 goto out;
850
833 c->nhead_lnum = lnum; 851 c->nhead_lnum = lnum;
834 c->nhead_offs = ALIGN(len, c->min_io_size); 852 c->nhead_offs = ALIGN(len, c->min_io_size);
835 853
@@ -853,6 +871,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
853 dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs); 871 dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs);
854out: 872out:
855 c->ltab = NULL; 873 c->ltab = NULL;
874 kfree(desc);
856 kfree(lsave); 875 kfree(lsave);
857 vfree(ltab); 876 vfree(ltab);
858 vfree(buf); 877 vfree(buf);
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index 7e08c8143316..572756579532 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c)
87 __le64 tmp_le64; 87 __le64 tmp_le64;
88 __le32 tmp_le32; 88 __le32 tmp_le32;
89 struct timespec64 ts; 89 struct timespec64 ts;
90 u8 hash_lpt[UBIFS_HASH_ARR_SZ];
90 91
91 /* Some functions called from here depend on the @c->key_len filed */ 92 /* Some functions called from here depend on the @c->key_len filed */
92 c->key_len = UBIFS_SK_LEN; 93 c->key_len = UBIFS_SK_LEN;
@@ -148,7 +149,7 @@ static int create_default_filesystem(struct ubifs_info *c)
148 c->lsave_cnt = DEFAULT_LSAVE_CNT; 149 c->lsave_cnt = DEFAULT_LSAVE_CNT;
149 c->max_leb_cnt = c->leb_cnt; 150 c->max_leb_cnt = c->leb_cnt;
150 err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs, 151 err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs,
151 &big_lpt); 152 &big_lpt, hash_lpt);
152 if (err) 153 if (err)
153 return err; 154 return err;
154 155
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index c26d3c600e4d..504b651b78f1 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1934,7 +1934,7 @@ int ubifs_clear_orphans(struct ubifs_info *c);
1934/* lpt.c */ 1934/* lpt.c */
1935int ubifs_calc_lpt_geom(struct ubifs_info *c); 1935int ubifs_calc_lpt_geom(struct ubifs_info *c);
1936int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, 1936int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
1937 int *lpt_lebs, int *big_lpt); 1937 int *lpt_lebs, int *big_lpt, u8 *hash);
1938int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr); 1938int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
1939struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum); 1939struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
1940struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum); 1940struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);