summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c
blob: d7d04b94e5ab0d8eb2fb1e8e175a34f09c9fa2ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/** @file
  EFI_FILE_PROTOCOL.Flush() member function for the Virtio Filesystem driver.

  Copyright (C) 2020, Red Hat, Inc.

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

#include "VirtioFsDxe.h"

EFI_STATUS
EFIAPI
VirtioFsSimpleFileFlush (
  IN EFI_FILE_PROTOCOL  *This
  )
{
  VIRTIO_FS_FILE  *VirtioFsFile;
  VIRTIO_FS       *VirtioFs;
  EFI_STATUS      Status;

  VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
  VirtioFs     = VirtioFsFile->OwnerFs;

  if (!VirtioFsFile->IsOpenForWriting) {
    return EFI_ACCESS_DENIED;
  }

  //
  // FUSE_FLUSH is for regular files only.
  //
  if (!VirtioFsFile->IsDirectory) {
    Status = VirtioFsFuseFlush (
               VirtioFs,
               VirtioFsFile->NodeId,
               VirtioFsFile->FuseHandle
               );
    if (EFI_ERROR (Status)) {
      return Status;
    }
  }

  Status = VirtioFsFuseFsyncFileOrDir (
             VirtioFs,
             VirtioFsFile->NodeId,
             VirtioFsFile->FuseHandle,
             VirtioFsFile->IsDirectory
             );
  return Status;
}