FuseRelease.c 4.0 KB

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