This source file includes following definitions.
- ntfs_collate_binary
- ntfs_collate_ntofs_ulong
- ntfs_collate
1
2
3
4
5
6
7
8 #include "collate.h"
9 #include "debug.h"
10 #include "ntfs.h"
11
12 static int ntfs_collate_binary(ntfs_volume *vol,
13 const void *data1, const int data1_len,
14 const void *data2, const int data2_len)
15 {
16 int rc;
17
18 ntfs_debug("Entering.");
19 rc = memcmp(data1, data2, min(data1_len, data2_len));
20 if (!rc && (data1_len != data2_len)) {
21 if (data1_len < data2_len)
22 rc = -1;
23 else
24 rc = 1;
25 }
26 ntfs_debug("Done, returning %i", rc);
27 return rc;
28 }
29
30 static int ntfs_collate_ntofs_ulong(ntfs_volume *vol,
31 const void *data1, const int data1_len,
32 const void *data2, const int data2_len)
33 {
34 int rc;
35 u32 d1, d2;
36
37 ntfs_debug("Entering.");
38
39 BUG_ON(data1_len != data2_len);
40 BUG_ON(data1_len != 4);
41 d1 = le32_to_cpup(data1);
42 d2 = le32_to_cpup(data2);
43 if (d1 < d2)
44 rc = -1;
45 else {
46 if (d1 == d2)
47 rc = 0;
48 else
49 rc = 1;
50 }
51 ntfs_debug("Done, returning %i", rc);
52 return rc;
53 }
54
55 typedef int (*ntfs_collate_func_t)(ntfs_volume *, const void *, const int,
56 const void *, const int);
57
58 static ntfs_collate_func_t ntfs_do_collate0x0[3] = {
59 ntfs_collate_binary,
60 NULL,
61 NULL,
62 };
63
64 static ntfs_collate_func_t ntfs_do_collate0x1[4] = {
65 ntfs_collate_ntofs_ulong,
66 NULL,
67 NULL,
68 NULL,
69 };
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 int ntfs_collate(ntfs_volume *vol, COLLATION_RULE cr,
88 const void *data1, const int data1_len,
89 const void *data2, const int data2_len) {
90 int i;
91
92 ntfs_debug("Entering.");
93
94
95
96
97 BUG_ON(cr != COLLATION_BINARY && cr != COLLATION_NTOFS_ULONG);
98 i = le32_to_cpu(cr);
99 BUG_ON(i < 0);
100 if (i <= 0x02)
101 return ntfs_do_collate0x0[i](vol, data1, data1_len,
102 data2, data2_len);
103 BUG_ON(i < 0x10);
104 i -= 0x10;
105 if (likely(i <= 3))
106 return ntfs_do_collate0x1[i](vol, data1, data1_len,
107 data2, data2_len);
108 BUG();
109 return 0;
110 }