Blame src/vmount/ntapi_vms_helper.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_port.h>
dd89bb
#include <ntapi/nt_vmount.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
dd89bb
nt_vms_node * __stdcall	__ntapi_vms_get_end_component_first_node(
dd89bb
	__in	nt_vms_system *		pvms_sys,
dd89bb
        __in	uint32_t		end_component_hash)
dd89bb
{
dd89bb
	nt_vms_node *	node;
dd89bb
dd89bb
	/* verify non-empty list and valid input */
dd89bb
	if (!pvms_sys->dev_name_head_node || !end_component_hash)
dd89bb
		return (nt_vms_node *)0;
dd89bb
dd89bb
	/* find first node by end component hash */
dd89bb
	node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node);
dd89bb
dd89bb
	while (node->next && (node->end_component_hash < end_component_hash))
dd89bb
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);
dd89bb
dd89bb
	if (node->end_component_hash == end_component_hash)
dd89bb
		return node;
dd89bb
	else
dd89bb
		return (nt_vms_node *)0;
dd89bb
}
dd89bb
dd89bb
dd89bb
static nt_vms_node * __stdcall	__ntapi_vms_get_node(
dd89bb
	__in	nt_vms_system *		pvms_sys,
dd89bb
        __in	uint32_t		end_component_hash,
dd89bb
        __in	uint32_t		dev_name_hash,
dd89bb
        __in	nt_large_integer	index_number)
dd89bb
{
dd89bb
	nt_vms_node *	node;
dd89bb
dd89bb
	/* verify non-empty list */
dd89bb
	if (!pvms_sys->dev_name_head_node)
dd89bb
		return (nt_vms_node *)0;
dd89bb
dd89bb
	/* end_component_hash */
dd89bb
	if (end_component_hash) {
dd89bb
		node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node);
dd89bb
dd89bb
		while (node->next && (node->end_component_hash < end_component_hash))
dd89bb
			node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);
dd89bb
dd89bb
		if (node->end_component_hash != end_component_hash)
dd89bb
			return (nt_vms_node *)0;
dd89bb
	} else
dd89bb
		node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->dev_name_head_node);
dd89bb
dd89bb
	/* find device nodes */
dd89bb
	while (node->next && (node->dev_name_hash < dev_name_hash))
dd89bb
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);
dd89bb
dd89bb
	if (node->dev_name_hash != dev_name_hash)
dd89bb
		return (nt_vms_node *)0;
dd89bb
dd89bb
	/* find mount-point nodes */
dd89bb
	while (node->next && (node->index_number.quad < index_number.quad))
dd89bb
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);
dd89bb
dd89bb
	if (node->index_number.quad != index_number.quad)
dd89bb
		return (nt_vms_node *)0;
dd89bb
dd89bb
	return node;
dd89bb
}
dd89bb
dd89bb
dd89bb
nt_vms_node * __stdcall		__ntapi_vms_get_node_by_dev_name(
dd89bb
	__in	nt_vms_system *		pvms_sys,
dd89bb
        __in	uint32_t		dev_name_hash,
dd89bb
        __in	nt_large_integer	index_number)
dd89bb
{
dd89bb
	return __ntapi_vms_get_node(
dd89bb
		pvms_sys,
dd89bb
		0,
dd89bb
		dev_name_hash,
dd89bb
		index_number);
dd89bb
}
dd89bb
dd89bb
dd89bb
nt_vms_node * __stdcall		__ntapi_vms_get_node_by_end_component(
dd89bb
	__in	nt_vms_system *		pvms_sys,
dd89bb
        __in	uint32_t		end_component_hash,
dd89bb
        __in	uint32_t		dev_name_hash,
dd89bb
        __in	nt_large_integer	index_number)
dd89bb
{
dd89bb
	return __ntapi_vms_get_node(
dd89bb
		pvms_sys,
dd89bb
		end_component_hash,
dd89bb
		dev_name_hash,
dd89bb
		index_number);
dd89bb
}
dd89bb
dd89bb
dd89bb
nt_vms_point * __stdcall	__ntapi_vms_get_top_of_stack_mount_point(
dd89bb
	__in	nt_vms_system *		pvms_sys,
dd89bb
	__in	nt_vms_node *		node)
dd89bb
{
dd89bb
	nt_vms_point *	point;
dd89bb
dd89bb
	point = (nt_vms_point *)((uintptr_t)pvms_sys + node->stack);
dd89bb
dd89bb
	while (point->next)
dd89bb
		point = (nt_vms_point *)((uintptr_t)pvms_sys + point->next);
dd89bb
dd89bb
	return point;
dd89bb
}