/*
* linux / fs / hfs / string . c
*
* Copyright ( C ) 1995 - 1997 Paul H . Hargrove
* ( C ) 2003 Ardis Technologies < roman @ ardistech . com >
* This file may be distributed under the terms of the GNU General Public License .
*
* This file contains the string comparison function for the
* Macintosh character set .
*
* The code in this file is derived from code which is copyright
* 1986 , 1989 , 1990 by Abacus Research and Development , Inc . ( ARDI )
* It is used here by the permission of ARDI ' s president Cliff Matthews .
*/
#include "hfs_fs.h"
#include <linux/dcache.h>
/*================ File-local variables ================*/
/*
* unsigned char caseorder [ ]
*
* Defines the lexical ordering of characters on the Macintosh
*
* Composition of the ' casefold ' and ' order ' tables from ARDI ' s code
* with the entry for 0 x20 changed to match that for 0 xCA to remove
* special case for those two characters .
*/
static unsigned char caseorder[256 ] = {
0 x00,0 x01,0 x02,0 x03,0 x04,0 x05,0 x06,0 x07,0 x08,0 x09,0 x0A,0 x0B,0 x0C,0 x0D,0 x0E,0 x0F,
0 x10,0 x11,0 x12,0 x13,0 x14,0 x15,0 x16,0 x17,0 x18,0 x19,0 x1A,0 x1B,0 x1C,0 x1D,0 x1E,0 x1F,
0 x20,0 x22,0 x23,0 x28,0 x29,0 x2A,0 x2B,0 x2C,0 x2F,0 x30,0 x31,0 x32,0 x33,0 x34,0 x35,0 x36,
0 x37,0 x38,0 x39,0 x3A,0 x3B,0 x3C,0 x3D,0 x3E,0 x3F,0 x40,0 x41,0 x42,0 x43,0 x44,0 x45,0 x46,
0 x47,0 x48,0 x57,0 x59,0 x5D,0 x5F,0 x66,0 x68,0 x6A,0 x6C,0 x72,0 x74,0 x76,0 x78,0 x7A,0 x7E,
0 x8C,0 x8E,0 x90,0 x92,0 x95,0 x97,0 x9E,0 xA0,0 xA2,0 xA4,0 xA7,0 xA9,0 xAA,0 xAB,0 xAC,0 xAD,
0 x4E,0 x48,0 x57,0 x59,0 x5D,0 x5F,0 x66,0 x68,0 x6A,0 x6C,0 x72,0 x74,0 x76,0 x78,0 x7A,0 x7E,
0 x8C,0 x8E,0 x90,0 x92,0 x95,0 x97,0 x9E,0 xA0,0 xA2,0 xA4,0 xA7,0 xAF,0 xB0,0 xB1,0 xB2,0 xB3,
0 x4A,0 x4C,0 x5A,0 x60,0 x7B,0 x7F,0 x98,0 x4F,0 x49,0 x51,0 x4A,0 x4B,0 x4C,0 x5A,0 x60,0 x63,
0 x64,0 x65,0 x6E,0 x6F,0 x70,0 x71,0 x7B,0 x84,0 x85,0 x86,0 x7F,0 x80,0 x9A,0 x9B,0 x9C,0 x98,
0 xB4,0 xB5,0 xB6,0 xB7,0 xB8,0 xB9,0 xBA,0 x94,0 xBB,0 xBC,0 xBD,0 xBE,0 xBF,0 xC0,0 x4D,0 x81,
0 xC1,0 xC2,0 xC3,0 xC4,0 xC5,0 xC6,0 xC7,0 xC8,0 xC9,0 xCA,0 xCB,0 x55,0 x8A,0 xCC,0 x4D,0 x81,
0 xCD,0 xCE,0 xCF,0 xD0,0 xD1,0 xD2,0 xD3,0 x26,0 x27,0 xD4,0 x20,0 x49,0 x4B,0 x80,0 x82,0 x82,
0 xD5,0 xD6,0 x24,0 x25,0 x2D,0 x2E,0 xD7,0 xD8,0 xA6,0 xD9,0 xDA,0 xDB,0 xDC,0 xDD,0 xDE,0 xDF,
0 xE0,0 xE1,0 xE2,0 xE3,0 xE4,0 xE5,0 xE6,0 xE7,0 xE8,0 xE9,0 xEA,0 xEB,0 xEC,0 xED,0 xEE,0 xEF,
0 xF0,0 xF1,0 xF2,0 xF3,0 xF4,0 xF5,0 xF6,0 xF7,0 xF8,0 xF9,0 xFA,0 xFB,0 xFC,0 xFD,0 xFE,0 xFF
};
/*================ Global functions ================*/
/*
* Hash a string to an integer in a case - independent way
*/
int hfs_hash_dentry(const struct dentry *dentry, struct qstr *this )
{
const unsigned char *name = this ->name;
unsigned int hash, len = this ->len;
if (len > HFS_NAMELEN)
len = HFS_NAMELEN;
hash = init_name_hash(dentry);
for (; len; len--)
hash = partial_name_hash(caseorder[*name++], hash);
this ->hash = end_name_hash(hash);
return 0 ;
}
/*
* Compare two strings in the HFS filename character ordering
* Returns positive , negative , or zero , not just 0 or ( + / - ) 1
*
* Equivalent to ARDI ' s call :
* ROMlib_RelString ( s1 + 1 , s2 + 1 , true , false , ( s1 [ 0 ] < < 16 ) | s2 [ 0 ] )
*/
int hfs_strcmp(const unsigned char *s1, unsigned int len1,
const unsigned char *s2, unsigned int len2)
{
int len, tmp;
len = (len1 > len2) ? len2 : len1;
while (len--) {
tmp = (int )caseorder[*(s1++)] - (int )caseorder[*(s2++)];
if (tmp)
return tmp;
}
return len1 - len2;
}
/*
* Test for equality of two strings in the HFS filename character ordering .
* return 1 on failure and 0 on success
*/
int hfs_compare_dentry(const struct dentry *dentry,
unsigned int len, const char *str, const struct qstr *name)
{
const unsigned char *n1, *n2;
if (len >= HFS_NAMELEN) {
if (name->len < HFS_NAMELEN)
return 1 ;
len = HFS_NAMELEN;
} else if (len != name->len)
return 1 ;
n1 = str;
n2 = name->name;
while (len--) {
if (caseorder[*n1++] != caseorder[*n2++])
return 1 ;
}
return 0 ;
}
Messung V0.5 in Prozent C=95 H=90 G=92
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-09-29)
¤
*© Formatika GbR, Deutschland