1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * collate.c - NTFS kernel collation handling. Part of the Linux-NTFS project.
5 * Copyright (c) 2004 Anton Altaparmakov
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
)
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
)
26 ntfs_debug("Done, returning %i", rc
);
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
)
37 ntfs_debug("Entering.");
38 // FIXME: We don't really want to bug here.
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
);
51 ntfs_debug("Done, returning %i", rc
);
55 typedef int (*ntfs_collate_func_t
)(ntfs_volume
*, const void *, const int,
56 const void *, const int);
58 static ntfs_collate_func_t ntfs_do_collate0x0
[3] = {
60 NULL
/*ntfs_collate_file_name*/,
61 NULL
/*ntfs_collate_unicode_string*/,
64 static ntfs_collate_func_t ntfs_do_collate0x1
[4] = {
65 ntfs_collate_ntofs_ulong
,
66 NULL
/*ntfs_collate_ntofs_sid*/,
67 NULL
/*ntfs_collate_ntofs_security_hash*/,
68 NULL
/*ntfs_collate_ntofs_ulongs*/,
72 * ntfs_collate - collate two data items using a specified collation rule
73 * @vol: ntfs volume to which the data items belong
74 * @cr: collation rule to use when comparing the items
75 * @data1: first data item to collate
76 * @data1_len: length in bytes of @data1
77 * @data2: second data item to collate
78 * @data2_len: length in bytes of @data2
80 * Collate the two data items @data1 and @data2 using the collation rule @cr
81 * and return -1, 0, ir 1 if @data1 is found, respectively, to collate before,
82 * to match, or to collate after @data2.
84 * For speed we use the collation rule @cr as an index into two tables of
85 * function pointers to call the appropriate collation function.
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
) {
92 ntfs_debug("Entering.");
94 * FIXME: At the moment we only support COLLATION_BINARY and
95 * COLLATION_NTOFS_ULONG, so we BUG() for everything else for now.
97 BUG_ON(cr
!= COLLATION_BINARY
&& cr
!= COLLATION_NTOFS_ULONG
);
101 return ntfs_do_collate0x0
[i
](vol
, data1
, data1_len
,
106 return ntfs_do_collate0x1
[i
](vol
, data1
, data1_len
,