Coverage Report

Created: 2025-10-21 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/edk2/MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
Line
Count
Source
1
/** @file
2
  UDF/ECMA-167 file system driver.
3
4
  Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
5
6
  SPDX-License-Identifier: BSD-2-Clause-Patent
7
**/
8
9
#include "Udf.h"
10
11
//
12
// UDF filesystem driver's Global Variables.
13
//
14
EFI_DRIVER_BINDING_PROTOCOL  gUdfDriverBinding = {
15
  UdfDriverBindingSupported,
16
  UdfDriverBindingStart,
17
  UdfDriverBindingStop,
18
  0x10,
19
  NULL,
20
  NULL
21
};
22
23
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  gUdfSimpleFsTemplate = {
24
  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
25
  UdfOpenVolume
26
};
27
28
/**
29
  Test to see if this driver supports ControllerHandle. Any ControllerHandle
30
  than contains a BlockIo and DiskIo protocol or a BlockIo2 protocol can be
31
  supported.
32
33
  @param[in]  This                Protocol instance pointer.
34
  @param[in]  ControllerHandle    Handle of device to test.
35
  @param[in]  RemainingDevicePath Optional parameter use to pick a specific
36
                                  child device to start.
37
38
  @retval EFI_SUCCESS         This driver supports this device.
39
  @retval EFI_ALREADY_STARTED This driver is already running on this device.
40
  @retval other               This driver does not support this device.
41
42
**/
43
EFI_STATUS
44
EFIAPI
45
UdfDriverBindingSupported (
46
  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
47
  IN EFI_HANDLE                   ControllerHandle,
48
  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
49
  )
50
0
{
51
0
  EFI_STATUS            Status;
52
0
  EFI_DISK_IO_PROTOCOL  *DiskIo;
53
54
  //
55
  // Open DiskIo protocol on ControllerHandle
56
  //
57
0
  Status = gBS->OpenProtocol (
58
0
                  ControllerHandle,
59
0
                  &gEfiDiskIoProtocolGuid,
60
0
                  (VOID **)&DiskIo,
61
0
                  This->DriverBindingHandle,
62
0
                  ControllerHandle,
63
0
                  EFI_OPEN_PROTOCOL_BY_DRIVER
64
0
                  );
65
0
  if (EFI_ERROR (Status)) {
66
0
    return Status;
67
0
  }
68
69
  //
70
  // Close DiskIo protocol on ControllerHandle
71
  //
72
0
  gBS->CloseProtocol (
73
0
         ControllerHandle,
74
0
         &gEfiDiskIoProtocolGuid,
75
0
         This->DriverBindingHandle,
76
0
         ControllerHandle
77
0
         );
78
79
  //
80
  // Test whether ControllerHandle supports BlockIo protocol
81
  //
82
0
  Status = gBS->OpenProtocol (
83
0
                  ControllerHandle,
84
0
                  &gEfiBlockIoProtocolGuid,
85
0
                  NULL,
86
0
                  This->DriverBindingHandle,
87
0
                  ControllerHandle,
88
0
                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL
89
0
                  );
90
91
0
  return Status;
92
0
}
93
94
/**
95
  Start this driver on ControllerHandle by opening a Block IO or a Block IO2
96
  or both, and Disk IO protocol, reading Device Path, and creating a child
97
  handle with a Disk IO and device path protocol.
98
99
  @param[in]  This                 Protocol instance pointer.
100
  @param[in]  ControllerHandle     Handle of device to bind driver to
101
  @param[in]  RemainingDevicePath  Optional parameter use to pick a specific
102
                                   child device to start.
103
104
  @retval EFI_SUCCESS          This driver is added to ControllerHandle.
105
  @retval EFI_ALREADY_STARTED  This driver is already running on
106
                               ControllerHandle.
107
  @retval other                This driver does not support this device.
108
109
**/
110
EFI_STATUS
111
EFIAPI
112
UdfDriverBindingStart (
113
  IN EFI_DRIVER_BINDING_PROTOCOL  *This,
114
  IN EFI_HANDLE                   ControllerHandle,
115
  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
116
  )
