TianoCore EDK2 master
Loading...
Searching...
No Matches
Helpers.c File Reference

Go to the source code of this file.

Enumerations

enum  PARSER_STATE {
  ParserInit , ParserEnd , ParserSlash , ParserDot ,
  ParserDotDot , ParserNormal
}
 

Functions

STATIC EFI_STATUS VirtioFsReadConfig (IN VIRTIO_DEVICE_PROTOCOL *Virtio, OUT VIRTIO_FS_CONFIG *Config)
 
EFI_STATUS VirtioFsInit (IN OUT VIRTIO_FS *VirtioFs)
 
VOID VirtioFsUninit (IN OUT VIRTIO_FS *VirtioFs)
 
VOID EFIAPI VirtioFsExitBoot (IN EFI_EVENT ExitBootEvent, IN VOID *VirtioFsAsVoid)
 
EFI_STATUS VirtioFsSgListsValidate (IN VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL)
 
EFI_STATUS VirtioFsSgListsSubmit (IN OUT VIRTIO_FS *VirtioFs, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *RequestSgList, IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList OPTIONAL)
 
EFI_STATUS VirtioFsFuseNewRequest (IN OUT VIRTIO_FS *VirtioFs, OUT VIRTIO_FS_FUSE_REQUEST *Request, IN UINT32 RequestSize, IN VIRTIO_FS_FUSE_OPCODE Opcode, IN UINT64 NodeId)
 
EFI_STATUS VirtioFsFuseCheckResponse (IN VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList, IN UINT64 RequestId, OUT UINTN *TailBufferFill)
 
EFI_STATUS VirtioFsErrnoToEfiStatus (IN INT32 Errno)
 
STATIC VOID ParserStripSlash (IN CHAR8 *Buffer, IN OUT UINTN *Position)
 
STATIC VOID ParserCopy (OUT CHAR8 *Buffer, IN OUT UINTN *Position, IN UINTN Size, IN CHAR8 Char8)
 
STATIC VOID ParserRewindDot (IN CHAR8 *Buffer, IN OUT UINTN *Position)
 
STATIC VOID ParserRewindDotDot (IN CHAR8 *Buffer, IN OUT UINTN *Position, OUT BOOLEAN *RootEscape)
 
EFI_STATUS VirtioFsAppendPath (IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape)
 
EFI_STATUS VirtioFsLookupMostSpecificParentDir (IN OUT VIRTIO_FS *VirtioFs, IN OUT CHAR8 *Path, OUT UINT64 *DirNodeId, OUT CHAR8 **LastComponent)
 
EFI_STATUS VirtioFsGetBasename (IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize)
 
EFI_STATUS VirtioFsComposeRenameDestination (IN CHAR8 *LhsPath8, IN CHAR16 *RhsPath16, OUT CHAR8 **ResultPath8, OUT BOOLEAN *RootEscape)
 
EFI_STATUS VirtioFsFuseAttrToEfiFileInfo (IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE *FuseAttr, OUT EFI_FILE_INFO *FileInfo)
 
EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo (IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent, IN OUT EFI_FILE_INFO *FileInfo)
 
VOID VirtioFsGetFuseSizeUpdate (IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *Update, OUT UINT64 *Size)
 
EFI_STATUS VirtioFsGetFuseTimeUpdates (IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *UpdateAtime, OUT BOOLEAN *UpdateMtime, OUT UINT64 *Atime, OUT UINT64 *Mtime)
 
EFI_STATUS VirtioFsGetFuseModeUpdate (IN EFI_FILE_INFO *Info, IN EFI_FILE_INFO *NewInfo, OUT BOOLEAN *Update, OUT UINT32 *Mode)
 

Detailed Description

Initialization and helper routines for the Virtio Filesystem device.

Copyright (C) 2020, Red Hat, Inc.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Helpers.c.

Enumeration Type Documentation

◆ PARSER_STATE

enum PARSER_STATE

Definition at line 1179 of file Helpers.c.

Function Documentation

◆ ParserCopy()

STATIC VOID ParserCopy ( OUT CHAR8 *  Buffer,
IN OUT UINTN Position,
IN UINTN  Size,
IN CHAR8  Char8 
)

Produce one character in the parser's output buffer.

