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