]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Misc.c
3 Copyright (c) 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Miscellaneous functions
28 FatAccessVolumeDirty (
29 IN FAT_VOLUME
*Volume
,
37 Set the volume as dirty or not
41 Volume - FAT file system volume.
42 IoMode - The access mode.
43 DirtyValue - Set the volume as dirty or not.
47 EFI_SUCCESS - Set the new FAT entry value sucessfully.
48 other - An error occurred when operation the FAT entries.
54 WriteCount
= Volume
->FatEntrySize
;
55 return FatDiskIo (Volume
, IoMode
, Volume
->FatPos
+ WriteCount
, WriteCount
, DirtyValue
);
60 IN FAT_VOLUME
*Volume
,
70 General disk access function
74 Volume - FAT file system volume.
75 IoMode - The access mode (disk read/write or cache access).
76 Offset - The starting byte offset to read from.
77 BufferSize - Size of Buffer.
78 Buffer - Buffer containing read data.
82 EFI_SUCCESS - The operation is performed successfully.
83 EFI_VOLUME_CORRUPTED - The accesss is
84 Others - The status of read/write the disk
89 EFI_DISK_IO_PROTOCOL
*DiskIo
;
90 EFI_DISK_READ IoFunction
;
93 // Verify the IO is in devices range
95 Status
= EFI_VOLUME_CORRUPTED
;
96 if (Offset
+ BufferSize
<= Volume
->VolumeSize
) {
97 if (CACHE_ENABLED (IoMode
)) {
101 Status
= FatAccessCache (Volume
, CACHE_TYPE (IoMode
), RAW_ACCESS (IoMode
), Offset
, BufferSize
, Buffer
);
104 // Access disk directly
106 DiskIo
= Volume
->DiskIo
;
107 IoFunction
= (IoMode
== READ_DISK
) ? DiskIo
->ReadDisk
: DiskIo
->WriteDisk
;
108 Status
= IoFunction (DiskIo
, Volume
->MediaId
, Offset
, BufferSize
, Buffer
);
112 if (EFI_ERROR (Status
)) {
113 Volume
->DiskError
= TRUE
;
114 DEBUG ((EFI_D_INFO
, "FatDiskIo: error %r\n", Status
));
140 EfiAcquireLock (&FatFsLock
);
151 Get the locking status of the volume.
159 TRUE - The volume is locked.
160 FALSE - The volume is not locked.
164 return (BOOLEAN
) (FatFsLock
.Lock
);
187 EfiReleaseLock (&FatFsLock
);
192 IN FAT_DIRENT
*DirEnt
198 Free directory entry.
202 DirEnt - The directory entry to be freed.
210 if (DirEnt
->FileString
!= NULL
) {
211 FreePool (DirEnt
->FileString
);
219 IN FAT_VOLUME
*Volume
225 Free volume structure (including the contents of directory cache and disk cache).
229 Volume - The volume structure to be freed.
240 if (Volume
->CacheBuffer
!= NULL
) {
241 FreePool (Volume
->CacheBuffer
);
244 // Free directory cache
246 FatCleanupODirCache (Volume
);
251 FatEfiTimeToFatTime (
253 OUT FAT_DATE_TIME
*FTime
259 Translate EFI time to FAT time.
263 ETime - The time of EFI_TIME.
264 FTime - The time of FAT_DATE_TIME.
273 // ignores timezone info in source ETime
275 if (ETime
->Year
> 1980) {
276 FTime
->Date
.Year
= (UINT16
) (ETime
->Year
- 1980);
279 if (ETime
->Year
>= 1980 + FAT_MAX_YEAR_FROM_1980
) {
280 FTime
->Date
.Year
= FAT_MAX_YEAR_FROM_1980
;
283 FTime
->Date
.Month
= ETime
->Month
;
284 FTime
->Date
.Day
= ETime
->Day
;
285 FTime
->Time
.Hour
= ETime
->Hour
;
286 FTime
->Time
.Minute
= ETime
->Minute
;
287 FTime
->Time
.DoubleSecond
= (UINT16
) (ETime
->Second
/ 2);
291 FatFatTimeToEfiTime (
292 IN FAT_DATE_TIME
*FTime
,
299 Translate Fat time to EFI time.
303 FTime - The time of FAT_DATE_TIME.
304 ETime - The time of EFI_TIME.
312 ETime
->Year
= (UINT16
) (FTime
->Date
.Year
+ 1980);
313 ETime
->Month
= (UINT8
) FTime
->Date
.Month
;
314 ETime
->Day
= (UINT8
) FTime
->Date
.Day
;
315 ETime
->Hour
= (UINT8
) FTime
->Time
.Hour
;
316 ETime
->Minute
= (UINT8
) FTime
->Time
.Minute
;
317 ETime
->Second
= (UINT8
) (FTime
->Time
.DoubleSecond
* 2);
318 ETime
->Nanosecond
= 0;
319 ETime
->TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
324 FatGetCurrentFatTime (
325 OUT FAT_DATE_TIME
*FatNow
331 Get Current FAT time.
335 FatNow - Current FAT time.
344 gRT
->GetTime (&Now
, NULL
);
345 FatEfiTimeToFatTime (&Now
, FatNow
);
356 Check whether a time is valid.
360 Time - The time of EFI_TIME.
364 TRUE - The time is valid.
365 FALSE - The time is not valid.
369 static UINT8 MonthDays
[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
376 // Check the fields for range problems
377 // Fat can only support from 1980
379 if (Time
->Year
< 1980 ||
387 Time
->Nanosecond
> 999999999
394 // Perform a more specific check of the day of the month
396 Day
= MonthDays
[Time
->Month
- 1];
397 if (Time
->Month
== 2 && IS_LEAP_YEAR (Time
->Year
)) {
400 // 1 extra day this month
403 if (Time
->Day
> Day
) {