Parameters
[out]BufferThe parser's output buffer. On return, Char8 will have been written.
[in,out]PositionOn entry, points at the next character to produce (i.e., right past the end of the output written by the parser thus far). On return, Position is incremented by one.
[in]SizeTotal allocated size of the parser's output buffer. Used for sanity-checking.
[in]Char8The character to place in the output buffer.

Definition at line 1238 of file Helpers.c.

◆ ParserRewindDot()

STATIC VOID ParserRewindDot ( IN CHAR8 *  Buffer,
IN OUT UINTN Position 
)

Rewind the last single-dot in the parser's output buffer.

Parameters
[in]BufferThe parser's output buffer. Only used for sanity-checking.
[in,out]PositionOn entry, points at the next character to produce (i.e., right past the end of the output written by the parser thus far); the parser's output buffer ends with the characters ('/', '.'). On return, the dot is rewound by decrementing Position by one; a slash character will reside at the new end of the parser's output buffer.

Definition at line 1265 of file Helpers.c.

◆ ParserRewindDotDot()

STATIC VOID ParserRewindDotDot ( IN CHAR8 *  Buffer,
IN OUT UINTN Position,
OUT BOOLEAN *  RootEscape 
)

Rewind the last dot-dot in the parser's output buffer.

Parameters
[in]BufferThe parser's output buffer. Only used for sanity-checking.
[in,out]PositionOn entry, points at the next character to produce (i.e., right past the end of the output written by the parser thus far); the parser's output buffer ends with the characters ('/', '.', '.'). On return, the ('.', '.') pair is rewound unconditionally, by decrementing Position by two; a slash character resides at the new end of the parser's output buffer.

If this slash character stands for the root directory, then RootEscape is set to TRUE.

Otherwise (i.e., if this slash character is not the one standing for the root directory), then the slash character, and the pathname component preceding it, are removed by decrementing Position further. In this case, the slash character preceding the removed pathname component will reside at the new end of the parser's output buffer.

Parameters
[out]RootEscapeSet to TRUE on output if the dot-dot component tries to escape the root directory, as described above. Otherwise, RootEscape is not modified.

Definition at line 1308 of file Helpers.c.

◆ ParserStripSlash()

STATIC VOID ParserStripSlash ( IN CHAR8 *  Buffer,
IN OUT UINTN Position 
)

Strip the trailing slash from the parser's output buffer, unless the trailing slash stands for the root directory.

Parameters
[in]BufferThe parser's output buffer. Only used for sanity-checking.
[in,out]PositionOn entry, points at the next character to produce (i.e., right past the end of the output written by the parser thus far). The last character in the parser's output buffer is a slash. On return, the slash is stripped, by decrementing Position by one. If this action would remove the slash character standing for the root directory, then the function has no effect.

Definition at line 1206 of file Helpers.c.

◆ VirtioFsAppendPath()

EFI_STATUS VirtioFsAppendPath ( IN CHAR8 *  LhsPath8,
IN CHAR16 *  RhsPath16,
OUT CHAR8 **  ResultPath8,
OUT BOOLEAN *  RootEscape 
)

Append the UEFI-style RhsPath16 to the POSIX-style, canonical format LhsPath8. Output the POSIX-style, canonical format result in ResultPath, as a dynamically allocated string.

Canonicalization (aka sanitization) establishes the following properties:

  • ResultPath is absolute (starts with "/"),
  • dot (.) and dot-dot (..) components are resolved/eliminated in ResultPath, with the usual semantics,
  • ResultPath uses forward slashes,
  • sequences of slashes are squashed in ResultPath,
  • the printable ASCII character set covers ResultPath,
  • CHAR8 encoding is used in ResultPath,
  • no trailing slash present in ResultPath except for the standalone root directory,
  • the length of ResultPath is at most VIRTIO_FS_MAX_PATHNAME_LENGTH.

Any dot-dot in RhsPath16 that would remove the root directory is dropped, and reported through RootEscape, without failing the function call.

