Skip to contentSkip to conversation

iso9660 endianness cleanup patch

DISCUSSION Andrzej Krzysztofowicz 4 participants 7 messages May 1, 2001 Isofs filesystem

lore
Share & tools
lore
#0 lore raw

Are you sure that the arguments of the following casting

Review

Quoted 7 lines
(quoted diff) +4 -0
+	return le16_to_cpu(*(u16 *)p);
 
+	return be16_to_cpu(*(u16 *)p);
 
+	return le32_to_cpu(*(u32 *)p);
 
+	return be32_to_cpu(*(u32 *)p);

are properly aligned ?
I did not revise the code to check it, but AFAIK improperly aligned char* pointers cause problem with casting to pointers to 16/32-bit data on some architectures (I heard of sucj a problem with alpha).

Maybe there was a reason that the original code did operate on bytes here...

Andrzej

Signature · 4 lines
=======================================================================
  Andrzej M. Krzysztofowicz               [email protected]
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Technical University of Gdansk
#1 lore raw
Quoted 9 lines · Andrzej Krzysztofowicz

Are you sure that the arguments of the following casting

Quoted 5 lines
(quoted diff) +3 -0
+     return le16_to_cpu(*(u16 *)p);
 
+     return be16_to_cpu(*(u16 *)p);
 
+     return le32_to_cpu(*(u32 *)p);
Quoted 9 lines
Quoted 1 line

+ return be32_to_cpu(*(u32 *)p);

are properly aligned ?
I did not revise the code to check it, but AFAIK improperly aligned char* pointers cause problem with casting to pointers to 16/32-bit data on some architectures (I heard of sucj a problem with alpha).

Maybe there was a reason that the original code did operate on bytes here...

Oh bother, you're right of course. We need some kind of standardized macro for indirecting through a potentially unaligned pointer. It can just do the dereference (e.g. x86), use left/right accesses (e.g. MIPS), or do it by byte (others).

Ports people, what do you think?

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt
#2 lore raw
Quoted 2 lines

Oh bother, you're right of course. We need some kind of standardized macro for indirecting through a potentially unaligned pointer. It can

get_unaligned()

#3 lore raw
In reply to H. Peter Anvin
Quoted 3 lines · H. Peter Anvin

Oh bother, you're right of course. We need some kind of standardized macro for indirecting through a potentially unaligned pointer.

No we don't - because it already exists.

It's called "get_unaligned()".

Linus

#4 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · H. Peter Anvin

Oh bother, you're right of course. We need some kind of standardized macro for indirecting through a potentially unaligned pointer.

No we don't - because it already exists.

It's called "get_unaligned()".

Well, we presumably do need it since it's there. I *did* correct this brain fault of mine a few hours ago.

Note that it might still be an idea to have get_unaligned_le32() & co... on some machines le32_to_cpu(get_unaligned()) could potentially be a lot more painful than it needs to be.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt
#5 lore raw
In reply to Andrzej Krzysztofowicz
Quoted 8 lines · [email protected] wrote:

Oh bother, you're right of course. We need some kind of standardized macro for indirecting through a potentially unaligned pointer. It can just do the dereference (e.g. x86), use left/right accesses (e.g. MIPS), or do it by byte (others).

Ports people, what do you think?

My, my, my... I'm really 100% alert this morning. Before anyone clues me in, I did find <asm/unaligned.h> when I actually bothered looking. New patch in the making.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt
#6 lore raw

Re: FIXED iso9660 endianness cleanup patch

In reply to Andrzej Krzysztofowicz

Okay, this one should actually work as advertised. Pardon the mental meltdown earlier.

This also changes "extern inline" to "static inline" (per Linus' request) and always ignores the bigendian part of a bi-endian datum (per Tim Riker's observation that lots of [Windoze?] programs get that wrong.)

It's still a bit of a loss to have to do unaligned load and endianness conversion as two operations; on some machines it's doubtlessly faster to do both at the same time. However, *those* macros I didn't find...

-hpa

fs/isofs/util.c renamed from linux-2.4.4/fs/isofs/util.c +1 -82
diff -ur stock3/linux-2.4.4/fs/isofs/util.c linux-2.4.4/fs/isofs/util.c
@@ -1,90 +1,9 @@
 /*
  *  linux/fs/isofs/util.c
- *
- *  The special functions in the file are numbered according to the section
- *  of the iso 9660 standard in which they are described.  isonum_733 will
- *  convert numbers according to section 7.3.3, etc.
- *
- *  isofs special functions.  This file was lifted in its entirety from
- *  the 386BSD iso9660 filesystem, by Pace Willisson <[email protected]>.
  */
 
 #include <linux/time.h>
-
-int
-isonum_711 (char * p)
-{
-	return (*p & 0xff);
-}
-
-int
-isonum_712 (char * p)
-{
-	int val;
-	
-	val = *p;
-	if (val & 0x80)
-		val |= 0xffffff00;
-	return (val);
-}
-
-int
-isonum_721 (char * p)
-{
-	return ((p[0] & 0xff) | ((p[1] & 0xff) << 8));
-}
-
-int
-isonum_722 (char * p)
-{
-	return (((p[0] & 0xff) << 8) | (p[1] & 0xff));
-}
-
-int
-isonum_723 (char * p)
-{
-#if 0
-	if (p[0] != p[3] || p[1] != p[2]) {
-		fprintf (stderr, "invalid format 7.2.3 number\n");
-		exit (1);
-	}
-#endif
-	return (isonum_721 (p));
-}
-
-int
-isonum_731 (char * p)
-{
-	return ((p[0] & 0xff)
-		| ((p[1] & 0xff) << 8)
-		| ((p[2] & 0xff) << 16)
-		| ((p[3] & 0xff) << 24));
-}
-
-int
-isonum_732 (char * p)
-{
-	return (((p[0] & 0xff) << 24)
-		| ((p[1] & 0xff) << 16)
-		| ((p[2] & 0xff) << 8)
-		| (p[3] & 0xff));
-}
-
-int
-isonum_733 (char * p)
-{
-#if 0
-	int i;
-
-	for (i = 0; i < 4; i++) {
-		if (p[i] != p[7-i]) {
-			fprintf (stderr, "bad format 7.3.3 number\n");
-			exit (1);
-		}
-	}
-#endif
-	return (isonum_731 (p));
-}
+#include <linux/iso_fs.h>
 
 /* 
  * We have to convert from a MM/DD/YY format to the Unix ctime format.
include/linux/iso_fs.h renamed from linux-2.4.4/include/linux/iso_fs.h +40 -8

54 lines not on this page · raw message