uint32_t udfperms;
uint16_t icbflags;
uint16_t crclen;
- int i;
kernel_timestamp cpu_time;
int err = 0;
struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
sizeof(tag), crclen,
0));
-
- use->descTag.tagChecksum = 0;
- for (i = 0; i < 16; i++)
- if (i != 4)
- use->descTag.tagChecksum +=
- ((uint8_t *)&(use->descTag))[i];
+ use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
mark_buffer_dirty(bh);
brelse(bh);
fe->descTag.descCRCLength = cpu_to_le16(crclen);
fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
crclen, 0));
-
- fe->descTag.tagChecksum = 0;
- for (i = 0; i < 16; i++)
- if (i != 4)
- fe->descTag.tagChecksum +=
- ((uint8_t *)&(fe->descTag))[i];
+ fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
/* write the data blocks */
mark_buffer_dirty(bh);
uint8_t *ea = NULL, *ad = NULL;
int offset;
uint16_t crclen;
- int i;
ea = UDF_I_DATA(inode);
if (UDF_I_LENEATTR(inode)) {
eahd->descTag.descCRCLength = cpu_to_le16(crclen);
eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
sizeof(tag), crclen, 0));
- eahd->descTag.tagChecksum = 0;
- for (i = 0; i < 16; i++)
- if (i != 4)
- eahd->descTag.tagChecksum +=
- ((uint8_t *)&(eahd->descTag))[i];
+ eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag);
UDF_I_LENEATTR(inode) += size;
return (struct genericFormat *)&ea[offset];
}
{
tag *tag_p;
struct buffer_head *bh = NULL;
- register uint8_t checksum;
- register int i;
struct udf_sb_info *sbi = UDF_SB(sb);
/* Read the block */
}
/* Verify the tag checksum */
- checksum = 0U;
- for (i = 0; i < 4; i++)
- checksum += (uint8_t)(bh->b_data[i]);
- for (i = 5; i < 16; i++)
- checksum += (uint8_t)(bh->b_data[i]);
- if (checksum != tag_p->tagChecksum) {
+ if (udf_tag_checksum(tag_p) != tag_p->tagChecksum) {
printk(KERN_ERR "udf: tag checksum failed block %d\n", block);
goto error_out;
}
void udf_update_tag(char *data, int length)
{
tag *tptr = (tag *)data;
- int i;
-
length -= sizeof(tag);
- tptr->tagChecksum = 0;
tptr->descCRCLength = cpu_to_le16(length);
tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
-
- for (i = 0; i < 16; i++)
- if (i != 4)
- tptr->tagChecksum += (uint8_t)(data[i]);
+ tptr->tagChecksum = udf_tag_checksum(tptr);
}
void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
tptr->tagLocation = cpu_to_le32(loc);
udf_update_tag(data, length);
}
+
+u8 udf_tag_checksum(const tag *t)
+{
+ u8 *data = (u8 *)t;
+ u8 checksum = 0;
+ int i;
+ for (i = 0; i < sizeof(tag); ++i)
+ if (i != 4) /* position of checksum */
+ checksum += data[i];
+ return checksum;
+}
{
uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
uint16_t crc;
- uint8_t checksum = 0;
- int i;
int offset;
uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
uint8_t lfi = cfi->lengthFileIdent;
cfi->descTag.descCRC = cpu_to_le16(crc);
cfi->descTag.descCRCLength = cpu_to_le16(crclen);
+ cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag);
- for (i = 0; i < 16; i++) {
- if (i != 4)
- checksum += ((uint8_t *)&cfi->descTag)[i];
- }
-
- cfi->descTag.tagChecksum = checksum;
if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
memcpy((uint8_t *)sfi, (uint8_t *)cfi,
sizeof(struct fileIdentDesc));
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
if (bh) {
- int i;
kernel_timestamp cpu_time;
struct logicalVolIntegrityDesc *lvid =
(struct logicalVolIntegrityDesc *)bh->b_data;
le16_to_cpu(lvid->descTag.descCRCLength),
0));
- lvid->descTag.tagChecksum = 0;
- for (i = 0; i < 16; i++)
- if (i != 4)
- lvid->descTag.tagChecksum +=
- ((uint8_t *) &(lvid->descTag))[i];
-
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
mark_buffer_dirty(bh);
}
}
static void udf_close_lvid(struct super_block *sb)
{
kernel_timestamp cpu_time;
- int i;
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = sbi->s_lvid_bh;
struct logicalVolIntegrityDesc *lvid;
le16_to_cpu(lvid->descTag.descCRCLength),
0));
- lvid->descTag.tagChecksum = 0;
- for (i = 0; i < 16; i++)
- if (i != 4)
- lvid->descTag.tagChecksum +=
- ((uint8_t *)&(lvid->descTag))[i];
-
+ lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
mark_buffer_dirty(bh);
}
}
#define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset))
+/* computes tag checksum */
+u8 udf_tag_checksum(const tag *t);
+
struct dentry;
struct inode;
struct task_struct;