Skip to content

Commit

Permalink
ubifs: Create hash for default LPT
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
saschahauer authored and richardweinberger committed Oct 23, 2018
1 parent 625700c commit b5b1f08
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion fs/ubifs/lpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,12 @@ static int calc_pnode_num_from_parent(const struct ubifs_info *c,
* @lpt_first: LEB number of first LPT LEB
* @lpt_lebs: number of LEBs for LPT is passed and returned here
* @big_lpt: use big LPT model is passed and returned here
* @hash: hash of the LPT is returned here
*
* This function returns %0 on success and a negative error code on failure.
*/
int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
int *lpt_lebs, int *big_lpt)
int *lpt_lebs, int *big_lpt, u8 *hash)
{
int lnum, err = 0, node_sz, iopos, i, j, cnt, len, alen, row;
int blnum, boffs, bsz, bcnt;
Expand All @@ -617,6 +618,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
void *buf = NULL, *p;
struct ubifs_lpt_lprops *ltab = NULL;
int *lsave = NULL;
struct shash_desc *desc;

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

desc = ubifs_hash_get_desc(c);
if (IS_ERR(desc))
return PTR_ERR(desc);

lsave = kmalloc_array(c->lsave_cnt, sizeof(int), GFP_KERNEL);
pnode = kzalloc(sizeof(struct ubifs_pnode), GFP_KERNEL);
nnode = kzalloc(sizeof(struct ubifs_nnode), GFP_KERNEL);
Expand Down Expand Up @@ -677,6 +683,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,

/* Add first pnode */
ubifs_pack_pnode(c, p, pnode);
err = ubifs_shash_update(c, desc, p, c->pnode_sz);
if (err)
goto out;

p += c->pnode_sz;
len = c->pnode_sz;
pnode->num += 1;
Expand Down Expand Up @@ -711,6 +721,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
len = 0;
}
ubifs_pack_pnode(c, p, pnode);
err = ubifs_shash_update(c, desc, p, c->pnode_sz);
if (err)
goto out;

p += c->pnode_sz;
len += c->pnode_sz;
/*
Expand Down Expand Up @@ -830,6 +844,10 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
if (err)
goto out;

err = ubifs_shash_final(c, desc, hash);
if (err)
goto out;

c->nhead_lnum = lnum;
c->nhead_offs = ALIGN(len, c->min_io_size);

Expand All @@ -853,6 +871,7 @@ int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
dbg_lp("LPT lsave is at %d:%d", c->lsave_lnum, c->lsave_offs);
out:
c->ltab = NULL;
kfree(desc);
kfree(lsave);
vfree(ltab);
vfree(buf);
Expand Down
3 changes: 2 additions & 1 deletion fs/ubifs/sb.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c)
__le64 tmp_le64;
__le32 tmp_le32;
struct timespec64 ts;
u8 hash_lpt[UBIFS_HASH_ARR_SZ];

/* Some functions called from here depend on the @c->key_len filed */
c->key_len = UBIFS_SK_LEN;
Expand Down Expand Up @@ -148,7 +149,7 @@ static int create_default_filesystem(struct ubifs_info *c)
c->lsave_cnt = DEFAULT_LSAVE_CNT;
c->max_leb_cnt = c->leb_cnt;
err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs,
&big_lpt);
&big_lpt, hash_lpt);
if (err)
return err;

Expand Down
2 changes: 1 addition & 1 deletion fs/ubifs/ubifs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ int ubifs_clear_orphans(struct ubifs_info *c);
/* lpt.c */
int ubifs_calc_lpt_geom(struct ubifs_info *c);
int ubifs_create_dflt_lpt(struct ubifs_info *c, int *main_lebs, int lpt_first,
int *lpt_lebs, int *big_lpt);
int *lpt_lebs, int *big_lpt, u8 *hash);
int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr);
struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum);
struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum);
Expand Down

0 comments on commit b5b1f08

Please sign in to comment.