Parameters
[in]LhsPath8Identifies the base directory. The caller is responsible for ensuring that LhsPath8 conform to the above canonical pathname format on entry.
[in]RhsPath16Identifies the desired file with a UEFI-style CHAR16 pathname. If RhsPath16 starts with a backslash, then RhsPath16 is considered absolute, and LhsPath8 is ignored; RhsPath16 is sanitized in isolation, for producing ResultPath8. Otherwise (i.e., if RhsPath16 is relative), RhsPath16 is transliterated to CHAR8, and naively appended to LhsPath8. The resultant fused pathname is then sanitized, to produce ResultPath8.
[out]ResultPath8The POSIX-style, canonical format pathname that leads to the file desired by the caller. After use, the caller is responsible for freeing ResultPath8.
[out]RootEscapeSet to TRUE if at least one dot-dot component in RhsPath16 attempted to escape the root directory; set to FALSE otherwise.
Return values
EFI_SUCCESSResultPath8 has been produced. RootEscape has been output.
EFI_INVALID_PARAMETERRhsPath16 is zero-length.
EFI_INVALID_PARAMETERRhsPath16 failed the VIRTIO_FS_MAX_PATHNAME_LENGTH check.
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_OUT_OF_RESOURCESResultPath8 would have failed the VIRTIO_FS_MAX_PATHNAME_LENGTH check.
EFI_UNSUPPORTEDRhsPath16 contains a character that either falls outside of the printable ASCII set, or is a forward slash.

Definition at line 1404 of file Helpers.c.

◆ VirtioFsComposeRenameDestination()

EFI_STATUS VirtioFsComposeRenameDestination ( IN CHAR8 *  LhsPath8,
IN CHAR16 *  RhsPath16,
OUT CHAR8 **  ResultPath8,
OUT BOOLEAN *  RootEscape 
)

Format the destination of a rename/move operation as a dynamically allocated canonical pathname.

Any dot-dot in RhsPath16 that would remove the root directory is dropped, and reported through RootEscape, without failing the function call.

Parameters
[in]LhsPath8The source pathname operand of the rename/move operation, expressed as a canonical pathname (as defined in the description of VirtioFsAppendPath()). The root directory "/" cannot be renamed/moved, and will be rejected.
[in]RhsPath16The destination pathname operand expressed as a UEFI-style CHAR16 pathname.

If RhsPath16 starts with a backslash, then RhsPath16 is considered absolute. Otherwise, RhsPath16 is interpreted relative to the most specific parent directory found in LhsPath8.

Independently, if RhsPath16 ends with a backslash (i.e., RhsPath16 is given in the "move into directory" convenience form), then RhsPath16 is interpreted with the basename of LhsPath8 appended. Otherwise, the last pathname component of RhsPath16 is taken as the last pathname component of the rename/move destination.

An empty RhsPath16 is rejected.

Parameters
[out]ResultPath8The POSIX-style, canonical format pathname that leads to the renamed/moved file. After use, the caller is responsible for freeing ResultPath8.
[out]RootEscapeSet to TRUE if at least one dot-dot component in RhsPath16 attempted to escape the root directory; set to FALSE otherwise.
Return values
EFI_SUCCESSResultPath8 has been produced. RootEscape has been output.
EFI_INVALID_PARAMETERLhsPath8 is "/".
EFI_INVALID_PARAMETERRhsPath16 is zero-length.
EFI_INVALID_PARAMETERRhsPath16 failed the VIRTIO_FS_MAX_PATHNAME_LENGTH check.
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_OUT_OF_RESOURCESResultPath8 would have failed the VIRTIO_FS_MAX_PATHNAME_LENGTH check.
EFI_UNSUPPORTEDRhsPath16 contains a character that either falls outside of the printable ASCII set, or is a forward slash.

Definition at line 1918 of file Helpers.c.

◆ VirtioFsErrnoToEfiStatus()

EFI_STATUS VirtioFsErrnoToEfiStatus ( IN INT32  Errno)

An ad-hoc function for mapping FUSE (well, Linux) "errno" values to EFI_STATUS.

Parameters
[in]ErrnoThe "VIRTIO_FS_FUSE_RESPONSE.Error" value, returned by the Virtio Filesystem device. The value is expected to be negative.
Returns
An EFI_STATUS error code that's deemed a passable mapping for the Errno value.
Return values
EFI_DEVICE_ERRORFallback EFI_STATUS code for unrecognized Errno values.

Definition at line 991 of file Helpers.c.

◆ VirtioFsExitBoot()

VOID EFIAPI VirtioFsExitBoot ( IN EFI_EVENT  ExitBootEvent,
IN VOID *  VirtioFsAsVoid 
)

