0001
0002
0003
0004
0005
0006
0007
0008 #include "collate.h"
0009 #include "debug.h"
0010 #include "ntfs.h"
0011
0012 static int ntfs_collate_binary(ntfs_volume *vol,
0013 const void *data1, const int data1_len,
0014 const void *data2, const int data2_len)
0015 {
0016 int rc;
0017
0018 ntfs_debug("Entering.");
0019 rc = memcmp(data1, data2, min(data1_len, data2_len));
0020 if (!rc && (data1_len != data2_len)) {
0021 if (data1_len < data2_len)
0022 rc = -1;
0023 else
0024 rc = 1;
0025 }
0026 ntfs_debug("Done, returning %i", rc);
0027 return rc;
0028 }
0029
0030 static int ntfs_collate_ntofs_ulong(ntfs_volume *vol,
0031 const void *data1, const int data1_len,
0032 const void *data2, const int data2_len)
0033 {
0034 int rc;
0035 u32 d1, d2;
0036
0037 ntfs_debug("Entering.");
0038
0039 BUG_ON(data1_len != data2_len);
0040 BUG_ON(data1_len != 4);
0041 d1 = le32_to_cpup(data1);
0042 d2 = le32_to_cpup(data2);
0043 if (d1 < d2)
0044 rc = -1;
0045 else {
0046 if (d1 == d2)
0047 rc = 0;
0048 else
0049 rc = 1;
0050 }
0051 ntfs_debug("Done, returning %i", rc);
0052 return rc;
0053 }
0054
0055 typedef int (*ntfs_collate_func_t)(ntfs_volume *, const void *, const int,
0056 const void *, const int);
0057
0058 static ntfs_collate_func_t ntfs_do_collate0x0[3] = {
0059 ntfs_collate_binary,
0060 NULL,
0061 NULL,
0062 };
0063
0064 static ntfs_collate_func_t ntfs_do_collate0x1[4] = {
0065 ntfs_collate_ntofs_ulong,
0066 NULL,
0067 NULL,
0068 NULL,
0069 };
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 int ntfs_collate(ntfs_volume *vol, COLLATION_RULE cr,
0088 const void *data1, const int data1_len,
0089 const void *data2, const int data2_len) {
0090 int i;
0091
0092 ntfs_debug("Entering.");
0093
0094
0095
0096
0097 BUG_ON(cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG);
0098 i = le32_to_cpu(cr);
0099 BUG_ON(i < 0);
0100 if (i <= 0x02)
0101 return ntfs_do_collate0x0[i](vol, data1, data1_len,
0102 data2, data2_len);
0103 BUG_ON(i < 0x10);
0104 i -= 0x10;
0105 if (likely(i <= 3))
0106 return ntfs_do_collate0x1[i](vol, data1, data1_len,
0107 data2, data2_len);
0108 BUG();
0109 return 0;
0110 }