Skip to content

Commit f845fce

Browse files
bcopelandjankara
authored andcommitted
udf: use crc_itu_t from lib instead of udf_crc
As pointed out by Sergey Vlasov, UDF implements its own version of the CRC ITU-T V.41. Convert it to use the one in the library. Signed-off-by: Bob Copeland <me@bobcopeland.com> Cc: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 706047a commit f845fce

9 files changed

Lines changed: 32 additions & 203 deletions

File tree

‎fs/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ config ZISOFS
663663

664664
config UDF_FS
665665
tristate "UDF file system support"
666+
select CRC_ITU_T
666667
help
667668
This is the new file system used on some CD-ROMs and DVDs. Say Y if
668669
you intend to mount DVD discs or CDRW's written in packet mode, or

‎fs/udf/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ obj-$(CONFIG_UDF_FS) += udf.o
66

77
udf-objs := balloc.o dir.o file.o ialloc.o inode.o lowlevel.o namei.o \
88
partition.o super.o truncate.o symlink.o fsync.o \
9-
crc.o directory.o misc.o udftime.o unicode.o
9+
directory.o misc.o udftime.o unicode.o

‎fs/udf/crc.c‎

Lines changed: 0 additions & 172 deletions
This file was deleted.

‎fs/udf/inode.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/buffer_head.h>
3838
#include <linux/writeback.h>
3939
#include <linux/slab.h>
40+
#include <linux/crc-itu-t.h>
4041

4142
#include "udf_i.h"
4243
#include "udf_sb.h"
@@ -1419,9 +1420,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
14191420
iinfo->i_location.
14201421
logicalBlockNum);
14211422
use->descTag.descCRCLength = cpu_to_le16(crclen);
1422-
use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
1423-
sizeof(tag), crclen,
1424-
0));
1423+
use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
1424+
sizeof(tag),
1425+
crclen));
14251426
use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
14261427

14271428
mark_buffer_dirty(bh);
@@ -1584,8 +1585,8 @@ static int udf_update_inode(struct inode *inode, int do_sync)
15841585
crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc -
15851586
sizeof(tag);
15861587
fe->descTag.descCRCLength = cpu_to_le16(crclen);
1587-
fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
1588-
crclen, 0));
1588+
fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(tag),
1589+
crclen));
15891590
fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
15901591

15911592
/* write the data blocks */

‎fs/udf/misc.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/fs.h>
2525
#include <linux/string.h>
2626
#include <linux/buffer_head.h>
27+
#include <linux/crc-itu-t.h>
2728

2829
#include "udf_i.h"
2930
#include "udf_sb.h"
@@ -135,8 +136,8 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
135136
/* rewrite CRC + checksum of eahd */
136137
crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
137138
eahd->descTag.descCRCLength = cpu_to_le16(crclen);
138-
eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
139-
sizeof(tag), crclen, 0));
139+
eahd->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)eahd +
140+
sizeof(tag), crclen));
140141
eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag);
141142
iinfo->i_lenEAttr += size;
142143
return (struct genericFormat *)&ea[offset];
@@ -241,8 +242,9 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
241242

242243
/* Verify the descriptor CRC */
243244
if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
244-
le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
245-
le16_to_cpu(tag_p->descCRCLength), 0))
245+
le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
246+
bh->b_data + sizeof(tag),
247+
le16_to_cpu(tag_p->descCRCLength)))
246248
return bh;
247249

248250
udf_debug("Crc failure block %d: crc = %d, crclen = %d\n", block,
@@ -266,7 +268,7 @@ void udf_update_tag(char *data, int length)
266268
length -= sizeof(tag);
267269

268270
tptr->descCRCLength = cpu_to_le16(length);
269-
tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
271+
tptr->descCRC = cpu_to_le16(crc_itu_t(0, data + sizeof(tag), length));
270272
tptr->tagChecksum = udf_tag_checksum(tptr);
271273
}
272274

‎fs/udf/namei.c‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/smp_lock.h>
3232
#include <linux/buffer_head.h>
3333
#include <linux/sched.h>
34+
#include <linux/crc-itu-t.h>
3435