ExitBootServices event notification function for a Virtio Filesystem object.

This function resets the VIRTIO_FS.Virtio device, causing it to release all references to guest-side resources. The function may only be called after VirtioFsInit() returns successfully and before VirtioFsUninit() is called.

Parameters
[in]ExitBootEventThe VIRTIO_FS.ExitBoot event that has been signaled.
[in]VirtioFsAsVoidPointer to the VIRTIO_FS object, passed in as (VOID*).

Definition at line 312 of file Helpers.c.

◆ VirtioFsFuseAttrToEfiFileInfo()

EFI_STATUS VirtioFsFuseAttrToEfiFileInfo ( IN VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr,
OUT EFI_FILE_INFO FileInfo 
)

Convert select fields of a VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to corresponding fields in EFI_FILE_INFO.

Parameters
[in]FuseAttrThe VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE object to convert the relevant fields from.
[out]FileInfoThe EFI_FILE_INFO structure to modify. Importantly, the FileInfo->Size and FileInfo->FileName fields are not overwritten.
Return values
EFI_SUCCESSConversion successful.
EFI_UNSUPPORTEDThe allocated size of the file is inexpressible in EFI_FILE_INFO.
EFI_UNSUPPORTEDOne of the file access times is inexpressible in EFI_FILE_INFO.
EFI_UNSUPPORTEDThe file type is inexpressible in EFI_FILE_INFO.
EFI_UNSUPPORTEDThe file is a regular file that has multiple names on the host side (i.e., its hard link count is greater than one).

Definition at line 2090 of file Helpers.c.

◆ VirtioFsFuseCheckResponse()

EFI_STATUS VirtioFsFuseCheckResponse ( IN VIRTIO_FS_SCATTER_GATHER_LIST ResponseSgList,
IN UINT64  RequestId,
OUT UINTN TailBufferFill 
)

Check the common FUSE response format.

The first buffer in the response scatter-gather list is assumed a VIRTIO_FS_FUSE_RESPONSE structure. Subsequent response buffers, if any, up to and excluding the last one, are assumed fixed size. The last response buffer may or may not be fixed size, as specified by the caller.

This function may only be called after VirtioFsSgListsSubmit() returns successfully.

Parameters
[in]ResponseSgListThe scatter-gather list that describes the response part of the exchange – the buffers that the Virtio Filesystem device filled in during the virtio transfer.
[in]RequestIdThe request identifier to which the response is expected to belong.
[out]TailBufferFillIf NULL, then the last buffer in ResponseSgList is considered fixed size. Otherwise, the last buffer is considered variable size, and on successful return, TailBufferFill reports the number of bytes in the last buffer.
Return values
EFI_INVALID_PARAMETERTailBufferFill is not NULL (i.e., the last buffer is considered variable size), and ResponseSgList->NumVec is 1.
EFI_INVALID_PARAMETERThe allocated size of the first buffer does not match sizeof(VIRTIO_FS_FUSE_RESPONSE).
EFI_PROTOCOL_ERRORThe VIRTIO_FS_FUSE_RESPONSE structure in the first buffer has not been fully populated.
EFI_PROTOCOL_ERROR"VIRTIO_FS_FUSE_RESPONSE.Len" in the first buffer does not equal the sum of the individual buffer sizes (as populated).
EFI_PROTOCOL_ERROR"VIRTIO_FS_FUSE_RESPONSE.Unique" in the first buffer does not equal RequestId.
EFI_PROTOCOL_ERROR"VIRTIO_FS_FUSE_RESPONSE.Error" in the first buffer is zero, but a subsequent fixed size buffer has not been fully populated.
EFI_DEVICE_ERROR"VIRTIO_FS_FUSE_RESPONSE.Error" in the first buffer is nonzero. The caller may investigate "VIRTIO_FS_FUSE_RESPONSE.Error". Note that the completeness of the subsequent fixed size buffers is not verified in this case.
EFI_SUCCESSVerification successful.

Definition at line 873 of file Helpers.c.

◆ VirtioFsFuseDirentPlusToEfiFileInfo()

EFI_STATUS VirtioFsFuseDirentPlusToEfiFileInfo ( IN VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE FuseDirent,
IN OUT EFI_FILE_INFO FileInfo 
)

Convert a VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename to an EFI_FILE_INFO filename.

Parameters
[in]FuseDirentThe VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE object to convert the filename byte array from. The caller is responsible for ensuring that FuseDirent->Namelen describe valid storage.
[in,out]FileInfoThe EFI_FILE_INFO structure to modify. On input, the caller is responsible for setting FileInfo->Size according to the allocated size. On successful return, FileInfo->Size is reduced to reflect the filename converted into FileInfo->FileName. FileInfo->FileName is set from the filename byte array that directly follows the FuseDirent header object. Fields other than FileInfo->Size and FileInfo->FileName are not modified.
Return values
EFI_SUCCESSConversion successful.
EFI_INVALID_PARAMETERVIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE() returns zero for FuseDirent->Namelen.
EFI_BUFFER_TOO_SMALLOn input, FileInfo->Size does not provide enough room for converting the filename byte array from FuseDirent.
EFI_UNSUPPORTEDThe FuseDirent filename byte array contains a byte that falls outside of the printable ASCII range, or is a forward slash or a backslash.

Definition at line 2219 of file Helpers.c.

◆ VirtioFsFuseNewRequest()

EFI_STATUS VirtioFsFuseNewRequest ( IN OUT VIRTIO_FS VirtioFs,
OUT VIRTIO_FS_FUSE_REQUEST Request,
IN UINT32  RequestSize,
IN VIRTIO_FS_FUSE_OPCODE  Opcode,
IN UINT64  NodeId 
)

Set up the fields of a new VIRTIO_FS_FUSE_REQUEST object.

The function may only be called after VirtioFsInit() returns successfully and before VirtioFsUninit() is called.

Parameters
[in,out]VirtioFsThe Virtio Filesystem device that the request is being prepared for. The "VirtioFs->RequestId" field will be copied into "Request->Unique". On output (on successful return), "VirtioFs->RequestId" will be incremented.
[out]RequestThe VIRTIO_FS_FUSE_REQUEST object whose fields are to be set.
[in]RequestSizeThe total size of the request, including sizeof(VIRTIO_FS_FUSE_REQUEST).
[in]OpcodeThe VIRTIO_FS_FUSE_OPCODE that identifies the command to send.
[in]NodeIdThe inode number of the file that the request refers to. When Opcode is VirtioFsFuseOpInit, NodeId is ignored by the Virtio Filesystem device.
Return values
EFI_INVALID_PARAMETERRequestSize is smaller than sizeof(VIRTIO_FS_FUSE_REQUEST).
EFI_OUT_OF_RESOURCES"VirtioFs->RequestId" is MAX_UINT64, and can be incremented no more.
EFI_SUCCESSRequest has been populated, "VirtioFs->RequestId" has been incremented.

Definition at line 790 of file Helpers.c.

◆ VirtioFsGetBasename()

EFI_STATUS VirtioFsGetBasename ( IN CHAR8 *  Path,
OUT CHAR16 *Basename  OPTIONAL,
IN OUT UINTN BasenameSize 
)

Format the last component of a canonical pathname into a caller-provided CHAR16 array.

Parameters
[in]PathThe canonical pathname (as defined in the description of VirtioFsAppendPath()) to format the last component of.
[out]BasenameIf BasenameSize is zero on input, Basename may be NULL. Otherwise, Basename is allocated by the caller. On successful return, Basename contains the last component of Path, formatted as a NUL-terminated CHAR16 string. When Path is "/" on input, Basename is L"" on output.
[in,out]BasenameSizeOn input, the number of bytes the caller provides in Basename. On output, regardless of return value, the number of bytes required for formatting Basename, including the terminating L'\0'.
Return values
EFI_SUCCESSBasename has been filled in.
EFI_BUFFER_TOO_SMALLBasenameSize was too small on input; Basename has not been modified.

Definition at line 1823 of file Helpers.c.

◆ VirtioFsGetFuseModeUpdate()

EFI_STATUS VirtioFsGetFuseModeUpdate ( IN EFI_FILE_INFO Info,
IN EFI_FILE_INFO NewInfo,
OUT BOOLEAN *  Update,
OUT UINT32 *  Mode 
)

Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() call, determine whether updating the file mode bits of the file is necessary, relative to an EFI_FILE_INFO object describing the current state of the file.

