]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/UdfDxe/Udf.h
MdeModulePkg/UDF: Fix creation of UDF logical partition
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UdfDxe / Udf.h
1 /** @file
2 UDF/ECMA-167 file system driver.
3
4 Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
5
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
12 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 **/
14
15 #ifndef _UDF_H_
16 #define _UDF_H_
17
18 #include <Uefi.h>
19 #include <Base.h>
20
21 #include <Protocol/BlockIo.h>
22 #include <Protocol/ComponentName.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/DriverBinding.h>
25 #include <Protocol/DiskIo.h>
26 #include <Protocol/SimpleFileSystem.h>
27
28 #include <Guid/FileInfo.h>
29 #include <Guid/FileSystemInfo.h>
30 #include <Guid/FileSystemVolumeLabelInfo.h>
31
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/BaseLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/DevicePathLib.h>
40
41 #include <IndustryStandard/ElTorito.h>
42 #include <IndustryStandard/Udf.h>
43
44 //
45 // C5BD4D42-1A76-4996-8956-73CDA326CD0A
46 //
47 #define EFI_UDF_DEVICE_PATH_GUID \
48 { 0xC5BD4D42, 0x1A76, 0x4996, \
49 { 0x89, 0x56, 0x73, 0xCD, 0xA3, 0x26, 0xCD, 0x0A } \
50 }
51
52 #define FE_ICB_FILE_TYPE(_Ptr) \
53 (UDF_FILE_ENTRY_TYPE)( \
54 ((UDF_DESCRIPTOR_TAG *)(_Ptr))->TagIdentifier == UdfFileEntry ? \
55 ((UDF_FILE_ENTRY *)(_Ptr))->IcbTag.FileType : \
56 ((UDF_EXTENDED_FILE_ENTRY *)(_Ptr))->IcbTag.FileType)
57
58 typedef enum {
59 UdfFileEntryDirectory = 4,
60 UdfFileEntryStandardFile = 5,
61 UdfFileEntrySymlink = 12,
62 } UDF_FILE_ENTRY_TYPE;
63
64 #define HIDDEN_FILE (1 << 0)
65 #define DIRECTORY_FILE (1 << 1)
66 #define DELETED_FILE (1 << 2)
67 #define PARENT_FILE (1 << 3)
68
69 #define IS_FID_HIDDEN_FILE(_Fid) \
70 (BOOLEAN)((_Fid)->FileCharacteristics & HIDDEN_FILE)
71 #define IS_FID_DIRECTORY_FILE(_Fid) \
72 (BOOLEAN)((_Fid)->FileCharacteristics & DIRECTORY_FILE)
73 #define IS_FID_DELETED_FILE(_Fid) \
74 (BOOLEAN)((_Fid)->FileCharacteristics & DELETED_FILE)
75 #define IS_FID_PARENT_FILE(_Fid) \
76 (BOOLEAN)((_Fid)->FileCharacteristics & PARENT_FILE)
77 #define IS_FID_NORMAL_FILE(_Fid) \
78 (BOOLEAN)(!IS_FID_DIRECTORY_FILE (_Fid) && \
79 !IS_FID_PARENT_FILE (_Fid))
80
81 typedef enum {
82 ShortAdsSequence,
83 LongAdsSequence,
84 ExtendedAdsSequence,
85 InlineData
86 } UDF_FE_RECORDING_FLAGS;
87
88 #define GET_FE_RECORDING_FLAGS(_Fe) \
89 ((UDF_FE_RECORDING_FLAGS)((UDF_ICB_TAG *)( \
90 (UINT8 *)(_Fe) + \
91 sizeof (UDF_DESCRIPTOR_TAG)))->Flags & 0x07)
92
93 typedef enum {
94 ExtentRecordedAndAllocated,
95 ExtentNotRecordedButAllocated,
96 ExtentNotRecordedNotAllocated,
97 ExtentIsNextExtent,
98 } UDF_EXTENT_FLAGS;
99
100 #define AD_LENGTH(_RecFlags) \
101 ((_RecFlags) == ShortAdsSequence ? \
102 ((UINT64)(sizeof (UDF_SHORT_ALLOCATION_DESCRIPTOR))) : \
103 ((UINT64)(sizeof (UDF_LONG_ALLOCATION_DESCRIPTOR))))
104
105 #define GET_EXTENT_FLAGS(_RecFlags, _Ad) \
106 ((_RecFlags) == ShortAdsSequence ? \
107 ((UDF_EXTENT_FLAGS)((((UDF_SHORT_ALLOCATION_DESCRIPTOR *)(_Ad))->ExtentLength >> \
108 30) & 0x3)) : \
109 ((UDF_EXTENT_FLAGS)((((UDF_LONG_ALLOCATION_DESCRIPTOR *)(_Ad))->ExtentLength >> \
110 30) & 0x3)))
111
112 #define GET_EXTENT_LENGTH(_RecFlags, _Ad) \
113 ((_RecFlags) == ShortAdsSequence ? \
114 ((UINT32)((((UDF_SHORT_ALLOCATION_DESCRIPTOR *)(_Ad))->ExtentLength & \
115 ~0xC0000000UL))) : \
116 ((UINT32)((((UDF_LONG_ALLOCATION_DESCRIPTOR *)(_Ad))->ExtentLength & \
117 ~0xC0000000UL))))
118
119 #define UDF_FILENAME_LENGTH 128
120 #define UDF_PATH_LENGTH 512
121
122 #define GET_FID_FROM_ADS(_Data, _Offs) \
123 ((UDF_FILE_IDENTIFIER_DESCRIPTOR *)((UINT8 *)(_Data) + (_Offs)))
124
125 #define IS_VALID_COMPRESSION_ID(_CompId) \
126 ((BOOLEAN)((_CompId) == 8 || (_CompId) == 16))
127
128 #define UDF_STANDARD_IDENTIFIER_LENGTH 5
129
130 #pragma pack(1)
131
132 typedef struct {
133 UINT8 StandardIdentifier[UDF_STANDARD_IDENTIFIER_LENGTH];
134 } UDF_STANDARD_IDENTIFIER;
135
136 #pragma pack()
137
138 typedef enum {
139 ReadFileGetFileSize,
140 ReadFileAllocateAndRead,
141 ReadFileSeekAndRead,
142 } UDF_READ_FILE_FLAGS;
143
144 typedef struct {
145 VOID *FileData;
146 UDF_READ_FILE_FLAGS Flags;
147 UINT64 FileDataSize;
148 UINT64 FilePosition;
149 UINT64 FileSize;
150 UINT64 ReadLength;
151 } UDF_READ_FILE_INFO;
152
153 #pragma pack(1)
154
155 typedef struct {
156 UINT16 TypeAndTimezone;
157 INT16 Year;
158 UINT8 Month;
159 UINT8 Day;
160 UINT8 Hour;
161 UINT8 Minute;
162 UINT8 Second;
163 UINT8 Centiseconds;
164 UINT8 HundredsOfMicroseconds;
165 UINT8 Microseconds;
166 } UDF_TIMESTAMP;
167
168 typedef struct {
169 UDF_DESCRIPTOR_TAG DescriptorTag;
170 UINT32 PrevAllocationExtentDescriptor;
171 UINT32 LengthOfAllocationDescriptors;
172 } UDF_ALLOCATION_EXTENT_DESCRIPTOR;
173
174 typedef struct {
175 UINT8 StructureType;
176 UINT8 StandardIdentifier[UDF_STANDARD_IDENTIFIER_LENGTH];
177 UINT8 StructureVersion;
178 UINT8 Reserved;
179 UINT8 StructureData[2040];
180 } UDF_VOLUME_DESCRIPTOR;
181
182 typedef struct {
183 UDF_DESCRIPTOR_TAG DescriptorTag;
184 UDF_TIMESTAMP RecordingDateTime;
185 UINT32 IntegrityType;
186 UDF_EXTENT_AD NextIntegrityExtent;
187 UINT8 LogicalVolumeContentsUse[32];
188 UINT32 NumberOfPartitions;
189 UINT32 LengthOfImplementationUse;
190 UINT8 Data[0];
191 } UDF_LOGICAL_VOLUME_INTEGRITY;
192
193 typedef struct {
194 UDF_DESCRIPTOR_TAG DescriptorTag;
195 UINT32 VolumeDescriptorSequenceNumber;
196 UINT16 PartitionFlags;
197 UINT16 PartitionNumber;
198 UDF_ENTITY_ID PartitionContents;
199 UINT8 PartitionContentsUse[128];
200 UINT32 AccessType;
201 UINT32 PartitionStartingLocation;
202 UINT32 PartitionLength;
203 UDF_ENTITY_ID ImplementationIdentifier;
204 UINT8 ImplementationUse[128];
205 UINT8 Reserved[156];
206 } UDF_PARTITION_DESCRIPTOR;
207
208 typedef struct {
209 UDF_DESCRIPTOR_TAG DescriptorTag;
210 UDF_TIMESTAMP RecordingDateAndTime;
211 UINT16 InterchangeLevel;
212 UINT16 MaximumInterchangeLevel;
213 UINT32 CharacterSetList;
214 UINT32 MaximumCharacterSetList;
215 UINT32 FileSetNumber;
216 UINT32 FileSetDescriptorNumber;
217 UDF_CHAR_SPEC LogicalVolumeIdentifierCharacterSet;
218 UINT8 LogicalVolumeIdentifier[128];
219 UDF_CHAR_SPEC FileSetCharacterSet;
220 UINT8 FileSetIdentifier[32];
221 UINT8 CopyrightFileIdentifier[32];
222 UINT8 AbstractFileIdentifier[32];
223 UDF_LONG_ALLOCATION_DESCRIPTOR RootDirectoryIcb;
224 UDF_ENTITY_ID DomainIdentifier;
225 UDF_LONG_ALLOCATION_DESCRIPTOR NextExtent;
226 UDF_LONG_ALLOCATION_DESCRIPTOR SystemStreamDirectoryIcb;
227 UINT8 Reserved[32];
228 } UDF_FILE_SET_DESCRIPTOR;
229
230 typedef struct {
231 UINT32 ExtentLength;
232 UINT32 ExtentPosition;
233 } UDF_SHORT_ALLOCATION_DESCRIPTOR;
234
235 typedef struct {
236 UDF_DESCRIPTOR_TAG DescriptorTag;
237 UINT16 FileVersionNumber;
238 UINT8 FileCharacteristics;
239 UINT8 LengthOfFileIdentifier;
240 UDF_LONG_ALLOCATION_DESCRIPTOR Icb;
241 UINT16 LengthOfImplementationUse;
242 UINT8 Data[0];
243 } UDF_FILE_IDENTIFIER_DESCRIPTOR;
244
245 typedef struct {
246 UINT32 PriorRecordNumberOfDirectEntries;
247 UINT16 StrategyType;
248 UINT16 StrategyParameter;
249 UINT16 MaximumNumberOfEntries;
250 UINT8 Reserved;
251 UINT8 FileType;
252 UDF_LB_ADDR ParentIcbLocation;
253 UINT16 Flags;
254 } UDF_ICB_TAG;
255
256 typedef struct {
257 UDF_DESCRIPTOR_TAG DescriptorTag;
258 UDF_ICB_TAG IcbTag;
259 UINT32 Uid;
260 UINT32 Gid;
261 UINT32 Permissions;
262 UINT16 FileLinkCount;
263 UINT8 RecordFormat;
264 UINT8 RecordDisplayAttributes;
265 UINT32 RecordLength;
266 UINT64 InformationLength;
267 UINT64 LogicalBlocksRecorded;
268 UDF_TIMESTAMP AccessTime;
269 UDF_TIMESTAMP ModificationTime;
270 UDF_TIMESTAMP AttributeTime;
271 UINT32 CheckPoint;
272 UDF_LONG_ALLOCATION_DESCRIPTOR ExtendedAttributeIcb;
273 UDF_ENTITY_ID ImplementationIdentifier;
274 UINT64 UniqueId;
275 UINT32 LengthOfExtendedAttributes;
276 UINT32 LengthOfAllocationDescriptors;
277 UINT8 Data[0]; // L_EA + L_AD
278 } UDF_FILE_ENTRY;
279
280 typedef struct {
281 UDF_DESCRIPTOR_TAG DescriptorTag;
282 UDF_ICB_TAG IcbTag;
283 UINT32 Uid;
284 UINT32 Gid;
285 UINT32 Permissions;
286 UINT16 FileLinkCount;
287 UINT8 RecordFormat;
288 UINT8 RecordDisplayAttributes;
289 UINT32 RecordLength;
290 UINT64 InformationLength;
291 UINT64 ObjectSize;
292 UINT64 LogicalBlocksRecorded;
293 UDF_TIMESTAMP AccessTime;
294 UDF_TIMESTAMP ModificationTime;
295 UDF_TIMESTAMP CreationTime;
296 UDF_TIMESTAMP AttributeTime;
297 UINT32 CheckPoint;
298 UINT32 Reserved;
299 UDF_LONG_ALLOCATION_DESCRIPTOR ExtendedAttributeIcb;
300 UDF_LONG_ALLOCATION_DESCRIPTOR StreamDirectoryIcb;
301 UDF_ENTITY_ID ImplementationIdentifier;
302 UINT64 UniqueId;
303 UINT32 LengthOfExtendedAttributes;
304 UINT32 LengthOfAllocationDescriptors;
305 UINT8 Data[0]; // L_EA + L_AD
306 } UDF_EXTENDED_FILE_ENTRY;
307
308 typedef struct {
309 UINT8 ComponentType;
310 UINT8 LengthOfComponentIdentifier;
311 UINT16 ComponentFileVersionNumber;
312 UINT8 ComponentIdentifier[0];
313 } UDF_PATH_COMPONENT;
314
315 #pragma pack()
316
317 //
318 // UDF filesystem driver's private data
319 //
320 typedef struct {
321 UINT64 MainVdsStartLocation;
322 UDF_LOGICAL_VOLUME_DESCRIPTOR LogicalVolDesc;
323 UDF_PARTITION_DESCRIPTOR PartitionDesc;
324 UDF_FILE_SET_DESCRIPTOR FileSetDesc;
325 UINTN FileEntrySize;
326 } UDF_VOLUME_INFO;
327
328 typedef struct {
329 VOID *FileEntry;
330 UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc;
331 } UDF_FILE_INFO;
332
333 typedef struct {
334 VOID *DirectoryData;
335 UINT64 DirectoryLength;
336 UINT64 FidOffset;
337 } UDF_READ_DIRECTORY_INFO;
338
339 #define PRIVATE_UDF_FILE_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'f', 'f')
340
341 #define PRIVATE_UDF_FILE_DATA_FROM_THIS(a) \
342 CR ( \
343 a, \
344 PRIVATE_UDF_FILE_DATA, \
345 FileIo, \
346 PRIVATE_UDF_FILE_DATA_SIGNATURE \
347 )
348
349 typedef struct {
350 UINTN Signature;
351 BOOLEAN IsRootDirectory;
352 UDF_FILE_INFO *Root;
353 UDF_FILE_INFO File;
354 UDF_READ_DIRECTORY_INFO ReadDirInfo;
355 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs;
356 EFI_FILE_PROTOCOL FileIo;
357 CHAR16 AbsoluteFileName[UDF_PATH_LENGTH];
358 CHAR16 FileName[UDF_FILENAME_LENGTH];
359 UINT64 FileSize;
360 UINT64 FilePosition;
361 } PRIVATE_UDF_FILE_DATA;
362
363 #define PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE SIGNATURE_32 ('U', 'd', 'f', 's')
364
365 #define PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS(a) \
366 CR ( \
367 a, \
368 PRIVATE_UDF_SIMPLE_FS_DATA, \
369 SimpleFs, \
370 PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE \
371 )
372
373 typedef struct {
374 UINTN Signature;
375 EFI_BLOCK_IO_PROTOCOL *BlockIo;
376 EFI_DISK_IO_PROTOCOL *DiskIo;
377 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs;
378 UDF_VOLUME_INFO Volume;
379 UDF_FILE_INFO Root;
380 UINTN OpenFiles;
381 EFI_HANDLE Handle;
382 } PRIVATE_UDF_SIMPLE_FS_DATA;
383
384 //
385 // Global Variables
386 //
387 extern EFI_DRIVER_BINDING_PROTOCOL gUdfDriverBinding;
388 extern EFI_COMPONENT_NAME_PROTOCOL gUdfComponentName;
389 extern EFI_COMPONENT_NAME2_PROTOCOL gUdfComponentName2;
390
391 //
392 // Function Prototypes
393 //
394
395 /**
396 Open the root directory on a volume.
397
398 @param This Protocol instance pointer.
399 @param Root Returns an Open file handle for the root directory
400
401 @retval EFI_SUCCESS The device was opened.
402 @retval EFI_UNSUPPORTED This volume does not support the file system.
403 @retval EFI_NO_MEDIA The device has no media.
404 @retval EFI_DEVICE_ERROR The device reported an error.
405 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
406 @retval EFI_ACCESS_DENIED The service denied access to the file.
407 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
408
409 **/
410 EFI_STATUS
411 EFIAPI
412 UdfOpenVolume (
413 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
414 OUT EFI_FILE_PROTOCOL **Root
415 );
416
417 /**
418 Opens a new file relative to the source file's location.
419
420 @param This The protocol instance pointer.
421 @param NewHandle Returns File Handle for FileName.
422 @param FileName Null terminated string. "\", ".", and ".." are supported.
423 @param OpenMode Open mode for file.
424 @param Attributes Only used for EFI_FILE_MODE_CREATE.
425
426 @retval EFI_SUCCESS The device was opened.
427 @retval EFI_NOT_FOUND The specified file could not be found on the device.
428 @retval EFI_NO_MEDIA The device has no media.
429 @retval EFI_MEDIA_CHANGED The media has changed.
430 @retval EFI_DEVICE_ERROR The device reported an error.
431 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
432 @retval EFI_ACCESS_DENIED The service denied access to the file.
433 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
434 @retval EFI_VOLUME_FULL The volume is full.
435
436 **/
437 EFI_STATUS
438 EFIAPI
439 UdfOpen (
440 IN EFI_FILE_PROTOCOL *This,
441 OUT EFI_FILE_PROTOCOL **NewHandle,
442 IN CHAR16 *FileName,
443 IN UINT64 OpenMode,
444 IN UINT64 Attributes
445 );
446
447 /**
448 Read data from the file.
449
450 @param This Protocol instance pointer.
451 @param BufferSize On input size of buffer, on output amount of data in buffer.
452 @param Buffer The buffer in which data is read.
453
454 @retval EFI_SUCCESS Data was read.
455 @retval EFI_NO_MEDIA The device has no media.
456 @retval EFI_DEVICE_ERROR The device reported an error.
457 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
458 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
459
460 **/
461 EFI_STATUS
462 EFIAPI
463 UdfRead (
464 IN EFI_FILE_PROTOCOL *This,
465 IN OUT UINTN *BufferSize,
466 OUT VOID *Buffer
467 );
468
469 /**
470 Close the file handle.
471
472 @param This Protocol instance pointer.
473
474 @retval EFI_SUCCESS The file was closed.
475
476 **/
477 EFI_STATUS
478 EFIAPI
479 UdfClose (
480 IN EFI_FILE_PROTOCOL *This
481 );
482
483 /**
484 Close and delete the file handle.
485
486 @param This Protocol instance pointer.
487
488 @retval EFI_SUCCESS The file was closed and deleted.
489 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not
490 deleted.
491
492 **/
493 EFI_STATUS
494 EFIAPI
495 UdfDelete (
496 IN EFI_FILE_PROTOCOL *This
497 );
498
499 /**
500 Write data to a file.
501
502 @param This Protocol instance pointer.
503 @param BufferSize On input size of buffer, on output amount of data in buffer.
504 @param Buffer The buffer in which data to write.
505
506 @retval EFI_SUCCESS Data was written.
507 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
508 @retval EFI_NO_MEDIA The device has no media.
509 @retval EFI_DEVICE_ERROR The device reported an error.
510 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
511 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
512 @retval EFI_WRITE_PROTECTED The device is write protected.
513 @retval EFI_ACCESS_DENIED The file was open for read only.
514 @retval EFI_VOLUME_FULL The volume is full.
515
516 **/
517 EFI_STATUS
518 EFIAPI
519 UdfWrite (
520 IN EFI_FILE_PROTOCOL *This,
521 IN OUT UINTN *BufferSize,
522 IN VOID *Buffer
523 );
524
525 /**
526 Get file's current position.
527
528 @param This Protocol instance pointer.
529 @param Position Byte position from the start of the file.
530
531 @retval EFI_SUCCESS Position was updated.
532 @retval EFI_UNSUPPORTED Seek request for directories is not valid.
533
534 **/
535 EFI_STATUS
536 EFIAPI
537 UdfGetPosition (
538 IN EFI_FILE_PROTOCOL *This,
539 OUT UINT64 *Position
540 );
541
542 /**
543 Set file's current position.
544
545 @param This Protocol instance pointer.
546 @param Position Byte position from the start of the file.
547
548 @retval EFI_SUCCESS Position was updated.
549 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
550
551 **/
552 EFI_STATUS
553 EFIAPI
554 UdfSetPosition (
555 IN EFI_FILE_PROTOCOL *This,
556 IN UINT64 Position
557 );
558
559 /**
560 Get information about a file.
561
562 @param This Protocol instance pointer.
563 @param InformationType Type of information to return in Buffer.
564 @param BufferSize On input size of buffer, on output amount of data in buffer.
565 @param Buffer The buffer to return data.
566
567 @retval EFI_SUCCESS Data was returned.
568 @retval EFI_UNSUPPORTED InformationType is not supported.
569 @retval EFI_NO_MEDIA The device has no media.
570 @retval EFI_DEVICE_ERROR The device reported an error.
571 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
572 @retval EFI_WRITE_PROTECTED The device is write protected.
573 @retval EFI_ACCESS_DENIED The file was open for read only.
574 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
575
576 **/
577 EFI_STATUS
578 EFIAPI
579 UdfGetInfo (
580 IN EFI_FILE_PROTOCOL *This,
581 IN EFI_GUID *InformationType,
582 IN OUT UINTN *BufferSize,
583 OUT VOID *Buffer
584 );
585
586 /**
587 Set information about a file.
588
589 @param This Protocol instance pointer.
590 @param InformationType Type of information in Buffer.
591 @param BufferSize Size of buffer.
592 @param Buffer The data to write.
593
594 @retval EFI_SUCCESS Data was set.
595 @retval EFI_UNSUPPORTED InformationType is not supported.
596 @retval EFI_NO_MEDIA The device has no media.
597 @retval EFI_DEVICE_ERROR The device reported an error.
598 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
599 @retval EFI_WRITE_PROTECTED The device is write protected.
600 @retval EFI_ACCESS_DENIED The file was open for read only.
601
602 **/
603 EFI_STATUS
604 EFIAPI
605 UdfSetInfo (
606 IN EFI_FILE_PROTOCOL *This,
607 IN EFI_GUID *InformationType,
608 IN UINTN BufferSize,
609 IN VOID *Buffer
610 );
611
612 /**
613 Flush data back for the file handle.
614
615 @param This Protocol instance pointer.
616
617 @retval EFI_SUCCESS Data was flushed.
618 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
619 @retval EFI_NO_MEDIA The device has no media.
620 @retval EFI_DEVICE_ERROR The device reported an error.
621 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
622 @retval EFI_WRITE_PROTECTED The device is write protected.
623 @retval EFI_ACCESS_DENIED The file was open for read only.
624 @retval EFI_VOLUME_FULL The volume is full.
625
626 **/
627 EFI_STATUS
628 EFIAPI
629 UdfFlush (
630 IN EFI_FILE_PROTOCOL *This
631 );
632
633 /**
634 Read volume information on a medium which contains a valid UDF file system.
635
636 @param[in] BlockIo BlockIo interface.
637 @param[in] DiskIo DiskIo interface.
638 @param[out] Volume UDF volume information structure.
639
640 @retval EFI_SUCCESS Volume information read.
641 @retval EFI_NO_MEDIA The device has no media.
642 @retval EFI_DEVICE_ERROR The device reported an error.
643 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
644 @retval EFI_OUT_OF_RESOURCES The volume was not read due to lack of resources.
645
646 **/
647 EFI_STATUS
648 ReadUdfVolumeInformation (
649 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
650 IN EFI_DISK_IO_PROTOCOL *DiskIo,
651 OUT UDF_VOLUME_INFO *Volume
652 );
653
654 /**
655 Find the root directory on an UDF volume.
656
657 @param[in] BlockIo BlockIo interface.
658 @param[in] DiskIo DiskIo interface.
659 @param[in] Volume UDF volume information structure.
660 @param[out] File Root directory file.
661
662 @retval EFI_SUCCESS Root directory found.
663 @retval EFI_NO_MEDIA The device has no media.
664 @retval EFI_DEVICE_ERROR The device reported an error.
665 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
666 @retval EFI_OUT_OF_RESOURCES The root directory was not found due to lack of
667 resources.
668
669 **/
670 EFI_STATUS
671 FindRootDirectory (
672 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
673 IN EFI_DISK_IO_PROTOCOL *DiskIo,
674 IN UDF_VOLUME_INFO *Volume,
675 OUT UDF_FILE_INFO *File
676 );
677
678 /**
679 Find either a File Entry or a Extended File Entry from a given ICB.
680
681 @param[in] BlockIo BlockIo interface.
682 @param[in] DiskIo DiskIo interface.
683 @param[in] Volume UDF volume information structure.
684 @param[in] Icb ICB of the FID.
685 @param[out] FileEntry File Entry or Extended File Entry.
686
687 @retval EFI_SUCCESS File Entry or Extended File Entry found.
688 @retval EFI_NO_MEDIA The device has no media.
689 @retval EFI_DEVICE_ERROR The device reported an error.
690 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
691 @retval EFI_OUT_OF_RESOURCES The FE/EFE entry was not found due to lack of
692 resources.
693
694 **/
695 EFI_STATUS
696 FindFileEntry (
697 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
698 IN EFI_DISK_IO_PROTOCOL *DiskIo,
699 IN UDF_VOLUME_INFO *Volume,
700 IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb,
701 OUT VOID **FileEntry
702 );
703
704 /**
705 Find a file given its absolute path on an UDF volume.
706
707 @param[in] BlockIo BlockIo interface.
708 @param[in] DiskIo DiskIo interface.
709 @param[in] Volume UDF volume information structure.
710 @param[in] FilePath File's absolute path.
711 @param[in] Root Root directory file.
712 @param[in] Parent Parent directory file.
713 @param[in] Icb ICB of Parent.
714 @param[out] File Found file.
715
716 @retval EFI_SUCCESS FilePath was found.
717 @retval EFI_NO_MEDIA The device has no media.
718 @retval EFI_DEVICE_ERROR The device reported an error.
719 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
720 @retval EFI_OUT_OF_RESOURCES The FilePath file was not found due to lack of
721 resources.
722
723 **/
724 EFI_STATUS
725 FindFile (
726 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
727 IN EFI_DISK_IO_PROTOCOL *DiskIo,
728 IN UDF_VOLUME_INFO *Volume,
729 IN CHAR16 *FilePath,
730 IN UDF_FILE_INFO *Root,
731 IN UDF_FILE_INFO *Parent,
732 IN UDF_LONG_ALLOCATION_DESCRIPTOR *Icb,
733 OUT UDF_FILE_INFO *File
734 );
735
736 /**
737 Read a directory entry at a time on an UDF volume.
738
739 @param[in] BlockIo BlockIo interface.
740 @param[in] DiskIo DiskIo interface.
741 @param[in] Volume UDF volume information structure.
742 @param[in] ParentIcb ICB of the parent file.
743 @param[in] FileEntryData FE/EFE of the parent file.
744 @param[in, out] ReadDirInfo Next read directory listing structure
745 information.
746 @param[out] FoundFid File Identifier Descriptor pointer.
747
748 @retval EFI_SUCCESS Directory entry read.
749 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
750 @retval EFI_NO_MEDIA The device has no media.
751 @retval EFI_DEVICE_ERROR The device reported an error.
752 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
753 @retval EFI_OUT_OF_RESOURCES The directory entry was not read due to lack of
754 resources.
755
756 **/
757 EFI_STATUS
758 ReadDirectoryEntry (
759 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
760 IN EFI_DISK_IO_PROTOCOL *DiskIo,
761 IN UDF_VOLUME_INFO *Volume,
762 IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb,
763 IN VOID *FileEntryData,
764 IN OUT UDF_READ_DIRECTORY_INFO *ReadDirInfo,
765 OUT UDF_FILE_IDENTIFIER_DESCRIPTOR **FoundFid
766 );
767
768 /**
769 Get a filename (encoded in OSTA-compressed format) from a File Identifier
770 Descriptor on an UDF volume.
771
772 @param[in] FileIdentifierDesc File Identifier Descriptor pointer.
773 @param[out] FileName Decoded filename.
774
775 @retval EFI_SUCCESS Filename decoded and read.
776 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
777 **/
778 EFI_STATUS
779 GetFileNameFromFid (
780 IN UDF_FILE_IDENTIFIER_DESCRIPTOR *FileIdentifierDesc,
781 OUT CHAR16 *FileName
782 );
783
784 /**
785 Resolve a symlink file on an UDF volume.
786
787 @param[in] BlockIo BlockIo interface.
788 @param[in] DiskIo DiskIo interface.
789 @param[in] Volume UDF volume information structure.
790 @param[in] Parent Parent file.
791 @param[in] FileEntryData FE/EFE structure pointer.
792 @param[out] File Resolved file.
793
794 @retval EFI_SUCCESS Symlink file resolved.
795 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
796 @retval EFI_NO_MEDIA The device has no media.
797 @retval EFI_DEVICE_ERROR The device reported an error.
798 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
799 @retval EFI_OUT_OF_RESOURCES The symlink file was not resolved due to lack of
800 resources.
801
802 **/
803 EFI_STATUS
804 ResolveSymlink (
805 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
806 IN EFI_DISK_IO_PROTOCOL *DiskIo,
807 IN UDF_VOLUME_INFO *Volume,
808 IN UDF_FILE_INFO *Parent,
809 IN VOID *FileEntryData,
810 OUT UDF_FILE_INFO *File
811 );
812
813 /**
814 Clean up in-memory UDF file information.
815
816 @param[in] File File information pointer.
817
818 **/
819 VOID
820 CleanupFileInformation (
821 IN UDF_FILE_INFO *File
822 );
823
824 /**
825 Find a file from its absolute path on an UDF volume.
826
827 @param[in] BlockIo BlockIo interface.
828 @param[in] DiskIo DiskIo interface.
829 @param[in] Volume UDF volume information structure.
830 @param[in] File File information structure.
831 @param[out] Size Size of the file.
832
833 @retval EFI_SUCCESS File size calculated and set in Size.
834 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
835 @retval EFI_NO_MEDIA The device has no media.
836 @retval EFI_DEVICE_ERROR The device reported an error.
837 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
838 @retval EFI_OUT_OF_RESOURCES The file size was not calculated due to lack of
839 resources.
840
841 **/
842 EFI_STATUS
843 GetFileSize (
844 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
845 IN EFI_DISK_IO_PROTOCOL *DiskIo,
846 IN UDF_VOLUME_INFO *Volume,
847 IN UDF_FILE_INFO *File,
848 OUT UINT64 *Size
849 );
850
851 /**
852 Set information about a file on an UDF volume.
853
854 @param[in] File File pointer.
855 @param[in] FileSize Size of the file.
856 @param[in] FileName Filename of the file.
857 @param[in, out] BufferSize Size of the returned file infomation.
858 @param[out] Buffer Data of the returned file information.
859
860 @retval EFI_SUCCESS File information set.
861 @retval EFI_NO_MEDIA The device has no media.
862 @retval EFI_DEVICE_ERROR The device reported an error.
863 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
864 @retval EFI_OUT_OF_RESOURCES The file information was not set due to lack of
865 resources.
866
867 **/
868 EFI_STATUS
869 SetFileInfo (
870 IN UDF_FILE_INFO *File,
871 IN UINT64 FileSize,
872 IN CHAR16 *FileName,
873 IN OUT UINTN *BufferSize,
874 OUT VOID *Buffer
875 );
876
877 /**
878 Get volume and free space size information of an UDF volume.
879
880 @param[in] BlockIo BlockIo interface.
881 @param[in] DiskIo DiskIo interface.
882 @param[in] Volume UDF volume information structure.
883 @param[out] VolumeSize Volume size.
884 @param[out] FreeSpaceSize Free space size.
885
886 @retval EFI_SUCCESS Volume and free space size calculated.
887 @retval EFI_NO_MEDIA The device has no media.
888 @retval EFI_DEVICE_ERROR The device reported an error.
889 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
890 @retval EFI_OUT_OF_RESOURCES The volume and free space size were not
891 calculated due to lack of resources.
892
893 **/
894 EFI_STATUS
895 GetVolumeSize (
896 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
897 IN EFI_DISK_IO_PROTOCOL *DiskIo,
898 IN UDF_VOLUME_INFO *Volume,
899 OUT UINT64 *VolumeSize,
900 OUT UINT64 *FreeSpaceSize
901 );
902
903 /**
904 Seek a file and read its data into memory on an UDF volume.
905
906 @param[in] BlockIo BlockIo interface.
907 @param[in] DiskIo DiskIo interface.
908 @param[in] Volume UDF volume information structure.
909 @param[in] File File information structure.
910 @param[in] FileSize Size of the file.
911 @param[in, out] FilePosition File position.
912 @param[in, out] Buffer File data.
913 @param[in, out] BufferSize Read size.
914
915 @retval EFI_SUCCESS File seeked and read.
916 @retval EFI_UNSUPPORTED Extended Allocation Descriptors not supported.
917 @retval EFI_NO_MEDIA The device has no media.
918 @retval EFI_DEVICE_ERROR The device reported an error.
919 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
920 @retval EFI_OUT_OF_RESOURCES The file's recorded data was not read due to lack
921 of resources.
922
923 **/
924 EFI_STATUS
925 ReadFileData (
926 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
927 IN EFI_DISK_IO_PROTOCOL *DiskIo,
928 IN UDF_VOLUME_INFO *Volume,
929 IN UDF_FILE_INFO *File,
930 IN UINT64 FileSize,
931 IN OUT UINT64 *FilePosition,
932 IN OUT VOID *Buffer,
933 IN OUT UINT64 *BufferSize
934 );
935
936 /**
937 Check if ControllerHandle supports an UDF file system.
938
939 @param[in] This Protocol instance pointer.
940 @param[in] ControllerHandle Handle of device to test.
941
942 @retval EFI_SUCCESS UDF file system found.
943 @retval EFI_UNSUPPORTED UDF file system not found.
944
945 **/
946 EFI_STATUS
947 SupportUdfFileSystem (
948 IN EFI_DRIVER_BINDING_PROTOCOL *This,
949 IN EFI_HANDLE ControllerHandle
950 );
951
952 /**
953 Mangle a filename by cutting off trailing whitespaces, "\\", "." and "..".
954
955 @param[in] FileName Filename.
956
957 @retval The mangled Filename.
958
959 **/
960 CHAR16 *
961 MangleFileName (
962 IN CHAR16 *FileName
963 );
964
965 /**
966 Test to see if this driver supports ControllerHandle. Any ControllerHandle
967 than contains a BlockIo and DiskIo protocol can be supported.
968
969 @param This Protocol instance pointer.
970 @param ControllerHandle Handle of device to test
971 @param RemainingDevicePath Optional parameter use to pick a specific child
972 device to start.
973
974 @retval EFI_SUCCESS This driver supports this device
975 @retval EFI_ALREADY_STARTED This driver is already running on this device
976 @retval other This driver does not support this device
977
978 **/
979 EFI_STATUS
980 EFIAPI
981 UdfDriverBindingSupported (
982 IN EFI_DRIVER_BINDING_PROTOCOL *This,
983 IN EFI_HANDLE ControllerHandle,
984 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
985 );
986
987 /**
988 Start this driver on ControllerHandle by opening a Block IO and Disk IO
989 protocol, reading Device Path, and creating a child handle with a
990 Disk IO and device path protocol.
991
992 @param This Protocol instance pointer.
993 @param ControllerHandle Handle of device to bind driver to
994 @param RemainingDevicePath Optional parameter use to pick a specific child
995 device to start.
996
997 @retval EFI_SUCCESS This driver is added to ControllerHandle
998 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
999 @retval other This driver does not support this device
1000
1001 **/
1002 EFI_STATUS
1003 EFIAPI
1004 UdfDriverBindingStart (
1005 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1006 IN EFI_HANDLE ControllerHandle,
1007 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1008 );
1009
1010 /**
1011 Stop this driver on ControllerHandle. Support stopping any child handles
1012 created by this driver.
1013
1014 @param This Protocol instance pointer.
1015 @param ControllerHandle Handle of device to stop driver on
1016 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1017 children is zero stop the entire bus driver.
1018 @param ChildHandleBuffer List of Child Handles to Stop.
1019
1020 @retval EFI_SUCCESS This driver is removed ControllerHandle
1021 @retval other This driver was not removed from this device
1022
1023 **/
1024 EFI_STATUS
1025 EFIAPI
1026 UdfDriverBindingStop (
1027 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1028 IN EFI_HANDLE ControllerHandle,
1029 IN UINTN NumberOfChildren,
1030 IN EFI_HANDLE *ChildHandleBuffer
1031 );
1032
1033 //
1034 // EFI Component Name Functions
1035 //
1036 /**
1037 Retrieves a Unicode string that is the user readable name of the driver.
1038
1039 This function retrieves the user readable name of a driver in the form of a
1040 Unicode string. If the driver specified by This has a user readable name in
1041 the language specified by Language, then a pointer to the driver name is
1042 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
1043 by This does not support the language specified by Language,
1044 then EFI_UNSUPPORTED is returned.
1045
1046 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
1047 EFI_COMPONENT_NAME_PROTOCOL instance.
1048
1049 @param Language[in] A pointer to a Null-terminated ASCII string
1050 array indicating the language. This is the
1051 language of the driver name that the caller is
1052 requesting, and it must match one of the
1053 languages specified in SupportedLanguages. The
1054 number of languages supported by a driver is up
1055 to the driver writer. Language is specified
1056 in RFC 4646 or ISO 639-2 language code format.
1057
1058 @param DriverName[out] A pointer to the Unicode string to return.
1059 This Unicode string is the name of the
1060 driver specified by This in the language
1061 specified by Language.
1062
1063 @retval EFI_SUCCESS The Unicode string for the Driver specified by
1064 This and the language specified by Language was
1065 returned in DriverName.
1066
1067 @retval EFI_INVALID_PARAMETER Language is NULL.
1068
1069 @retval EFI_INVALID_PARAMETER DriverName is NULL.
1070
1071 @retval EFI_UNSUPPORTED The driver specified by This does not support
1072 the language specified by Language.
1073
1074 **/
1075 EFI_STATUS
1076 EFIAPI
1077 UdfComponentNameGetDriverName (
1078 IN EFI_COMPONENT_NAME_PROTOCOL *This,
1079 IN CHAR8 *Language,
1080 OUT CHAR16 **DriverName
1081 );
1082
1083 /**
1084 Retrieves a Unicode string that is the user readable name of the controller
1085 that is being managed by a driver.
1086
1087 This function retrieves the user readable name of the controller specified by
1088 ControllerHandle and ChildHandle in the form of a Unicode string. If the
1089 driver specified by This has a user readable name in the language specified by
1090 Language, then a pointer to the controller name is returned in ControllerName,
1091 and EFI_SUCCESS is returned. If the driver specified by This is not currently
1092 managing the controller specified by ControllerHandle and ChildHandle,
1093 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
1094 support the language specified by Language, then EFI_UNSUPPORTED is returned.
1095
1096 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
1097 EFI_COMPONENT_NAME_PROTOCOL instance.
1098
1099 @param ControllerHandle[in] The handle of a controller that the driver
1100 specified by This is managing. This handle
1101 specifies the controller whose name is to be
1102 returned.
1103
1104 @param ChildHandle[in] The handle of the child controller to retrieve
1105 the name of. This is an optional parameter that
1106 may be NULL. It will be NULL for device
1107 drivers. It will also be NULL for a bus drivers
1108 that wish to retrieve the name of the bus
1109 controller. It will not be NULL for a bus
1110 driver that wishes to retrieve the name of a
1111 child controller.
1112
1113 @param Language[in] A pointer to a Null-terminated ASCII string
1114 array indicating the language. This is the
1115 language of the driver name that the caller is
1116 requesting, and it must match one of the
1117 languages specified in SupportedLanguages. The
1118 number of languages supported by a driver is up
1119 to the driver writer. Language is specified in
1120 RFC 4646 or ISO 639-2 language code format.
1121
1122 @param ControllerName[out] A pointer to the Unicode string to return.
1123 This Unicode string is the name of the
1124 controller specified by ControllerHandle and
1125 ChildHandle in the language specified by
1126 Language from the point of view of the driver
1127 specified by This.
1128
1129 @retval EFI_SUCCESS The Unicode string for the user readable name in
1130 the language specified by Language for the
1131 driver specified by This was returned in
1132 DriverName.
1133
1134 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
1135
1136 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
1137 EFI_HANDLE.
1138
1139 @retval EFI_INVALID_PARAMETER Language is NULL.
1140
1141 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
1142
1143 @retval EFI_UNSUPPORTED The driver specified by This is not currently
1144 managing the controller specified by
1145 ControllerHandle and ChildHandle.
1146
1147 @retval EFI_UNSUPPORTED The driver specified by This does not support
1148 the language specified by Language.
1149
1150 **/
1151 EFI_STATUS
1152 EFIAPI
1153 UdfComponentNameGetControllerName (
1154 IN EFI_COMPONENT_NAME_PROTOCOL *This,
1155 IN EFI_HANDLE ControllerHandle,
1156 IN EFI_HANDLE ChildHandle OPTIONAL,
1157 IN CHAR8 *Language,
1158 OUT CHAR16 **ControllerName
1159 );
1160
1161 #endif // _UDF_H_