117
0
{
118
0
  EFI_TPL                     OldTpl;
119
0
  EFI_STATUS                  Status;
120
0
  EFI_BLOCK_IO_PROTOCOL       *BlockIo;
121
0
  EFI_DISK_IO_PROTOCOL        *DiskIo;
122
0
  PRIVATE_UDF_SIMPLE_FS_DATA  *PrivFsData;
123
124
0
  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
125
126
  //
127
  // Open BlockIo protocol on ControllerHandle
128
  //
129
0
  Status = gBS->OpenProtocol (
130
0
                  ControllerHandle,
131
0
                  &gEfiBlockIoProtocolGuid,
132
0
                  (VOID **)&BlockIo,
133
0
                  This->DriverBindingHandle,
134
0
                  ControllerHandle,
135
0
                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
136
0
                  );
137
0
  ASSERT_EFI_ERROR (Status);
138
139
  //
140
  // Open DiskIo protocol on ControllerHandle
141
  //
142
0
  Status = gBS->OpenProtocol (
143
0
                  ControllerHandle,
144
0
                  &gEfiDiskIoProtocolGuid,
145
0
                  (VOID **)&DiskIo,
146
0
                  This->DriverBindingHandle,
147
0
                  ControllerHandle,
148
0
                  EFI_OPEN_PROTOCOL_BY_DRIVER
149
0
                  );
150
0
  ASSERT_EFI_ERROR (Status);
151
152
  //
153
  // Check if ControllerHandle supports an UDF file system
154
  //
155
0
  Status = SupportUdfFileSystem (This, ControllerHandle);
156
0
  if (EFI_ERROR (Status)) {
157
0
    goto Exit;
158
0
  }
159
160
  //
161
  // Initialize private file system structure
162
  //
163
0
  PrivFsData =
164
0
    (PRIVATE_UDF_SIMPLE_FS_DATA *)
165
0
    AllocateZeroPool (sizeof (PRIVATE_UDF_SIMPLE_FS_DATA));
166
0
  if (PrivFsData == NULL) {
167
0
    Status = EFI_OUT_OF_RESOURCES;
168
0
    goto Exit;
169
0
  }
170
171
  //
172
  // Create new child handle
173
  //
174
0
  PrivFsData->Signature = PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE;
175
0
  PrivFsData->BlockIo   = BlockIo;
176
0
  PrivFsData->DiskIo    = DiskIo;
177
0
  PrivFsData->Handle    = ControllerHandle;
178
179
  //
180
  // Set up SimpleFs protocol
181
  //
182
0
  CopyMem (
183
0
    (VOID *)&PrivFsData->SimpleFs,
184
0
    (VOID *)&gUdfSimpleFsTemplate,
185
0
    sizeof (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL)
186
0
    );
187
188
  //
189
  // Install child handle
190
  //
191
0
  Status = gBS->InstallMultipleProtocolInterfaces (
192
0
                  &PrivFsData->Handle,
193
0
                  &gEfiSimpleFileSystemProtocolGuid,
194
0
                  &PrivFsData->SimpleFs,
195
0
                  NULL
196
0
                  );
197
198
0
Exit:
199
0
  if (EFI_ERROR (Status)) {
200
    //
201
    // Close DiskIo protocol on ControllerHandle
202
    //
203
0
    gBS->CloseProtocol (
204
0
           ControllerHandle,
205
0
           &gEfiDiskIoProtocolGuid,
206
0
           This->DriverBindingHandle,
207
0
           ControllerHandle
208
0
           );
209
    //
210
    // Close BlockIo protocol on ControllerHandle
211
    //
212
0
    gBS->CloseProtocol (
213
0
           ControllerHandle,
214
0
           &gEfiBlockIoProtocolGuid,
215
0
           This->DriverBindingHandle,
216
0
           ControllerHandle
217
0
           );
218
0
  }
219
220
0
  gBS->RestoreTPL (OldTpl);
221
222
0
  return Status;
223
0
}
224
225
/**
226
  Stop this driver on ControllerHandle. Support stopping any child handles
227
  created by this driver.
228
229
  @param  This              Protocol instance pointer.
230
  @param  ControllerHandle  Handle of device to stop driver on
231
  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of
232
                            children is zero stop the entire bus driver.
233
  @param  ChildHandleBuffer List of Child Handles to Stop.
234
235
  @retval EFI_SUCCESS       This driver is removed ControllerHandle
236
  @retval other             This driver was not removed from this device
237
238
**/
239
EFI_STATUS
240
EFIAPI
241
UdfDriverBindingStop (
242
  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
243
  IN  EFI_HANDLE                   ControllerHandle,
244
  IN  UINTN                        NumberOfChildren,
245
  IN  EFI_HANDLE                   *ChildHandleBuffer
246
  )
