summaryrefslogtreecommitdiffhomepage
path: root/src/vmount/ntapi_vms_helper.c
blob: 4d07bf04269f2e1e7a23c8deec58e90e519c8fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2016  Z. Gilboa                 */
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
/********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/nt_port.h>
#include <ntapi/nt_vmount.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"


nt_vms_node * __stdcall	__ntapi_vms_get_end_component_first_node(
	__in	nt_vms_system *		pvms_sys,
        __in	uint32_t		end_component_hash)
{
	nt_vms_node *	node;

	/* verify non-empty list and valid input */
	if (!pvms_sys->dev_name_head_node || !end_component_hash)
		return (nt_vms_node *)0;

	/* find first node by end component hash */
	node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node);

	while (node->next && (node->end_component_hash < end_component_hash))
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);

	if (node->end_component_hash == end_component_hash)
		return node;
	else
		return (nt_vms_node *)0;
}


static nt_vms_node * __stdcall	__ntapi_vms_get_node(
	__in	nt_vms_system *		pvms_sys,
        __in	uint32_t		end_component_hash,
        __in	uint32_t		dev_name_hash,
        __in	nt_large_integer	index_number)
{
	nt_vms_node *	node;

	/* verify non-empty list */
	if (!pvms_sys->dev_name_head_node)
		return (nt_vms_node *)0;

	/* end_component_hash */
	if (end_component_hash) {
		node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->end_component_head_node);

		while (node->next && (node->end_component_hash < end_component_hash))
			node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);

		if (node->end_component_hash != end_component_hash)
			return (nt_vms_node *)0;
	} else
		node = (nt_vms_node *)((uintptr_t)pvms_sys + pvms_sys->dev_name_head_node);

	/* find device nodes */
	while (node->next && (node->dev_name_hash < dev_name_hash))
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);

	if (node->dev_name_hash != dev_name_hash)
		return (nt_vms_node *)0;

	/* find mount-point nodes */
	while (node->next && (node->index_number.quad < index_number.quad))
		node = (nt_vms_node *)((uintptr_t)pvms_sys + node->next);

	if (node->index_number.quad != index_number.quad)
		return (nt_vms_node *)0;

	return node;
}


nt_vms_node * __stdcall		__ntapi_vms_get_node_by_dev_name(
	__in	nt_vms_system *		pvms_sys,
        __in	uint32_t		dev_name_hash,
        __in	nt_large_integer	index_number)
{
	return __ntapi_vms_get_node(
		pvms_sys,
		0,
		dev_name_hash,
		index_number);
}


nt_vms_node * __stdcall		__ntapi_vms_get_node_by_end_component(
	__in	nt_vms_system *		pvms_sys,
        __in	uint32_t		end_component_hash,
        __in	uint32_t		dev_name_hash,
        __in	nt_large_integer	index_number)
{
	return __ntapi_vms_get_node(
		pvms_sys,
		end_component_hash,
		dev_name_hash,
		index_number);
}


nt_vms_point * __stdcall	__ntapi_vms_get_top_of_stack_mount_point(
	__in	nt_vms_system *		pvms_sys,
	__in	nt_vms_node *		node)
{
	nt_vms_point *	point;

	point = (nt_vms_point *)((uintptr_t)pvms_sys + node->stack);

	while (point->next)
		point = (nt_vms_point *)((uintptr_t)pvms_sys + point->next);

	return point;
}