Home | History | Annotate | Download | only in BootMonFs

Lines Matching defs:File

1 /** @file

17 // Clear a file's image description on storage media:
18 // UEFI allows you to seek past the end of a file, a subsequent write will grow
19 // the file. It does not specify how space between the former end of the file
21 // BootMonFs metadata, that comes after the end of a file, could be left there
26 IN BOOTMON_FS_FILE *File
35 DiskIo = File->Instance->DiskIo;
36 BlockIo = File->Instance->BlockIo;
47 File->HwDescAddress,
58 Write the description of a file to storage media.
63 @param[in] File Description of the file whose description on the
65 @param[in] FileName Name of the file. Its length is assumed to be
67 @param[in] DataSize Number of data bytes of the file.
68 @param[in] FileStart File's starting position on media. FileStart must
79 IN BOOTMON_FS_FILE *File,
91 DiskIo = File->Instance->DiskIo;
92 BlockSize = File->Instance->BlockIo->Media->BlockSize;
96 // Construct the file description
100 Description = &File->HwDescription;
126 File->HwDescAddress = ((Description->BlockEnd + 1) * BlockSize) - sizeof (HW_IMAGE_DESCRIPTION);
128 // Update the file description on the media
131 File->Instance->Media->MediaId,
132 File->HwDescAddress,
141 // Find a space on media for a file that has not yet been flushed to disk.
144 // - Find space for moving an existing file that has outgrown its space
146 // - Find space for a fragment of a file that has outgrown its space
152 // File - the new (not yet flushed) file for which we need to find space.
153 // FileStart - the position on media of the file (in bytes).
157 IN BOOTMON_FS_FILE *File,
168 Media = File->Instance->BlockIo->Media;
170 RootFile = File->Instance->RootFile;
172 // This function must only be called for file which has not been flushed into
174 ASSERT (File->HwDescription.RegionCount == 0);
189 // If the free space preceding the file is big enough to contain the new
190 // file then use it!
193 // The file list must be in disk-order
194 RemoveEntryList (&File->Link);
195 File->Link.BackLink = FileLink->BackLink;
196 File->Link.ForwardLink = FileLink;
197 FileLink->BackLink->ForwardLink = &File->Link;
198 FileLink->BackLink = &File->Link;
205 // See if there's space after the last file
213 // Free the resources in the file's Region list.
217 IN BOOTMON_FS_FILE *File
223 RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);
224 while (!IsNull (&File->RegionToFlushLink, RegionToFlushLink)) {
231 RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);
236 Flush all modified data associated with a file to a device.
239 file handle to flush.
242 @retval EFI_ACCESS_DENIED The file was opened read-only.
264 BOOTMON_FS_FILE *File;
282 File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);
283 if (File->Info == NULL) {
287 if (File->OpenMode == EFI_FILE_MODE_READ) {
291 Instance = File->Instance;
292 Info = File->Info;
300 // If the file doesn't exist then find a space for it
301 if (File->HwDescription.RegionCount == 0) {
303 File,
311 FileStart = File->HwDescription.BlockStart * BlockSize;
313 // FileEnd is the current NOR address of the end of the file's data
314 FileEnd = FileStart + File->HwDescription.Region[0].Size;
316 for (RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);
317 !IsNull (&File->RegionToFlushLink, RegionToFlushLink);
318 RegionToFlushLink = GetNextNode (&File->RegionToFlushLink, RegionToFlushLink)
332 // Handle regions representing edits to existing portions of the file
333 // Write the region data straight into the file
344 // Handle regions representing appends to the file
346 // Note: Since seeking past the end of the file with SetPosition() is
348 // the file and the beginning of the new region. Since the UEFI spec
350 // the file"), we just leave garbage in the gap.
356 CurrentPhysicalSize = BootMonFsGetPhysicalSize (File);
360 // Get the File Description for the next file
361 FileLink = GetNextNode (&Instance->RootFile->Link, &File->Link);
365 // If there is space between the beginning of the current file and the
366 // beginning of the next file then use it
369 // We are flushing the last file.
378 // Invalidate the current image description of the file if any.
379 if (File->HwDescAddress != 0) {
380 Status = InvalidateImageDescription (File);
386 // Write the new file data
398 Status = WriteFileDescription (File, AsciiFileName, NewDataSize, FileStart);
404 // There isn't a space for the file.
405 // Options here are to move the file or fragment it. However as files
415 FreeFileRegions (File);
416 Info->PhysicalSize = BootMonFsGetPhysicalSize (File);
418 if ((AsciiStrCmp (AsciiFileName, File->HwDescription.Footer.Filename) != 0) ||
419 (Info->FileSize != File->HwDescription.Region[0].Size) ) {
420 Status = WriteFileDescription (File, AsciiFileName, Info->FileSize, FileStart);
434 Close a specified file handle.
436 @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the file
439 @retval EFI_SUCCESS The file was closed.
441 file handle.
450 BOOTMON_FS_FILE *File;
456 File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);
457 if (File->Info == NULL) {
461 // In the case of a file and not the root directory
462 if (This != &File->Instance->RootFile->File) {
464 FreePool (File->Info);
465 File->Info = NULL;
472 Open a file on the boot monitor file system.
474 The boot monitor file system does not allow for sub-directories. There is only
479 the file handle to source location.
481 file.
482 @param[in] FileName The Null-terminated string of the name of the file
484 @param[in] OpenMode The mode to open the file : Read or Read/Write or
486 @param[in] Attributes Attributes of the file in case of a file creation
488 @retval EFI_SUCCESS The file was open.
489 @retval EFI_NOT_FOUND The specified file could not be found or the specified
490 directory in which to create a file could not be found.
493 with the Boot Monitor file system.
494 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
510 BOOTMON_FS_FILE *File;
554 // Copy the file path to be able to work on it. We do not want to
555 // modify the input file name string "FileName".
595 // Look for a '\' in the file path. If one is found then
614 // Attempt to open a file or a directory that is not in the
643 *NewHandle = &Instance->RootFile->File;
655 // Allocate a buffer to store the characteristics of the file while the
656 // file is open. We allocate the maximum size to not have to reallocate
657 // if the file name is changed.
667 // Open or create a file in the root directory.
670 Status = BootMonGetFileFromAsciiFileName (Instance, AsciiFileName, &File);
676 Status = BootMonFsCreateFile (Instance, &File);
680 InsertHeadList (&Instance->RootFile->Link, &File->Link);
684 // File already open, not supported yet.
686 if (File->Info != NULL) {
692 Info->FileSize = BootMonFsGetImageLength (File);
693 Info->PhysicalSize = BootMonFsGetPhysicalSize (File);
696 File->Info = Info;
698 File->Position = 0;
699 File->OpenMode = OpenMode;
701 *NewHandle = &File->File;
730 Close and delete a file from the boot monitor file system.
732 @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the file
735 @retval EFI_SUCCESS The file was closed and deleted.
737 file handle.
738 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not deleted.
748 BOOTMON_FS_FILE *File;
756 File = BOOTMON_FS_FILE_FROM_FILE_THIS (This);
757 if (File->Info == NULL) {
761 if (!IsListEmpty (&File->RegionToFlushLink)) {
763 RegionToFlushLink = GetFirstNode (&File->RegionToFlushLink);
776 } while (!IsListEmpty (&File->RegionToFlushLink));
779 // If (RegionCount is greater than 0) then the file already exists
780 if (File->HwDescription.RegionCount > 0) {
782 Status = InvalidateImageDescription (File);
790 RemoveEntryList (&File->Link);
791 FreePool (File->Info);
792 FreePool (File);