Parameters
[in]InfoThe EFI_FILE_INFO describing the current state of the file. The caller is responsible for populating Info on input with VirtioFsFuseAttrToEfiFileInfo(), from the current FUSE attributes of the file. The Info->Size and Info->FileName members are ignored.
[in]NewInfoThe EFI_FILE_INFO object received in the EFI_FILE_PROTOCOL.SetInfo() call.
[out]UpdateSet to TRUE on output if the file mode bits need to be updated. Set to FALSE otherwise.
[out]ModeIf Update is set to TRUE, then Mode provides the file mode bits to set. Otherwise, Mode is not written to.
Return values
EFI_SUCCESSOutput parameters have been set successfully.
EFI_ACCESS_DENIEDNewInfo requests toggling an unknown bit in the Attribute bitmask.
EFI_ACCESS_DENIEDNewInfo requests toggling EFI_FILE_DIRECTORY in the Attribute bitmask.

Definition at line 2459 of file Helpers.c.

◆ VirtioFsGetFuseSizeUpdate()

VOID VirtioFsGetFuseSizeUpdate ( IN EFI_FILE_INFO Info,
IN EFI_FILE_INFO NewInfo,
OUT BOOLEAN *  Update,
OUT UINT64 *  Size 
)

Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() call, determine whether updating the size of the file is necessary, relative to an EFI_FILE_INFO object describing the current state of the file.

Parameters
[in]InfoThe EFI_FILE_INFO describing the current state of the file. The caller is responsible for populating Info on input with VirtioFsFuseAttrToEfiFileInfo(), from the current FUSE attributes of the file. The Info->Size and Info->FileName members are ignored.
[in]NewInfoThe EFI_FILE_INFO object received in the EFI_FILE_PROTOCOL.SetInfo() call.
[out]UpdateSet to TRUE on output if the file size needs to be updated. Set to FALSE otherwise.
[out]SizeIf Update is set to TRUE, then Size provides the new file size to set. Otherwise, Size is not written to.

Definition at line 2290 of file Helpers.c.

◆ VirtioFsGetFuseTimeUpdates()

EFI_STATUS VirtioFsGetFuseTimeUpdates ( IN EFI_FILE_INFO Info,
IN EFI_FILE_INFO NewInfo,
OUT BOOLEAN *  UpdateAtime,
OUT BOOLEAN *  UpdateMtime,
OUT UINT64 *  Atime,
OUT UINT64 *  Mtime 
)

Given an EFI_FILE_INFO object received in an EFI_FILE_PROTOCOL.SetInfo() call, determine whether updating the last access time and/or the last modification time of the file is necessary, relative to an EFI_FILE_INFO object describing the current state of the file.

Parameters
[in]InfoThe EFI_FILE_INFO describing the current state of the file. The caller is responsible for populating Info on input with VirtioFsFuseAttrToEfiFileInfo(), from the current FUSE attributes of the file. The Info->Size and Info->FileName members are ignored.
[in]NewInfoThe EFI_FILE_INFO object received in the EFI_FILE_PROTOCOL.SetInfo() call.
[out]UpdateAtimeSet to TRUE on output if the last access time needs to be updated. Set to FALSE otherwise.
[out]UpdateMtimeSet to TRUE on output if the last modification time needs to be updated. Set to FALSE otherwise.
[out]AtimeIf UpdateAtime is set to TRUE, then Atime provides the last access timestamp to set (as seconds since the Epoch). Otherwise, Atime is not written to.
[out]MtimeIf UpdateMtime is set to TRUE, then Mtime provides the last modification timestamp to set (as seconds since the Epoch). Otherwise, Mtime is not written to.
Return values
EFI_SUCCESSOutput parameters have been set successfully.
EFI_INVALID_PARAMETERAt least one of the CreateTime, LastAccessTime and ModificationTime fields in NewInfo represents an actual update relative to the current state of the file (expressed in Info), but does not satisfy the UEFI spec requirements on EFI_TIME.
EFI_ACCESS_DENIEDNewInfo requests changing both CreateTime and ModificationTime, but to values that differ from each other. The Virtio Filesystem device does not support this.

Definition at line 2355 of file Helpers.c.

◆ VirtioFsInit()

EFI_STATUS VirtioFsInit ( IN OUT VIRTIO_FS VirtioFs)

Configure the Virtio Filesystem device underlying VirtioFs.

