audk/OvmfPkg/VirtioFsDxe
Laszlo Ersek c3f76ef89d OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path
The EFI_FILE_PROTOCOL.SetInfo() member is somewhat under-specified; one of
its modes of operation is renaming/moving the file.

In order to create the destination pathname in canonical format, 2*2=4
cases have to be considered. For the sake of discussion, assume the
current canonical pathname of a VIRTIO_FS_FILE is "/home/user/f1.txt".
Then, consider the following rename/move requests from
EFI_FILE_PROTOCOL.SetInfo():

  Destination requested  Destination  Move into   Destination in
  by SetInfo()           relative?    directory?  canonical format
  ---------------------  -----------  ----------  -----------------------
  L"\\dir\\f2.txt"       no           no          "/dir/f2.txt"
  L"\\dir\\"             no           yes         "/dir/f1.txt"
  L"dir\\f2.txt"         yes          no          "/home/user/dir/f2.txt"
  L"dir\\"               yes          yes         "/home/user/dir/f1.txt"

Add the VirtioFsComposeRenameDestination() function, for composing the
last column from the current canonical pathname and the SetInfo() input.

The function works on the following principles:

- The prefix of the destination path is "/", if the SetInfo() rename
  request is absolute.

  Otherwise, the dest prefix is the "current directory" (the most specific
  parent directory) of the original pathname (in the above example,
  "/home/user").

- The suffix of the destination path is precisely the SetInfo() request
  string, if the "move into directory" convenience format -- the trailing
  backslash -- is not used. (In the above example, L"\\dir\\f2.txt" and
  L"dir\\f2.txt".)

  Otherwise, the suffix is the SetInfo() request, plus the original
  basename (in the above example, L"\\dir\\f1.txt" and L"dir\\f1.txt").

- The complete destination is created by fusing the dest prefix and the
  dest suffix, using the VirtioFsAppendPath() function.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-43-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
2020-12-21 17:16:23 +00:00
..
DriverBinding.c OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() 2020-12-21 17:16:23 +00:00
FuseFlush.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FLUSH 2020-12-21 17:16:23 +00:00
FuseForget.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_FORGET 2020-12-21 17:16:23 +00:00
FuseFsync.c OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_FSYNC / FUSE_FSYNCDIR 2020-12-21 17:16:23 +00:00
FuseGetAttr.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_GETATTR 2020-12-21 17:16:23 +00:00
FuseInit.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE 2020-12-21 17:16:23 +00:00
FuseLookup.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_LOOKUP 2020-12-21 17:16:23 +00:00
FuseMkDir.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_MKDIR 2020-12-21 17:16:23 +00:00
FuseOpen.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPEN 2020-12-21 17:16:23 +00:00
FuseOpenDir.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_OPENDIR 2020-12-21 17:16:23 +00:00
FuseOpenOrCreate.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_CREATE 2020-12-21 17:16:23 +00:00
FuseRead.c OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_READ / FUSE_READDIRPLUS 2020-12-21 17:16:23 +00:00
FuseRelease.c OvmfPkg/VirtioFsDxe: add shared wrapper for FUSE_RELEASE / FUSE_RELEASEDIR 2020-12-21 17:16:23 +00:00
FuseRename.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2 2020-12-21 17:16:23 +00:00
FuseStatFs.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_STATFS 2020-12-21 17:16:23 +00:00
FuseUnlink.c OvmfPkg/VirtioFsDxe: add a shared wrapper for FUSE_UNLINK / FUSE_RMDIR 2020-12-21 17:16:23 +00:00
FuseWrite.c OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_WRITE 2020-12-21 17:16:23 +00:00
Helpers.c OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path 2020-12-21 17:16:23 +00:00
SimpleFsClose.c OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE 2020-12-21 17:16:23 +00:00
SimpleFsDelete.c OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE 2020-12-21 17:16:23 +00:00
SimpleFsFlush.c OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Flush() 2020-12-21 17:16:23 +00:00
SimpleFsGetInfo.c OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetInfo() 2020-12-21 17:16:23 +00:00
SimpleFsGetPosition.c OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.GetPosition, .SetPosition 2020-12-21 17:16:23 +00:00
SimpleFsOpen.c OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE 2020-12-21 17:16:23 +00:00
SimpleFsOpenVolume.c OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE 2020-12-21 17:16:23 +00:00
SimpleFsRead.c OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Read() for directories 2020-12-21 17:16:23 +00:00
SimpleFsSetInfo.c OvmfPkg/VirtioFsDxe: handle the volume label in EFI_FILE_PROTOCOL.SetInfo 2020-12-21 17:16:23 +00:00
SimpleFsSetPosition.c OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE 2020-12-21 17:16:23 +00:00
SimpleFsWrite.c OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Write() 2020-12-21 17:16:23 +00:00
VirtioFsDxe.h OvmfPkg/VirtioFsDxe: add helper for composing rename/move destination path 2020-12-21 17:16:23 +00:00
VirtioFsDxe.inf OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_RENAME2 2020-12-21 17:16:23 +00:00