1 | /** @file
|
---|
2 | EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem
|
---|
3 | driver.
|
---|
4 |
|
---|
5 | Copyright (C) 2020, Red Hat, Inc.
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include <Library/MemoryAllocationLib.h> // FreePool()
|
---|
11 |
|
---|
12 | #include "VirtioFsDxe.h"
|
---|
13 |
|
---|
14 | EFI_STATUS
|
---|
15 | EFIAPI
|
---|
16 | VirtioFsSimpleFileSetPosition (
|
---|
17 | IN EFI_FILE_PROTOCOL *This,
|
---|
18 | IN UINT64 Position
|
---|
19 | )
|
---|
20 | {
|
---|
21 | VIRTIO_FS_FILE *VirtioFsFile;
|
---|
22 | VIRTIO_FS *VirtioFs;
|
---|
23 | EFI_STATUS Status;
|
---|
24 | VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr;
|
---|
25 |
|
---|
26 | VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
|
---|
27 |
|
---|
28 | //
|
---|
29 | // Directories can only be rewound, per spec.
|
---|
30 | //
|
---|
31 | if (VirtioFsFile->IsDirectory) {
|
---|
32 | if (Position != 0) {
|
---|
33 | return EFI_UNSUPPORTED;
|
---|
34 | }
|
---|
35 | VirtioFsFile->FilePosition = 0;
|
---|
36 | if (VirtioFsFile->FileInfoArray != NULL) {
|
---|
37 | FreePool (VirtioFsFile->FileInfoArray);
|
---|
38 | VirtioFsFile->FileInfoArray = NULL;
|
---|
39 | }
|
---|
40 | VirtioFsFile->SingleFileInfoSize = 0;
|
---|
41 | VirtioFsFile->NumFileInfo = 0;
|
---|
42 | VirtioFsFile->NextFileInfo = 0;
|
---|
43 | return EFI_SUCCESS;
|
---|
44 | }
|
---|
45 |
|
---|
46 | //
|
---|
47 | // Regular file.
|
---|
48 | //
|
---|
49 | if (Position < MAX_UINT64) {
|
---|
50 | //
|
---|
51 | // Caller is requesting absolute file position.
|
---|
52 | //
|
---|
53 | VirtioFsFile->FilePosition = Position;
|
---|
54 | return EFI_SUCCESS;
|
---|
55 | }
|
---|
56 |
|
---|
57 | //
|
---|
58 | // Caller is requesting a seek to EOF.
|
---|
59 | //
|
---|
60 | VirtioFs = VirtioFsFile->OwnerFs;
|
---|
61 | Status = VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr);
|
---|
62 | if (EFI_ERROR (Status)) {
|
---|
63 | return Status;
|
---|
64 | }
|
---|
65 | VirtioFsFile->FilePosition = FuseAttr.Size;
|
---|
66 | return EFI_SUCCESS;
|
---|
67 | }
|
---|