public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: iso9660 endianness cleanup patch
@ 2001-05-01 14:40 Andrzej Krzysztofowicz
  2001-05-01 18:16 ` H. Peter Anvin
  0 siblings, 1 reply; 18+ messages in thread
From: Andrzej Krzysztofowicz @ 2001-05-01 14:40 UTC (permalink / raw)
  To: hpa; +Cc: Alan Cox, kernel list, torvalds, Andries.Brouwer


Are you sure that the arguments of the following casting

> +	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

-- 
=======================================================================
  Andrzej M. Krzysztofowicz               ankry@mif.pg.gda.pl
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Technical University of Gdansk

^ permalink raw reply	[flat|nested] 18+ messages in thread
* iso9660 endianness cleanup patch
@ 2001-05-01  5:30 H. Peter Anvin
  2001-05-01  6:14 ` Linus Torvalds
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: H. Peter Anvin @ 2001-05-01  5:30 UTC (permalink / raw)
  To: Alan Cox, Linus Torvalds, Andries Brouwer,
	Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

Hi guys,

I was looking over the iso9660 code, and noticed that it was doing
endianness conversion via ad hoc *functions*, not even inlines; nor did
it take any advantage of the fact that iso9660 is bi-endian (has "all"
data in both bigendian and littleendian format.)

The attached patch fixes both.  It is against 2.4.4, but from the looks
of it it should patch against -ac as well.

	-hpa

[-- Attachment #2: isofs-2.4.4-1.diff --]
[-- Type: text/plain, Size: 3152 bytes --]

--- linux-2.4.4/include/linux/iso_fs.h	Fri Apr 27 15:48:20 2001
+++ linux-2.4.4-ciso/include/linux/iso_fs.h	Mon Apr 30 20:09:31 2001
@@ -165,14 +165,51 @@
 #define ISOFS_SUPER_MAGIC 0x9660
 
 #ifdef __KERNEL__
-extern int isonum_711(char *);
-extern int isonum_712(char *);
-extern int isonum_721(char *);
-extern int isonum_722(char *);
-extern int isonum_723(char *);
-extern int isonum_731(char *);
-extern int isonum_732(char *);
-extern int isonum_733(char *);
+/* Number conversion inlines, named after the section in ISO 9660
+   they correspond to. */
+
+#include <asm/byteorder.h>
+
+extern inline int isonum_711(char *p)
+{
+	return *(u8 *)p;
+}
+extern inline int isonum_712(char *p)
+{
+	return *(s8 *)p;
+}
+extern inline int isonum_721(char *p)
+{
+	return le16_to_cpu(*(u16 *)p);
+}
+extern inline int isonum_722(char *p)
+{
+	return be16_to_cpu(*(u16 *)p);
+}
+extern inline int isonum_723(char *p)
+{
+#ifdef __BIG_ENDIAN
+	return be16_to_cpu(*(u16 *)(p+2));
+#else
+	return le16_to_cpu(*(u16 *)p);
+#endif
+}
+extern inline int isonum_731(char *p)
+{
+	return le32_to_cpu(*(u32 *)p);
+}
+extern inline int isonum_732(char *p)
+{
+	return be32_to_cpu(*(u32 *)p);
+}
+extern inline int isonum_733(char *p)
+{
+#ifdef __BIG_ENDIAN
+	return be32_to_cpu(*(u32 *)(p+4));
+#else
+	return le32_to_cpu(*(u32 *)p);
+#endif
+}
 extern int iso_date(char *, int);
 
 extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *);
--- linux-2.4.4/fs/isofs/util.c	Wed Nov 29 10:11:38 2000
+++ linux-2.4.4-ciso/fs/isofs/util.c	Mon Apr 30 20:04:24 2001
@@ -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 <pace@blitz.com>.
  */
 
 #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.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2001-05-04  8:10 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-05-01 14:40 iso9660 endianness cleanup patch Andrzej Krzysztofowicz
2001-05-01 18:16 ` H. Peter Anvin
2001-05-01 18:43   ` H. Peter Anvin
2001-05-01 18:48   ` FIXED " H. Peter Anvin
2001-05-01 20:44   ` Alan Cox
2001-05-01 20:59   ` Linus Torvalds
2001-05-01 21:06     ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2001-05-01  5:30 H. Peter Anvin
2001-05-01  6:14 ` Linus Torvalds
2001-05-01  6:18   ` H. Peter Anvin
2001-05-01 20:21     ` Pavel Machek
2001-05-04  1:51       ` Albert D. Cahalan
2001-05-04  4:59         ` Mike Galbraith
2001-05-01  6:37   ` Albert D. Cahalan
2001-05-01  9:52 ` Tim Riker
2001-05-02  8:52 ` Martin Dalecki
2001-05-02 16:03   ` H. Peter Anvin
2001-05-03 21:59   ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox