From nobody Mon Feb 9 04:59:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69033+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69033+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608155499; cv=none; d=zohomail.com; s=zohoarc; b=OxaaOtShXqZl7NByJp1EFJeM730agftFkSVlMPyrUIr9LOUV8sUlN0nRU9NyGTdvYSKu4kV+0CAuO8gD+T1MZhn4qQRUrwFRUg5n/Y9Rm13Y/9vSbGOrnLAESPbTzqM9lXPE3Sa1I0RTOxJXBzbwZ7Hv3CLvEiO38cy4r69Mhss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608155499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=eiE09NSSdP3cthsHcReNcrVJ8Sh2YF4QFJZLnakFKBg=; b=Ha/leVlUdaX6TBkMflRV5nSsz6rjjdaHJkbKx6SgdhtkxQXSt8PwRffdyRnaeTxONfm3mV6aZGkTXr7q0S/JTE7WfHbmZeaJMjrdB4eRvv/rAGaCoWqlBwoZ/HDhbdtnpybZoYSda+mLU4M7Ng7JzTtF52o7JIC2PYh3EPCT9y8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69033+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608155499237789.7209239092789; Wed, 16 Dec 2020 13:51:39 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZoDAYY1788612xwh6ZIv0O4C; Wed, 16 Dec 2020 13:51:38 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web11.4066.1608155498253760753 for ; Wed, 16 Dec 2020 13:51:38 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-369-cprC8zIQPRy2FcxgsXtsGw-1; Wed, 16 Dec 2020 16:51:33 -0500 X-MC-Unique: cprC8zIQPRy2FcxgsXtsGw-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E85959; Wed, 16 Dec 2020 21:51:32 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8363227C3D; Wed, 16 Dec 2020 21:51:27 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 19/48] OvmfPkg/VirtioFsDxe: implement the wrapper function for FUSE_MKDIR Date: Wed, 16 Dec 2020 22:10:56 +0100 Message-Id: <20201216211125.19496-20-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: HwrecNSpwWnt2vK1o8tnkVobx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608155498; bh=eiE09NSSdP3cthsHcReNcrVJ8Sh2YF4QFJZLnakFKBg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gtgwazjGk7Sa746FISpuZGKpxqlBXvY/sQRJzZgkTMS/er2JfQd1pR+2phoERpIsr36 v4HNMmk2Ui2niKWyoXWqIdGgB8wLyc88cajKzJyctrlBVxLQJavPcUe44BCYxfd9Ii1tI fPOMgmU+VFEpd7ib9x1XFnHNAA/cskZuwr0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsFuseMkDir() function, for sending the FUSE_MKDIR command to the Virtio Filesystem device. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 55 ++++++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 1 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 8 ++ OvmfPkg/VirtioFsDxe/FuseMkDir.c | 134 ++++++++++++++++++++ 4 files changed, 198 insertions(+) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index 7b6f30335577..9ffeb9c8c954 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -76,27 +76,35 @@ typedef struct { #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 // // The inode number of the root directory. // #define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 =20 +// +// File mode bitmasks. +// +#define VIRTIO_FS_FUSE_MODE_PERM_RWXU 0000700u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXG 0000070u +#define VIRTIO_FS_FUSE_MODE_PERM_RWXO 0000007u + // // Flags for VirtioFsFuseOpOpen. // #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDONLY 0 #define VIRTIO_FS_FUSE_OPEN_REQ_F_RDWR 2 =20 // // FUSE operation codes. // typedef enum { VirtioFsFuseOpForget =3D 2, + VirtioFsFuseOpMkDir =3D 9, VirtioFsFuseOpOpen =3D 14, VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpFsync =3D 20, VirtioFsFuseOpFlush =3D 25, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, VirtioFsFuseOpFsyncDir =3D 30, @@ -118,23 +126,70 @@ typedef struct { } VIRTIO_FS_FUSE_REQUEST; =20 typedef struct { UINT32 Len; INT32 Error; UINT64 Unique; } VIRTIO_FS_FUSE_RESPONSE; =20 +// +// Structure with which the Virtio Filesystem device reports a NodeId to t= he +// FUSE client (i.e., to the Virtio Filesystem driver). This structure is a +// part of the response headers for operations that inform the FUSE client= of +// an inode. +// +typedef struct { + UINT64 NodeId; + UINT64 Generation; + UINT64 EntryValid; + UINT64 AttrValid; + UINT32 EntryValidNsec; + UINT32 AttrValidNsec; +} VIRTIO_FS_FUSE_NODE_RESPONSE; + +// +// Structure describing the host-side attributes of an inode. This structu= re is +// a part of the response headers for operations that inform the FUSE clie= nt of +// an inode. +// +typedef struct { + UINT64 Ino; + UINT64 Size; + UINT64 Blocks; + UINT64 Atime; + UINT64 Mtime; + UINT64 Ctime; + UINT32 AtimeNsec; + UINT32 MtimeNsec; + UINT32 CtimeNsec; + UINT32 Mode; + UINT32 Nlink; + UINT32 Uid; + UINT32 Gid; + UINT32 Rdev; + UINT32 Blksize; + UINT32 Padding; +} VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE; + // // Header for VirtioFsFuseOpForget. // typedef struct { UINT64 NumberOfLookups; } VIRTIO_FS_FUSE_FORGET_REQUEST; =20 +// +// Header for VirtioFsFuseOpMkDir. +// +typedef struct { + UINT32 Mode; + UINT32 Umask; +} VIRTIO_FS_FUSE_MKDIR_REQUEST; + // // Headers for VirtioFsFuseOpOpen and VirtioFsFuseOpOpenDir. // typedef struct { UINT32 Flags; UINT32 Unused; } VIRTIO_FS_FUSE_OPEN_REQUEST; =20 diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index dc9a12820f3d..eebb86f7c275 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,16 +81,17 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseFlush.c FuseForget.c FuseFsync.c FuseInit.c + FuseMkDir.c FuseOpen.c FuseOpenDir.c FuseRelease.c Helpers.c SimpleFsClose.c SimpleFsDelete.c SimpleFsFlush.c SimpleFsGetInfo.c diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index c13258a2e08f..8fd56bdbf6e1 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -230,16 +230,24 @@ VirtioFsAppendPath ( // =20 EFI_STATUS VirtioFsFuseForget ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId ); =20 +EFI_STATUS +VirtioFsFuseMkDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId + ); + EFI_STATUS VirtioFsFuseOpen ( IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN BOOLEAN ReadWrite, OUT UINT64 *FuseHandle ); =20 diff --git a/OvmfPkg/VirtioFsDxe/FuseMkDir.c b/OvmfPkg/VirtioFsDxe/FuseMkDi= r.c new file mode 100644 index 000000000000..541ff330cd1e --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/FuseMkDir.c @@ -0,0 +1,134 @@ +/** @file + FUSE_MKDIR wrapper for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // AsciiStrSize() + +#include "VirtioFsDxe.h" + +/** + Send a FUSE_MKDIR request to the Virtio Filesystem device, for creating a + directory. + + The function may only be called after VirtioFsFuseInitSession() returns + successfully and before VirtioFsUninit() is called. + + @param[in,out] VirtioFs The Virtio Filesystem device to send the FUSE_M= KDIR + request to. On output, the FUSE request counter + "VirtioFs->RequestId" will have been incremente= d. + + @param[in] ParentNodeId The inode number of the direct parent directory= of + the directory to create. + + @param[in] Name The single-component filename of the directory = to + create, under the parent directory identified by + ParentNodeId. + + @param[out] NodeId The inode number of the new directory. + + @retval EFI_SUCCESS The directory has been created. + + @return The "errno" value mapped to an EFI_STATUS code, if = the + Virtio Filesystem device explicitly reported an err= or. + + @return Error codes propagated from VirtioFsSgListsValidate= (), + VirtioFsFuseNewRequest(), VirtioFsSgListsSubmit(), + VirtioFsFuseCheckResponse(). +**/ +EFI_STATUS +VirtioFsFuseMkDir ( + IN OUT VIRTIO_FS *VirtioFs, + IN UINT64 ParentNodeId, + IN CHAR8 *Name, + OUT UINT64 *NodeId + ) +{ + VIRTIO_FS_FUSE_REQUEST CommonReq; + VIRTIO_FS_FUSE_MKDIR_REQUEST MkDirReq; + VIRTIO_FS_IO_VECTOR ReqIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST ReqSgList; + VIRTIO_FS_FUSE_RESPONSE CommonResp; + VIRTIO_FS_FUSE_NODE_RESPONSE NodeResp; + VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE AttrResp; + VIRTIO_FS_IO_VECTOR RespIoVec[3]; + VIRTIO_FS_SCATTER_GATHER_LIST RespSgList; + EFI_STATUS Status; + + // + // Set up the scatter-gather lists. + // + ReqIoVec[0].Buffer =3D &CommonReq; + ReqIoVec[0].Size =3D sizeof CommonReq; + ReqIoVec[1].Buffer =3D &MkDirReq; + ReqIoVec[1].Size =3D sizeof MkDirReq; + ReqIoVec[2].Buffer =3D Name; + ReqIoVec[2].Size =3D AsciiStrSize (Name); + ReqSgList.IoVec =3D ReqIoVec; + ReqSgList.NumVec =3D ARRAY_SIZE (ReqIoVec); + + RespIoVec[0].Buffer =3D &CommonResp; + RespIoVec[0].Size =3D sizeof CommonResp; + RespIoVec[1].Buffer =3D &NodeResp; + RespIoVec[1].Size =3D sizeof NodeResp; + RespIoVec[2].Buffer =3D &AttrResp; + RespIoVec[2].Size =3D sizeof AttrResp; + RespSgList.IoVec =3D RespIoVec; + RespSgList.NumVec =3D ARRAY_SIZE (RespIoVec); + + // + // Validate the scatter-gather lists; calculate the total transfer sizes. + // + Status =3D VirtioFsSgListsValidate (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the common request header. + // + Status =3D VirtioFsFuseNewRequest (VirtioFs, &CommonReq, ReqSgList.Total= Size, + VirtioFsFuseOpMkDir, ParentNodeId); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Populate the FUSE_MKDIR-specific fields. + // + MkDirReq.Mode =3D (VIRTIO_FS_FUSE_MODE_PERM_RWXU | + VIRTIO_FS_FUSE_MODE_PERM_RWXG | + VIRTIO_FS_FUSE_MODE_PERM_RWXO); + MkDirReq.Umask =3D 0; + + // + // Submit the request. + // + Status =3D VirtioFsSgListsSubmit (VirtioFs, &ReqSgList, &RespSgList); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Verify the response (all response buffers are fixed size). + // + Status =3D VirtioFsFuseCheckResponse (&RespSgList, CommonReq.Unique, NUL= L); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_DEVICE_ERROR) { + DEBUG ((DEBUG_ERROR, "%a: Label=3D\"%s\" ParentNodeId=3D%Lu Name=3D\= "%a\" " + "Errno=3D%d\n", __FUNCTION__, VirtioFs->Label, ParentNodeId, Name, + CommonResp.Error)); + Status =3D VirtioFsErrnoToEfiStatus (CommonResp.Error); + } + return Status; + } + + // + // Output the NodeId of the new directory. + // + *NodeId =3D NodeResp.NodeId; + return EFI_SUCCESS; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69033): https://edk2.groups.io/g/devel/message/69033 Mute This Topic: https://groups.io/mt/79023350/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-