summaryrefslogtreecommitdiffstats
path: root/memtestEDK/Memtest/ProtocolInformation/ProtocolInformation.c
blob: 20ac4bc5b0e2c8db6fa7e9ae4d1494943f36713e (plain) (blame)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <stdio.h>

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>


EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
/*
    EFI_STATUS efiStatus;

  EFI_BOOT_SERVICES* bs = SystemTable->BootServices;
  EFI_GUID sfspGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
  EFI_HANDLE* handleBuffer = NULL;   
  UINTN handleCount = 0;
  UINTN HandleIndex;
  EFI_GUID **ProtocolGuidArray;
  UINTN ArrayCount;
  UINTN ProtocolIndex;
  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
  UINTN OpenInfoIndex;
  UINTN OpenInfoCount;

  efiStatus = bs->LocateHandleBuffer (
    AllHandles,
    NULL,
    NULL,
    handleCount,
    &handleBuffer
  );

  Print(L"Number of handles found: %d\n", handleCount);

  if (!EFI_ERROR (efiStatus)) {
    for (HandleIndex = 0; HandleIndex < handleCount; HandleIndex++) {
    	//
    	// Retrieve the list of all the protocols on each handle
    	//
		efiStatus = bs->ProtocolsPerHandle (
		handleBuffer[HandleIndex],
		&ProtocolGuidArray,
		&ArrayCount
		);

        Print(L"Number of Protocols per Handle: %d\n", ArrayCount);

		if (!EFI_ERROR (efiStatus)) {
			for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
				//
				// Retrieve the protocol instance for each protocol
				//

				efiStatus = bs->OpenProtocol (
				handleBuffer[HandleIndex],
				ProtocolGuidArray[ProtocolIndex],
				NULL,
				ImageHandle,
				NULL,
				EFI_OPEN_PROTOCOL_GET_PROTOCOL
				);
				//
				// Retrieve the list of agents that have opened each protocol
				//
				efiStatus = bs->OpenProtocolInformation (
				handleBuffer[HandleIndex],
				ProtocolGuidArray[ProtocolIndex],
				&OpenInfo,
				&OpenInfoCount
				);
				if (!EFI_ERROR (efiStatus)) {
					for (OpenInfoIndex=0;OpenInfoIndex<OpenInfoCount;OpenInfoIndex++) {
						//
						// HandleBuffer[HandleIndex] is the handle
						// ProtocolGuidArray[ProtocolIndex] is the protocol GUID
						// Instance is the protocol instance for the protocol
						// OpenInfo[OpenInfoIndex] is an agent that has opened a protocol
						//
					}
					if (OpenInfo != NULL) {
						bs->FreePool(OpenInfo);
					}
				}
 	 		}
  			if (ProtocolGuidArray != NULL) {
				bs->FreePool(ProtocolGuidArray);
  			}
		}
		if (handleBuffer != NULL) {
			bs->FreePool (handleBuffer);
		}
	}
  }
*/
 /* efiStatus = bs->LocateHandleBuffer(ByProtocol, 
                                   &sfspGuid, 
                                   NULL, 
                                   &handleCount, 
                                   &handles);

  Print(L"Handle count: %d\n", handleCount);

  for (int index = 0; index < (int)handleCount; ++ index)
  {
    EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs = NULL;
   
    Print(L"sfspGuid: %d\n", sfspGuid);

    efiStatus = bs->HandleProtocol( // TODO Should use OpenProtocol() in new implementations
        handles[index],
        &sfspGuid,
        (void**)&fs
        );
    	Print(L"Status after HandleProtocol: %r\n", efiStatus);
        Print(L"Volume %d found\n", index);
        Print(L"fs pointer: %p\n", fs);
        EFI_FILE_PROTOCOL* root = NULL;
        efiStatus = fs->OpenVolume(fs, &root);
        Print(L"Status after open volume: %r\n", efiStatus);
        EFI_GUID fsiGuid = EFI_FILE_SYSTEM_INFO_ID;
        UINTN bufSize = 0;
        VOID* buffer = NULL;

        efiStatus = root->GetInfo(
        	root,
        	&fsiGuid,
        	&bufSize,
        	&buffer);

        Print(L"Status: %r\n", efiStatus);
        Print(L"Required buffer size: %d\n", bufSize );


        efiStatus = bs->AllocatePool(EfiLoaderData, (UINTN) (bufSize) , (void **)&buffer);


        efiStatus = root->GetInfo(
        	root,
        	&fsiGuid,
        	&bufSize,
        	&buffer);

        Print(L"Status: %r\n", efiStatus);

        EFI_FILE_SYSTEM_INFO* fhgf = buffer;

        Print(L"buffer pointer %p\n", buffer);
        Print(L"fhgf pointer %p\n", fhgf);

        Print(L"VolumeLabel: %s\n", fhgf->VolumeLabel);
        Print(L"Size: %d\n", fhgf->Size);
        Print(L"ReadOnly: %d\n", fhgf->ReadOnly);
        Print(L"VolumeSize: %d\n", fhgf->VolumeSize);
        Print(L"FreeSpace: %d\n", fhgf->FreeSpace);
        Print(L"BlockSize: %d\n", fhgf->BlockSize);
        Print(L"Number of handle found %d\n", (index + 1));

        efiStatus = bs->FreePool((void **)&buffer);
        Print(L"efiStatus after FreePool: %r\n", efiStatus);
   }*/
/*    
...




        EFI_FILE_PROTOCOL* token = NULL;
efiStatus = root->Open(
        root, 
        &token,
        L"myfolder\\token.bin",
        EFI_FILE_MODE_READ,
        EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);*/

/*
          EFI_FILE_OPEN         Open;
  EFI_FILE_CLOSE        Close;
  EFI_FILE_DELETE       Delete;
  EFI_FILE_READ         Read;
  EFI_FILE_WRITE        Write;
  EFI_FILE_GET_POSITION GetPosition;
  EFI_FILE_SET_POSITION SetPosition;
  EFI_FILE_GET_INFO     GetInfo;
  EFI_FILE_SET_INFO     SetInfo;
  EFI_FILE_FLUSH        Flush;*/

  return EFI_SUCCESS;
}