Parameters
[in,out]VirtioFsThe VIRTIO_FS object for which Virtio communication should be set up. On input, the caller is responsible for VirtioFs->Virtio having been initialized. On output, synchronous Virtio Filesystem commands (primitives) may be submitted to the device.
Return values
EFI_SUCCESSVirtio machinery has been set up.
EFI_UNSUPPORTEDThe host-side configuration of the Virtio Filesystem is not supported by this driver.
Returns
Error codes from underlying functions.

Definition at line 80 of file Helpers.c.

◆ VirtioFsLookupMostSpecificParentDir()

EFI_STATUS VirtioFsLookupMostSpecificParentDir ( IN OUT VIRTIO_FS VirtioFs,
IN OUT CHAR8 *  Path,
OUT UINT64 *  DirNodeId,
OUT CHAR8 **  LastComponent 
)

For a given canonical pathname (as defined at VirtioFsAppendPath()), look up the NodeId of the most specific parent directory, plus output a pointer to the last pathname component (which is therefore a direct child of said parent directory).

The function may only be called after VirtioFsFuseInitSession() returns successfully and before VirtioFsUninit() is called.

Parameters
[in,out]VirtioFsThe Virtio Filesystem device to send FUSE_LOOKUP and FUSE_FORGET requests to. On output, the FUSE request counter "VirtioFs->RequestId" will have been incremented several times.
[in,out]PathThe canonical pathname (as defined in the description of VirtioFsAppendPath()) to split. Path is modified in-place temporarily; however, on return (successful or otherwise), Path reassumes its original contents.
[out]DirNodeIdThe NodeId of the most specific parent directory identified by Path. The caller is responsible for sending a FUSE_FORGET request to the Virtio Filesystem device for DirNodeId – unless DirNodeId equals VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID –, when DirNodeId's use ends.
[out]LastComponentA pointer into Path, pointing at the start of the last pathname component.
Return values
EFI_SUCCESSSplitting successful.
EFI_INVALID_PARAMETERPath is "/".
EFI_ACCESS_DENIEDOne of the components on Path before the last is not a directory.
Returns
Error codes propagated from VirtioFsFuseLookup() and VirtioFsFuseAttrToEfiFileInfo().

Definition at line 1701 of file Helpers.c.

◆ VirtioFsReadConfig()

STATIC EFI_STATUS VirtioFsReadConfig ( IN VIRTIO_DEVICE_PROTOCOL Virtio,
OUT VIRTIO_FS_CONFIG Config 
)

Read the Virtio Filesystem device configuration structure in full.

Parameters
[in]VirtioThe Virtio protocol underlying the VIRTIO_FS object.
[out]ConfigThe fully populated VIRTIO_FS_CONFIG structure.
Return values
EFI_SUCCESSConfig has been filled in.
Returns
Error codes propagated from Virtio->ReadDevice(). The contents of Config are indeterminate.

Definition at line 31 of file Helpers.c.

◆ VirtioFsSgListsSubmit()

EFI_STATUS VirtioFsSgListsSubmit ( IN OUT VIRTIO_FS VirtioFs,
IN OUT VIRTIO_FS_SCATTER_GATHER_LIST RequestSgList,
IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList  OPTIONAL 
)

Submit a validated pair of (request buffer list, response buffer list) to the Virtio Filesystem device.

On input, the pair of VIRTIO_FS_SCATTER_GATHER_LIST objects must have been validated together, using the VirtioFsSgListsValidate() function.

On output (on successful return), the following fields will be re-initialized to zero (after temporarily setting them to different values):

  • VIRTIO_FS_IO_VECTOR.Mapped,
  • VIRTIO_FS_IO_VECTOR.MappedAddress,
  • VIRTIO_FS_IO_VECTOR.Mapping.

On output (on successful return), the following fields will be calculated:

  • VIRTIO_FS_IO_VECTOR.Transferred.

The function may only be called after VirtioFsInit() returns successfully and before VirtioFsUninit() is called.

