]>
Commit | Line | Data |
---|---|---|
2e151d26 LE |
1 | /** @file\r |
2 | FUSE_FSYNC / FUSE_FSYNCDIR wrapper for the Virtio Filesystem device.\r | |
3 | \r | |
4 | Copyright (C) 2020, Red Hat, Inc.\r | |
5 | \r | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | **/\r | |
8 | \r | |
9 | #include "VirtioFsDxe.h"\r | |
10 | \r | |
11 | /**\r | |
12 | Synchronize the in-core state of a regular file or a directory with the\r | |
13 | storage device on the host, by sending the FUSE_FSYNC or FUSE_FSYNCDIR\r | |
14 | request to the Virtio Filesystem device.\r | |
15 | \r | |
16 | The function may only be called after VirtioFsFuseInitSession() returns\r | |
17 | successfully and before VirtioFsUninit() is called.\r | |
18 | \r | |
19 | @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_FSYNC\r | |
20 | / FUSE_FSYNCDIR request to. On output, the FUSE\r | |
21 | request counter "VirtioFs->RequestId" will have been\r | |
22 | incremented.\r | |
23 | \r | |
24 | @param[in] NodeId The inode number of the file or directory to sync.\r | |
25 | \r | |
26 | @param[in] FuseHandle The open handle to the file or directory to sync.\r | |
27 | \r | |
28 | @param[in] IsDir TRUE if NodeId and FuseHandle refer to a directory,\r | |
29 | FALSE if NodeId and FuseHandle refer to a regular\r | |
30 | file.\r | |
31 | \r | |
32 | @retval EFI_SUCCESS The file or directory has been synchronized.\r | |
33 | \r | |
34 | @return The "errno" value mapped to an EFI_STATUS code, if the\r | |
35 | Virtio Filesystem device explicitly reported an error.\r | |
36 | \r | |
37 | @return Error codes propagated from VirtioFsSgListsValidate(),\r | |
38 | VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(),\r | |
39 | VirtioFsFuseCheckResponse().\r | |
40 | **/\r | |
41 | EFI_STATUS\r | |
42 | VirtioFsFuseFsyncFileOrDir (\r | |
ac0a286f MK |
43 | IN OUT VIRTIO_FS *VirtioFs,\r |
44 | IN UINT64 NodeId,\r | |
45 | IN UINT64 FuseHandle,\r | |
46 | IN BOOLEAN IsDir\r | |
2e151d26 LE |
47 | )\r |
48 | {\r | |
ac0a286f MK |
49 | VIRTIO_FS_FUSE_REQUEST CommonReq;\r |
50 | VIRTIO_FS_FUSE_FSYNC_REQUEST FsyncReq;\r | |
51 | VIRTIO_FS_IO_VECTOR ReqIoVec[2];\r | |
52 | VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList;\r | |
53 | VIRTIO_FS_FUSE_RESPONSE CommonResp;\r | |
54 | VIRTIO_FS_IO_VECTOR RespIoVec[1];\r | |
55 | VIRTIO_FS_SCATTER_GATHER_LIST RespSgList;\r | |
56 | EFI_STATUS Status;\r | |
2e151d26 LE |
57 | \r |
58 | //\r | |
59 | // Set up the scatter-gather lists.\r | |
60 | //\r | |
61 | ReqIoVec[0].Buffer = &CommonReq;\r | |
62 | ReqIoVec[0].Size = sizeof CommonReq;\r | |
63 | ReqIoVec[1].Buffer = &FsyncReq;\r | |
64 | ReqIoVec[1].Size = sizeof FsyncReq;\r | |
65 | ReqSgList.IoVec = ReqIoVec;\r | |
66 | ReqSgList.NumVec = ARRAY_SIZE (ReqIoVec);\r | |
67 | \r | |
68 | RespIoVec[0].Buffer = &CommonResp;\r | |
69 | RespIoVec[0].Size = sizeof CommonResp;\r | |
70 | RespSgList.IoVec = RespIoVec;\r | |
71 | RespSgList.NumVec = ARRAY_SIZE (RespIoVec);\r | |
72 | \r | |
73 | //\r | |
74 | // Validate the scatter-gather lists; calculate the total transfer sizes.\r | |
75 | //\r | |
76 | Status = VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList);\r | |
77 | if (EFI_ERROR (Status)) {\r | |
78 | return Status;\r | |
79 | }\r | |
80 | \r | |
81 | //\r | |
82 | // Populate the common request header.\r | |
83 | //\r | |
84 | Status = VirtioFsFuseNewRequest (\r | |
85 | VirtioFs,\r | |
86 | &CommonReq,\r | |
87 | ReqSgList.TotalSize,\r | |
88 | IsDir ? VirtioFsFuseOpFsyncDir : VirtioFsFuseOpFsync,\r | |
89 | NodeId\r | |
90 | );\r | |
91 | if (EFI_ERROR (Status)) {\r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
95 | //\r | |
96 | // Populate the FUSE_FSYNC- / FUSE_FSYNCDIR-specific fields.\r | |
97 | //\r | |
98 | FsyncReq.FileHandle = FuseHandle;\r | |
99 | FsyncReq.FsyncFlags = 0;\r | |
100 | FsyncReq.Padding = 0;\r | |
101 | \r | |
102 | //\r | |
103 | // Submit the request.\r | |
104 | //\r | |
105 | Status = VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList);\r | |
106 | if (EFI_ERROR (Status)) {\r | |
107 | return Status;\r | |
108 | }\r | |
109 | \r | |
110 | //\r | |
111 | // Verify the response (all response buffers are fixed size).\r | |
112 | //\r | |
113 | Status = VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NULL);\r | |
114 | if (Status == EFI_DEVICE_ERROR) {\r | |
ac0a286f MK |
115 | DEBUG ((\r |
116 | DEBUG_ERROR,\r | |
117 | "%a: Label=\"%s\" NodeId=%Lu FuseHandle=%Lu "\r | |
118 | "IsDir=%d Errno=%d\n",\r | |
119 | __FUNCTION__,\r | |
120 | VirtioFs->Label,\r | |
121 | NodeId,\r | |
122 | FuseHandle,\r | |
123 | IsDir,\r | |
124 | CommonResp.Error\r | |
125 | ));\r | |
2e151d26 LE |
126 | Status = VirtioFsErrnoToEfiStatus (CommonResp.Error);\r |
127 | }\r | |
ac0a286f | 128 | \r |
2e151d26 LE |
129 | return Status;\r |
130 | }\r |