3536
static inline int udf_match(int len1, const char *name1, int len2,
3637
const char *name2)
@@ -97,25 +98,23 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
9798
memset(fibh->ebh->b_data, 0x00, padlen + offset);
9899
}
99100

100-
crc = udf_crc((uint8_t *)cfi + sizeof(tag),
101-
sizeof(struct fileIdentDesc) - sizeof(tag), 0);
101+
crc = crc_itu_t(0, (uint8_t *)cfi + sizeof(tag),
102+
sizeof(struct fileIdentDesc) - sizeof(tag));
102103

103104
if (fibh->sbh == fibh->ebh) {
104-
crc = udf_crc((uint8_t *)sfi->impUse,
105+
crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
105106
crclen + sizeof(tag) -
106-
sizeof(struct fileIdentDesc), crc);
107+
sizeof(struct fileIdentDesc));
107108
} else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
108-
crc = udf_crc(fibh->ebh->b_data +
109+
crc = crc_itu_t(crc, fibh->ebh->b_data +
109110
sizeof(struct fileIdentDesc) +
110111
fibh->soffset,
111112
crclen + sizeof(tag) -
112-
sizeof(struct fileIdentDesc),
113-
crc);
113+
sizeof(struct fileIdentDesc));
114114
} else {
115-
crc = udf_crc((uint8_t *)sfi->impUse,
116-
-fibh->soffset - sizeof(struct fileIdentDesc),
117-
crc);
118-
crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
115+
crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
116+
-fibh->soffset - sizeof(struct fileIdentDesc));
117+
crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset);
119118
}
120119

121120
cfi->descTag.descCRC = cpu_to_le16(crc);

‎fs/udf/super.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <linux/mount.h>
5757
#include <linux/seq_file.h>
5858
#include <linux/bitmap.h>
59+
#include <linux/crc-itu-t.h>
5960
#include <asm/byteorder.h>
6061

6162
#include "udf_sb.h"
@@ -1765,8 +1766,8 @@ static void udf_open_lvid(struct super_block *sb)
17651766
lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
17661767

17671768
lvid->descTag.descCRC = cpu_to_le16(
1768-
udf_crc((char *)lvid + sizeof(tag),
1769-
le16_to_cpu(lvid->descTag.descCRCLength), 0));
1769+
crc_itu_t(0, (char *)lvid + sizeof(tag),
1770+
le16_to_cpu(lvid->descTag.descCRCLength)));
17701771

17711772
lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
17721773
mark_buffer_dirty(bh);
@@ -1800,9 +1801,8 @@ static void udf_close_lvid(struct super_block *sb)
18001801
lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
18011802

18021803
lvid->descTag.descCRC = cpu_to_le16(
1803-
udf_crc((char *)lvid + sizeof(tag),
1804-
le16_to_cpu(lvid->descTag.descCRCLength),
1805-
0));
1804+
crc_itu_t(0, (char *)lvid + sizeof(tag),
1805+
le16_to_cpu(lvid->descTag.descCRCLength)));
18061806

18071807
lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
18081808
mark_buffer_dirty(bh);

‎fs/udf/udfdecl.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
220220
extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
221221
extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
222222

223-
/* crc.c */
224-
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);
225-
226223
/* udftime.c */
227224
extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
228225
timestamp src);

‎fs/udf/unicode.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/kernel.h>
2424
#include <linux/string.h> /* for memset */
2525
#include <linux/nls.h>
26+
#include <linux/crc-itu-t.h>
2627

2728
#include "udf_sb.h"
2829

@@ -454,7 +455,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
454455
} else if (newIndex > 250)
455456
newIndex = 250;
456457
newName[newIndex++] = CRC_MARK;
457-
valueCRC = udf_crc(fidName, fidNameLen, 0);
458+
valueCRC = crc_itu_t(0, fidName, fidNameLen);
458459
newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
459460
newName[newIndex++] = hexChar[(valueCRC & 0x0f00) >> 8];
460461
newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4];

0 commit comments

Comments
 (0)