Parameters
[in,out]VirtioFsThe Virtio Filesystem device that the request-response exchange, expressed via RequestSgList and ResponseSgList, should now be submitted to.
[in,out]RequestSgListThe scatter-gather list that describes the request part of the exchange – the buffers that should be sent to the Virtio Filesystem device in the virtio transfer.
[in,out]ResponseSgListThe scatter-gather list that describes the response part of the exchange – the buffers that the Virtio Filesystem device should populate in the virtio transfer. May be NULL if and only if NULL was passed to VirtioFsSgListsValidate() as ResponseSgList.
Return values
EFI_SUCCESSTransfer complete. The caller should investigate the VIRTIO_FS_IO_VECTOR.Transferred fields in ResponseSgList, to ensure coverage of the relevant response buffers. Subsequently, the caller should investigate the contents of those buffers.
EFI_DEVICE_ERRORThe Virtio Filesystem device reported populating more response bytes than ResponseSgList->TotalSize.
Returns
Error codes propagated from VirtioMapAllBytesInSharedBuffer(), VirtioFlush(), or VirtioFs->Virtio->UnmapSharedBuffer().

Definition at line 538 of file Helpers.c.

◆ VirtioFsSgListsValidate()

EFI_STATUS VirtioFsSgListsValidate ( IN VIRTIO_FS VirtioFs,
IN OUT VIRTIO_FS_SCATTER_GATHER_LIST RequestSgList,
IN OUT VIRTIO_FS_SCATTER_GATHER_LIST *ResponseSgList  OPTIONAL 
)

Validate two VIRTIO_FS_SCATTER_GATHER_LIST objects – list of request buffers, list of response buffers – together.

On input, the caller is required to populate the following fields:

  • VIRTIO_FS_IO_VECTOR.Buffer,
  • VIRTIO_FS_IO_VECTOR.Size,
  • VIRTIO_FS_SCATTER_GATHER_LIST.IoVec,
  • VIRTIO_FS_SCATTER_GATHER_LIST.NumVec.

On output (on successful return), the following fields will be zero-initialized:

  • VIRTIO_FS_IO_VECTOR.Mapped,
  • VIRTIO_FS_IO_VECTOR.MappedAddress,
  • VIRTIO_FS_IO_VECTOR.Mapping,
  • VIRTIO_FS_IO_VECTOR.Transferred.

On output (on successful return), the following fields will be calculated:

  • VIRTIO_FS_SCATTER_GATHER_LIST.TotalSize.

The function may only be called after VirtioFsInit() returns successfully and before VirtioFsUninit() is called.

Parameters
[in]VirtioFsThe Virtio Filesystem device that the request-response exchange, expressed via RequestSgList and ResponseSgList, will be submitted to.
[in,out]RequestSgListThe scatter-gather list that describes the request part of the exchange – the buffers that should be sent to the Virtio Filesystem device in the virtio transfer.
[in,out]ResponseSgListThe scatter-gather list that describes the response part of the exchange – the buffers that the Virtio Filesystem device should populate in the virtio transfer. May be NULL if the exchange with the Virtio Filesystem device consists of a request only, with the response part omitted altogether.
Return values
EFI_SUCCESSRequestSgList and ResponseSgList have been validated, output fields have been set.
EFI_INVALID_PARAMETERRequestSgList is NULL.
EFI_INVALID_PARAMETEROn input, a VIRTIO_FS_SCATTER_GATHER_LIST.IoVec field is NULL, or a VIRTIO_FS_SCATTER_GATHER_LIST.NumVec field is zero.
EFI_INVALID_PARAMETEROn input, a VIRTIO_FS_IO_VECTOR.Buffer field is NULL, or a VIRTIO_FS_IO_VECTOR.Size field is zero.
EFI_UNSUPPORTED(RequestSgList->NumVec + ResponseSgList->NumVec) exceeds VirtioFs->QueueSize, meaning that the total list of buffers cannot be placed on the virtio queue in a single descriptor chain (with one descriptor per buffer).
EFI_UNSUPPORTEDOne of the VIRTIO_FS_SCATTER_GATHER_LIST.TotalSize fields would exceed MAX_UINT32.

Definition at line 398 of file Helpers.c.

◆ VirtioFsUninit()

VOID VirtioFsUninit ( IN OUT VIRTIO_FS VirtioFs)

De-configure the Virtio Filesystem device underlying VirtioFs.

Parameters
[in]VirtioFsThe VIRTIO_FS object for which Virtio communication should be torn down. On input, the caller is responsible for having called VirtioFsInit(). On output, Virtio Filesystem commands (primitives) must no longer be submitted to the device.

Definition at line 284 of file Helpers.c.