iso9660 endianness cleanup patch
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
include/linux/iso_fs.h +45 -8
@@ -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 *);
fs/isofs/util.c +1 -82
91 lines not on this page · raw message
Quoted 3 lines · H. Peter Anvin
The attached patch fixes both. It is against 2.4.4, but from the looks of it it should patch against -ac as well.
Btw, please use "static inline" instead of "extern inline", as gcc may decide not to inline the latter at all, leading to confusing link-time errors. (Gcc may also decide not to inline "static inline", but then gcc will output the actual body of the function out-of-line if it gets used, so you don't get the link-time failure).
Right now only certain broken versions of gcc will actually show this behaviour, I think, but it's at least in theory going to be an issue.
Linus
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · H. Peter Anvin
The attached patch fixes both. It is against 2.4.4, but from the looks of it it should patch against -ac as well.
Quoted 9 lines
Btw, please use "static inline" instead of "extern inline", as gcc may decide not to inline the latter at all, leading to confusing link-time errors. (Gcc may also decide not to inline "static inline", but then gcc will output the actual body of the function out-of-line if it gets used, so you don't get the link-time failure).
Right now only certain broken versions of gcc will actually show this behaviour, I think, but it's at least in theory going to be an issue.
I guess I personally prefer an error over completely broken behaviour, but feel free to change it.
-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
Quoted 8 lines · Linus Torvalds
Btw, please use "static inline" instead of "extern inline", as gcc may decide not to inline the latter at all, leading to confusing link-time errors. (Gcc may also decide not to inline "static inline", but then gcc will output the actual body of the function out-of-line if it gets used, so you don't get the link-time failure).
Right now only certain broken versions of gcc will actually show this behaviour, I think, but it's at least in theory going to be an issue.
Since the best choice depends on compiler version:
#if(GCC_VERSION_FOO)
#define __inline extern inline
#else
#define __inline static inline
#endif
(that, or _INLINE if you prefer)
Hi!
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
The attached patch fixes both. It is against 2.4.4, but from the looks of it it should patch against -ac as well.
Btw, please use "static inline" instead of "extern inline", as gcc may decide not to inline the latter at all, leading to confusing link-time errors. (Gcc may also decide not to inline "static inline", but then gcc will output the actual body of the function out-of-line if it gets used, so you don't get the link-time failure).
Quoted 6 lines
Quoted 3 lines
Right now only certain broken versions of gcc will actually show this behaviour, I think, but it's at least in theory going to be an issue.
I guess I personally prefer an error over completely broken behaviour, but feel free to change it.
It should ot break anything. gcc decides its bad to inline it, so it does not inline it. Small code growth at worst. Compiler has right to make your code bigger or slower, if it decides to do so.
Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt, details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
Quoted 3 lines · Pavel Machek
It should ot break anything. gcc decides its bad to inline it, so it does not inline it. Small code growth at worst. Compiler has right to make your code bigger or slower, if it decides to do so.
Oh come on. The logical way:
inline Compiler must inline (only!) or report an error. extern inline This is a contradiction. Report an error. static inline This is a contradiction. Report an error.
Anything else is obvious crap. It isn't OK for the compiler to ever ignore me; inline recursive functions are just wrong. Taking the address of an inline function is just wrong too.
Of course the above is not what we are given. We get crap. The old gcc behavior was crap, and I guess the C99 behavior is too. So the only sane thing is a #define that is set to whatever makes the compiler behave as nicely as possible. Then we use _INLINE everywhere, and get decent behavior out of both old and new compilers.
Quoted 9 lines · Albert D. Cahalan
Quoted 3 lines · Pavel Machek
It should ot break anything. gcc decides its bad to inline it, so it does not inline it. Small code growth at worst. Compiler has right to make your code bigger or slower, if it decides to do so.
Oh come on. The logical way:
inline Compiler must inline (only!) or report an error.
That's doable now.. if the code is otherwise warning free.
-Mike
hpa,
I'd remove the __BIG_ENDIAN test cases if I were you. Having written many a iso9660 decoder I will tell you that the "required" bi-endian implementation is sometimes broken as many vendors only test CDs with a certain single endian OS. I've seen these set to 0s, or -1 or just a copy of the le data byte for byte. I opened many a bug report with the different CD formatting software vendors, some fixed them, many didn't care. The extra savings does not justify the hassles IMHO.
The other changes look great!
Tim
Quoted 12 lines · H. Peter Anvin
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
Signature · 3 lines
Tim Riker - http://rikers.org/ - short SIGs! <g> All I need to know I could have learned in Kindergarten ... if I'd just been paying attention.
Quoted 10 lines · H. Peter Anvin
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.
Please beware: There is a can of worms you are openning up here, since there are many broken CD producer programms out there, which only provide the little endian data and incorrect big endian entries. I had some CD's of this form myself. So the endian neutrality of the iso9660 is only in the theory present...
Quoted 10 lines · Martin Dalecki
Quoted 8 lines · H. Peter Anvin
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.)
Quoted 9 lines
Quoted 2 lines
The attached patch fixes both. It is against 2.4.4, but from the looks of it it should patch against -ac as well.
Please beware: There is a can of worms you are openning up here, since there are many broken CD producer programms out there, which only provide the little endian data and incorrect big endian entries. I had some CD's of this form myself. So the endian neutrality of the iso9660 is only in the theory present...
So it has been discussed, and been updated.
-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
Hi!
Quoted 5 lines
Quoted 5 lines
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.)
Quoted 8 lines
Quoted 2 lines
The attached patch fixes both. It is against 2.4.4, but from the looks of it it should patch against -ac as well.
Please beware: There is a can of worms you are openning up here, since there are many broken CD producer programms out there, which only provide the little endian data and incorrect big endian entries. I had some CD's of this form myself. So the endian neutrality of the iso9660 is only in the theory present...
Hmm, perhaps there's time to fsck.iso9660?
Pavel
PS: It might be funny to *deliberately* create different filesystems; one on little endian side and one on big endian side. That way windows users would see "macs suck" and mac users "PCs suck", and that with just one cd ;-).
Signature · 2 lines
I'm [email protected]. "In my country we have almost anarchy and I don't care." Panos Katsaloulis describing me w.r.t. patents at [email protected]