mirror of https://github.com/acidanthera/audk.git
FatPkg: Adds support for read-only mode
Implements gEfiFatPkgTokenSpaceGuid token space and adds token which disables write operations. By default driver still supports read-write mode Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com>
This commit is contained in:
parent
30afd72eaf
commit
ba02e8cc6c
|
@ -44,7 +44,7 @@ FatDelete (
|
|||
//
|
||||
// If the file is read-only, then don't delete it
|
||||
//
|
||||
if (IFile->ReadOnly) {
|
||||
if (IFile->ReadOnly || FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
Status = EFI_WRITE_PROTECTED;
|
||||
goto Done;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,10 @@ FatStoreDirEnt (
|
|||
UINT8 EntryCount;
|
||||
UINT8 LfnOrdinal;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
EntryPos = DirEnt->EntryPos;
|
||||
EntryCount = DirEnt->EntryCount;
|
||||
//
|
||||
|
@ -709,6 +713,9 @@ FatExpandODir (
|
|||
IN FAT_OFILE *OFile
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
return FatExpandOFile (OFile, OFile->FileSize + OFile->Volume->ClusterSize);
|
||||
}
|
||||
|
||||
|
@ -954,6 +961,10 @@ FatSetVolumeEntry (
|
|||
FAT_DIRENT LabelDirEnt;
|
||||
FAT_OFILE *Root;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
Root = Volume->Root;
|
||||
Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
|
||||
if (EFI_ERROR (Status)) {
|
||||
|
@ -1001,6 +1012,10 @@ FatCreateDotDirEnts (
|
|||
EFI_STATUS Status;
|
||||
FAT_DIRENT *DirEnt;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
Status = FatExpandODir (OFile);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
|
@ -1048,6 +1063,10 @@ FatCreateDirEnt (
|
|||
FAT_ODIR *ODir;
|
||||
EFI_STATUS Status;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
ASSERT (OFile != NULL);
|
||||
ODir = OFile->ODir;
|
||||
ASSERT (ODir != NULL);
|
||||
|
@ -1105,6 +1124,10 @@ FatRemoveDirEnt (
|
|||
{
|
||||
FAT_ODIR *ODir;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
ODir = OFile->ODir;
|
||||
if (ODir->CurrentCursor == &DirEnt->Link) {
|
||||
//
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
FatPkg/FatPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
UefiRuntimeServicesTableLib
|
||||
|
@ -82,6 +83,7 @@
|
|||
gEfiUnicodeCollation2ProtocolGuid ## TO_START
|
||||
|
||||
[Pcd]
|
||||
gEfiFatPkgTokenSpaceGuid.PcdFatReadOnlyMode ## CONSUMES
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLang ## SOMETIMES_CONSUMES
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## SOMETIMES_CONSUMES
|
||||
[UserExtensions.TianoCore."ExtraFiles"]
|
||||
|
|
|
@ -362,6 +362,10 @@ FatShrinkEof (
|
|||
UINTN Cluster;
|
||||
UINTN LastCluster;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
Volume = OFile->Volume;
|
||||
ASSERT_VOLUME_LOCKED (Volume);
|
||||
|
||||
|
@ -440,6 +444,10 @@ FatGrowEof (
|
|||
UINTN NewCluster;
|
||||
UINTN ClusterCount;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
//
|
||||
// For FAT file system, the max file is 4GB.
|
||||
//
|
||||
|
|
|
@ -35,6 +35,10 @@ FatFlushEx (
|
|||
EFI_STATUS Status;
|
||||
FAT_TASK *Task;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
IFile = IFILE_FROM_FHAND (FHand);
|
||||
OFile = IFile->OFile;
|
||||
Volume = OFile->Volume;
|
||||
|
@ -112,6 +116,9 @@ FatFlush (
|
|||
IN EFI_FILE_PROTOCOL *FHand
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
return FatFlushEx (FHand, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ FatAllocateVolume (
|
|||
Volume->DiskIo2 = DiskIo2;
|
||||
Volume->BlockIo = BlockIo;
|
||||
Volume->MediaId = BlockIo->Media->MediaId;
|
||||
Volume->ReadOnly = BlockIo->Media->ReadOnly;
|
||||
Volume->ReadOnly = BlockIo->Media->ReadOnly || FeaturePcdGet (PcdFatReadOnlyMode);
|
||||
Volume->VolumeInterface.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
|
||||
Volume->VolumeInterface.OpenVolume = FatOpenVolume;
|
||||
InitializeListHead (&Volume->CheckRef);
|
||||
|
|
|
@ -224,8 +224,12 @@ FatOpenEx (
|
|||
//
|
||||
switch (OpenMode) {
|
||||
case EFI_FILE_MODE_READ:
|
||||
break;
|
||||
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
|
||||
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -211,6 +211,10 @@ FatIFileAccess (
|
|||
UINT64 EndPosition;
|
||||
FAT_TASK *Task;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode) && IoMode == WriteData) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
IFile = IFILE_FROM_FHAND (FHand);
|
||||
OFile = IFile->OFile;
|
||||
Volume = OFile->Volume;
|
||||
|
@ -414,6 +418,9 @@ FatWrite (
|
|||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
return FatIFileAccess (FHand, WriteData, BufferSize, Buffer, NULL);
|
||||
}
|
||||
|
||||
|
@ -437,6 +444,9 @@ FatWriteEx (
|
|||
IN OUT EFI_FILE_IO_TOKEN *Token
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
return FatIFileAccess (FHand, WriteData, &Token->BufferSize, Token->Buffer, Token);
|
||||
}
|
||||
|
||||
|
@ -471,6 +481,10 @@ FatAccessOFile (
|
|||
EFI_STATUS Status;
|
||||
UINTN BufferSize;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode) && IoMode == WriteData) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
BufferSize = *DataBufferSize;
|
||||
Volume = OFile->Volume;
|
||||
ASSERT_VOLUME_LOCKED (Volume);
|
||||
|
@ -542,6 +556,10 @@ FatExpandOFile (
|
|||
EFI_STATUS Status;
|
||||
UINTN WritePos;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
WritePos = OFile->FileSize;
|
||||
Status = FatGrowEof (OFile, ExpandedSize);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
|
@ -575,6 +593,10 @@ FatWriteZeroPool (
|
|||
UINTN BufferSize;
|
||||
UINTN WriteSize;
|
||||
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
AppendedSize = OFile->FileSize - WritePos;
|
||||
BufferSize = AppendedSize;
|
||||
if (AppendedSize > FAT_MAX_ALLOCATE_SIZE) {
|
||||
|
@ -624,6 +646,10 @@ FatTruncateOFile (
|
|||
IN UINTN TruncatedSize
|
||||
)
|
||||
{
|
||||
if (FeaturePcdGet (PcdFatReadOnlyMode)) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
OFile->FileSize = TruncatedSize;
|
||||
return FatShrinkEof (OFile);
|
||||
}
|
||||
|
|
|
@ -17,3 +17,16 @@
|
|||
|
||||
[UserExtensions.TianoCore."ExtraFiles"]
|
||||
FatPkgExtra.uni
|
||||
|
||||
[Guids]
|
||||
#
|
||||
# GUID defined in package
|
||||
#
|
||||
gEfiFatPkgTokenSpaceGuid = { 0xbe1f59ff, 0x65f5, 0x4b28, {0xb2, 0x8d, 0x56, 0x85, 0x36, 0x4a, 0xb1, 0xd2 } }
|
||||
|
||||
[PcdsFeatureFlag.common]
|
||||
## Indicates if driver is in read-only mode.<BR><BR>
|
||||
# TRUE - Restricts write operations.<BR>
|
||||
# FALSE - Write operations allowed. Default behavior<BR>
|
||||
# @Prompt Disables write operations on fat filesystem.
|
||||
gEfiFatPkgTokenSpaceGuid.PcdFatReadOnlyMode |FALSE|BOOLEAN|0x00000001
|
||||
|
|
|
@ -82,3 +82,6 @@
|
|||
[Components]
|
||||
FatPkg/FatPei/FatPei.inf
|
||||
FatPkg/EnhancedFatDxe/Fat.inf
|
||||
|
||||
[PcdsFeatureFlag]
|
||||
gEfiFatPkgTokenSpaceGuid.PcdFatReadOnlyMode|FALSE
|
||||
|
|
Loading…
Reference in New Issue