aboutsummaryrefslogtreecommitdiffstats
path: root/fs/udf/misc.c
diff options
context:
space:
mode:
authorMarcin Slusarz <marcin.slusarz@gmail.com>2008-02-08 07:20:39 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:35 -0500
commit3f2587bb22bbcd679e9cf034fb4a29bb48b051b3 (patch)
tree47052ce02f10d5f72656b41763feab86d105ea6a /fs/udf/misc.c
parent4b11111aba6c80cc2969fd1806d2a869bfc9f357 (diff)
udf: create common function for tag checksumming
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com> Acked-by: Jan Kara <jack@suse.cz> Cc: Christoph Hellwig <hch@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/udf/misc.c')
-rw-r--r--fs/udf/misc.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/fs/udf/misc.c b/fs/udf/misc.c
index a0bf4158f1f1..585e4eaed254 100644
--- a/fs/udf/misc.c
+++ b/fs/udf/misc.c
@@ -51,7 +51,6 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
51 uint8_t *ea = NULL, *ad = NULL; 51 uint8_t *ea = NULL, *ad = NULL;
52 int offset; 52 int offset;
53 uint16_t crclen; 53 uint16_t crclen;
54 int i;
55 54
56 ea = UDF_I_DATA(inode); 55 ea = UDF_I_DATA(inode);
57 if (UDF_I_LENEATTR(inode)) { 56 if (UDF_I_LENEATTR(inode)) {
@@ -138,11 +137,7 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
138 eahd->descTag.descCRCLength = cpu_to_le16(crclen); 137 eahd->descTag.descCRCLength = cpu_to_le16(crclen);
139 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd + 138 eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
140 sizeof(tag), crclen, 0)); 139 sizeof(tag), crclen, 0));
141 eahd->descTag.tagChecksum = 0; 140 eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag);
142 for (i = 0; i < 16; i++)
143 if (i != 4)
144 eahd->descTag.tagChecksum +=
145 ((uint8_t *)&(eahd->descTag))[i];
146 UDF_I_LENEATTR(inode) += size; 141 UDF_I_LENEATTR(inode) += size;
147 return (struct genericFormat *)&ea[offset]; 142 return (struct genericFormat *)&ea[offset];
148 } 143 }
@@ -207,8 +202,6 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
207{ 202{
208 tag *tag_p; 203 tag *tag_p;
209 struct buffer_head *bh = NULL; 204 struct buffer_head *bh = NULL;
210 register uint8_t checksum;
211 register int i;
212 struct udf_sb_info *sbi = UDF_SB(sb); 205 struct udf_sb_info *sbi = UDF_SB(sb);
213 206
214 /* Read the block */ 207 /* Read the block */
@@ -234,12 +227,7 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
234 } 227 }
235 228
236 /* Verify the tag checksum */ 229 /* Verify the tag checksum */
237 checksum = 0U; 230 if (udf_tag_checksum(tag_p) != tag_p->tagChecksum) {
238 for (i = 0; i < 4; i++)
239 checksum += (uint8_t)(bh->b_data[i]);
240 for (i = 5; i < 16; i++)
241 checksum += (uint8_t)(bh->b_data[i]);
242 if (checksum != tag_p->tagChecksum) {
243 printk(KERN_ERR "udf: tag checksum failed block %d\n", block); 231 printk(KERN_ERR "udf: tag checksum failed block %d\n", block);
244 goto error_out; 232 goto error_out;
245 } 233 }
@@ -277,17 +265,11 @@ struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
277void udf_update_tag(char *data, int length) 265void udf_update_tag(char *data, int length)
278{ 266{
279 tag *tptr = (tag *)data; 267 tag *tptr = (tag *)data;
280 int i;
281
282 length -= sizeof(tag); 268 length -= sizeof(tag);
283 269
284 tptr->tagChecksum = 0;
285 tptr->descCRCLength = cpu_to_le16(length); 270 tptr->descCRCLength = cpu_to_le16(length);
286 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0)); 271 tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
287 272 tptr->tagChecksum = udf_tag_checksum(tptr);
288 for (i = 0; i < 16; i++)
289 if (i != 4)
290 tptr->tagChecksum += (uint8_t)(data[i]);
291} 273}
292 274
293void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, 275void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
@@ -300,3 +282,14 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
300 tptr->tagLocation = cpu_to_le32(loc); 282 tptr->tagLocation = cpu_to_le32(loc);
301 udf_update_tag(data, length); 283 udf_update_tag(data, length);
302} 284}
285
286u8 udf_tag_checksum(const tag *t)
287{
288 u8 *data = (u8 *)t;
289 u8 checksum = 0;
290 int i;
291 for (i = 0; i < sizeof(tag); ++i)
292 if (i != 4) /* position of checksum */
293 checksum += data[i];
294 return checksum;
295}