Skip to content

Commit dead972

Browse files
saschahauerrichardweinberger
authored andcommitted
ubifs: Add separate functions to init/crc a node
When adding authentication support we will embed a HMAC into some nodes. To prepare these nodes we have to first initialize the nodes, then add a HMAC and finally add a CRC. To accomplish this add separate ubifs_init_node/ubifs_crc_node functions. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 5125cfd commit dead972

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

fs/ubifs/io.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,20 +365,8 @@ static unsigned long long next_sqnum(struct ubifs_info *c)
365365
return sqnum;
366366
}
367367

368-
/**
369-
* ubifs_prepare_node - prepare node to be written to flash.
370-
* @c: UBIFS file-system description object
371-
* @node: the node to pad
372-
* @len: node length
373-
* @pad: if the buffer has to be padded
374-
*
375-
* This function prepares node at @node to be written to the media - it
376-
* calculates node CRC, fills the common header, and adds proper padding up to
377-
* the next minimum I/O unit if @pad is not zero.
378-
*/
379-
void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
368+
void ubifs_init_node(struct ubifs_info *c, void *node, int len, int pad)
380369
{
381-
uint32_t crc;
382370
struct ubifs_ch *ch = node;
383371
unsigned long long sqnum = next_sqnum(c);
384372

@@ -389,8 +377,6 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
389377
ch->group_type = UBIFS_NO_NODE_GROUP;
390378
ch->sqnum = cpu_to_le64(sqnum);
391379
ch->padding[0] = ch->padding[1] = 0;
392-
crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
393-
ch->crc = cpu_to_le32(crc);
394380

395381
if (pad) {
396382
len = ALIGN(len, 8);
@@ -399,6 +385,32 @@ void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
399385
}
400386
}
401387

388+
void ubifs_crc_node(struct ubifs_info *c, void *node, int len)
389+
{
390+
struct ubifs_ch *ch = node;
391+
uint32_t crc;
392+
393+
crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
394+
ch->crc = cpu_to_le32(crc);
395+
}
396+
397+
/**
398+
* ubifs_prepare_node - prepare node to be written to flash.
399+
* @c: UBIFS file-system description object
400+
* @node: the node to pad
401+
* @len: node length
402+
* @pad: if the buffer has to be padded
403+
*
404+
* This function prepares node at @node to be written to the media - it
405+
* calculates node CRC, fills the common header, and adds proper padding up to
406+
* the next minimum I/O unit if @pad is not zero.
407+
*/
408+
void ubifs_prepare_node(struct ubifs_info *c, void *node, int len, int pad)
409+
{
410+
ubifs_init_node(c, node, len, pad);
411+
ubifs_crc_node(c, node, len);
412+
}
413+
402414
/**
403415
* ubifs_prep_grp_node - prepare node of a group to be written to flash.
404416
* @c: UBIFS file-system description object

fs/ubifs/ubifs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,8 @@ int ubifs_write_node(struct ubifs_info *c, void *node, int len, int lnum,
14941494
int offs);
14951495
int ubifs_check_node(const struct ubifs_info *c, const void *buf, int lnum,
14961496
int offs, int quiet, int must_chk_crc);
1497+
void ubifs_init_node(struct ubifs_info *c, void *buf, int len, int pad);
1498+
void ubifs_crc_node(struct ubifs_info *c, void *buf, int len);
14971499
void ubifs_prepare_node(struct ubifs_info *c, void *buf, int len, int pad);
14981500
void ubifs_prep_grp_node(struct ubifs_info *c, void *node, int len, int last);
14991501
int ubifs_io_init(struct ubifs_info *c);

0 commit comments

Comments
 (0)