- Instance = INSTANCE_FROM_FVB_THIS(This);\r
-\r
- if (!Instance->Initialized && Instance->Initialize) {\r
- Instance->Initialize(Instance);\r
- }\r
-\r
- DEBUG ((DEBUG_BLKIO, "FvbWrite(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));\r
-\r
- Status = EFI_SUCCESS;\r
- TempStatus = Status;\r
-\r
- // Detect WriteDisabled state\r
- if (Instance->Media.ReadOnly == TRUE) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not write: Device is in WriteDisabled state.\n"));\r
- // It is in WriteDisabled state, return an error right away\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- // Cache the block size to avoid de-referencing pointers all the time\r
- BlockSize = Instance->Media.BlockSize;\r
-\r
- // The write must not span block boundaries.\r
- // We need to check each variable individually because adding two large values together overflows.\r
- if ( ( Offset >= BlockSize ) ||\r
- ( *NumBytes > BlockSize ) ||\r
- ( (Offset + *NumBytes) > BlockSize ) ) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
- return EFI_BAD_BUFFER_SIZE;\r
- }\r
-\r
- // We must have some bytes to write\r
- if (*NumBytes == 0) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
- return EFI_BAD_BUFFER_SIZE;\r
- }\r