fs/ntfs/collate.c

Source file repositories/reference/linux-study-clean/fs/ntfs/collate.c

File Facts

System
Linux kernel
Corpus path
fs/ntfs/collate.c
Extension
.c
Size
3950 bytes
Lines
147
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * NTFS kernel collation handling.
 *
 * Copyright (c) 2004 Anton Altaparmakov
 *
 * Part of this file is based on code from the NTFS-3G.
 * and is copyrighted by the respective authors below:
 * Copyright (c) 2004 Anton Altaparmakov
 * Copyright (c) 2005 Yura Pakhuchiy
 */

#include "collate.h"
#include "debug.h"
#include "ntfs.h"

#include <linux/sort.h>

static int ntfs_collate_binary(struct ntfs_volume *vol,
		const void *data1, const u32 data1_len,
		const void *data2, const u32 data2_len)
{
	int rc;

	rc = memcmp(data1, data2, min(data1_len, data2_len));
	if (!rc && (data1_len != data2_len)) {
		if (data1_len < data2_len)
			rc = -1;
		else
			rc = 1;
	}
	return rc;
}

static int ntfs_collate_ntofs_ulong(struct ntfs_volume *vol,
		const void *data1, const u32 data1_len,
		const void *data2, const u32 data2_len)
{
	int rc;
	u32 d1 = le32_to_cpup(data1), d2 = le32_to_cpup(data2);

	if (data1_len != data2_len || data1_len != 4)
		return -EINVAL;

	if (d1 < d2)
		rc = -1;
	else {
		if (d1 == d2)
			rc = 0;
		else
			rc = 1;
	}
	return rc;
}

/*
 * ntfs_collate_ntofs_ulongs - Which of two le32 arrays should be listed first
 * @vol: ntfs volume
 * @data1: first ulong array to collate
 * @data1_len: length in bytes of @data1
 * @data2: second ulong array to collate
 * @data2_len: length in bytes of @data2
 *
 * Returns: -1, 0 or 1 depending of how the arrays compare
 */
static int ntfs_collate_ntofs_ulongs(struct ntfs_volume *vol,
		const void *data1, const u32 data1_len,
		const void *data2, const u32 data2_len)
{
	int len;
	const __le32 *p1 = data1, *p2 = data2;
	u32 d1, d2;

	if (data1_len != data2_len || data1_len & 3) {
		ntfs_error(vol->sb, "data1_len or data2_len not valid\n");
		return -1;
	}

	len = data1_len;
	do {
		d1 = le32_to_cpup(p1);
		p1++;
		d2 = le32_to_cpup(p2);
		p2++;
	} while (d1 == d2 && (len -= 4) > 0);
	return cmp_int(d1, d2);
}

/*
 * ntfs_collate_file_name - Which of two filenames should be listed first

Annotation

Implementation Notes