Skip to content

Commit b5b1f08

Browse files
saschahauerrichardweinberger
authored andcommitted
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>
1 parent 625700c commit b5b1f08

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

fs/ubifs/lpt.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,12 @@ static int calc_pnode_num_from_parent(const struct ubifs_info *c,
604604
* @lpt_first: LEB number of first LPT LEB
605605
* @lpt_lebs: number of LEBs for LPT is passed and returned here
606606
* @big_lpt: use big LPT model is passed and returned here
607+
* @hash: hash of the LPT is returned here
607608
*
608609
* This function returns %0 on success and a negative error code on failure.
609610
*/
610611
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)
612613
{
613614
int lnum, err = 0, node_sz, iopos, i, j, cnt, len, alen, row;
614615
int blnum, boffs, bsz, bcnt;
@@ -617,6 +618,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
617618
void *buf = NULL, *p;
618619
struct ubifs_lpt_lprops *ltab = NULL;
619620
int *lsave = NULL;
621+
struct shash_desc *desc;
620622

621623
err = calc_dflt_lpt_geom(c, main_lebs, big_lpt);
622624
if (err)
@@ -630,6 +632,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
630632
/* Needed by 'ubifs_pack_lsave()' */
631633
c->main_first = c->leb_cnt - *main_lebs;
632634

635+
desc = ubifs_hash_get_desc(c);
636+
if (IS_ERR(desc))
637+
return PTR_ERR(desc);
638+
633639
lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_KERNEL);
634640
pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
635641
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,
677683

678684
/* Add first pnode */
679685
ubifs_pack_pnode(c, p, pnode);
686+
err = ubifs_shash_update(c, desc, p, c->pnode_sz);
687+
if (err)
688+
goto out;
689+
680690
p += c->pnode_sz;
681691
len = c->pnode_sz;
682692
pnode->num += 1;
@@ -711,6 +721,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
711721
len = 0;
712722
}
713723
ubifs_pack_pnode(c, p, pnode);
724+
err = ubifs_shash_update(c, desc, p, c->pnode_sz);
725+
if (err)
726+
goto out;
727+
714728
p += c->pnode_sz;
715729
len += c->pnode_sz;
716730
/*
@@ -830,6 +844,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
830844
if (err)
831845
goto out;
832846

847+
err = ubifs_shash_final(c, desc, hash);
848+
if (err)
849+
goto out;
850+
833851
c->nhead_lnum = lnum;
834852
c->nhead_offs = ALIGN(len, c->min_io_size);
835853

@@ -853,6 +871,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
853871
dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs);
854872
out:
855873
c->ltab = NULL;
874+
kfree(desc);
856875
kfree(lsave);
857876
vfree(ltab);
858877
vfree(buf);

fs/ubifs/sb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c)
8787
__le64 tmp_le64;
8888
__le32 tmp_le32;
8989
struct timespec64 ts;
90+
u8 hash_lpt[UBIFS_HASH_ARR_SZ];
9091

9192
/* Some functions called from here depend on the @c->key_len filed */
9293
c->key_len = UBIFS_SK_LEN;
@@ -148,7 +149,7 @@ static int create_default_filesystem(struct ubifs_info *c)
148149
c->lsave_cnt = DEFAULT_LSAVE_CNT;
149150
c->max_leb_cnt = c->leb_cnt;
150151
err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs,
151-
&big_lpt);
152+
&big_lpt, hash_lpt);
152153
if (err)
153154
return err;
154155

fs/ubifs/ubifs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ int ubifs_clear_orphans(struct ubifs_info *c);
19341934
/* lpt.c */
19351935
int ubifs_calc_lpt_geom(struct ubifs_info *c);
19361936
int 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);
19381938
int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
19391939
struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
19401940
struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);

0 commit comments

Comments
 (0)