]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Misc.c
3 Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
4 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
);
144 FatAcquireLockOrFail (
152 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
153 Otherwise, EFI_SUCCESS is returned.
161 EFI_SUCCESS - The volume is locked.
162 EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
166 return EfiAcquireLockOrFail (&FatFsLock
);
189 EfiReleaseLock (&FatFsLock
);
194 IN FAT_DIRENT
*DirEnt
200 Free directory entry.
204 DirEnt - The directory entry to be freed.
212 if (DirEnt
->FileString
!= NULL
) {
213 FreePool (DirEnt
->FileString
);
221 IN FAT_VOLUME
*Volume
227 Free volume structure (including the contents of directory cache and disk cache).
231 Volume - The volume structure to be freed.
242 if (Volume
->CacheBuffer
!= NULL
) {
243 FreePool (Volume
->CacheBuffer
);
246 // Free directory cache
248 FatCleanupODirCache (Volume
);
253 FatEfiTimeToFatTime (
255 OUT FAT_DATE_TIME
*FTime
261 Translate EFI time to FAT time.
265 ETime - The time of EFI_TIME.
266 FTime - The time of FAT_DATE_TIME.
275 // ignores timezone info in source ETime
277 if (ETime
->Year
> 1980) {
278 FTime
->Date
.Year
= (UINT16
) (ETime
->Year
- 1980);
281 if (ETime
->Year
>= 1980 + FAT_MAX_YEAR_FROM_1980
) {
282 FTime
->Date
.Year
= FAT_MAX_YEAR_FROM_1980
;
285 FTime
->Date
.Month
= ETime
->Month
;
286 FTime
->Date
.Day
= ETime
->Day
;
287 FTime
->Time
.Hour
= ETime
->Hour
;
288 FTime
->Time
.Minute
= ETime
->Minute
;
289 FTime
->Time
.DoubleSecond
= (UINT16
) (ETime
->Second
/ 2);
293 FatFatTimeToEfiTime (
294 IN FAT_DATE_TIME
*FTime
,
301 Translate Fat time to EFI time.
305 FTime - The time of FAT_DATE_TIME.
306 ETime - The time of EFI_TIME.
314 ETime
->Year
= (UINT16
) (FTime
->Date
.Year
+ 1980);
315 ETime
->Month
= (UINT8
) FTime
->Date
.Month
;
316 ETime
->Day
= (UINT8
) FTime
->Date
.Day
;
317 ETime
->Hour
= (UINT8
) FTime
->Time
.Hour
;
318 ETime
->Minute
= (UINT8
) FTime
->Time
.Minute
;
319 ETime
->Second
= (UINT8
) (FTime
->Time
.DoubleSecond
* 2);
320 ETime
->Nanosecond
= 0;
321 ETime
->TimeZone
= EFI_UNSPECIFIED_TIMEZONE
;
326 FatGetCurrentFatTime (
327 OUT FAT_DATE_TIME
*FatNow
333 Get Current FAT time.
337 FatNow - Current FAT time.
346 gRT
->GetTime (&Now
, NULL
);
347 FatEfiTimeToFatTime (&Now
, FatNow
);
358 Check whether a time is valid.
362 Time - The time of EFI_TIME.
366 TRUE - The time is valid.
367 FALSE - The time is not valid.
371 static UINT8 MonthDays
[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
378 // Check the fields for range problems
379 // Fat can only support from 1980
381 if (Time
->Year
< 1980 ||
389 Time
->Nanosecond
> 999999999
396 // Perform a more specific check of the day of the month
398 Day
= MonthDays
[Time
->Month
- 1];
399 if (Time
->Month
== 2 && IS_LEAP_YEAR (Time
->Year
)) {
402 // 1 extra day this month
405 if (Time
->Day
> Day
) {