Skip to content

Commit

Permalink
udf: use crc_itu_t from lib instead of udf_crc
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bob Copeland authored and Jan Kara committed Apr 17, 2008
1 parent 706047a commit f845fce
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 203 deletions.
1 change: 1 addition & 0 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ config ZISOFS

config UDF_FS
tristate "UDF file system support"
select CRC_ITU_T
help
This is the new file system used on some CD-ROMs and DVDs. Say Y if
you intend to mount DVD discs or CDRW's written in packet mode, or
Expand Down
2 changes: 1 addition & 1 deletion fs/udf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ obj-$(CONFIG_UDF_FS) += udf.o

udf-objs := balloc.o dir.o file.o ialloc.o inode.o lowlevel.o namei.o \
partition.o super.o truncate.o symlink.o fsync.o \
crc.o directory.o misc.o udftime.o unicode.o
directory.o misc.o udftime.o unicode.o
172 changes: 0 additions & 172 deletions fs/udf/crc.c

This file was deleted.

11 changes: 6 additions & 5 deletions fs/udf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <linux/buffer_head.h>
#include <linux/writeback.h>
#include <linux/slab.h>
#include <linux/crc-itu-t.h>

#include "udf_i.h"
#include "udf_sb.h"
Expand Down Expand Up @@ -1419,9 +1420,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
iinfo->i_location.
logicalBlockNum);
use->descTag.descCRCLength = cpu_to_le16(crclen);
use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
sizeof(tag), crclen,
0));
use->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)use +
sizeof(tag),
crclen));
use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);

mark_buffer_dirty(bh);
Expand Down Expand Up @@ -1584,8 +1585,8 @@ static int udf_update_inode(struct inode *inode, int do_sync)
crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc -
sizeof(tag);
fe->descTag.descCRCLength = cpu_to_le16(crclen);
fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
crclen, 0));
fe->descTag.descCRC = cpu_to_le16(crc_itu_t(0, (char *)fe + sizeof(tag),
crclen));
fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);

/* write the data blocks */
Expand Down
12 changes: 7 additions & 5 deletions fs/udf/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/buffer_head.h>
#include <linux/crc-itu-t.h>

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

/* Verify the descriptor CRC */
if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
le16_to_cpu(tag_p->descCRCLength), 0))
le16_to_cpu(tag_p->descCRC) == crc_itu_t(0,
bh->b_data + sizeof(tag),
le16_to_cpu(tag_p->descCRCLength)))
return bh;

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

tptr->descCRCLength = cpu_to_le16(length);
tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
tptr->descCRC = cpu_to_le16(crc_itu_t(0, data + sizeof(tag), length));
tptr->tagChecksum = udf_tag_checksum(tptr);
}

Expand Down
21 changes: 10 additions & 11 deletions fs/udf/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <linux/smp_lock.h>
#include <linux/buffer_head.h>
#include <linux/sched.h>
#include <linux/crc-itu-t.h>

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

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

if (fibh->sbh == fibh->ebh) {
crc = udf_crc((uint8_t *)sfi->impUse,
crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
crclen + sizeof(tag) -
sizeof(struct fileIdentDesc), crc);
sizeof(struct fileIdentDesc));
} else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
crc = udf_crc(fibh->ebh->b_data +
crc = crc_itu_t(crc, fibh->ebh->b_data +
sizeof(struct fileIdentDesc) +
fibh->soffset,
crclen + sizeof(tag) -
sizeof(struct fileIdentDesc),
crc);
sizeof(struct fileIdentDesc));
} else {
crc = udf_crc((uint8_t *)sfi->impUse,
-fibh->soffset - sizeof(struct fileIdentDesc),
crc);
crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
crc = crc_itu_t(crc, (uint8_t *)sfi->impUse,
-fibh->soffset - sizeof(struct fileIdentDesc));
crc = crc_itu_t(crc, fibh->ebh->b_data, fibh->eoffset);
}

cfi->descTag.descCRC = cpu_to_le16(crc);
Expand Down
10 changes: 5 additions & 5 deletions fs/udf/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <linux/mount.h>
#include <linux/seq_file.h>
#include <linux/bitmap.h>
#include <linux/crc-itu-t.h>
#include <asm/byteorder.h>

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

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

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

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

lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
mark_buffer_dirty(bh);
Expand Down
3 changes: 0 additions & 3 deletions fs/udf/udfdecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);

/* crc.c */
extern uint16_t udf_crc(const uint8_t *, uint32_t, uint16_t);

/* udftime.c */
extern struct timespec *udf_disk_stamp_to_time(struct timespec *dest,
timestamp src);
Expand Down
3 changes: 2 additions & 1 deletion fs/udf/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/kernel.h>
#include <linux/string.h> /* for memset */
#include <linux/nls.h>
#include <linux/crc-itu-t.h>

#include "udf_sb.h"

Expand Down Expand Up @@ -454,7 +455,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
} else if (newIndex > 250)
newIndex = 250;
newName[newIndex++] = CRC_MARK;
valueCRC = udf_crc(fidName, fidNameLen, 0);
valueCRC = crc_itu_t(0, fidName, fidNameLen);
newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
newName[newIndex++] = hexChar[(valueCRC & 0x0f00) >> 8];
newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4];
Expand Down

0 comments on commit f845fce

Please sign in to comment.