1 | /** @file
|
---|
2 | Main header file for EFI FAT file system driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #ifndef _FAT_H_
|
---|
10 | #define _FAT_H_
|
---|
11 |
|
---|
12 | #include <Uefi.h>
|
---|
13 |
|
---|
14 | #include <Guid/FileInfo.h>
|
---|
15 | #include <Guid/FileSystemInfo.h>
|
---|
16 | #include <Guid/FileSystemVolumeLabelInfo.h>
|
---|
17 | #include <Protocol/BlockIo.h>
|
---|
18 | #include <Protocol/DiskIo.h>
|
---|
19 | #include <Protocol/DiskIo2.h>
|
---|
20 | #include <Protocol/SimpleFileSystem.h>
|
---|
21 | #include <Protocol/UnicodeCollation.h>
|
---|
22 |
|
---|
23 | #include <Library/PcdLib.h>
|
---|
24 | #include <Library/DebugLib.h>
|
---|
25 | #include <Library/UefiLib.h>
|
---|
26 | #include <Library/BaseLib.h>
|
---|
27 | #include <Library/BaseMemoryLib.h>
|
---|
28 | #include <Library/MemoryAllocationLib.h>
|
---|
29 | #include <Library/UefiDriverEntryPoint.h>
|
---|
30 | #include <Library/UefiBootServicesTableLib.h>
|
---|
31 | #include <Library/UefiRuntimeServicesTableLib.h>
|
---|
32 |
|
---|
33 | #include "FatFileSystem.h"
|
---|
34 |
|
---|
35 | //
|
---|
36 | // The FAT signature
|
---|
37 | //
|
---|
38 | #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
|
---|
39 | #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
|
---|
40 | #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
|
---|
41 | #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
|
---|
42 | #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
|
---|
43 | #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
|
---|
44 | #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
|
---|
45 |
|
---|
46 | #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
|
---|
47 |
|
---|
48 | #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
|
---|
49 |
|
---|
50 | #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
|
---|
51 |
|
---|
52 | #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
|
---|
53 |
|
---|
54 | #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
|
---|
55 |
|
---|
56 | #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
|
---|
57 |
|
---|
58 | #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
|
---|
59 |
|
---|
60 | #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
|
---|
61 |
|
---|
62 | //
|
---|
63 | // Minimum sector size is 512B, Maximum sector size is 4096B
|
---|
64 | // Max sectors per cluster is 128
|
---|
65 | //
|
---|
66 | #define MAX_BLOCK_ALIGNMENT 12
|
---|
67 | #define MIN_BLOCK_ALIGNMENT 9
|
---|
68 | #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
|
---|
69 |
|
---|
70 | //
|
---|
71 | // Efi Time Definition
|
---|
72 | //
|
---|
73 | #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
|
---|
74 |
|
---|
75 | //
|
---|
76 | // Minimum fat page size is 8K, maximum fat page alignment is 32K
|
---|
77 | // Minimum data page size is 8K, maximum fat page alignment is 64K
|
---|
78 | //
|
---|
79 | #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
|
---|
80 | #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
|
---|
81 | #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
|
---|
82 | #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
|
---|
83 | #define FAT_DATACACHE_GROUP_COUNT 64
|
---|
84 | #define FAT_FATCACHE_GROUP_MIN_COUNT 1
|
---|
85 | #define FAT_FATCACHE_GROUP_MAX_COUNT 16
|
---|
86 |
|
---|
87 | // For cache block bits, use a UINT64
|
---|
88 | typedef UINT64 DIRTY_BLOCKS;
|
---|
89 | #define BITS_PER_BYTE 8
|
---|
90 | #define DIRTY_BITS_PER_BLOCK ((sizeof (DIRTY_BLOCKS) * BITS_PER_BYTE))
|
---|
91 |
|
---|
92 | // largest cache line (64KB) / MinLbaSize (512) = 128 bits
|
---|
93 | #define DIRTY_BITS ((1 << FAT_DATACACHE_PAGE_MAX_ALIGNMENT) / (1 << MIN_BLOCK_ALIGNMENT))
|
---|
94 |
|
---|
95 | // Number of DIRTY_BLOCKS to hold DIRTY_BITS bits.
|
---|
96 | #define DIRTY_BLOCKS_SIZE (DIRTY_BITS / sizeof (DIRTY_BLOCKS))
|
---|
97 |
|
---|
98 | STATIC_ASSERT ((((1 << FAT_DATACACHE_PAGE_MAX_ALIGNMENT) / (1 << MIN_BLOCK_ALIGNMENT)) % sizeof (DIRTY_BLOCKS)) == 0, "DIRTY_BLOCKS not a proper size");
|
---|
99 |
|
---|
100 | //
|
---|
101 | // Used in 8.3 generation algorithm
|
---|
102 | //
|
---|
103 | #define MAX_SPEC_RETRY 4
|
---|
104 | #define SPEC_BASE_TAG_LEN 6
|
---|
105 | #define HASH_BASE_TAG_LEN 2
|
---|
106 | #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
|
---|
107 |
|
---|
108 | //
|
---|
109 | // Path name separator is back slash
|
---|
110 | //
|
---|
111 | #define PATH_NAME_SEPARATOR L'\\'
|
---|
112 |
|
---|
113 | #define EFI_PATH_STRING_LENGTH 260
|
---|
114 | #define EFI_FILE_STRING_LENGTH 255
|
---|
115 | #define FAT_MAX_ALLOCATE_SIZE 0xA00000
|
---|
116 | #define LC_ISO_639_2_ENTRY_SIZE 3
|
---|
117 | #define MAX_LANG_CODE_SIZE 100
|
---|
118 |
|
---|
119 | #define FAT_MAX_DIR_CACHE_COUNT 8
|
---|
120 | #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
|
---|
121 | typedef CHAR8 LC_ISO_639_2;
|
---|
122 |
|
---|
123 | //
|
---|
124 | // The fat types we support
|
---|
125 | //
|
---|
126 | typedef enum {
|
---|
127 | Fat12,
|
---|
128 | Fat16,
|
---|
129 | Fat32,
|
---|
130 | FatUndefined
|
---|
131 | } FAT_VOLUME_TYPE;
|
---|
132 |
|
---|
133 | typedef enum {
|
---|
134 | CacheFat,
|
---|
135 | CacheData,
|
---|
136 | CacheMaxType
|
---|
137 | } CACHE_DATA_TYPE;
|
---|
138 |
|
---|
139 | //
|
---|
140 | // Used in FatDiskIo
|
---|
141 | //
|
---|
142 | typedef enum {
|
---|
143 | ReadDisk = 0, // raw disk read
|
---|
144 | WriteDisk = 1, // raw disk write
|
---|
145 | ReadFat = 2, // read fat cache
|
---|
146 | WriteFat = 3, // write fat cache
|
---|
147 | ReadData = 6, // read data cache
|
---|
148 | WriteData = 7 // write data cache
|
---|
149 | } IO_MODE;
|
---|
150 |
|
---|
151 | #define CACHE_ENABLED(a) ((a) >= 2)
|
---|
152 | #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
|
---|
153 | #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
|
---|
154 |
|
---|
155 | //
|
---|
156 | // Disk cache tag
|
---|
157 | //
|
---|
158 | typedef struct {
|
---|
159 | UINTN PageNo;
|
---|
160 | UINTN RealSize;
|
---|
161 | BOOLEAN Dirty;
|
---|
162 | DIRTY_BLOCKS DirtyBlocks[DIRTY_BLOCKS_SIZE];
|
---|
163 | } CACHE_TAG;
|
---|
164 |
|
---|
165 | typedef struct {
|
---|
166 | UINT64 BaseAddress;
|
---|
167 | UINT64 LimitAddress;
|
---|
168 | UINT8 *CacheBase;
|
---|
169 | UINT32 BlockSize;
|
---|
170 | BOOLEAN Dirty;
|
---|
171 | UINT8 PageAlignment;
|
---|
172 | UINTN GroupMask;
|
---|
173 | CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
|
---|
174 | } DISK_CACHE;
|
---|
175 |
|
---|
176 | //
|
---|
177 | // Hash table size
|
---|
178 | //
|
---|
179 | #define HASH_TABLE_SIZE 0x400
|
---|
180 | #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
|
---|
181 |
|
---|
182 | //
|
---|
183 | // The directory entry for opened directory
|
---|
184 | //
|
---|
185 |
|
---|
186 | typedef struct _FAT_DIRENT FAT_DIRENT;
|
---|
187 | typedef struct _FAT_ODIR FAT_ODIR;
|
---|
188 | typedef struct _FAT_OFILE FAT_OFILE;
|
---|
189 | typedef struct _FAT_VOLUME FAT_VOLUME;
|
---|
190 |
|
---|
191 | struct _FAT_DIRENT {
|
---|
192 | UINTN Signature;
|
---|
193 | UINT16 EntryPos; // The position of this directory entry in the parent directory file
|
---|
194 | UINT8 EntryCount; // The count of the directory entry in the parent directory file
|
---|
195 | BOOLEAN Invalid; // Indicate whether this directory entry is valid
|
---|
196 | CHAR16 *FileString; // The unicode long file name for this directory entry
|
---|
197 | FAT_OFILE *OFile; // The OFile of the corresponding directory entry
|
---|
198 | FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
|
---|
199 | FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
|
---|
200 | LIST_ENTRY Link; // Connection of every directory entry
|
---|
201 | FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
|
---|
202 | };
|
---|
203 |
|
---|
204 | struct _FAT_ODIR {
|
---|
205 | UINTN Signature;
|
---|
206 | UINT32 CurrentEndPos; // Current end position of the directory
|
---|
207 | UINT32 CurrentPos; // Current position of the directory
|
---|
208 | LIST_ENTRY *CurrentCursor; // Current directory entry pointer
|
---|
209 | LIST_ENTRY ChildList; // List of all directory entries
|
---|
210 | BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
|
---|
211 | LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
|
---|
212 | UINTN DirCacheTag; // The identification of the directory when in directory cache
|
---|
213 | FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
|
---|
214 | FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
|
---|
215 | };
|
---|
216 |
|
---|
217 | typedef struct {
|
---|
218 | UINTN Signature;
|
---|
219 | EFI_FILE_PROTOCOL Handle;
|
---|
220 | UINT64 Position;
|
---|
221 | BOOLEAN ReadOnly;
|
---|
222 | FAT_OFILE *OFile;
|
---|
223 | LIST_ENTRY Tasks; // List of all FAT_TASKs
|
---|
224 | LIST_ENTRY Link; // Link to other IFiles
|
---|
225 | } FAT_IFILE;
|
---|
226 |
|
---|
227 | typedef struct {
|
---|
228 | UINTN Signature;
|
---|
229 | EFI_FILE_IO_TOKEN *FileIoToken;
|
---|
230 | FAT_IFILE *IFile;
|
---|
231 | LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs
|
---|
232 | LIST_ENTRY Link; // Link to other FAT_TASKs
|
---|
233 | } FAT_TASK;
|
---|
234 |
|
---|
235 | typedef struct {
|
---|
236 | UINTN Signature;
|
---|
237 | EFI_DISK_IO2_TOKEN DiskIo2Token;
|
---|
238 | FAT_TASK *Task;
|
---|
239 | BOOLEAN Write;
|
---|
240 | UINT64 Offset;
|
---|
241 | VOID *Buffer;
|
---|
242 | UINTN BufferSize;
|
---|
243 | LIST_ENTRY Link;
|
---|
244 | } FAT_SUBTASK;
|
---|
245 |
|
---|
246 | //
|
---|
247 | // FAT_OFILE - Each opened file
|
---|
248 | //
|
---|
249 | struct _FAT_OFILE {
|
---|
250 | UINTN Signature;
|
---|
251 | FAT_VOLUME *Volume;
|
---|
252 | //
|
---|
253 | // A permanent error code to return to all accesses to
|
---|
254 | // this opened file
|
---|
255 | //
|
---|
256 | EFI_STATUS Error;
|
---|
257 | //
|
---|
258 | // A list of the IFILE instances for this OFile
|
---|
259 | //
|
---|
260 | LIST_ENTRY Opens;
|
---|
261 |
|
---|
262 | //
|
---|
263 | // The dynamic information
|
---|
264 | //
|
---|
265 | UINTN FileSize;
|
---|
266 | UINTN FileCluster;
|
---|
267 | UINTN FileCurrentCluster;
|
---|
268 | UINTN FileLastCluster;
|
---|
269 |
|
---|
270 | //
|
---|
271 | // Dirty is set if there have been any updates to the
|
---|
272 | // file
|
---|
273 | // Archive is set if the archive attribute in the file's
|
---|
274 | // directory entry needs to be set when performing flush
|
---|
275 | // PreserveLastMod is set if the last modification of the
|
---|
276 | // file is specified by SetInfo API
|
---|
277 | //
|
---|
278 | BOOLEAN Dirty;
|
---|
279 | BOOLEAN IsFixedRootDir;
|
---|
280 | BOOLEAN PreserveLastModification;
|
---|
281 | BOOLEAN Archive;
|
---|
282 | //
|
---|
283 | // Set by an OFile SetPosition
|
---|
284 | //
|
---|
285 | UINTN Position; // within file
|
---|
286 | UINT64 PosDisk; // on the disk
|
---|
287 | UINTN PosRem; // remaining in this disk run
|
---|
288 | //
|
---|
289 | // The opened parent, full path length and currently opened child files
|
---|
290 | //
|
---|
291 | FAT_OFILE *Parent;
|
---|
292 | UINTN FullPathLen;
|
---|
293 | LIST_ENTRY ChildHead;
|
---|
294 | LIST_ENTRY ChildLink;
|
---|
295 |
|
---|
296 | //
|
---|
297 | // The opened directory structure for a directory; if this
|
---|
298 | // OFile represents a file, then ODir = NULL
|
---|
299 | //
|
---|
300 | FAT_ODIR *ODir;
|
---|
301 | //
|
---|
302 | // The directory entry for the Ofile
|
---|
303 | //
|
---|
304 | FAT_DIRENT *DirEnt;
|
---|
305 |
|
---|
306 | //
|
---|
307 | // Link in Volume's reference list
|
---|
308 | //
|
---|
309 | LIST_ENTRY CheckLink;
|
---|
310 | };
|
---|
311 |
|
---|
312 | struct _FAT_VOLUME {
|
---|
313 | UINTN Signature;
|
---|
314 |
|
---|
315 | EFI_HANDLE Handle;
|
---|
316 | BOOLEAN Valid;
|
---|
317 | BOOLEAN DiskError;
|
---|
318 |
|
---|
319 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
|
---|
320 |
|
---|
321 | //
|
---|
322 | // If opened, the parent handle and BlockIo interface
|
---|
323 | //
|
---|
324 | EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
---|
325 | EFI_DISK_IO_PROTOCOL *DiskIo;
|
---|
326 | EFI_DISK_IO2_PROTOCOL *DiskIo2;
|
---|
327 | UINT32 MediaId;
|
---|
328 | BOOLEAN ReadOnly;
|
---|
329 |
|
---|
330 | //
|
---|
331 | // Computed values from fat bpb info
|
---|
332 | //
|
---|
333 | UINT64 VolumeSize;
|
---|
334 | UINT64 FatPos; // Disk pos of fat tables
|
---|
335 | UINT64 RootPos; // Disk pos of root directory
|
---|
336 | UINT64 FirstClusterPos; // Disk pos of first cluster
|
---|
337 | UINTN FatSize; // Number of bytes in each fat
|
---|
338 | UINTN MaxCluster; // Max cluster number
|
---|
339 | UINTN ClusterSize; // Cluster size of fat partition
|
---|
340 | UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
|
---|
341 | FAT_VOLUME_TYPE FatType;
|
---|
342 |
|
---|
343 | //
|
---|
344 | // Current part of fat table that's present
|
---|
345 | //
|
---|
346 | UINT64 FatEntryPos; // Location of buffer
|
---|
347 | UINTN FatEntrySize; // Size of buffer
|
---|
348 | UINT32 FatEntryBuffer; // The buffer
|
---|
349 | FAT_INFO_SECTOR FatInfoSector; // Free cluster info
|
---|
350 | UINTN FreeInfoPos; // Pos with the free cluster info
|
---|
351 | BOOLEAN FreeInfoValid; // If free cluster info is valid
|
---|
352 | //
|
---|
353 | // Unpacked Fat BPB info
|
---|
354 | //
|
---|
355 | UINTN NumFats;
|
---|
356 | UINTN RootEntries; // < FAT32, root dir is fixed size
|
---|
357 | UINTN RootCluster; // >= FAT32, root cluster chain head
|
---|
358 | //
|
---|
359 | // info for marking the volume dirty or not
|
---|
360 | //
|
---|
361 | BOOLEAN FatDirty; // If fat-entries have been updated
|
---|
362 | UINT32 DirtyValue;
|
---|
363 | UINT32 NotDirtyValue;
|
---|
364 |
|
---|
365 | //
|
---|
366 | // The root directory entry and opened root file
|
---|
367 | //
|
---|
368 | FAT_DIRENT RootDirEnt;
|
---|
369 | //
|
---|
370 | // File Name of root OFile, it is empty string
|
---|
371 | //
|
---|
372 | CHAR16 RootFileString[1];
|
---|
373 | FAT_OFILE *Root;
|
---|
374 |
|
---|
375 | //
|
---|
376 | // New OFiles are added to this list so they
|
---|
377 | // can be cleaned up if they aren't referenced.
|
---|
378 | //
|
---|
379 | LIST_ENTRY CheckRef;
|
---|
380 |
|
---|
381 | //
|
---|
382 | // Directory cache List
|
---|
383 | //
|
---|
384 | LIST_ENTRY DirCacheList;
|
---|
385 | UINTN DirCacheCount;
|
---|
386 |
|
---|
387 | //
|
---|
388 | // Disk Cache for this volume
|
---|
389 | //
|
---|
390 | VOID *CacheBuffer;
|
---|
391 | DISK_CACHE DiskCache[CacheMaxType];
|
---|
392 | };
|
---|
393 |
|
---|
394 | //
|
---|
395 | // Function Prototypes
|
---|
396 | //
|
---|
397 |
|
---|
398 | /**
|
---|
399 |
|
---|
400 | Implements Open() of Simple File System Protocol.
|
---|
401 |
|
---|
402 | @param FHand - File handle of the file serves as a starting reference point.
|
---|
403 | @param NewHandle - Handle of the file that is newly opened.
|
---|
404 | @param FileName - File name relative to FHand.
|
---|
405 | @param OpenMode - Open mode.
|
---|
406 | @param Attributes - Attributes to set if the file is created.
|
---|
407 |
|
---|
408 |
|
---|
409 | @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
|
---|
410 | The OpenMode is not supported.
|
---|
411 | The Attributes is not the valid attributes.
|
---|
412 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
|
---|
413 | @retval EFI_SUCCESS - Open the file successfully.
|
---|
414 | @return Others - The status of open file.
|
---|
415 |
|
---|
416 | **/
|
---|
417 | EFI_STATUS
|
---|
418 | EFIAPI
|
---|
419 | FatOpen (
|
---|
420 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
421 | OUT EFI_FILE_PROTOCOL **NewHandle,
|
---|
422 | IN CHAR16 *FileName,
|
---|
423 | IN UINT64 OpenMode,
|
---|
424 | IN UINT64 Attributes
|
---|
425 | )
|
---|
426 | ;
|
---|
427 |
|
---|
428 | /**
|
---|
429 |
|
---|
430 | Implements OpenEx() of Simple File System Protocol.
|
---|
431 |
|
---|
432 | @param FHand - File handle of the file serves as a starting reference point.
|
---|
433 | @param NewHandle - Handle of the file that is newly opened.
|
---|
434 | @param FileName - File name relative to FHand.
|
---|
435 | @param OpenMode - Open mode.
|
---|
436 | @param Attributes - Attributes to set if the file is created.
|
---|
437 | @param Token - A pointer to the token associated with the transaction.
|
---|
438 |
|
---|
439 | @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
|
---|
440 | The OpenMode is not supported.
|
---|
441 | The Attributes is not the valid attributes.
|
---|
442 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
|
---|
443 | @retval EFI_SUCCESS - Open the file successfully.
|
---|
444 | @return Others - The status of open file.
|
---|
445 |
|
---|
446 | **/
|
---|
447 | EFI_STATUS
|
---|
448 | EFIAPI
|
---|
449 | FatOpenEx (
|
---|
450 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
451 | OUT EFI_FILE_PROTOCOL **NewHandle,
|
---|
452 | IN CHAR16 *FileName,
|
---|
453 | IN UINT64 OpenMode,
|
---|
454 | IN UINT64 Attributes,
|
---|
455 | IN OUT EFI_FILE_IO_TOKEN *Token
|
---|
456 | )
|
---|
457 | ;
|
---|
458 |
|
---|
459 | /**
|
---|
460 |
|
---|
461 | Get the file's position of the file
|
---|
462 |
|
---|
463 | @param FHand - The handle of file.
|
---|
464 | @param Position - The file's position of the file.
|
---|
465 |
|
---|
466 | @retval EFI_SUCCESS - Get the info successfully.
|
---|
467 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
468 | @retval EFI_UNSUPPORTED - The open file is not a file.
|
---|
469 |
|
---|
470 | **/
|
---|
471 | EFI_STATUS
|
---|
472 | EFIAPI
|
---|
473 | FatGetPosition (
|
---|
474 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
475 | OUT UINT64 *Position
|
---|
476 | )
|
---|
477 | ;
|
---|
478 |
|
---|
479 | /**
|
---|
480 |
|
---|
481 | Get the some types info of the file into Buffer
|
---|
482 |
|
---|
483 | @param FHand - The handle of file.
|
---|
484 | @param Type - The type of the info.
|
---|
485 | @param BufferSize - Size of Buffer.
|
---|
486 | @param Buffer - Buffer containing volume info.
|
---|
487 |
|
---|
488 | @retval EFI_SUCCESS - Get the info successfully.
|
---|
489 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
490 |
|
---|
491 | **/
|
---|
492 | EFI_STATUS
|
---|
493 | EFIAPI
|
---|
494 | FatGetInfo (
|
---|
495 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
496 | IN EFI_GUID *Type,
|
---|
497 | IN OUT UINTN *BufferSize,
|
---|
498 | OUT VOID *Buffer
|
---|
499 | )
|
---|
500 | ;
|
---|
501 |
|
---|
502 | /**
|
---|
503 |
|
---|
504 | Set the some types info of the file into Buffer.
|
---|
505 |
|
---|
506 | @param FHand - The handle of file.
|
---|
507 | @param Type - The type of the info.
|
---|
508 | @param BufferSize - Size of Buffer.
|
---|
509 | @param Buffer - Buffer containing volume info.
|
---|
510 |
|
---|
511 | @retval EFI_SUCCESS - Set the info successfully.
|
---|
512 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
513 |
|
---|
514 | **/
|
---|
515 | EFI_STATUS
|
---|
516 | EFIAPI
|
---|
517 | FatSetInfo (
|
---|
518 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
519 | IN EFI_GUID *Type,
|
---|
520 | IN UINTN BufferSize,
|
---|
521 | IN VOID *Buffer
|
---|
522 | )
|
---|
523 | ;
|
---|
524 |
|
---|
525 | /**
|
---|
526 |
|
---|
527 | Flushes all data associated with the file handle.
|
---|
528 |
|
---|
529 | @param FHand - Handle to file to flush
|
---|
530 |
|
---|
531 | @retval EFI_SUCCESS - Flushed the file successfully
|
---|
532 | @retval EFI_WRITE_PROTECTED - The volume is read only
|
---|
533 | @retval EFI_ACCESS_DENIED - The volume is not read only
|
---|
534 | but the file is read only
|
---|
535 | @return Others - Flushing of the file is failed
|
---|
536 |
|
---|
537 | **/
|
---|
538 | EFI_STATUS
|
---|
539 | EFIAPI
|
---|
540 | FatFlush (
|
---|
541 | IN EFI_FILE_PROTOCOL *FHand
|
---|
542 | )
|
---|
543 | ;
|
---|
544 |
|
---|
545 | /**
|
---|
546 |
|
---|
547 | Flushes all data associated with the file handle.
|
---|
548 |
|
---|
549 | @param FHand - Handle to file to flush.
|
---|
550 | @param Token - A pointer to the token associated with the transaction.
|
---|
551 |
|
---|
552 | @retval EFI_SUCCESS - Flushed the file successfully.
|
---|
553 | @retval EFI_WRITE_PROTECTED - The volume is read only.
|
---|
554 | @retval EFI_ACCESS_DENIED - The file is read only.
|
---|
555 | @return Others - Flushing of the file failed.
|
---|
556 |
|
---|
557 | **/
|
---|
558 | EFI_STATUS
|
---|
559 | EFIAPI
|
---|
560 | FatFlushEx (
|
---|
561 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
562 | IN EFI_FILE_IO_TOKEN *Token
|
---|
563 | )
|
---|
564 | ;
|
---|
565 |
|
---|
566 | /**
|
---|
567 |
|
---|
568 | Flushes & Closes the file handle.
|
---|
569 |
|
---|
570 | @param FHand - Handle to the file to delete.
|
---|
571 |
|
---|
572 | @retval EFI_SUCCESS - Closed the file successfully.
|
---|
573 |
|
---|
574 | **/
|
---|
575 | EFI_STATUS
|
---|
576 | EFIAPI
|
---|
577 | FatClose (
|
---|
578 | IN EFI_FILE_PROTOCOL *FHand
|
---|
579 | )
|
---|
580 | ;
|
---|
581 |
|
---|
582 | /**
|
---|
583 |
|
---|
584 | Deletes the file & Closes the file handle.
|
---|
585 |
|
---|
586 | @param FHand - Handle to the file to delete.
|
---|
587 |
|
---|
588 | @retval EFI_SUCCESS - Delete the file successfully.
|
---|
589 | @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
|
---|
590 |
|
---|
591 | **/
|
---|
592 | EFI_STATUS
|
---|
593 | EFIAPI
|
---|
594 | FatDelete (
|
---|
595 | IN EFI_FILE_PROTOCOL *FHand
|
---|
596 | )
|
---|
597 | ;
|
---|
598 |
|
---|
599 | /**
|
---|
600 |
|
---|
601 | Set the file's position of the file.
|
---|
602 |
|
---|
603 | @param FHand - The handle of file
|
---|
604 | @param Position - The file's position of the file
|
---|
605 |
|
---|
606 | @retval EFI_SUCCESS - Set the info successfully
|
---|
607 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file
|
---|
608 | @retval EFI_UNSUPPORTED - Set a directory with a not-zero position
|
---|
609 |
|
---|
610 | **/
|
---|
611 | EFI_STATUS
|
---|
612 | EFIAPI
|
---|
613 | FatSetPosition (
|
---|
614 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
615 | IN UINT64 Position
|
---|
616 | )
|
---|
617 | ;
|
---|
618 |
|
---|
619 | /**
|
---|
620 |
|
---|
621 | Get the file info.
|
---|
622 |
|
---|
623 | @param FHand - The handle of the file.
|
---|
624 | @param BufferSize - Size of Buffer.
|
---|
625 | @param Buffer - Buffer containing read data.
|
---|
626 |
|
---|
627 | @retval EFI_SUCCESS - Get the file info successfully.
|
---|
628 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
629 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
|
---|
630 | @return other - An error occurred when operation the disk.
|
---|
631 |
|
---|
632 | **/
|
---|
633 | EFI_STATUS
|
---|
634 | EFIAPI
|
---|
635 | FatRead (
|
---|
636 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
637 | IN OUT UINTN *BufferSize,
|
---|
638 | OUT VOID *Buffer
|
---|
639 | )
|
---|
640 | ;
|
---|
641 |
|
---|
642 | /**
|
---|
643 |
|
---|
644 | Get the file info.
|
---|
645 |
|
---|
646 | @param FHand - The handle of the file.
|
---|
647 | @param Token - A pointer to the token associated with the transaction.
|
---|
648 |
|
---|
649 | @retval EFI_SUCCESS - Get the file info successfully.
|
---|
650 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
651 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
|
---|
652 | @return other - An error occurred when operation the disk.
|
---|
653 |
|
---|
654 | **/
|
---|
655 | EFI_STATUS
|
---|
656 | EFIAPI
|
---|
657 | FatReadEx (
|
---|
658 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
659 | IN OUT EFI_FILE_IO_TOKEN *Token
|
---|
660 | )
|
---|
661 | ;
|
---|
662 |
|
---|
663 | /**
|
---|
664 |
|
---|
665 | Set the file info.
|
---|
666 |
|
---|
667 | @param FHand - The handle of the file.
|
---|
668 | @param BufferSize - Size of Buffer.
|
---|
669 | @param Buffer - Buffer containing write data.
|
---|
670 |
|
---|
671 | @retval EFI_SUCCESS - Set the file info successfully.
|
---|
672 | @retval EFI_WRITE_PROTECTED - The disk is write protected.
|
---|
673 | @retval EFI_ACCESS_DENIED - The file is read-only.
|
---|
674 | @retval EFI_DEVICE_ERROR - The OFile is not valid.
|
---|
675 | @retval EFI_UNSUPPORTED - The open file is not a file.
|
---|
676 | - The writing file size is larger than 4GB.
|
---|
677 | @return other - An error occurred when operation the disk.
|
---|
678 |
|
---|
679 | **/
|
---|
680 | EFI_STATUS
|
---|
681 | EFIAPI
|
---|
682 | FatWrite (
|
---|
683 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
684 | IN OUT UINTN *BufferSize,
|
---|
685 | IN VOID *Buffer
|
---|
686 | )
|
---|
687 | ;
|
---|
688 |
|
---|
689 | /**
|
---|
690 |
|
---|
691 | Get the file info.
|
---|
692 |
|
---|
693 | @param FHand - The handle of the file.
|
---|
694 | @param Token - A pointer to the token associated with the transaction.
|
---|
695 |
|
---|
696 | @retval EFI_SUCCESS - Get the file info successfully.
|
---|
697 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
|
---|
698 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
|
---|
699 | @return other - An error occurred when operation the disk.
|
---|
700 |
|
---|
701 | **/
|
---|
702 | EFI_STATUS
|
---|
703 | EFIAPI
|
---|
704 | FatWriteEx (
|
---|
705 | IN EFI_FILE_PROTOCOL *FHand,
|
---|
706 | IN OUT EFI_FILE_IO_TOKEN *Token
|
---|
707 | )
|
---|
708 | ;
|
---|
709 |
|
---|
710 | //
|
---|
711 | // DiskCache.c
|
---|
712 | //
|
---|
713 |
|
---|
714 | /**
|
---|
715 |
|
---|
716 | Initialize the disk cache according to Volume's FatType.
|
---|
717 |
|
---|
718 | @param Volume - FAT file system volume.
|
---|
719 |
|
---|
720 | @retval EFI_SUCCESS - The disk cache is successfully initialized.
|
---|
721 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.
|
---|
722 |
|
---|
723 | **/
|
---|
724 | EFI_STATUS
|
---|
725 | FatInitializeDiskCache (
|
---|
726 | IN FAT_VOLUME *Volume
|
---|
727 | );
|
---|
728 |
|
---|
729 | /**
|
---|
730 |
|
---|
731 | Read BufferSize bytes from the position of Offset into Buffer,
|
---|
732 | or write BufferSize bytes from Buffer into the position of Offset.
|
---|
733 |
|
---|
734 | Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into
|
---|
735 | the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):
|
---|
736 |
|
---|
737 | 1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache
|
---|
738 | page hit, just return the cache page; else update the related cache page and return
|
---|
739 | the right cache page.
|
---|
740 | 2. Access of Data cache (CACHE_DATA):
|
---|
741 | The access data will be divided into UnderRun data, Aligned data and OverRun data;
|
---|
742 | The UnderRun data and OverRun data will be accessed by the Data cache,
|
---|
743 | but the Aligned data will be accessed with disk directly.
|
---|
744 |
|
---|
745 | @param Volume - FAT file system volume.
|
---|
746 | @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.
|
---|
747 | @param IoMode - Indicate the type of disk access.
|
---|
748 | @param Offset - The starting byte offset to read from.
|
---|
749 | @param BufferSize - Size of Buffer.
|
---|
750 | @param Buffer - Buffer containing cache data.
|
---|
751 | @param Task point to task instance.
|
---|
752 |
|
---|
753 | @retval EFI_SUCCESS - The data was accessed correctly.
|
---|
754 | @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.
|
---|
755 | @return Others - An error occurred when accessing cache.
|
---|
756 |
|
---|
757 | **/
|
---|
758 | EFI_STATUS
|
---|
759 | FatAccessCache (
|
---|
760 | IN FAT_VOLUME *Volume,
|
---|
761 | IN CACHE_DATA_TYPE CacheDataType,
|
---|
762 | IN IO_MODE IoMode,
|
---|
763 | IN UINT64 Offset,
|
---|
764 | IN UINTN BufferSize,
|
---|
765 | IN OUT UINT8 *Buffer,
|
---|
766 | IN FAT_TASK *Task
|
---|
767 | );
|
---|
768 |
|
---|
769 | /**
|
---|
770 |
|
---|
771 | Flush all the dirty cache back, include the FAT cache and the Data cache.
|
---|
772 |
|
---|
773 | @param Volume - FAT file system volume.
|
---|
774 | @param Task point to task instance.
|
---|
775 |
|
---|
776 | @retval EFI_SUCCESS - Flush all the dirty cache back successfully
|
---|
777 | @return other - An error occurred when writing the data into the disk
|
---|
778 |
|
---|
779 | **/
|
---|
780 | EFI_STATUS
|
---|
781 | FatVolumeFlushCache (
|
---|
782 | IN FAT_VOLUME *Volume,
|
---|
783 | IN FAT_TASK *Task
|
---|
784 | );
|
---|
785 |
|
---|
786 | //
|
---|
787 | // Flush.c
|
---|
788 | //
|
---|
789 |
|
---|
790 | /**
|
---|
791 |
|
---|
792 | Flush the data associated with an open file.
|
---|
793 | In this implementation, only last Mod/Access time is updated.
|
---|
794 |
|
---|
795 | @param OFile - The open file.
|
---|
796 |
|
---|
797 | @retval EFI_SUCCESS - The OFile is flushed successfully.
|
---|
798 | @return Others - An error occurred when flushing this OFile.
|
---|
799 |
|
---|
800 | **/
|
---|
801 | EFI_STATUS
|
---|
802 | FatOFileFlush (
|
---|
803 | IN FAT_OFILE *OFile
|
---|
804 | );
|
---|
805 |
|
---|
806 | /**
|
---|
807 |
|
---|
808 | Check the references of the OFile.
|
---|
809 | If the OFile (that is checked) is no longer
|
---|
810 | referenced, then it is freed.
|
---|
811 |
|
---|
812 | @param OFile - The OFile to be checked.
|
---|
813 |
|
---|
814 | @retval TRUE - The OFile is not referenced and freed.
|
---|
815 | @retval FALSE - The OFile is kept.
|
---|
816 |
|
---|
817 | **/
|
---|
818 | BOOLEAN
|
---|
819 | FatCheckOFileRef (
|
---|
820 | IN FAT_OFILE *OFile
|
---|
821 | );
|
---|
822 |
|
---|
823 | /**
|
---|
824 |
|
---|
825 | Set the OFile and its child OFile with the error Status
|
---|
826 |
|
---|
827 | @param OFile - The OFile whose permanent error code is to be set.
|
---|
828 | @param Status - Error code to be set.
|
---|
829 |
|
---|
830 | **/
|
---|
831 | VOID
|
---|
832 | FatSetVolumeError (
|
---|
833 | IN FAT_OFILE *OFile,
|
---|
834 | IN EFI_STATUS Status
|
---|
835 | );
|
---|
836 |
|
---|
837 | /**
|
---|
838 |
|
---|
839 | Close the open file instance.
|
---|
840 |
|
---|
841 | @param IFile - Open file instance.
|
---|
842 |
|
---|
843 | @retval EFI_SUCCESS - Closed the file successfully.
|
---|
844 |
|
---|
845 | **/
|
---|
846 | EFI_STATUS
|
---|
847 | FatIFileClose (
|
---|
848 | FAT_IFILE *IFile
|
---|
849 | );
|
---|
850 |
|
---|
851 | /**
|
---|
852 |
|
---|
853 | Set error status for a specific OFile, reference checking the volume.
|
---|
854 | If volume is already marked as invalid, and all resources are freed
|
---|
855 | after reference checking, the file system protocol is uninstalled and
|
---|
856 | the volume structure is freed.
|
---|
857 |
|
---|
858 | @param Volume - the Volume that is to be reference checked and unlocked.
|
---|
859 | @param OFile - the OFile whose permanent error code is to be set.
|
---|
860 | @param EfiStatus - error code to be set.
|
---|
861 | @param Task point to task instance.
|
---|
862 |
|
---|
863 | @retval EFI_SUCCESS - Clean up the volume successfully.
|
---|
864 | @return Others - Cleaning up of the volume is failed.
|
---|
865 |
|
---|
866 | **/
|
---|
867 | EFI_STATUS
|
---|
868 | FatCleanupVolume (
|
---|
869 | IN FAT_VOLUME *Volume,
|
---|
870 | IN FAT_OFILE *OFile,
|
---|
871 | IN EFI_STATUS EfiStatus,
|
---|
872 | IN FAT_TASK *Task
|
---|
873 | );
|
---|
874 |
|
---|
875 | //
|
---|
876 | // FileSpace.c
|
---|
877 | //
|
---|
878 |
|
---|
879 | /**
|
---|
880 |
|
---|
881 | Shrink the end of the open file base on the file size.
|
---|
882 |
|
---|
883 | @param OFile - The open file.
|
---|
884 |
|
---|
885 | @retval EFI_SUCCESS - Shrinked successfully.
|
---|
886 | @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.
|
---|
887 |
|
---|
888 | **/
|
---|
889 | EFI_STATUS
|
---|
890 | FatShrinkEof (
|
---|
891 | IN FAT_OFILE *OFile
|
---|
892 | );
|
---|
893 |
|
---|
894 | /**
|
---|
895 |
|
---|
896 | Grow the end of the open file base on the NewSizeInBytes.
|
---|
897 |
|
---|
898 | @param OFile - The open file.
|
---|
899 | @param NewSizeInBytes - The new size in bytes of the open file.
|
---|
900 |
|
---|
901 | @retval EFI_SUCCESS - The file is grown successfully.
|
---|
902 | @retval EFI_UNSUPPORTED - The file size is larger than 4GB.
|
---|
903 | @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.
|
---|
904 | @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.
|
---|
905 |
|
---|
906 | **/
|
---|
907 | EFI_STATUS
|
---|
908 | FatGrowEof (
|
---|
909 | IN FAT_OFILE *OFile,
|
---|
910 | IN UINT64 NewSizeInBytes
|
---|
911 | );
|
---|
912 |
|
---|
913 | /**
|
---|
914 |
|
---|
915 | Get the size of directory of the open file.
|
---|
916 |
|
---|
917 | @param Volume - The File System Volume.
|
---|
918 | @param Cluster - The Starting cluster.
|
---|
919 |
|
---|
920 | @return The physical size of the file starting at the input cluster, if there is error in the
|
---|
921 | cluster chain, the return value is 0.
|
---|
922 |
|
---|
923 | **/
|
---|
924 | UINTN
|
---|
925 | FatPhysicalDirSize (
|
---|
926 | IN FAT_VOLUME *Volume,
|
---|
927 | IN UINTN Cluster
|
---|
928 | );
|
---|
929 |
|
---|
930 | /**
|
---|
931 |
|
---|
932 | Get the physical size of a file on the disk.
|
---|
933 |
|
---|
934 | @param Volume - The file system volume.
|
---|
935 | @param RealSize - The real size of a file.
|
---|
936 |
|
---|
937 | @return The physical size of a file on the disk.
|
---|
938 |
|
---|
939 | **/
|
---|
940 | UINT64
|
---|
941 | FatPhysicalFileSize (
|
---|
942 | IN FAT_VOLUME *Volume,
|
---|
943 | IN UINTN RealSize
|
---|
944 | );
|
---|
945 |
|
---|
946 | /**
|
---|
947 |
|
---|
948 | Seek OFile to requested position, and calculate the number of
|
---|
949 | consecutive clusters from the position in the file
|
---|
950 |
|
---|
951 | @param OFile - The open file.
|
---|
952 | @param Position - The file's position which will be accessed.
|
---|
953 | @param PosLimit - The maximum length current reading/writing may access
|
---|
954 |
|
---|
955 | @retval EFI_SUCCESS - Set the info successfully.
|
---|
956 | @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.
|
---|
957 |
|
---|
958 | **/
|
---|
959 | EFI_STATUS
|
---|
960 | FatOFilePosition (
|
---|
961 | IN FAT_OFILE *OFile,
|
---|
962 | IN UINTN Position,
|
---|
963 | IN UINTN PosLimit
|
---|
964 | );
|
---|
965 |
|
---|
966 | /**
|
---|
967 |
|
---|
968 | Update the free cluster info of FatInfoSector of the volume.
|
---|
969 |
|
---|
970 | @param Volume - FAT file system volume.
|
---|
971 |
|
---|
972 | **/
|
---|
973 | VOID
|
---|
974 | FatComputeFreeInfo (
|
---|
975 | IN FAT_VOLUME *Volume
|
---|
976 | );
|
---|
977 |
|
---|
978 | //
|
---|
979 | // Init.c
|
---|
980 | //
|
---|
981 |
|
---|
982 | /**
|
---|
983 |
|
---|
984 | Allocates volume structure, detects FAT file system, installs protocol,
|
---|
985 | and initialize cache.
|
---|
986 |
|
---|
987 | @param Handle - The handle of parent device.
|
---|
988 | @param DiskIo - The DiskIo of parent device.
|
---|
989 | @param DiskIo2 - The DiskIo2 of parent device.
|
---|
990 | @param BlockIo - The BlockIo of parent device.
|
---|
991 |
|
---|
992 | @retval EFI_SUCCESS - Allocate a new volume successfully.
|
---|
993 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
|
---|
994 | @return Others - Allocating a new volume failed.
|
---|
995 |
|
---|
996 | **/
|
---|
997 | EFI_STATUS
|
---|
998 | FatAllocateVolume (
|
---|
999 | IN EFI_HANDLE Handle,
|
---|
1000 | IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
---|
1001 | IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
|
---|
1002 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo
|
---|
1003 | );
|
---|
1004 |
|
---|
1005 | /**
|
---|
1006 |
|
---|
1007 | Detects FAT file system on Disk and set relevant fields of Volume.
|
---|
1008 |
|
---|
1009 | @param Volume - The volume structure.
|
---|
1010 |
|
---|
1011 | @retval EFI_SUCCESS - The Fat File System is detected successfully
|
---|
1012 | @retval EFI_UNSUPPORTED - The volume is not FAT file system.
|
---|
1013 | @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.
|
---|
1014 |
|
---|
1015 | **/
|
---|
1016 | EFI_STATUS
|
---|
1017 | FatOpenDevice (
|
---|
1018 | IN OUT FAT_VOLUME *Volume
|
---|
1019 | );
|
---|
1020 |
|
---|
1021 | /**
|
---|
1022 |
|
---|
1023 | Called by FatDriverBindingStop(), Abandon the volume.
|
---|
1024 |
|
---|
1025 | @param Volume - The volume to be abandoned.
|
---|
1026 |
|
---|
1027 | @retval EFI_SUCCESS - Abandoned the volume successfully.
|
---|
1028 | @return Others - Can not uninstall the protocol interfaces.
|
---|
1029 |
|
---|
1030 | **/
|
---|
1031 | EFI_STATUS
|
---|
1032 | FatAbandonVolume (
|
---|
1033 | IN FAT_VOLUME *Volume
|
---|
1034 | );
|
---|
1035 |
|
---|
1036 | //
|
---|
1037 | // Misc.c
|
---|
1038 | //
|
---|
1039 |
|
---|
1040 | /**
|
---|
1041 |
|
---|
1042 | Create the task
|
---|
1043 |
|
---|
1044 | @param IFile - The instance of the open file.
|
---|
1045 | @param Token - A pointer to the token associated with the transaction.
|
---|
1046 |
|
---|
1047 | @return FAT_TASK * - Return the task instance.
|
---|
1048 |
|
---|
1049 | **/
|
---|
1050 | FAT_TASK *
|
---|
1051 | FatCreateTask (
|
---|
1052 | FAT_IFILE *IFile,
|
---|
1053 | EFI_FILE_IO_TOKEN *Token
|
---|
1054 | );
|
---|
1055 |
|
---|
1056 | /**
|
---|
1057 |
|
---|
1058 | Destroy the task.
|
---|
1059 |
|
---|
1060 | @param Task - The task to be destroyed.
|
---|
1061 |
|
---|
1062 | **/
|
---|
1063 | VOID
|
---|
1064 | FatDestroyTask (
|
---|
1065 | FAT_TASK *Task
|
---|
1066 | );
|
---|
1067 |
|
---|
1068 | /**
|
---|
1069 |
|
---|
1070 | Wait all non-blocking requests complete.
|
---|
1071 |
|
---|
1072 | @param IFile - The instance of the open file.
|
---|
1073 |
|
---|
1074 | **/
|
---|
1075 | VOID
|
---|
1076 | FatWaitNonblockingTask (
|
---|
1077 | FAT_IFILE *IFile
|
---|
1078 | );
|
---|
1079 |
|
---|
1080 | /**
|
---|
1081 |
|
---|
1082 | Remove the subtask from subtask list.
|
---|
1083 |
|
---|
1084 | @param Subtask - The subtask to be removed.
|
---|
1085 |
|
---|
1086 | @return LIST_ENTRY * - The next node in the list.
|
---|
1087 |
|
---|
1088 | **/
|
---|
1089 | LIST_ENTRY *
|
---|
1090 | FatDestroySubtask (
|
---|
1091 | FAT_SUBTASK *Subtask
|
---|
1092 | );
|
---|
1093 |
|
---|
1094 | /**
|
---|
1095 |
|
---|
1096 | Execute the task.
|
---|
1097 |
|
---|
1098 | @param IFile - The instance of the open file.
|
---|
1099 | @param Task - The task to be executed.
|
---|
1100 |
|
---|
1101 | @retval EFI_SUCCESS - The task was executed successfully.
|
---|
1102 | @return other - An error occurred when executing the task.
|
---|
1103 |
|
---|
1104 | **/
|
---|
1105 | EFI_STATUS
|
---|
1106 | FatQueueTask (
|
---|
1107 | IN FAT_IFILE *IFile,
|
---|
1108 | IN FAT_TASK *Task
|
---|
1109 | );
|
---|
1110 |
|
---|
1111 | /**
|
---|
1112 |
|
---|
1113 | Set the volume as dirty or not.
|
---|
1114 |
|
---|
1115 | @param Volume - FAT file system volume.
|
---|
1116 | @param IoMode - The access mode.
|
---|
1117 | @param DirtyValue - Set the volume as dirty or not.
|
---|
1118 |
|
---|
1119 | @retval EFI_SUCCESS - Set the new FAT entry value successfully.
|
---|
1120 | @return other - An error occurred when operation the FAT entries.
|
---|
1121 |
|
---|
1122 | **/
|
---|
1123 | EFI_STATUS
|
---|
1124 | FatAccessVolumeDirty (
|
---|
1125 | IN FAT_VOLUME *Volume,
|
---|
1126 | IN IO_MODE IoMode,
|
---|
1127 | IN VOID *DirtyValue
|
---|
1128 | );
|
---|
1129 |
|
---|
1130 | /**
|
---|
1131 |
|
---|
1132 | General disk access function.
|
---|
1133 |
|
---|
1134 | @param Volume - FAT file system volume.
|
---|
1135 | @param IoMode - The access mode (disk read/write or cache access).
|
---|
1136 | @param Offset - The starting byte offset to read from.
|
---|
1137 | @param BufferSize - Size of Buffer.
|
---|
1138 | @param Buffer - Buffer containing read data.
|
---|
1139 | @param Task point to task instance.
|
---|
1140 |
|
---|
1141 | @retval EFI_SUCCESS - The operation is performed successfully.
|
---|
1142 | @retval EFI_VOLUME_CORRUPTED - The access is
|
---|
1143 | @return Others - The status of read/write the disk
|
---|
1144 |
|
---|
1145 | **/
|
---|
1146 | EFI_STATUS
|
---|
1147 | FatDiskIo (
|
---|
1148 | IN FAT_VOLUME *Volume,
|
---|
1149 | IN IO_MODE IoMode,
|
---|
1150 | IN UINT64 Offset,
|
---|
1151 | IN UINTN BufferSize,
|
---|
1152 | IN OUT VOID *Buffer,
|
---|
1153 | IN FAT_TASK *Task
|
---|
1154 | );
|
---|
1155 |
|
---|
1156 | /**
|
---|
1157 |
|
---|
1158 | Lock the volume.
|
---|
1159 |
|
---|
1160 | **/
|
---|
1161 | VOID
|
---|
1162 | FatAcquireLock (
|
---|
1163 | VOID
|
---|
1164 | );
|
---|
1165 |
|
---|
1166 | /**
|
---|
1167 |
|
---|
1168 | Unlock the volume.
|
---|
1169 |
|
---|
1170 | **/
|
---|
1171 | VOID
|
---|
1172 | FatReleaseLock (
|
---|
1173 | VOID
|
---|
1174 | );
|
---|
1175 |
|
---|
1176 | /**
|
---|
1177 |
|
---|
1178 | Lock the volume.
|
---|
1179 | If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
|
---|
1180 | Otherwise, EFI_SUCCESS is returned.
|
---|
1181 |
|
---|
1182 | @retval EFI_SUCCESS - The volume is locked.
|
---|
1183 | @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
|
---|
1184 |
|
---|
1185 | **/
|
---|
1186 | EFI_STATUS
|
---|
1187 | FatAcquireLockOrFail (
|
---|
1188 | VOID
|
---|
1189 | );
|
---|
1190 |
|
---|
1191 | /**
|
---|
1192 |
|
---|
1193 | Free directory entry.
|
---|
1194 |
|
---|
1195 | @param DirEnt - The directory entry to be freed.
|
---|
1196 |
|
---|
1197 | **/
|
---|
1198 | VOID
|
---|
1199 | FatFreeDirEnt (
|
---|
1200 | IN FAT_DIRENT *DirEnt
|
---|
1201 | );
|
---|
1202 |
|
---|
1203 | /**
|
---|
1204 |
|
---|
1205 | Free volume structure (including the contents of directory cache and disk cache).
|
---|
1206 |
|
---|
1207 | @param Volume - The volume structure to be freed.
|
---|
1208 |
|
---|
1209 | **/
|
---|
1210 | VOID
|
---|
1211 | FatFreeVolume (
|
---|
1212 | IN FAT_VOLUME *Volume
|
---|
1213 | );
|
---|
1214 |
|
---|
1215 | /**
|
---|
1216 |
|
---|
1217 | Translate EFI time to FAT time.
|
---|
1218 |
|
---|
1219 | @param ETime - The time of EFI_TIME.
|
---|
1220 | @param FTime - The time of FAT_DATE_TIME.
|
---|
1221 |
|
---|
1222 | **/
|
---|
1223 | VOID
|
---|
1224 | FatEfiTimeToFatTime (
|
---|
1225 | IN EFI_TIME *ETime,
|
---|
1226 | OUT FAT_DATE_TIME *FTime
|
---|
1227 | );
|
---|
1228 |
|
---|
1229 | /**
|
---|
1230 |
|
---|
1231 | Translate Fat time to EFI time.
|
---|
1232 |
|
---|
1233 | @param FTime - The time of FAT_DATE_TIME.
|
---|
1234 | @param ETime - The time of EFI_TIME..
|
---|
1235 |
|
---|
1236 | **/
|
---|
1237 | VOID
|
---|
1238 | FatFatTimeToEfiTime (
|
---|
1239 | IN FAT_DATE_TIME *FTime,
|
---|
1240 | OUT EFI_TIME *ETime
|
---|
1241 | );
|
---|
1242 |
|
---|
1243 | /**
|
---|
1244 |
|
---|
1245 | Get Current FAT time.
|
---|
1246 |
|
---|
1247 | @param FatTime - Current FAT time.
|
---|
1248 |
|
---|
1249 | **/
|
---|
1250 | VOID
|
---|
1251 | FatGetCurrentFatTime (
|
---|
1252 | OUT FAT_DATE_TIME *FatTime
|
---|
1253 | );
|
---|
1254 |
|
---|
1255 | /**
|
---|
1256 |
|
---|
1257 | Check whether a time is valid.
|
---|
1258 |
|
---|
1259 | @param Time - The time of EFI_TIME.
|
---|
1260 |
|
---|
1261 | @retval TRUE - The time is valid.
|
---|
1262 | @retval FALSE - The time is not valid.
|
---|
1263 |
|
---|
1264 | **/
|
---|
1265 | BOOLEAN
|
---|
1266 | FatIsValidTime (
|
---|
1267 | IN EFI_TIME *Time
|
---|
1268 | );
|
---|
1269 |
|
---|
1270 | //
|
---|
1271 | // UnicodeCollation.c
|
---|
1272 | //
|
---|
1273 |
|
---|
1274 | /**
|
---|
1275 | Initialize Unicode Collation support.
|
---|
1276 |
|
---|
1277 | It tries to locate Unicode Collation 2 protocol and matches it with current
|
---|
1278 | platform language code. If for any reason the first attempt fails, it then tries to
|
---|
1279 | use Unicode Collation Protocol.
|
---|
1280 |
|
---|
1281 | @param AgentHandle The handle used to open Unicode Collation (2) protocol.
|
---|
1282 |
|
---|
1283 | @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
|
---|
1284 | @retval Others The Unicode Collation (2) protocol has not been located.
|
---|
1285 |
|
---|
1286 | **/
|
---|
1287 | EFI_STATUS
|
---|
1288 | InitializeUnicodeCollationSupport (
|
---|
1289 | IN EFI_HANDLE AgentHandle
|
---|
1290 | );
|
---|
1291 |
|
---|
1292 | /**
|
---|
1293 | Convert FAT string to unicode string.
|
---|
1294 |
|
---|
1295 | @param FatSize The size of FAT string.
|
---|
1296 | @param Fat The FAT string.
|
---|
1297 | @param String The unicode string.
|
---|
1298 |
|
---|
1299 | @return None.
|
---|
1300 |
|
---|
1301 | **/
|
---|
1302 | VOID
|
---|
1303 | FatFatToStr (
|
---|
1304 | IN UINTN FatSize,
|
---|
1305 | IN CHAR8 *Fat,
|
---|
1306 | OUT CHAR16 *String
|
---|
1307 | );
|
---|
1308 |
|
---|
1309 | /**
|
---|
1310 | Convert unicode string to Fat string.
|
---|
1311 |
|
---|
1312 | @param String The unicode string.
|
---|
1313 | @param FatSize The size of the FAT string.
|
---|
1314 | @param Fat The FAT string.
|
---|
1315 |
|
---|
1316 | @retval TRUE Convert successfully.
|
---|
1317 | @retval FALSE Convert error.
|
---|
1318 |
|
---|
1319 | **/
|
---|
1320 | BOOLEAN
|
---|
1321 | FatStrToFat (
|
---|
1322 | IN CHAR16 *String,
|
---|
1323 | IN UINTN FatSize,
|
---|
1324 | OUT CHAR8 *Fat
|
---|
1325 | );
|
---|
1326 |
|
---|
1327 | /**
|
---|
1328 | Lowercase a string
|
---|
1329 |
|
---|
1330 | @param Str The string which will be lower-cased.
|
---|
1331 |
|
---|
1332 | **/
|
---|
1333 | VOID
|
---|
1334 | FatStrLwr (
|
---|
1335 | IN CHAR16 *Str
|
---|
1336 | );
|
---|
1337 |
|
---|
1338 | /**
|
---|
1339 | Uppercase a string.
|
---|
1340 |
|
---|
1341 | @param Str The string which will be upper-cased.
|
---|
1342 |
|
---|
1343 | **/
|
---|
1344 | VOID
|
---|
1345 | FatStrUpr (
|
---|
1346 | IN CHAR16 *Str
|
---|
1347 | );
|
---|
1348 |
|
---|
1349 | /**
|
---|
1350 | Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
---|
1351 |
|
---|
1352 | @param Str1 A pointer to a Null-terminated Unicode string.
|
---|
1353 | @param Str2 A pointer to a Null-terminated Unicode string.
|
---|
1354 |
|
---|
1355 | @retval 0 S1 is equivalent to S2.
|
---|
1356 | @retval >0 S1 is lexically greater than S2.
|
---|
1357 | @retval <0 S1 is lexically less than S2.
|
---|
1358 | **/
|
---|
1359 | INTN
|
---|
1360 | FatStriCmp (
|
---|
1361 | IN CHAR16 *Str1,
|
---|
1362 | IN CHAR16 *Str2
|
---|
1363 | );
|
---|
1364 |
|
---|
1365 | //
|
---|
1366 | // Open.c
|
---|
1367 | //
|
---|
1368 |
|
---|
1369 | /**
|
---|
1370 |
|
---|
1371 | Open a file for a file name relative to an existing OFile.
|
---|
1372 | The IFile of the newly opened file is passed out.
|
---|
1373 |
|
---|
1374 | @param OFile - The file that serves as a starting reference point.
|
---|
1375 | @param NewIFile - The newly generated IFile instance.
|
---|
1376 | @param FileName - The file name relative to the OFile.
|
---|
1377 | @param OpenMode - Open mode.
|
---|
1378 | @param Attributes - Attributes to set if the file is created.
|
---|
1379 |
|
---|
1380 |
|
---|
1381 | @retval EFI_SUCCESS - Open the file successfully.
|
---|
1382 | @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes
|
---|
1383 | or the file name is not valid.
|
---|
1384 | @retval EFI_NOT_FOUND - Conflicts between dir intention and attribute.
|
---|
1385 | @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.
|
---|
1386 | @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the
|
---|
1387 | open is for read-write fail it.
|
---|
1388 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
|
---|
1389 |
|
---|
1390 | **/
|
---|
1391 | EFI_STATUS
|
---|
1392 | FatOFileOpen (
|
---|
1393 | IN FAT_OFILE *OFile,
|
---|
1394 | OUT FAT_IFILE **NewIFile,
|
---|
1395 | IN CHAR16 *FileName,
|
---|
1396 | IN UINT64 OpenMode,
|
---|
1397 | IN UINT8 Attributes
|
---|
1398 | );
|
---|
1399 |
|
---|
1400 | /**
|
---|
1401 |
|
---|
1402 | Create an Open instance for the existing OFile.
|
---|
1403 | The IFile of the newly opened file is passed out.
|
---|
1404 |
|
---|
1405 | @param OFile - The file that serves as a starting reference point.
|
---|
1406 | @param PtrIFile - The newly generated IFile instance.
|
---|
1407 |
|
---|
1408 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile
|
---|
1409 | @retval EFI_SUCCESS - Create the new IFile for the OFile successfully
|
---|
1410 |
|
---|
1411 | **/
|
---|
1412 | EFI_STATUS
|
---|
1413 | FatAllocateIFile (
|
---|
1414 | IN FAT_OFILE *OFile,
|
---|
1415 | OUT FAT_IFILE **PtrIFile
|
---|
1416 | );
|
---|
1417 |
|
---|
1418 | //
|
---|
1419 | // OpenVolume.c
|
---|
1420 | //
|
---|
1421 |
|
---|
1422 | /**
|
---|
1423 |
|
---|
1424 | Implements Simple File System Protocol interface function OpenVolume().
|
---|
1425 |
|
---|
1426 | @param This - Calling context.
|
---|
1427 | @param File - the Root Directory of the volume.
|
---|
1428 |
|
---|
1429 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
|
---|
1430 | @retval EFI_VOLUME_CORRUPTED - The FAT type is error.
|
---|
1431 | @retval EFI_SUCCESS - Open the volume successfully.
|
---|
1432 |
|
---|
1433 | **/
|
---|
1434 | EFI_STATUS
|
---|
1435 | EFIAPI
|
---|
1436 | FatOpenVolume (
|
---|
1437 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
|
---|
1438 | OUT EFI_FILE_PROTOCOL **File
|
---|
1439 | );
|
---|
1440 |
|
---|
1441 | //
|
---|
1442 | // ReadWrite.c
|
---|
1443 | //
|
---|
1444 |
|
---|
1445 | /**
|
---|
1446 |
|
---|
1447 | This function reads data from a file or writes data to a file.
|
---|
1448 | It uses OFile->PosRem to determine how much data can be accessed in one time.
|
---|
1449 |
|
---|
1450 | @param OFile - The open file.
|
---|
1451 | @param IoMode - Indicate whether the access mode is reading or writing.
|
---|
1452 | @param Position - The position where data will be accessed.
|
---|
1453 | @param DataBufferSize - Size of Buffer.
|
---|
1454 | @param UserBuffer - Buffer containing data.
|
---|
1455 | @param Task point to task instance.
|
---|
1456 |
|
---|
1457 | @retval EFI_SUCCESS - Access the data successfully.
|
---|
1458 | @return other - An error occurred when operating on the disk.
|
---|
1459 |
|
---|
1460 | **/
|
---|
1461 | EFI_STATUS
|
---|
1462 | FatAccessOFile (
|
---|
1463 | IN FAT_OFILE *OFile,
|
---|
1464 | IN IO_MODE IoMode,
|
---|
1465 | IN UINTN Position,
|
---|
1466 | IN UINTN *DataBufferSize,
|
---|
1467 | IN UINT8 *UserBuffer,
|
---|
1468 | IN FAT_TASK *Task
|
---|
1469 | );
|
---|
1470 |
|
---|
1471 | /**
|
---|
1472 |
|
---|
1473 | Expand OFile by appending zero bytes at the end of OFile.
|
---|
1474 |
|
---|
1475 | @param OFile - The open file.
|
---|
1476 | @param ExpandedSize - The number of zero bytes appended at the end of the file.
|
---|
1477 |
|
---|
1478 | @retval EFI_SUCCESS - The file is expanded successfully.
|
---|
1479 | @return other - An error occurred when expanding file.
|
---|
1480 |
|
---|
1481 | **/
|
---|
1482 | EFI_STATUS
|
---|
1483 | FatExpandOFile (
|
---|
1484 | IN FAT_OFILE *OFile,
|
---|
1485 | IN UINT64 ExpandedSize
|
---|
1486 | );
|
---|
1487 |
|
---|
1488 | /**
|
---|
1489 |
|
---|
1490 | Write zero pool from the WritePos to the end of OFile.
|
---|
1491 |
|
---|
1492 | @param OFile - The open file to write zero pool.
|
---|
1493 | @param WritePos - The number of zero bytes written.
|
---|
1494 |
|
---|
1495 | @retval EFI_SUCCESS - Write the zero pool successfully.
|
---|
1496 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.
|
---|
1497 | @return other - An error occurred when writing disk.
|
---|
1498 |
|
---|
1499 | **/
|
---|
1500 | EFI_STATUS
|
---|
1501 | FatWriteZeroPool (
|
---|
1502 | IN FAT_OFILE *OFile,
|
---|
1503 | IN UINTN WritePos
|
---|
1504 | );
|
---|
1505 |
|
---|
1506 | /**
|
---|
1507 |
|
---|
1508 | Truncate the OFile to smaller file size.
|
---|
1509 |
|
---|
1510 | @param OFile - The open file.
|
---|
1511 | @param TruncatedSize - The new file size.
|
---|
1512 |
|
---|
1513 | @retval EFI_SUCCESS - The file is truncated successfully.
|
---|
1514 | @return other - An error occurred when truncating file.
|
---|
1515 |
|
---|
1516 | **/
|
---|
1517 | EFI_STATUS
|
---|
1518 | FatTruncateOFile (
|
---|
1519 | IN FAT_OFILE *OFile,
|
---|
1520 | IN UINTN TruncatedSize
|
---|
1521 | );
|
---|
1522 |
|
---|
1523 | //
|
---|
1524 | // DirectoryManage.c
|
---|
1525 | //
|
---|
1526 |
|
---|
1527 | /**
|
---|
1528 |
|
---|
1529 | Set the OFile's current directory cursor to the list head.
|
---|
1530 |
|
---|
1531 | @param OFile - The directory OFile whose directory cursor is reset.
|
---|
1532 |
|
---|
1533 | **/
|
---|
1534 | VOID
|
---|
1535 | FatResetODirCursor (
|
---|
1536 | IN FAT_OFILE *OFile
|
---|
1537 | );
|
---|
1538 |
|
---|
1539 | /**
|
---|
1540 |
|
---|
1541 | Set the directory's cursor to the next and get the next directory entry.
|
---|
1542 |
|
---|
1543 | @param OFile - The parent OFile.
|
---|
1544 | @param PtrDirEnt - The next directory entry.
|
---|
1545 |
|
---|
1546 | @retval EFI_SUCCESS - We get the next directory entry successfully.
|
---|
1547 | @return other - An error occurred when get next directory entry.
|
---|
1548 |
|
---|
1549 | **/
|
---|
1550 | EFI_STATUS
|
---|
1551 | FatGetNextDirEnt (
|
---|
1552 | IN FAT_OFILE *OFile,
|
---|
1553 | OUT FAT_DIRENT **PtrDirEnt
|
---|
1554 | );
|
---|
1555 |
|
---|
1556 | /**
|
---|
1557 |
|
---|
1558 | Remove this directory entry node from the list of directory entries and hash table.
|
---|
1559 |
|
---|
1560 | @param OFile - The parent OFile.
|
---|
1561 | @param DirEnt - The directory entry to be removed.
|
---|
1562 |
|
---|
1563 | @retval EFI_SUCCESS - The directory entry is successfully removed.
|
---|
1564 | @return other - An error occurred when removing the directory entry.
|
---|
1565 |
|
---|
1566 | **/
|
---|
1567 | EFI_STATUS
|
---|
1568 | FatRemoveDirEnt (
|
---|
1569 | IN FAT_OFILE *OFile,
|
---|
1570 | IN FAT_DIRENT *DirEnt
|
---|
1571 | );
|
---|
1572 |
|
---|
1573 | /**
|
---|
1574 |
|
---|
1575 | Save the directory entry to disk.
|
---|
1576 |
|
---|
1577 | @param OFile - The parent OFile which needs to update.
|
---|
1578 | @param DirEnt - The directory entry to be saved.
|
---|
1579 |
|
---|
1580 | @retval EFI_SUCCESS - Store the directory entry successfully.
|
---|
1581 | @return other - An error occurred when writing the directory entry.
|
---|
1582 |
|
---|
1583 | **/
|
---|
1584 | EFI_STATUS
|
---|
1585 | FatStoreDirEnt (
|
---|
1586 | IN FAT_OFILE *OFile,
|
---|
1587 | IN FAT_DIRENT *DirEnt
|
---|
1588 | );
|
---|
1589 |
|
---|
1590 | /**
|
---|
1591 |
|
---|
1592 | Create a directory entry in the parent OFile.
|
---|
1593 |
|
---|
1594 | @param OFile - The parent OFile.
|
---|
1595 | @param FileName - The filename of the newly-created directory entry.
|
---|
1596 | @param Attributes - The attribute of the newly-created directory entry.
|
---|
1597 | @param PtrDirEnt - The pointer to the newly-created directory entry.
|
---|
1598 |
|
---|
1599 | @retval EFI_SUCCESS - The directory entry is successfully created.
|
---|
1600 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.
|
---|
1601 | @return other - An error occurred when creating the directory entry.
|
---|
1602 |
|
---|
1603 | **/
|
---|
1604 | EFI_STATUS
|
---|
1605 | FatCreateDirEnt (
|
---|
1606 | IN FAT_OFILE *OFile,
|
---|
1607 | IN CHAR16 *FileName,
|
---|
1608 | IN UINT8 Attributes,
|
---|
1609 | OUT FAT_DIRENT **PtrDirEnt
|
---|
1610 | );
|
---|
1611 |
|
---|
1612 | /**
|
---|
1613 |
|
---|
1614 | Determine whether the directory entry is "." or ".." entry.
|
---|
1615 |
|
---|
1616 | @param DirEnt - The corresponding directory entry.
|
---|
1617 |
|
---|
1618 | @retval TRUE - The directory entry is "." or ".." directory entry
|
---|
1619 | @retval FALSE - The directory entry is not "." or ".." directory entry
|
---|
1620 |
|
---|
1621 | **/
|
---|
1622 | BOOLEAN
|
---|
1623 | FatIsDotDirEnt (
|
---|
1624 | IN FAT_DIRENT *DirEnt
|
---|
1625 | );
|
---|
1626 |
|
---|
1627 | /**
|
---|
1628 |
|
---|
1629 | Set the OFile's cluster and size info in its directory entry.
|
---|
1630 |
|
---|
1631 | @param OFile - The corresponding OFile.
|
---|
1632 |
|
---|
1633 | **/
|
---|
1634 | VOID
|
---|
1635 | FatUpdateDirEntClusterSizeInfo (
|
---|
1636 | IN FAT_OFILE *OFile
|
---|
1637 | );
|
---|
1638 |
|
---|
1639 | /**
|
---|
1640 |
|
---|
1641 | Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.
|
---|
1642 |
|
---|
1643 | @param DirEnt1 - The destination directory entry.
|
---|
1644 | @param DirEnt2 - The source directory entry.
|
---|
1645 |
|
---|
1646 | **/
|
---|
1647 | VOID
|
---|
1648 | FatCloneDirEnt (
|
---|
1649 | IN FAT_DIRENT *DirEnt1,
|
---|
1650 | IN FAT_DIRENT *DirEnt2
|
---|
1651 | );
|
---|
1652 |
|
---|
1653 | /**
|
---|
1654 |
|
---|
1655 | Get the directory entry's info into Buffer.
|
---|
1656 |
|
---|
1657 | @param Volume - FAT file system volume.
|
---|
1658 | @param DirEnt - The corresponding directory entry.
|
---|
1659 | @param BufferSize - Size of Buffer.
|
---|
1660 | @param Buffer - Buffer containing file info.
|
---|
1661 |
|
---|
1662 | @retval EFI_SUCCESS - Get the file info successfully.
|
---|
1663 | @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.
|
---|
1664 |
|
---|
1665 | **/
|
---|
1666 | EFI_STATUS
|
---|
1667 | FatGetDirEntInfo (
|
---|
1668 | IN FAT_VOLUME *Volume,
|
---|
1669 | IN FAT_DIRENT *DirEnt,
|
---|
1670 | IN OUT UINTN *BufferSize,
|
---|
1671 | OUT VOID *Buffer
|
---|
1672 | );
|
---|
1673 |
|
---|
1674 | /**
|
---|
1675 |
|
---|
1676 | Open the directory entry to get the OFile.
|
---|
1677 |
|
---|
1678 | @param Parent - The parent OFile.
|
---|
1679 | @param DirEnt - The directory entry to be opened.
|
---|
1680 |
|
---|
1681 | @retval EFI_SUCCESS - The directory entry is successfully opened.
|
---|
1682 | @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.
|
---|
1683 | @return other - An error occurred when opening the directory entry.
|
---|
1684 |
|
---|
1685 | **/
|
---|
1686 | EFI_STATUS
|
---|
1687 | FatOpenDirEnt (
|
---|
1688 | IN FAT_OFILE *OFile,
|
---|
1689 | IN FAT_DIRENT *DirEnt
|
---|
1690 | );
|
---|
1691 |
|
---|
1692 | /**
|
---|
1693 |
|
---|
1694 | Create "." and ".." directory entries in the newly-created parent OFile.
|
---|
1695 |
|
---|
1696 | @param OFile - The parent OFile.
|
---|
1697 |
|
---|
1698 | @retval EFI_SUCCESS - The dot directory entries are successfully created.
|
---|
1699 | @return other - An error occurred when creating the directory entry.
|
---|
1700 |
|
---|
1701 | **/
|
---|
1702 | EFI_STATUS
|
---|
1703 | FatCreateDotDirEnts (
|
---|
1704 | IN FAT_OFILE *OFile
|
---|
1705 | );
|
---|
1706 |
|
---|
1707 | /**
|
---|
1708 |
|
---|
1709 | Close the directory entry and free the OFile.
|
---|
1710 |
|
---|
1711 | @param DirEnt - The directory entry to be closed.
|
---|
1712 |
|
---|
1713 | **/
|
---|
1714 | VOID
|
---|
1715 | FatCloseDirEnt (
|
---|
1716 | IN FAT_DIRENT *DirEnt
|
---|
1717 | );
|
---|
1718 |
|
---|
1719 | /**
|
---|
1720 |
|
---|
1721 | Traverse filename and open all OFiles that can be opened.
|
---|
1722 | Update filename pointer to the component that can't be opened.
|
---|
1723 | If more than one name component remains, returns an error;
|
---|
1724 | otherwise, return the remaining name component so that the caller might choose to create it.
|
---|
1725 |
|
---|
1726 | @param PtrOFile - As input, the reference OFile; as output, the located OFile.
|
---|
1727 | @param FileName - The file name relevant to the OFile.
|
---|
1728 | @param Attributes - The attribute of the destination OFile.
|
---|
1729 | @param NewFileName - The remaining file name.
|
---|
1730 |
|
---|
1731 | @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one
|
---|
1732 | components within the name left (this means the name can
|
---|
1733 | not be created either).
|
---|
1734 | @retval EFI_INVALID_PARAMETER - The parameter is not valid.
|
---|
1735 | @retval EFI_SUCCESS - Open the file successfully.
|
---|
1736 | @return other - An error occurred when locating the OFile.
|
---|
1737 |
|
---|
1738 | **/
|
---|
1739 | EFI_STATUS
|
---|
1740 | FatLocateOFile (
|
---|
1741 | IN OUT FAT_OFILE **PtrOFile,
|
---|
1742 | IN CHAR16 *FileName,
|
---|
1743 | IN UINT8 Attributes,
|
---|
1744 | OUT CHAR16 *NewFileName
|
---|
1745 | );
|
---|
1746 |
|
---|
1747 | /**
|
---|
1748 |
|
---|
1749 | Get the directory entry for the volume.
|
---|
1750 |
|
---|
1751 | @param Volume - FAT file system volume.
|
---|
1752 | @param Name - The file name of the volume.
|
---|
1753 |
|
---|
1754 | @retval EFI_SUCCESS - Update the volume with the directory entry successfully.
|
---|
1755 | @return others - An error occurred when getting volume label.
|
---|
1756 |
|
---|
1757 | **/
|
---|
1758 | EFI_STATUS
|
---|
1759 | FatGetVolumeEntry (
|
---|
1760 | IN FAT_VOLUME *Volume,
|
---|
1761 | IN CHAR16 *Name
|
---|
1762 | );
|
---|
1763 |
|
---|
1764 | /**
|
---|
1765 |
|
---|
1766 | Set the relevant directory entry into disk for the volume.
|
---|
1767 |
|
---|
1768 | @param Volume - FAT file system volume.
|
---|
1769 | @param Name - The new file name of the volume.
|
---|
1770 |
|
---|
1771 | @retval EFI_SUCCESS - Update the Volume successfully.
|
---|
1772 | @retval EFI_UNSUPPORTED - The input label is not a valid volume label.
|
---|
1773 | @return other - An error occurred when setting volume label.
|
---|
1774 |
|
---|
1775 | **/
|
---|
1776 | EFI_STATUS
|
---|
1777 | FatSetVolumeEntry (
|
---|
1778 | IN FAT_VOLUME *Volume,
|
---|
1779 | IN CHAR16 *Name
|
---|
1780 | );
|
---|
1781 |
|
---|
1782 | //
|
---|
1783 | // Hash.c
|
---|
1784 | //
|
---|
1785 |
|
---|
1786 | /**
|
---|
1787 |
|
---|
1788 | Search the long name hash table for the directory entry.
|
---|
1789 |
|
---|
1790 | @param ODir - The directory to be searched.
|
---|
1791 | @param LongNameString - The long name string to search.
|
---|
1792 |
|
---|
1793 | @return The previous long name hash node of the directory entry.
|
---|
1794 |
|
---|
1795 | **/
|
---|
1796 | FAT_DIRENT **
|
---|
1797 | FatLongNameHashSearch (
|
---|
1798 | IN FAT_ODIR *ODir,
|
---|
1799 | IN CHAR16 *LongNameString
|
---|
1800 | );
|
---|
1801 |
|
---|
1802 | /**
|
---|
1803 |
|
---|
1804 | Search the short name hash table for the directory entry.
|
---|
1805 |
|
---|
1806 | @param ODir - The directory to be searched.
|
---|
1807 | @param ShortNameString - The short name string to search.
|
---|
1808 |
|
---|
1809 | @return The previous short name hash node of the directory entry.
|
---|
1810 |
|
---|
1811 | **/
|
---|
1812 | FAT_DIRENT **
|
---|
1813 | FatShortNameHashSearch (
|
---|
1814 | IN FAT_ODIR *ODir,
|
---|
1815 | IN CHAR8 *ShortNameString
|
---|
1816 | );
|
---|
1817 |
|
---|
1818 | /**
|
---|
1819 |
|
---|
1820 | Insert directory entry to hash table.
|
---|
1821 |
|
---|
1822 | @param ODir - The parent directory.
|
---|
1823 | @param DirEnt - The directory entry node.
|
---|
1824 |
|
---|
1825 | **/
|
---|
1826 | VOID
|
---|
1827 | FatInsertToHashTable (
|
---|
1828 | IN FAT_ODIR *ODir,
|
---|
1829 | IN FAT_DIRENT *DirEnt
|
---|
1830 | );
|
---|
1831 |
|
---|
1832 | /**
|
---|
1833 |
|
---|
1834 | Delete directory entry from hash table.
|
---|
1835 |
|
---|
1836 | @param ODir - The parent directory.
|
---|
1837 | @param DirEnt - The directory entry node.
|
---|
1838 |
|
---|
1839 | **/
|
---|
1840 | VOID
|
---|
1841 | FatDeleteFromHashTable (
|
---|
1842 | IN FAT_ODIR *ODir,
|
---|
1843 | IN FAT_DIRENT *DirEnt
|
---|
1844 | );
|
---|
1845 |
|
---|
1846 | //
|
---|
1847 | // FileName.c
|
---|
1848 | //
|
---|
1849 |
|
---|
1850 | /**
|
---|
1851 |
|
---|
1852 | This function checks whether the input FileName is a valid 8.3 short name.
|
---|
1853 | If the input FileName is a valid 8.3, the output is the 8.3 short name;
|
---|
1854 | otherwise, the output is the base tag of 8.3 short name.
|
---|
1855 |
|
---|
1856 | @param FileName - The input unicode filename.
|
---|
1857 | @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.
|
---|
1858 |
|
---|
1859 | @retval TRUE - The input unicode filename is a valid 8.3 short name.
|
---|
1860 | @retval FALSE - The input unicode filename is not a valid 8.3 short name.
|
---|
1861 |
|
---|
1862 | **/
|
---|
1863 | BOOLEAN
|
---|
1864 | FatCheckIs8Dot3Name (
|
---|
1865 | IN CHAR16 *FileName,
|
---|
1866 | OUT CHAR8 *File8Dot3Name
|
---|
1867 | );
|
---|
1868 |
|
---|
1869 | /**
|
---|
1870 |
|
---|
1871 | This function generates 8Dot3 name from user specified name for a newly created file.
|
---|
1872 |
|
---|
1873 | @param Parent - The parent directory.
|
---|
1874 | @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.
|
---|
1875 |
|
---|
1876 | **/
|
---|
1877 | VOID
|
---|
1878 | FatCreate8Dot3Name (
|
---|
1879 | IN FAT_OFILE *Parent,
|
---|
1880 | IN FAT_DIRENT *DirEnt
|
---|
1881 | );
|
---|
1882 |
|
---|
1883 | /**
|
---|
1884 |
|
---|
1885 | Convert the ascii fat name to the unicode string and strip trailing spaces,
|
---|
1886 | and if necessary, convert the unicode string to lower case.
|
---|
1887 |
|
---|
1888 | @param FatName - The Char8 string needs to be converted.
|
---|
1889 | @param Len - The length of the fat name.
|
---|
1890 | @param LowerCase - Indicate whether to convert the string to lower case.
|
---|
1891 | @param Str - The result of the conversion.
|
---|
1892 |
|
---|
1893 | **/
|
---|
1894 | VOID
|
---|
1895 | FatNameToStr (
|
---|
1896 | IN CHAR8 *FatName,
|
---|
1897 | IN UINTN Len,
|
---|
1898 | IN UINTN LowerCase,
|
---|
1899 | IN CHAR16 *Str
|
---|
1900 | );
|
---|
1901 |
|
---|
1902 | /**
|
---|
1903 |
|
---|
1904 | Set the caseflag value for the directory entry.
|
---|
1905 |
|
---|
1906 | @param DirEnt - The logical directory entry whose caseflag value is to be set.
|
---|
1907 |
|
---|
1908 | **/
|
---|
1909 | VOID
|
---|
1910 | FatSetCaseFlag (
|
---|
1911 | IN FAT_DIRENT *DirEnt
|
---|
1912 | );
|
---|
1913 |
|
---|
1914 | /**
|
---|
1915 |
|
---|
1916 | Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.
|
---|
1917 |
|
---|
1918 | @param DirEnt - The corresponding directory entry.
|
---|
1919 | @param FileString - The output Unicode file name.
|
---|
1920 | @param FileStringMax The max length of FileString.
|
---|
1921 |
|
---|
1922 | **/
|
---|
1923 | VOID
|
---|
1924 | FatGetFileNameViaCaseFlag (
|
---|
1925 | IN FAT_DIRENT *DirEnt,
|
---|
1926 | IN OUT CHAR16 *FileString,
|
---|
1927 | IN UINTN FileStringMax
|
---|
1928 | );
|
---|
1929 |
|
---|
1930 | /**
|
---|
1931 |
|
---|
1932 | Get the Check sum for a short name.
|
---|
1933 |
|
---|
1934 | @param ShortNameString - The short name for a file.
|
---|
1935 |
|
---|
1936 | @retval Sum - UINT8 checksum.
|
---|
1937 |
|
---|
1938 | **/
|
---|
1939 | UINT8
|
---|
1940 | FatCheckSum (
|
---|
1941 | IN CHAR8 *ShortNameString
|
---|
1942 | );
|
---|
1943 |
|
---|
1944 | /**
|
---|
1945 |
|
---|
1946 | Takes Path as input, returns the next name component
|
---|
1947 | in Name, and returns the position after Name (e.g., the
|
---|
1948 | start of the next name component)
|
---|
1949 |
|
---|
1950 | @param Path - The path of one file.
|
---|
1951 | @param Name - The next name component in Path.
|
---|
1952 |
|
---|
1953 | The position after Name in the Path
|
---|
1954 |
|
---|
1955 | **/
|
---|
1956 | CHAR16 *
|
---|
1957 | FatGetNextNameComponent (
|
---|
1958 | IN CHAR16 *Path,
|
---|
1959 | OUT CHAR16 *Name
|
---|
1960 | );
|
---|
1961 |
|
---|
1962 | /**
|
---|
1963 |
|
---|
1964 | Check whether the IFileName is valid long file name. If the IFileName is a valid
|
---|
1965 | long file name, then we trim the possible leading blanks and leading/trailing dots.
|
---|
1966 | the trimmed filename is stored in OutputFileName
|
---|
1967 |
|
---|
1968 | @param InputFileName - The input file name.
|
---|
1969 | @param OutputFileName - The output file name.
|
---|
1970 |
|
---|
1971 | @retval TRUE - The InputFileName is a valid long file name.
|
---|
1972 | @retval FALSE - The InputFileName is not a valid long file name.
|
---|
1973 |
|
---|
1974 | **/
|
---|
1975 | BOOLEAN
|
---|
1976 | FatFileNameIsValid (
|
---|
1977 | IN CHAR16 *InputFileName,
|
---|
1978 | OUT CHAR16 *OutputFileName
|
---|
1979 | );
|
---|
1980 |
|
---|
1981 | //
|
---|
1982 | // DirectoryCache.c
|
---|
1983 | //
|
---|
1984 |
|
---|
1985 | /**
|
---|
1986 |
|
---|
1987 | Discard the directory structure when an OFile will be freed.
|
---|
1988 | Volume will cache this directory if the OFile does not represent a deleted file.
|
---|
1989 |
|
---|
1990 | @param OFile - The OFile whose directory structure is to be discarded.
|
---|
1991 |
|
---|
1992 | **/
|
---|
1993 | VOID
|
---|
1994 | FatDiscardODir (
|
---|
1995 | IN FAT_OFILE *OFile
|
---|
1996 | );
|
---|
1997 |
|
---|
1998 | /**
|
---|
1999 |
|
---|
2000 | Request the directory structure when an OFile is newly generated.
|
---|
2001 | If the directory structure is cached by volume, then just return this directory;
|
---|
2002 | Otherwise, allocate a new one for OFile.
|
---|
2003 |
|
---|
2004 | @param OFile - The OFile which requests directory structure.
|
---|
2005 |
|
---|
2006 | **/
|
---|
2007 | VOID
|
---|
2008 | FatRequestODir (
|
---|
2009 | IN FAT_OFILE *OFile
|
---|
2010 | );
|
---|
2011 |
|
---|
2012 | /**
|
---|
2013 |
|
---|
2014 | Clean up all the cached directory structures when the volume is going to be abandoned.
|
---|
2015 |
|
---|
2016 | @param Volume - FAT file system volume.
|
---|
2017 |
|
---|
2018 | **/
|
---|
2019 | VOID
|
---|
2020 | FatCleanupODirCache (
|
---|
2021 | IN FAT_VOLUME *Volume
|
---|
2022 | );
|
---|
2023 |
|
---|
2024 | //
|
---|
2025 | // Global Variables
|
---|
2026 | //
|
---|
2027 | extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
|
---|
2028 | extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
|
---|
2029 | extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
|
---|
2030 | extern EFI_LOCK FatFsLock;
|
---|
2031 | extern EFI_LOCK FatTaskLock;
|
---|
2032 | extern EFI_FILE_PROTOCOL FatFileInterface;
|
---|
2033 |
|
---|
2034 | #endif
|
---|