@@ -394,6 +394,39 @@ void ubifs_crc_node(struct ubifs_info *c, void *node, int len)
394
394
ch -> crc = cpu_to_le32 (crc );
395
395
}
396
396
397
+ /**
398
+ * ubifs_prepare_node_hmac - 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
+ * @hmac_offs: offset of the HMAC in the node
403
+ * @pad: if the buffer has to be padded
404
+ *
405
+ * This function prepares node at @node to be written to the media - it
406
+ * calculates node CRC, fills the common header, and adds proper padding up to
407
+ * the next minimum I/O unit if @pad is not zero. if @hmac_offs is positive then
408
+ * a HMAC is inserted into the node at the given offset.
409
+ *
410
+ * This function returns 0 for success or a negative error code otherwise.
411
+ */
412
+ int ubifs_prepare_node_hmac (struct ubifs_info * c , void * node , int len ,
413
+ int hmac_offs , int pad )
414
+ {
415
+ int err ;
416
+
417
+ ubifs_init_node (c , node , len , pad );
418
+
419
+ if (hmac_offs > 0 ) {
420
+ err = ubifs_node_insert_hmac (c , node , len , hmac_offs );
421
+ if (err )
422
+ return err ;
423
+ }
424
+
425
+ ubifs_crc_node (c , node , len );
426
+
427
+ return 0 ;
428
+ }
429
+
397
430
/**
398
431
* ubifs_prepare_node - prepare node to be written to flash.
399
432
* @c: UBIFS file-system description object
@@ -407,8 +440,11 @@ void ubifs_crc_node(struct ubifs_info *c, void *node, int len)
407
440
*/
408
441
void ubifs_prepare_node (struct ubifs_info * c , void * node , int len , int pad )
409
442
{
410
- ubifs_init_node (c , node , len , pad );
411
- ubifs_crc_node (c , node , len );
443
+ /*
444
+ * Deliberately ignore return value since this function can only fail
445
+ * when a hmac offset is given.
446
+ */
447
+ ubifs_prepare_node_hmac (c , node , len , 0 , pad );
412
448
}
413
449
414
450
/**
@@ -861,21 +897,22 @@ int ubifs_wbuf_write_nolock(struct ubifs_wbuf *wbuf, void *buf, int len)
861
897
}
862
898
863
899
/**
864
- * ubifs_write_node - write node to the media.
900
+ * ubifs_write_node_hmac - write node to the media.
865
901
* @c: UBIFS file-system description object
866
902
* @buf: the node to write
867
903
* @len: node length
868
904
* @lnum: logical eraseblock number
869
905
* @offs: offset within the logical eraseblock
906
+ * @hmac_offs: offset of the HMAC within the node
870
907
*
871
908
* This function automatically fills node magic number, assigns sequence
872
909
* number, and calculates node CRC checksum. The length of the @buf buffer has
873
910
* to be aligned to the minimal I/O unit size. This function automatically
874
911
* appends padding node and padding bytes if needed. Returns zero in case of
875
912
* success and a negative error code in case of failure.
876
913
*/
877
- int ubifs_write_node (struct ubifs_info * c , void * buf , int len , int lnum ,
878
- int offs )
914
+ int ubifs_write_node_hmac (struct ubifs_info * c , void * buf , int len , int lnum ,
915
+ int offs , int hmac_offs )
879
916
{
880
917
int err , buf_len = ALIGN (len , c -> min_io_size );
881
918
@@ -890,14 +927,37 @@ int ubifs_write_node(struct ubifs_info *c, void *buf, int len, int lnum,
890
927
if (c -> ro_error )
891
928
return - EROFS ;
892
929
893
- ubifs_prepare_node (c , buf , len , 1 );
930
+ err = ubifs_prepare_node_hmac (c , buf , len , hmac_offs , 1 );
931
+ if (err )
932
+ return err ;
933
+
894
934
err = ubifs_leb_write (c , lnum , buf , offs , buf_len );
895
935
if (err )
896
936
ubifs_dump_node (c , buf );
897
937
898
938
return err ;
899
939
}
900
940
941
+ /**
942
+ * ubifs_write_node - write node to the media.
943
+ * @c: UBIFS file-system description object
944
+ * @buf: the node to write
945
+ * @len: node length
946
+ * @lnum: logical eraseblock number
947
+ * @offs: offset within the logical eraseblock
948
+ *
949
+ * This function automatically fills node magic number, assigns sequence
950
+ * number, and calculates node CRC checksum. The length of the @buf buffer has
951
+ * to be aligned to the minimal I/O unit size. This function automatically
952
+ * appends padding node and padding bytes if needed. Returns zero in case of
953
+ * success and a negative error code in case of failure.
954
+ */
955
+ int ubifs_write_node (struct ubifs_info * c , void * buf , int len , int lnum ,
956
+ int offs )
957
+ {
958
+ return ubifs_write_node_hmac (c , buf , len , lnum , offs , -1 );
959
+ }
960
+
901
961
/**
902
962
* ubifs_read_node_wbuf - read node from the media or write-buffer.
903
963
* @wbuf: wbuf to check for un-written data
0 commit comments