247
0
{
248
0
  PRIVATE_UDF_SIMPLE_FS_DATA       *PrivFsData;
249
0
  EFI_STATUS                       Status;
250
0
  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *SimpleFs;
251
252
  //
253
  // Open SimpleFs protocol on ControllerHandle
254
  //
255
0
  Status = gBS->OpenProtocol (
256
0
                  ControllerHandle,
257
0
                  &gEfiSimpleFileSystemProtocolGuid,
258
0
                  (VOID **)&SimpleFs,
259
0
                  This->DriverBindingHandle,
260
0
                  ControllerHandle,
261
0
                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
262
0
                  );
263
0
  if (!EFI_ERROR (Status)) {
264
0
    PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (SimpleFs);
265
266
    //
267
    // Uninstall child handle
268
    //
269
0
    Status = gBS->UninstallMultipleProtocolInterfaces (
270
0
                    PrivFsData->Handle,
271
0
                    &gEfiSimpleFileSystemProtocolGuid,
272
0
                    &PrivFsData->SimpleFs,
273
0
                    NULL
274
0
                    );
275
276
0
    FreePool ((VOID *)PrivFsData);
277
0
  }
278
279
0
  if (!EFI_ERROR (Status)) {
280
    //
281
    // Close DiskIo protocol on ControllerHandle
282
    //
283
0
    gBS->CloseProtocol (
284
0
           ControllerHandle,
285
0
           &gEfiDiskIoProtocolGuid,
286
0
           This->DriverBindingHandle,
287
0
           ControllerHandle
288
0
           );
289
    //
290
    // Close BlockIo protocol on ControllerHandle
291
    //
292
0
    gBS->CloseProtocol (
293
0
           ControllerHandle,
294
0
           &gEfiBlockIoProtocolGuid,
295
0
           This->DriverBindingHandle,
296
0
           ControllerHandle
297
0
           );
298
0
  }
299
300
0
  return Status;
301
0
}
302
303
/**
304
  The user Entry Point for UDF file system driver. The user code starts with
305
  this function.
306
307
  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
308
  @param[in] SystemTable    A pointer to the EFI System Table.
309
310
  @retval EFI_SUCCESS       The entry point is executed successfully.
311
  @retval other             Some error occurs when executing this entry point.
312
313
**/
314
EFI_STATUS
315
EFIAPI
316
InitializeUdf (
317
  IN EFI_HANDLE        ImageHandle,
318
  IN EFI_SYSTEM_TABLE  *SystemTable
319
  )
320
0
{
321
0
  EFI_STATUS  Status;
322
323
0
  Status = EfiLibInstallDriverBindingComponentName2 (
324
0
             ImageHandle,
325
0
             SystemTable,
326
0
             &gUdfDriverBinding,
327
0
             ImageHandle,
328
0
             &gUdfComponentName,
329
0
             &gUdfComponentName2
330
0
             );
331
0
  ASSERT_EFI_ERROR (Status);
332
333
0
  return Status;
334
0
}