diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-09-07 08:36:41 -0400 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2018-10-23 07:48:56 -0400 |
commit | b5b1f08369222394540fb4b3b947fe26a2557d1d (patch) | |
tree | 58b94ec0ca6804ea7006f0fc1ed89d04b9559b94 /fs/ubifs/lpt.c | |
parent | 625700ccb5069ec81d15aae3b47282ecc59d63b5 (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>
Diffstat (limited to 'fs/ubifs/lpt.c')
-rw-r--r-- | fs/ubifs/lpt.c | 21 |
1 files changed, 20 insertions, 1 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 | */ |
610 | int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first, | 611 | int 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); |
854 | out: | 872 | out: |
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); |