From patchwork Mon Apr 25 14:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 575B9C433F5 for ; Mon, 25 Apr 2022 14:36:33 +0000 (UTC) Received: from localhost ([::1]:59004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizpI-0005sX-Ec for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:36:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgO-0006Sk-F8 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:20 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:34527) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgM-0004ha-RD for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:20 -0400 Received: by mail-pg1-x52c.google.com with SMTP id z21so5919933pgj.1 for ; Mon, 25 Apr 2022 07:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t9wxe2NnzThJXmH701I7MFDWCA+taSH4hJNR9Xh8jHE=; b=E0SNec/PfBpADb6q0GdLmI7FqFdqdqcQqUO7+j+LaPshUKYShmm0auVBjpDE1n+KpE bte09l2coi0gbuj0LYszp2LvJYCrtsazictokF7FRKqyvFk0sKPGiGrmasGe4spJ8x2C PSbhtcj4X/WcfyJ0kGgA6F+uyAx3KBlXJbcWlxnLPNax75ozURbCTVmcwpaMn24HjTzn dmMbYsF45SZD2jMzhQLJ1q2ifUd+xFZxZFxwIVfq7HQqHWqmRnIK9gwNFUQxnVLlj2qX L1D9nDh6fMWCUSyW+efpfVvDFVeZXaAYB+P36VHeSzzVf8cZ5MVRduKrjIBBhVaLclz1 LLJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t9wxe2NnzThJXmH701I7MFDWCA+taSH4hJNR9Xh8jHE=; b=SyJeXxbeCQ1GezsnreZFjK2xkY5/GiMbTJzEVErZVv35jwAhPq+4OduB8Ru6XV0CPk QThgsqz14QxpYKtXzxJyDsoCaCuzgf6C/bnjh1J4cPG2FQnpMb0ZHl1+1Nr0rZfvtObx vVPtTAoe+3DuYtJL56+hwl9uUqDIbET6HeFC+R9Z9RYbV0nazFMzy9J+VbTc5ddZKAZ6 di2ZD9nfBMatrZYmJIgXAY8J63efVzCHqDbZ9VG+3jKGIxoRYMBNol4K2hwuClJxw7Nl cfDqE/3v0o8sWDg3h+Z19C1sJFTHyQvBF3lGfhjSQoU2PsnDyP6B3HVrsVluZbEhk0ua 9sTg== X-Gm-Message-State: AOAM533ChzOp9xyD8CXCXgf6w1NsTheF5ceHGT6glkQqNClnCQ0+ejJU wmMnZczftE5IvoVQaJQErywcWZ5kJBI= X-Google-Smtp-Source: ABdhPJxJ2pl37kQWuiEBGuc9Nb7qdu4lBNVHGvXuUMd7IsVTKDiNJRg+zCK6t+LpJhMYn0bMEyT7dA== X-Received: by 2002:a63:88c3:0:b0:3ab:2edc:b95b with SMTP id l186-20020a6388c3000000b003ab2edcb95bmr5355015pgd.233.1650896837626; Mon, 25 Apr 2022 07:27:17 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:17 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 1/9] hw/9pfs: Compile 9p-local.c and 9p-proxy.c for Linux and macOS Date: Mon, 25 Apr 2022 22:26:57 +0800 Message-Id: <20220425142705.2099270-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52c; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng For better readability, Windows support of 9pfs local backend driver will be provided in a separate 9p-local-win32.c file, hence let's only compile 9p-local.c for Linux and macOS. As we don't plan to support 9p proxy on Windows, apply the same to 9p-proxy.c. Signed-off-by: Bin Meng --- hw/9pfs/meson.build | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build index 12443b6ad5..b4a8ff0913 100644 --- a/hw/9pfs/meson.build +++ b/hw/9pfs/meson.build @@ -1,8 +1,6 @@ fs_ss = ss.source_set() fs_ss.add(files( - '9p-local.c', '9p-posix-acl.c', - '9p-proxy.c', '9p-synth.c', '9p-xattr-user.c', '9p-xattr.c', @@ -13,8 +11,12 @@ fs_ss.add(files( 'coth.c', 'coxattr.c', )) -fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-util-linux.c')) -fs_ss.add(when: 'CONFIG_DARWIN', if_true: files('9p-util-darwin.c')) +fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-local.c', + '9p-proxy.c', + '9p-util-linux.c')) +fs_ss.add(when: 'CONFIG_DARWIN', if_true: files('9p-local.c', + '9p-proxy.c', + '9p-util-darwin.c')) fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c')) softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss) From patchwork Mon Apr 25 14:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA82AC433EF for ; Mon, 25 Apr 2022 14:39:39 +0000 (UTC) Received: from localhost ([::1]:41078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizsJ-0004D9-1c for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:39:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgU-0006UC-6h for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:26 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:45994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgS-0004ho-Q4 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:25 -0400 Received: by mail-pj1-x102e.google.com with SMTP id n33-20020a17090a5aa400b001d28f5ee3f9so6044740pji.4 for ; Mon, 25 Apr 2022 07:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/65BMxjgN2mK/5Pu9C5+z++998qk7KcZ4nDu6mhJk3k=; b=RTx/kMh2eD8FhSTzwREsmyklITekC9gw3uAfU4P23D7/9Legosj2+8U7NhNGAaF+Xd f0ILfNYx/1xJBs4wwQH6KHq6ZbCaKbyzOlia91qfpT0RxnMc6Dqx33wqg1iXfrgGsQ55 SjahDJYXo5Ectm3vKalAQIwmA1ONLTtAFHoD/5Sp3JJ6c1pBzZTIPtayJ8sZBh6c7PQ0 qSnA1Yh6Nf36I9AoP5YRbMlGX9zNtg28Rkvww6plVwVJGW0ZonGcaWkeVAUbWYkHD2LG CX3Knfr+YA5jRf37yR0b+ToM4q8GmyLyiMHLadoWywvDyxjB2SpjS6RfzgyHncwFxfW+ y0eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/65BMxjgN2mK/5Pu9C5+z++998qk7KcZ4nDu6mhJk3k=; b=NeFdmpcFCAU/Wdc8arr78UZlrLJY1zgkhFbJPt3kjj1Sy5e8C87VuGHjj1H2PiUwdJ l+20/G3WirhHJDfdCCCIs4aO0GJn7+qbyQroqVfxvb/rJ9AML+q+edFoQ74MtlerQMf8 tOnbLRyk51b4IuC37s1suS43QhYxV527LD6IMe4okE7zsvckR/nR4MgpwlnVD5HeJm0F LiJ4O10dXzRG/zi72br/sH6abgoLcsMIDFWgxVXEzUa2WepOUcenTpD3ls2g+bnNtQB0 51MRCeTK/WCGcmbGcsi7Sji/I+UEJotch/cm20f5zeyTdxDNJzwtE7t43WCl51NM9C9d cR/Q== X-Gm-Message-State: AOAM532utpSCi4Vu7z6rQJOiDoUKo0FoIyavgzgiR0cFyg5piker6WY/ w4bjJm5Hu+U6IRCm3H+wvDPVN33vSq4= X-Google-Smtp-Source: ABdhPJx6RV5kvf/PxpDiZiP9VDI/Dfz77Urmz4/Ber9hVrvToUdQFviYXYV+HPmsa+EruhZorkI97w== X-Received: by 2002:a17:902:8d8e:b0:159:4f6:c4aa with SMTP id v14-20020a1709028d8e00b0015904f6c4aamr18415434plo.115.1650896840853; Mon, 25 Apr 2022 07:27:20 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:20 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 2/9] qemu/xatth.h: Update for Windows build Date: Mon, 25 Apr 2022 22:26:58 +0800 Message-Id: <20220425142705.2099270-3-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng Windows does not have . Signed-off-by: Bin Meng --- include/qemu/xattr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/qemu/xattr.h b/include/qemu/xattr.h index f1d0f7be74..b08a934acc 100644 --- a/include/qemu/xattr.h +++ b/include/qemu/xattr.h @@ -25,7 +25,9 @@ # if !defined(ENOATTR) # define ENOATTR ENODATA # endif -# include +# ifndef CONFIG_WIN32 +# include +# endif #endif #endif From patchwork Mon Apr 25 14:26:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A10BDC433FE for ; Mon, 25 Apr 2022 14:35:59 +0000 (UTC) Received: from localhost ([::1]:56426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizok-0004B5-Kl for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:35:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgV-0006W0-Eo for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:32 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:39751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgT-0004hx-9h for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:27 -0400 Received: by mail-pj1-x1033.google.com with SMTP id bd19-20020a17090b0b9300b001d98af6dcd1so94333pjb.4 for ; Mon, 25 Apr 2022 07:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cgH1nLMBp7dm1saUWSPVOv3Pj2nqgXKX1pYTbouhGLY=; b=EsnMLo7tCKfVqKoNvjdOBZY6ZlWcCxm8BWo/21jmVzb0AORQVUYe+qP30zoudIwypU xea0S1XUz2cckoXa6msLQUKjiyEjhQzA9pQVJc0bL0Fl+9Fq1V0iIqg2pEM3BZ6NVSrT SztZZbx+Uqoyj1IR4up3RLnDLS2V0tn5Vq9QGNivEBW83cuIZbIk1DU7tqwsdnZLU2Yb IPge+2OmHIwmElFqLO9u4X0MxXWvVlwZIKL4iPA/77v3nZCOLyl5p7ifkXIL1J0xNrTY pLa24AcI+liQ48sDUVPddjKrASeu9yq2zM2vXkacZKfsLBGzpfhjAq7zHuUPkGE5sMHk KW/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cgH1nLMBp7dm1saUWSPVOv3Pj2nqgXKX1pYTbouhGLY=; b=TMcj9IKepiMFc8SmGb4hrLpefWun83GCJsMaeN1ouO/bgvQ8wgYRazlZELoqNoOKYj APOEMlS8gKL3aFXjE3RdR4UfQPwjBK/VoPu47wQ0Jz5ackuXf0WY5blXp1HiaT7N2/RL kFlEMAoF392pgJY9S3Osnn1L7oCqFwbyW4hl8VtinPz3VwSR8chRchURZrtDGi9Ez79Y b3uxkLDCjAQsA4Gop/A0/s0plPVsiqiMQjBqFQKzfU2N52srrqs4HwspvrKvCMduYAI4 T4voaWIe4X1zZGNXLp+FMAJaKTRA3TeWM6QzrD4lqhrnycKNv2iYYJSaqoezM6y2pBYw THXg== X-Gm-Message-State: AOAM531JZnsaRqHGA3OHKJx7LclQ5ePjSteBnHHfYW/stBaV2KPlS0TB 8+sebUQ/LVsjCuzB7w40woSvUGwCKsM= X-Google-Smtp-Source: ABdhPJz7+Utexi/OtniKH/v8bqHtMrhi6haKUsnWX+G325CwrQ3T7Bw6XkZ3V0YABldL6it8+5j+zw== X-Received: by 2002:a17:902:8605:b0:15d:10dc:1c6f with SMTP id f5-20020a170902860500b0015d10dc1c6fmr5851453plo.4.1650896843951; Mon, 25 Apr 2022 07:27:23 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:23 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 3/9] hw/9pfs: Extract common stuff to 9p-local.h Date: Mon, 25 Apr 2022 22:26:59 +0800 Message-Id: <20220425142705.2099270-4-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Some macros (e.g.: VIRTFS_META_DIR) are used by both Linux and macOS, and will be used by the upcoming Windows support too, extract them from 9p-local.c to 9p-local.h. Note local_is_mapped_file_metadata()is changed to an inline function. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- hw/9pfs/9p-local.h | 16 ++++++++++++++++ hw/9pfs/9p-local.c | 14 -------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/hw/9pfs/9p-local.h b/hw/9pfs/9p-local.h index 32c72749d9..55ea4b7883 100644 --- a/hw/9pfs/9p-local.h +++ b/hw/9pfs/9p-local.h @@ -13,6 +13,22 @@ #ifndef QEMU_9P_LOCAL_H #define QEMU_9P_LOCAL_H +#define VIRTFS_META_DIR ".virtfs_metadata" +#define VIRTFS_META_ROOT_FILE VIRTFS_META_DIR "_root" + +#define ATTR_MAX 100 + +typedef struct { + int mountfd; +} LocalData; + +static inline bool local_is_mapped_file_metadata(FsContext *fs_ctx, + const char *name) +{ + return + !strcmp(name, VIRTFS_META_DIR) || !strcmp(name, VIRTFS_META_ROOT_FILE); +} + int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, mode_t mode); int local_opendir_nofollow(FsContext *fs_ctx, const char *path); diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index d42ce6d8b8..73beef84a9 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -53,10 +53,6 @@ #define BTRFS_SUPER_MAGIC 0x9123683E #endif -typedef struct { - int mountfd; -} LocalData; - int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, mode_t mode) { @@ -114,9 +110,6 @@ static void unlinkat_preserve_errno(int dirfd, const char *path, int flags) errno = serrno; } -#define VIRTFS_META_DIR ".virtfs_metadata" -#define VIRTFS_META_ROOT_FILE VIRTFS_META_DIR "_root" - static FILE *local_fopenat(int dirfd, const char *name, const char *mode) { int fd, o_mode = 0; @@ -144,7 +137,6 @@ static FILE *local_fopenat(int dirfd, const char *name, const char *mode) return fp; } -#define ATTR_MAX 100 static void local_mapped_file_attr(int dirfd, const char *name, struct stat *stbuf) { @@ -547,12 +539,6 @@ static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs) return telldir(fs->dir.stream); } -static bool local_is_mapped_file_metadata(FsContext *fs_ctx, const char *name) -{ - return - !strcmp(name, VIRTFS_META_DIR) || !strcmp(name, VIRTFS_META_ROOT_FILE); -} - static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) { struct dirent *entry; From patchwork Mon Apr 25 14:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F0AEC433EF for ; Mon, 25 Apr 2022 14:42:10 +0000 (UTC) Received: from localhost ([::1]:47906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizuj-0000Na-Nm for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:42:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgZ-0006WG-Sm for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:35 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:41668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgX-0004iK-PX for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:31 -0400 Received: by mail-pg1-x52f.google.com with SMTP id t13so13558160pgn.8 for ; Mon, 25 Apr 2022 07:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KrgU3+IX4XWkPyP4DiZKgG5uVyLxX2CCY6D8wOC32zw=; b=Q/LX7OCam4PEcRI3xgzXBE4UtssxTZzNGxzMZoeMI9Elr5gx+kw91aVHrWx7sB1N8G uOj9zvYre/a2qf2FqwsDpiKUhUjhqkf7Lm+5BiWqfgac9J6Q2Vpkwmq3HgZtv4++7Hvd v9vNGeUkO1qocu2yH6Tf520uDcgL2Yqao8AjQTnJw68gmtLTTykt39T+BhoiNc9AM/8d wnNUdA/ryltqcWpv0wSe7xCsx/WFXaZZf0lmFP4UuWSRARApSJN1hrg6soRM3PIUjfsn iQNFvt0W98Vbz70MeTGYOMLVui4pbhqELctpRRKk9j/aykyNmla3LOEi34jHIETZuYQB khKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KrgU3+IX4XWkPyP4DiZKgG5uVyLxX2CCY6D8wOC32zw=; b=Ba9U27fkSpBwDM3fldsTc86zOKQ4yrnbz75OoIru3Viyvv0/HCgWD8Iv+zx3b6CstK t3jBD/1QRYcCuPHjq0J2xOKZdJ4ephReHsyeyvTEKT2sRrwqGweIaVO+E4c0VmLwaOVU huNy1Oo3gHAtFIwK/VEMS5I0K+sN2N3BVthWzN5KhaOe4t2IS0zQ3im1Ixuc5sv2NqYu Rdz8wyZcp8oOQXV4djCJbJpB1CfD7z7PsxqTf6LR1D4U9QBNoaw5mboEgiugMTX2HVpH WHLP74oYLyqvham25ztusmODfwzGra/cpUhu4AT2HnY2cIB83aqx8maQg6JkJrPtmSJX ocDg== X-Gm-Message-State: AOAM530a9ALUJH9trNaAqtP6hxKphIh0N5dLSd5pwxp/Sc9PKvzM3kVg ItkO79fDfeFWFlBJRybCCHW7was7HcA= X-Google-Smtp-Source: ABdhPJxweqr0oWCPyvUdyFXzy6JvcnfGwUkp2kTFtiiZ8r6LhE84U4M4s8Cmy5cN2+NcSzCHbORx7g== X-Received: by 2002:a63:4412:0:b0:3a9:e7e1:81a6 with SMTP id r18-20020a634412000000b003a9e7e181a6mr15269269pga.532.1650896847032; Mon, 25 Apr 2022 07:27:27 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:26 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 4/9] fsdev: Add missing definitions for Windows in file-op-9p.h Date: Mon, 25 Apr 2022 22:27:00 +0800 Message-Id: <20220425142705.2099270-5-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=bmeng.cn@gmail.com; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Add uid_t, gid_t and struct statfs definitions, which are currently missing from Windows headers, but are required when we add 9p file system support for Windows in later patches. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- fsdev/file-op-9p.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 4997677460..7d9a736b66 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -27,6 +27,39 @@ # include #endif +#ifdef CONFIG_WIN32 + +/* POSIX structure not defined in Windows */ + +typedef uint32_t uid_t; +typedef uint32_t gid_t; + +/* from http://man7.org/linux/man-pages/man2/statfs.2.html */ +typedef uint32_t __fsword_t; +typedef uint32_t fsblkcnt_t; +typedef uint32_t fsfilcnt_t; + +/* from linux/include/uapi/asm-generic/posix_types.h */ +typedef struct { + long __val[2]; +} fsid_t; + +struct statfs { + __fsword_t f_type; + __fsword_t f_bsize; + fsblkcnt_t f_blocks; + fsblkcnt_t f_bfree; + fsblkcnt_t f_bavail; + fsfilcnt_t f_files; + fsfilcnt_t f_ffree; + fsid_t f_fsid; + __fsword_t f_namelen; + __fsword_t f_frsize; + __fsword_t f_flags; +}; + +#endif /* CONFIG_WIN32 */ + #define SM_LOCAL_MODE_BITS 0600 #define SM_LOCAL_DIR_MODE_BITS 0700 From patchwork Mon Apr 25 14:27:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B3A5C433F5 for ; Mon, 25 Apr 2022 14:44:52 +0000 (UTC) Received: from localhost ([::1]:53902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizxL-0004Lp-Lo for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:44:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgg-0006Yr-1b for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:39 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:36556) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgb-0004ia-QK for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:37 -0400 Received: by mail-pf1-x431.google.com with SMTP id z16so14935020pfh.3 for ; Mon, 25 Apr 2022 07:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D6iS52cEqnA17Eh0qoHrEaZEA10oXUglka0Yf/n3Dwg=; b=lJVI8uDA7qXY3ku/NOdHtL54sGrxuoYdPtzGBM0/GbBtQ0SUU1PqtETMeD2ba+BpSy TR8Nuj//OhoRPQnNCX4o1td88djSLnxxwz5L28M4W9PaR3dmso62ChfHVBDhw9W4oQSd k1Ggth8NBLsHlWJOFyFadMKbQpNtyrqILxIVbVewq1krjtd2uLqC4EZBRGqLpszagrtd NtqrouRBlOn965Iel4D1YHHIDYm9Gj8EbpvcgpuQBn5Nja3JEvBeczpnBjV8P6Rb6diG 0i8W8Q7/L76ZUMNlzbkQJIYBT9nVVWBihoNsptA141mgsTxhmJFkP/vPSDzIRHuPCgXV E9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D6iS52cEqnA17Eh0qoHrEaZEA10oXUglka0Yf/n3Dwg=; b=Fp14MLuseY5vqEdw/FC9AHHYnchcRq4256CqfP14EhZ+GjmQkEqX5KPGz8bZRLgdES bbd8IZmMtnm8goI1guhB7ZdAjMrgoVxXhR1EjFUerhVMea5aWIQ+HQrv9UMYeRxsKse9 N4PbmtmrBhD3XGllZCm9vW9gmnzoTOkPp8GY/2ZP8iM8at4RhUkcC7/Hiu4U5oXkBmxJ YwOnKCv/Qu8h2FI6Xi/EKojEpsEHW6m4rG5PqOuMkpnwGqBx4VbrH75s2kDUNftIcL80 OyLUthjnLL76RNyR5xOET+IvX3riF/OT+EBpe91n2BCHFG1X499pBCUTjfxzL8gvJ2xR B3vQ== X-Gm-Message-State: AOAM531MGmNaYbUilSge/bjofOPA3OE8yZ2H0qjhhoqvaZOW0BOmcJUa zQcvqfwCVyJDQPNXVE93F24= X-Google-Smtp-Source: ABdhPJwIOnBe2VeFARIymaC+HJl8ZdpOWb2UW6loOhX5ZvsYoT6ZTi6QlFmKakS4kpZoowf2OWGOkw== X-Received: by 2002:a63:f118:0:b0:3aa:2a2b:5702 with SMTP id f24-20020a63f118000000b003aa2a2b5702mr15513037pgi.127.1650896851317; Mon, 25 Apr 2022 07:27:31 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:30 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 5/9] hw/9pfs: Add a 'local' file system backend driver for Windows Date: Mon, 25 Apr 2022 22:27:01 +0800 Message-Id: <20220425142705.2099270-6-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=bmeng.cn@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_OTHER_BAD_TLD=1.997, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Add a 9p local file system backend driver to support Windows, including open, read, write, close, rename, remove, etc. All security models are supported. The mapped (mapped-xattr) security model is implemented using NTFS Alternate Data Stream (ADS) so the 9p export path shall be on an NTFS partition. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- hw/9pfs/9p-linux-errno.h | 151 +++++ hw/9pfs/9p-local.h | 4 + hw/9pfs/9p-util.h | 41 ++ hw/9pfs/9p.h | 23 + hw/9pfs/9p-local-win32.c | 1242 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p-util-win32.c | 303 ++++++++++ hw/9pfs/9p-xattr.c | 113 ++++ hw/9pfs/9p.c | 91 ++- hw/9pfs/codir.c | 15 + 9 files changed, 1982 insertions(+), 1 deletion(-) create mode 100644 hw/9pfs/9p-linux-errno.h create mode 100644 hw/9pfs/9p-local-win32.c create mode 100644 hw/9pfs/9p-util-win32.c diff --git a/hw/9pfs/9p-linux-errno.h b/hw/9pfs/9p-linux-errno.h new file mode 100644 index 0000000000..b0d6ac45ac --- /dev/null +++ b/hw/9pfs/9p-linux-errno.h @@ -0,0 +1,151 @@ +/* + * 9p Linux errno translation definition + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include + +#ifndef QEMU_9P_LINUX_ERRNO_H +#define QEMU_9P_LINUX_ERRNO_H + +/* + * This file contains the Linux errno definitions to translate errnos set by + * the 9P server (running on Windows) to a corresponding errno value. + * + * This list should be periodically reviewed and updated; particularly for + * errnos that might be set as a result of a file system operation. + */ + +#define L_EPERM 1 /* Operation not permitted */ +#define L_ENOENT 2 /* No such file or directory */ +#define L_ESRCH 3 /* No such process */ +#define L_EINTR 4 /* Interrupted system call */ +#define L_EIO 5 /* I/O error */ +#define L_ENXIO 6 /* No such device or address */ +#define L_E2BIG 7 /* Argument list too long */ +#define L_ENOEXEC 8 /* Exec format error */ +#define L_EBADF 9 /* Bad file number */ +#define L_ECHILD 10 /* No child processes */ +#define L_EAGAIN 11 /* Try again */ +#define L_ENOMEM 12 /* Out of memory */ +#define L_EACCES 13 /* Permission denied */ +#define L_EFAULT 14 /* Bad address */ +#define L_ENOTBLK 15 /* Block device required */ +#define L_EBUSY 16 /* Device or resource busy */ +#define L_EEXIST 17 /* File exists */ +#define L_EXDEV 18 /* Cross-device link */ +#define L_ENODEV 19 /* No such device */ +#define L_ENOTDIR 20 /* Not a directory */ +#define L_EISDIR 21 /* Is a directory */ +#define L_EINVAL 22 /* Invalid argument */ +#define L_ENFILE 23 /* File table overflow */ +#define L_EMFILE 24 /* Too many open files */ +#define L_ENOTTY 25 /* Not a typewriter */ +#define L_ETXTBSY 26 /* Text file busy */ +#define L_EFBIG 27 /* File too large */ +#define L_ENOSPC 28 /* No space left on device */ +#define L_ESPIPE 29 /* Illegal seek */ +#define L_EROFS 30 /* Read-only file system */ +#define L_EMLINK 31 /* Too many links */ +#define L_EPIPE 32 /* Broken pipe */ +#define L_EDOM 33 /* Math argument out of domain of func */ +#define L_ERANGE 34 /* Math result not representable */ +#define L_EDEADLK 35 /* Resource deadlock would occur */ +#define L_ENAMETOOLONG 36 /* File name too long */ +#define L_ENOLCK 37 /* No record locks available */ +#define L_ENOSYS 38 /* Function not implemented */ +#define L_ENOTEMPTY 39 /* Directory not empty */ +#define L_ELOOP 40 /* Too many symbolic links encountered */ +#define L_ENOMSG 42 /* No message of desired type */ +#define L_EIDRM 43 /* Identifier removed */ +#define L_ECHRNG 44 /* Channel number out of range */ +#define L_EL2NSYNC 45 /* Level 2 not synchronized */ +#define L_EL3HLT 46 /* Level 3 halted */ +#define L_EL3RST 47 /* Level 3 reset */ +#define L_ELNRNG 48 /* Link number out of range */ +#define L_EUNATCH 49 /* Protocol driver not attached */ +#define L_ENOCSI 50 /* No CSI structure available */ +#define L_EL2HLT 51 /* Level 2 halted */ +#define L_EBADE 52 /* Invalid exchange */ +#define L_EBADR 53 /* Invalid request descriptor */ +#define L_EXFULL 54 /* Exchange full */ +#define L_ENOANO 55 /* No anode */ +#define L_EBADRQC 56 /* Invalid request code */ +#define L_EBADSLT 57 /* Invalid slot */ +#define L_EBFONT 58 /* Bad font file format */ +#define L_ENOSTR 59 /* Device not a stream */ +#define L_ENODATA 61 /* No data available */ +#define L_ETIME 62 /* Timer expired */ +#define L_ENOSR 63 /* Out of streams resources */ +#define L_ENONET 64 /* Machine is not on the network */ +#define L_ENOPKG 65 /* Package not installed */ +#define L_EREMOTE 66 /* Object is remote */ +#define L_ENOLINK 67 /* Link has been severed */ +#define L_EADV 68 /* Advertise error */ +#define L_ESRMNT 69 /* Srmount error */ +#define L_ECOMM 70 /* Communication error on send */ +#define L_EPROTO 71 /* Protocol error */ +#define L_EMULTIHOP 72 /* Multihop attempted */ +#define L_EDOTDOT 73 /* RFS specific error */ +#define L_EBADMSG 74 /* Not a data message */ +#define L_EOVERFLOW 75 /* Value too large for defined data type */ +#define L_ENOTUNIQ 76 /* Name not unique on network */ +#define L_EBADFD 77 /* File descriptor in bad state */ +#define L_EREMCHG 78 /* Remote address changed */ +#define L_ELIBACC 79 /* Can not access a needed shared library */ +#define L_ELIBBAD 80 /* Accessing a corrupted shared library */ +#define L_ELIBSCN 81 /* .lib section in a.out corrupted */ +#define L_ELIBMAX 82 /* Attempting to link in too many shared libs */ +#define L_ELIBEXEC 83 /* Cannot exec a shared library directly */ +#define L_EILSEQ 84 /* Illegal byte sequence */ +#define L_ERESTART 85 /* Interrupted system call should be restarted */ +#define L_ESTRPIPE 86 /* Streams pipe error */ +#define L_EUSERS 87 /* Too many users */ +#define L_ENOTSOCK 88 /* Socket operation on non-socket */ +#define L_EDESTADDRREQ 89 /* Destination address required */ +#define L_EMSGSIZE 90 /* Message too long */ +#define L_EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define L_ENOPROTOOPT 92 /* Protocol not available */ +#define L_EPROTONOSUPPORT 93 /* Protocol not supported */ +#define L_ESOCKTNOSUPPORT 94 /* Socket type not supported */ +#define L_EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define L_EPFNOSUPPORT 96 /* Protocol family not supported */ +#define L_EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define L_EADDRINUSE 98 /* Address already in use */ +#define L_EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define L_ENETDOWN 100 /* Network is down */ +#define L_ENETUNREACH 101 /* Network is unreachable */ +#define L_ENETRESET 102 /* Network dropped connection because of reset */ +#define L_ECONNABORTED 103 /* Software caused connection abort */ +#define L_ECONNRESET 104 /* Connection reset by peer */ +#define L_ENOBUFS 105 /* No buffer space available */ +#define L_EISCONN 106 /* Transport endpoint is already connected */ +#define L_ENOTCONN 107 /* Transport endpoint is not connected */ +#define L_ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ +#define L_ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define L_ETIMEDOUT 110 /* Connection timed out */ +#define L_ECONNREFUSED 111 /* Connection refused */ +#define L_EHOSTDOWN 112 /* Host is down */ +#define L_EHOSTUNREACH 113 /* No route to host */ +#define L_EALREADY 114 /* Operation already in progress */ +#define L_EINPROGRESS 115 /* Operation now in progress */ +#define L_ESTALE 116 /* Stale NFS file handle */ +#define L_EUCLEAN 117 /* Structure needs cleaning */ +#define L_ENOTNAM 118 /* Not a XENIX named type file */ +#define L_ENAVAIL 119 /* No XENIX semaphores available */ +#define L_EISNAM 120 /* Is a named type file */ +#define L_EREMOTEIO 121 /* Remote I/O error */ +#define L_EDQUOT 122 /* Quota exceeded */ +#define L_ENOMEDIUM 123 /* No medium found */ +#define L_EMEDIUMTYPE 124 /* Wrong medium type */ +#define L_ECANCELED 125 /* Operation Canceled */ +#define L_ENOKEY 126 /* Required key not available */ +#define L_EKEYEXPIRED 127 /* Key has expired */ +#define L_EKEYREVOKED 128 /* Key has been revoked */ +#define L_EKEYREJECTED 129 /* Key was rejected by service */ +#define L_EOWNERDEAD 130 /* Owner died */ +#define L_ENOTRECOVERABLE 131 /* State not recoverable */ + +#endif /* QEMU_9P_LINUX_ERRNO_H */ diff --git a/hw/9pfs/9p-local.h b/hw/9pfs/9p-local.h index 55ea4b7883..4c75876e19 100644 --- a/hw/9pfs/9p-local.h +++ b/hw/9pfs/9p-local.h @@ -31,6 +31,10 @@ static inline bool local_is_mapped_file_metadata(FsContext *fs_ctx, int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, mode_t mode); +#ifndef CONFIG_WIN32 int local_opendir_nofollow(FsContext *fs_ctx, const char *path); +#else +DIR *local_opendir_nofollow(FsContext *fs_ctx, const char *path); +#endif #endif diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 97e681e167..6eadb38e1d 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -43,6 +43,7 @@ static inline void close_preserve_errno(int fd) errno = serrno; } +#ifndef CONFIG_WIN32 static inline int openat_dir(int dirfd, const char *name) { return openat(dirfd, name, @@ -89,7 +90,9 @@ again: errno = serrno; return fd; } +#endif /* !CONFIG_WIN32 */ +#ifndef CONFIG_WIN32 ssize_t fgetxattrat_nofollow(int dirfd, const char *path, const char *name, void *value, size_t size); int fsetxattrat_nofollow(int dirfd, const char *path, const char *name, @@ -98,7 +101,38 @@ ssize_t flistxattrat_nofollow(int dirfd, const char *filename, char *list, size_t size); ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name); +#else + +ssize_t fgetxattrat_nofollow(const char *dirname, const char *filename, + const char *name, void *value, size_t size); +int fsetxattrat_nofollow(const char *dirname, const char *filename, + const char *name, void *value, size_t size, + int flags); +ssize_t flistxattrat_nofollow(const char *dirname, const char *filename, + char *list, size_t size); +ssize_t fremovexattrat_nofollow(const char *dirname, const char *filename, + const char *name); + +int qemu_statfs(const char *fs_root, struct statfs *stbuf); + +static inline char *merge_fs_path(const char *path1, const char *path2) +{ + char *full_fs_path; + size_t full_fs_path_len; + + full_fs_path_len = strlen(path1) + strlen(path2) + 2; + full_fs_path = g_malloc(full_fs_path_len); + strcpy(full_fs_path, path1); + strcat(full_fs_path, "\\"); + strcat(full_fs_path, path2); + + return full_fs_path; +} + +#endif /* !CONFIG_WIN32 */ + +#ifndef CONFIG_WIN32 /* * Darwin has d_seekoff, which appears to function similarly to d_off. * However, it does not appear to be supported on all file systems, @@ -113,6 +147,7 @@ static inline off_t qemu_dirent_off(struct dirent *dent) return dent->d_off; #endif } +#endif /* !CONFIG_WIN32 */ /** * qemu_dirent_dup() - Duplicate directory entry @dent. @@ -154,6 +189,12 @@ static inline struct dirent *qemu_dirent_dup(struct dirent *dent) #if defined CONFIG_DARWIN && defined CONFIG_PTHREAD_FCHDIR_NP int pthread_fchdir_np(int fd) __attribute__((weak_import)); #endif + +#ifndef CONFIG_WIN32 int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev); +#else +int qemu_mknodat(const char *dirname, const char *filename, + mode_t mode, dev_t dev); +#endif #endif diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 994f952600..87e8eac840 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -3,13 +3,36 @@ #include #include +#ifndef CONFIG_WIN32 #include +#endif #include "fsdev/file-op-9p.h" #include "fsdev/9p-iov-marshal.h" #include "qemu/thread.h" #include "qemu/coroutine.h" #include "qemu/qht.h" +#ifdef CONFIG_WIN32 + +#define O_NOCTTY 0 +#define O_NDELAY 0 +#define O_NONBLOCK 0 +#define O_DSYNC 0 +#define O_DIRECT 0 +#define O_NOFOLLOW 0 +#define O_NOATIME 0 +#define O_SYNC 0 +#define O_ASYNC 0 +#define O_DIRECTORY 02000000 + +#define FASYNC 0 + +#define AT_REMOVEDIR 1 + +#define NAME_MAX 260 + +#endif + enum { P9_TLERROR = 6, P9_RLERROR, diff --git a/hw/9pfs/9p-local-win32.c b/hw/9pfs/9p-local-win32.c new file mode 100644 index 0000000000..aab7c9f7b5 --- /dev/null +++ b/hw/9pfs/9p-local-win32.c @@ -0,0 +1,1242 @@ +/* + * 9p Windows callback + * + * Copyright (c) 2022 Wind River Systems, Inc. + * + * Based on hw/9pfs/9p-local.c + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +/* + * Not so fast! You might want to read the 9p developer docs first: + * https://wiki.qemu.org/Documentation/9p + */ + +#include "qemu/osdep.h" +#include +#include +#include "9p.h" +#include "9p-local.h" +#include "9p-xattr.h" +#include "9p-util.h" +#include "fsdev/qemu-fsdev.h" /* local_ops */ +#include "qapi/error.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "qemu/option.h" +#include + +static inline int openfile_with_ctx(FsContext *fs_ctx, const char *name, + int flags, mode_t mode) +{ + char *full_file_name; + int fd; + + full_file_name = merge_fs_path(fs_ctx->fs_root, name); + fd = open(full_file_name, flags | _O_BINARY, mode); + g_free(full_file_name); + + return fd; +} + +static inline DIR *opendir_with_ctx(FsContext *fs_ctx, const char *name) +{ + char *full_file_name; + DIR *dir; + + full_file_name = merge_fs_path(fs_ctx->fs_root, name); + dir = opendir(full_file_name); + g_free(full_file_name); + return dir; +} + +int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, + mode_t mode) +{ + int fd; + + if (path[strlen(path) - 1] == '/' || (flags & O_DIRECTORY) != 0) { + /* Windows does not allow call open() for a directory */ + fd = -1; + } else { + fd = openfile_with_ctx(fs_ctx, path, flags, mode); + } + + return fd; +} + +DIR *local_opendir_nofollow(FsContext *fs_ctx, const char *path) +{ + return opendir_with_ctx(fs_ctx, path); +} + +static FILE *local_fopenat(const char *dirname, const char *name, + const char *mode) +{ + char *full_file_name; + char modestr[3] = {0}; + FILE *fp; + + /* + * only supports two modes + */ + if (mode[0] == 'r') { + modestr[0] = 'r'; + } else if (mode[0] == 'w') { + modestr[0] = 'w'; + } else { + return NULL; + } + /* Windows host needs 'b' flag */ + modestr[1] = 'b'; + + full_file_name = merge_fs_path(dirname, name); + fp = fopen(full_file_name, modestr); + g_free(full_file_name); + + return fp; +} + +static void local_mapped_file_attr(const char *dirpath, const char *name, + struct stat *stbuf) +{ + FILE *fp; + char buf[ATTR_MAX]; + char *full_file_name; + + if (strcmp(name, ".") != 0) { + full_file_name = merge_fs_path(dirpath, VIRTFS_META_DIR); + fp = local_fopenat(full_file_name, name, "r"); + g_free(full_file_name); + } else { + fp = local_fopenat(dirpath, VIRTFS_META_ROOT_FILE, "r"); + } + if (!fp) { + return; + } + + memset(buf, 0, ATTR_MAX); + while (fgets(buf, ATTR_MAX, fp)) { + if (!strncmp(buf, "virtfs.uid", 10)) { + stbuf->st_uid = atoi(buf + 11); + } else if (!strncmp(buf, "virtfs.gid", 10)) { + stbuf->st_gid = atoi(buf + 11); + } else if (!strncmp(buf, "virtfs.mode", 11)) { + stbuf->st_mode = (stbuf->st_mode & ~0777); + stbuf->st_mode |= (atoi(buf + 12) & 0777); + } else if (!strncmp(buf, "virtfs.rdev", 11)) { + stbuf->st_rdev = atoi(buf + 12); + } + memset(buf, 0, ATTR_MAX); + } + fclose(fp); +} + +static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) +{ + int err = -1; + char *full_dir_name, *full_file_name; + char *dirpath = g_path_get_dirname(fs_path->data); + char *name = g_path_get_basename(fs_path->data); + + full_dir_name = merge_fs_path(fs_ctx->fs_root, dirpath); + full_file_name = merge_fs_path(full_dir_name, name); + err = stat(full_file_name, stbuf); + + if (err == 0 && strcmp(fs_path->data, ".") == 0) { + /* + * Hard code for root directory on Windows host. + * This will root directory have a special inode number, + * then guest OS can detect it is a special directory. + */ + stbuf->st_ino = 2; + } + + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + /* Actual credentials are part of extended attrs */ + uid_t tmp_uid; + gid_t tmp_gid; + mode_t tmp_mode; + dev_t tmp_dev; + + if (fgetxattrat_nofollow(full_dir_name, name, "user.virtfs.uid", + &tmp_uid, sizeof(uid_t)) > 0) { + stbuf->st_uid = le32_to_cpu(tmp_uid); + } + if (fgetxattrat_nofollow(full_dir_name, name, "user.virtfs.gid", + &tmp_gid, sizeof(gid_t)) > 0) { + stbuf->st_gid = le32_to_cpu(tmp_gid); + } + if (fgetxattrat_nofollow(full_dir_name, name, "user.virtfs.mode", + &tmp_mode, sizeof(mode_t)) > 0) { + stbuf->st_mode = (stbuf->st_mode & ~0777); + stbuf->st_mode |= le32_to_cpu(tmp_mode); + } + if (fgetxattrat_nofollow(full_dir_name, name, "user.virtfs.rdev", + &tmp_dev, sizeof(dev_t)) > 0) { + stbuf->st_rdev = le64_to_cpu(tmp_dev); + } + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + local_mapped_file_attr(full_dir_name, name, stbuf); + } + + g_free(full_file_name); + g_free(full_dir_name); + + if (err) { + goto err_out; + } + +err_out: + g_free(name); + g_free(dirpath); + return err; +} + +static int local_set_mapped_file_attrat(const char *dirname, const char *name, + FsCred *credp) +{ + FILE *fp; + int ret; + char buf[ATTR_MAX]; + int uid = -1, gid = -1, mode = -1, rdev = -1; + bool is_root = !strcmp(name, "."); + char *full_dir_name; + + if (is_root) { + fp = local_fopenat(dirname, VIRTFS_META_ROOT_FILE, "r"); + if (!fp) { + if (errno == ENOENT) { + goto update_map_file; + } else { + return -1; + } + } + } else { + /* + * mapped-file: + * attribute stored to: + * + VIRTFS_META_DIR + + */ + full_dir_name = merge_fs_path(dirname, VIRTFS_META_DIR); + ret = mkdir(full_dir_name); + + if (ret < 0 && errno != EEXIST) { + g_free(full_dir_name); + return -1; + } + + fp = local_fopenat(full_dir_name, name, "r"); + if (!fp) { + if (errno == ENOENT) { + goto update_map_file; + } else { + g_free(full_dir_name); + return -1; + } + } + } + + memset(buf, 0, ATTR_MAX); + while (fgets(buf, ATTR_MAX, fp)) { + if (!strncmp(buf, "virtfs.uid", 10)) { + uid = atoi(buf + 11); + } else if (!strncmp(buf, "virtfs.gid", 10)) { + gid = atoi(buf + 11); + } else if (!strncmp(buf, "virtfs.mode", 11)) { + mode = atoi(buf + 12); + } else if (!strncmp(buf, "virtfs.rdev", 11)) { + rdev = atoi(buf + 12); + } + memset(buf, 0, ATTR_MAX); + } + fclose(fp); + +update_map_file: + if (is_root) { + fp = local_fopenat(dirname, VIRTFS_META_ROOT_FILE, "w"); + } else { + fp = local_fopenat(full_dir_name, name, "w"); + g_free(full_dir_name); + } + if (!fp) { + return -1; + } + + if (credp->fc_uid != -1) { + uid = credp->fc_uid; + } + if (credp->fc_gid != -1) { + gid = credp->fc_gid; + } + if (credp->fc_mode != (mode_t)-1) { + mode = credp->fc_mode; + } + if (credp->fc_rdev != -1) { + rdev = credp->fc_rdev; + } + + if (uid != -1) { + fprintf(fp, "virtfs.uid=%d\n", uid); + } + if (gid != -1) { + fprintf(fp, "virtfs.gid=%d\n", gid); + } + if (mode != -1) { + fprintf(fp, "virtfs.mode=%d\n", mode); + } + if (rdev != -1) { + fprintf(fp, "virtfs.rdev=%d\n", rdev); + } + fclose(fp); + + return 0; +} + +static int local_set_xattrat(const char *dirname, const char *path, + FsCred *credp) +{ + int err; + + if (credp->fc_uid != -1) { + uint32_t tmp_uid = cpu_to_le32(credp->fc_uid); + err = fsetxattrat_nofollow(dirname, path, "user.virtfs.uid", + &tmp_uid, sizeof(uid_t), 0); + if (err) { + return err; + } + } + if (credp->fc_gid != -1) { + uint32_t tmp_gid = cpu_to_le32(credp->fc_gid); + err = fsetxattrat_nofollow(dirname, path, "user.virtfs.gid", + &tmp_gid, sizeof(gid_t), 0); + if (err) { + return err; + } + } + if (credp->fc_mode != (mode_t)-1) { + uint32_t tmp_mode = cpu_to_le32(credp->fc_mode); + err = fsetxattrat_nofollow(dirname, path, "user.virtfs.mode", + &tmp_mode, sizeof(mode_t), 0); + if (err) { + return err; + } + } + if (credp->fc_rdev != -1) { + uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev); + err = fsetxattrat_nofollow(dirname, path, "user.virtfs.rdev", + &tmp_rdev, sizeof(dev_t), 0); + if (err) { + return err; + } + } + return 0; +} + +static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path, + char *buf, size_t bufsz) +{ + return -1; +} + +static int local_close(FsContext *ctx, V9fsFidOpenState *fs) +{ + return close(fs->fd); +} + +static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs) +{ + return closedir(fs->dir.stream); +} + +static int local_open(FsContext *ctx, V9fsPath *fs_path, + int flags, V9fsFidOpenState *fs) +{ + int fd; + + fd = local_open_nofollow(ctx, fs_path->data, flags, 0); + if (fd == -1) { + return -1; + } + fs->fd = fd; + return fs->fd; +} + +static int local_opendir(FsContext *ctx, + V9fsPath *fs_path, V9fsFidOpenState *fs) +{ + DIR *stream; + char *full_file_name; + + full_file_name = merge_fs_path(ctx->fs_root, fs_path->data); + stream = opendir(full_file_name); + g_free(full_file_name); + + if (!stream) { + return -1; + } + + fs->dir.stream = stream; + return 0; +} + +static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs) +{ + rewinddir(fs->dir.stream); +} + +static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs) +{ + return telldir(fs->dir.stream); +} + +static struct dirent *local_readdir(FsContext *ctx, V9fsFidOpenState *fs) +{ + struct dirent *entry; + +again: + entry = readdir(fs->dir.stream); + if (!entry) { + return NULL; + } + + if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { + if (local_is_mapped_file_metadata(ctx, entry->d_name)) { + /* skip the meta data */ + goto again; + } + } + + return entry; +} + +static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) +{ + off_t count; + struct dirent *findentry; + struct dirent *entry; + size_t namelen[3] = {0}; + off_t direntoff[3] = {-1, -1, -1}; + char *d_name[3]; + int i; + + /* + * MinGW's seekdir() requires directory is not modified. If guest OS is + * modifying the directory when calling seekdir(), e.g.: "rm -rf *", + * then MinGW's seekdir() will seek to a wrong offset. + * + * This function saves some old offset directory entry name, + * and lookup current entry again, and compare the offset. + * + * If new offset is less than old offset, that means someone is deleting + * files in the directory, thus we need to seek offset backward. + * + * If new offset is larger than old offset, that means someone is creating + * files in the directory, thus we need to seek offset forward. + */ + + direntoff[0] = telldir(fs->dir.stream); + + /* do nothing if current offset is 0 or EOF */ + if (direntoff[0] == 0 || direntoff[0] < 0) { + seekdir(fs->dir.stream, off); + return ; + } + + d_name[0] = g_malloc0(sizeof(entry->d_name) * 3); + d_name[1] = d_name[0] + sizeof(entry->d_name); + d_name[2] = d_name[1] + sizeof(entry->d_name); + + /* save 3 nearest entries and offsets */ + for (i = 0; i < 3; i++) { + entry = &fs->dir.stream->dd_dir; + + memcpy(d_name[i], entry->d_name, entry->d_namlen); + namelen[i] = strlen(d_name[i]) + 1; + + direntoff[i] = telldir(fs->dir.stream); + + entry = readdir(fs->dir.stream); + if (entry == NULL) { + break; + } + } + + /* lookup saved entries again */ + for (i = 0; i < 3 && direntoff[i] != -1; i++) { + rewinddir(fs->dir.stream); + count = 0; + while ((findentry = readdir(fs->dir.stream)) != NULL) { + count++; + + if (memcmp(findentry->d_name, d_name[i], namelen[i]) == 0) { + if (count + i == direntoff[i]) { + seekdir(fs->dir.stream, off); + goto out; + } else if (count + i < direntoff[i]) { + off = off - (direntoff[i] - count) - i; + if (off <= 0) { + off = 0; + } + seekdir(fs->dir.stream, off); + goto out; + } else { + off = off + (count - direntoff[i]) - i; + seekdir(fs->dir.stream, off); + goto out; + } + } + } + } + /* can not get anything, seek backward */ + off = off - 1; + + seekdir(fs->dir.stream, off); +out: + g_free(d_name[0]); + return ; +} + +static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs, + const struct iovec *iov, + int iovcnt, off_t offset) +{ +#ifdef CONFIG_PREADV + return preadv(fs->fd, iov, iovcnt, offset); +#else + int err = lseek(fs->fd, offset, SEEK_SET); + if (err == -1) { + return err; + } else { + return readv(fs->fd, iov, iovcnt); + } +#endif +} + +static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs, + const struct iovec *iov, + int iovcnt, off_t offset) +{ + ssize_t ret; +#ifdef CONFIG_PREADV + ret = pwritev(fs->fd, iov, iovcnt, offset); +#else + int err = lseek(fs->fd, offset, SEEK_SET); + if (err == -1) { + return err; + } else { + ret = writev(fs->fd, iov, iovcnt); + } +#endif +#ifdef CONFIG_SYNC_FILE_RANGE + if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) { + /* + * Initiate a writeback. This is not a data integrity sync. + * We want to ensure that we don't leave dirty pages in the cache + * after write when writeout=immediate is sepcified. + */ + sync_file_range(fs->fd, offset, ret, + SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE); + } +#endif + return ret; +} + +static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) +{ + char *dirpath = g_path_get_dirname(fs_path->data); + char *name = g_path_get_basename(fs_path->data); + int ret = -1; + char *full_file_name = NULL; + DIR *dir; + dir = local_opendir_nofollow(fs_ctx, dirpath); + if (dir == NULL) { + goto out; + } + full_file_name = merge_fs_path(fs_ctx->fs_root, dirpath); + + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + ret = local_set_xattrat(full_file_name, name, credp); + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + ret = local_set_mapped_file_attrat(full_file_name, name, credp); + } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || + fs_ctx->export_flags & V9FS_SM_NONE) { + ret = -1; + errno = ENOTSUP; + } + closedir(dir); + +out: + if (full_file_name != NULL) { + g_free(full_file_name); + } + + g_free(dirpath); + g_free(name); + return ret; +} + +static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path, + const char *name, FsCred *credp) +{ + return -1; +} + +static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, + const char *name, FsCred *credp) +{ + int err = -1; + char *full_file_name; + char *full_dir_name; + DIR *dir; + + if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE && + local_is_mapped_file_metadata(fs_ctx, name)) { + errno = EINVAL; + return -1; + } + + dir = local_opendir_nofollow(fs_ctx, dir_path->data); + if (dir == NULL) { + return -1; + } + closedir(dir); + + full_dir_name = merge_fs_path(fs_ctx->fs_root, dir_path->data); + full_file_name = merge_fs_path(full_dir_name, name); + + if (fs_ctx->export_flags & V9FS_SM_MAPPED || + fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + err = mkdir(full_file_name); + if (err == -1) { + goto out; + } + credp->fc_mode = credp->fc_mode; + + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + err = local_set_xattrat(full_dir_name, name, credp); + } else { + err = local_set_mapped_file_attrat(full_dir_name, name, credp); + } + if (err == -1) { + rmdir(full_file_name); + } + } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || + fs_ctx->export_flags & V9FS_SM_NONE) { + err = mkdir(full_file_name); + if (err == -1) { + goto out; + } + /* Windows does not support chmod, do nothing here */ + } + + goto out; + +out: + g_free(full_dir_name); + g_free(full_file_name); + return err; +} + +static int local_fstat(FsContext *fs_ctx, int fid_type, + V9fsFidOpenState *fs, struct stat *stbuf) +{ + + int err, fd; + char filename[NAME_MAX]; + char *dirpath; + char *name; + HANDLE hFile; + DWORD dwRet; + + if (fid_type == P9_FID_DIR) { + /* Windows does not support open directory */ + return -1; + } else { + fd = fs->fd; + } + + err = fstat(fd, stbuf); + if (err) { + return err; + } + + /* get real file name by fd */ + hFile = (HANDLE)_get_osfhandle(fd); + dwRet = GetFinalPathNameByHandle(hFile, filename, sizeof(filename), 0); + + if (dwRet >= NAME_MAX) { + return -1; + } + /* skip string "\\\\?\\" return from GetFinalPathNameByHandle() */ + memmove(filename, filename + 4, NAME_MAX - 4); + + dirpath = g_path_get_dirname(filename); + name = g_path_get_basename(filename); + + if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + /* Actual credentials are part of extended attrs */ + uid_t tmp_uid; + gid_t tmp_gid; + mode_t tmp_mode; + dev_t tmp_dev; + + if (fgetxattrat_nofollow(dirpath, name, "user.virtfs.uid", + &tmp_uid, sizeof(uid_t)) > 0) { + stbuf->st_uid = le32_to_cpu(tmp_uid); + } + if (fgetxattrat_nofollow(dirpath, name, "user.virtfs.gid", + &tmp_gid, sizeof(gid_t)) > 0) { + stbuf->st_gid = le32_to_cpu(tmp_gid); + } + if (fgetxattrat_nofollow(dirpath, name, "user.virtfs.mode", + &tmp_mode, sizeof(mode_t)) > 0) { + stbuf->st_mode = (stbuf->st_mode & ~0777); + stbuf->st_mode |= le32_to_cpu(tmp_mode); + } + if (fgetxattrat_nofollow(dirpath, name, "user.virtfs.rdev", + &tmp_dev, sizeof(dev_t)) > 0) { + stbuf->st_rdev = le64_to_cpu(tmp_dev); + } + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + errno = EOPNOTSUPP; + g_free(dirpath); + g_free(name); + return -1; + } + + g_free(dirpath); + g_free(name); + + return err; +} + +static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, + int flags, FsCred *credp, V9fsFidOpenState *fs) +{ + int fd = -1; + int err = -1; + char *full_file_name; + + if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE && + local_is_mapped_file_metadata(fs_ctx, name)) { + errno = EINVAL; + return -1; + } + + full_file_name = merge_fs_path(dir_path->data, name); + fd = openfile_with_ctx(fs_ctx, full_file_name, flags, credp->fc_mode); + g_free(full_file_name); + + err = fd; + fs->fd = fd; + goto out; + + close_preserve_errno(fd); +out: + return err; +} + + +static int local_symlink(FsContext *fs_ctx, const char *oldpath, + V9fsPath *dir_path, const char *name, FsCred *credp) +{ + return -1; +} + +static int local_link(FsContext *ctx, V9fsPath *oldpath, + V9fsPath *dirpath, const char *name) +{ + return -1; +} + +static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) +{ + int fd, ret; + + fd = local_open_nofollow(ctx, fs_path->data, O_WRONLY, 0); + if (fd == -1) { + return -1; + } + ret = ftruncate(fd, size); + close_preserve_errno(fd); + return ret; +} + +static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp) +{ + char *full_file_name; + char *dirpath = g_path_get_dirname(fs_path->data); + char *name = g_path_get_basename(fs_path->data); + int ret = -1; + DIR *dir; + + dir = local_opendir_nofollow(fs_ctx, dirpath); + if (dir == NULL) { + goto out; + } + full_file_name = merge_fs_path(fs_ctx->fs_root, dirpath); + + if ((credp->fc_uid == -1 && credp->fc_gid == -1) || + (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || + (fs_ctx->export_flags & V9FS_SM_NONE)) { + /* Windows does not support chown() */ + ret = -1; + errno = ENOTSUP; + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) { + ret = local_set_xattrat(full_file_name, name, credp); + } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { + ret = local_set_mapped_file_attrat(full_file_name, name, credp); + } + g_free(full_file_name); + closedir(dir); +out: + g_free(name); + g_free(dirpath); + return ret; +} + +static int local_utimensat(FsContext *s, V9fsPath *fs_path, + const struct timespec *buf) +{ + struct utimbuf tm; + char *full_file_name; + int err; + + tm.actime = buf[0].tv_sec; + tm.modtime = buf[1].tv_sec; + + full_file_name = merge_fs_path(s->fs_root, fs_path->data); + err = utime(full_file_name, &tm); + g_free(full_file_name); + + return err; +} + +static int local_unlinkat_common(FsContext *ctx, const char *dirname, + const char *name, int flags) +{ + int ret; + char *full_file_name; + char *full_dir_name; + + full_dir_name = merge_fs_path(ctx->fs_root, dirname); + full_file_name = merge_fs_path(full_dir_name, name); + + if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { + char *full_meta_dir_name; + char *full_meta_file_name; + + /* + * We need to remove the metadata as well: + * - the metadata directory if we're removing a directory + * - the metadata file in the parent's metadata directory + * + * If any of these are missing (ie, ENOENT) then we're probably + * trying to remove something that wasn't created in mapped-file + * mode. We just ignore the error. + */ + + if ((flags & AT_REMOVEDIR) != 0) { + full_meta_dir_name = merge_fs_path(full_file_name, VIRTFS_META_DIR); + ret = rmdir(full_meta_dir_name); + g_free(full_meta_dir_name); + + if (ret < 0 && errno != ENOENT) { + g_free(full_file_name); + g_free(full_dir_name); + return -1; + } + } + + full_meta_dir_name = merge_fs_path(full_dir_name, VIRTFS_META_DIR); + full_meta_file_name = merge_fs_path(full_meta_dir_name, name); + ret = remove(full_meta_file_name); + g_free(full_meta_dir_name); + g_free(full_meta_file_name); + + if (ret < 0 && errno != ENOENT) { + g_free(full_dir_name); + g_free(full_file_name); + + return -1; + } + } + + if ((flags & AT_REMOVEDIR) != 0) { + ret = rmdir(full_file_name); + } else { + ret = remove(full_file_name); + } + + g_free(full_dir_name); + g_free(full_file_name); + + return ret; +} + +static int local_remove(FsContext *ctx, const char *path) +{ + int err; + DIR *stream; + char *full_file_name; + char *dirpath = g_path_get_dirname(path); + char *name = g_path_get_basename(path); + int flags = 0; + + full_file_name = merge_fs_path(ctx->fs_root, path); + stream = opendir(full_file_name); + if (stream != NULL) { + closedir(stream); + flags |= AT_REMOVEDIR; + } + err = local_unlinkat_common(ctx, dirpath, name, flags); + + g_free(name); + g_free(dirpath); + g_free(full_file_name); + return err; +} + +static int local_fsync(FsContext *ctx, int fid_type, + V9fsFidOpenState *fs, int datasync) +{ + if (fid_type != P9_FID_DIR) { + return _commit(fs->fd); + } + return 0; +} + +static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf) +{ + int ret; + ret = qemu_statfs(s->fs_root, stbuf); + if (ret == 0) { + /* use context address as fsid */ + memcpy(&stbuf->f_fsid, s, sizeof(long)); + } + + return ret; +} + +static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path, + const char *name, void *value, size_t size) +{ + return -1; +} + +static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path, + void *value, size_t size) +{ + return -1; +} + +static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name, + void *value, size_t size, int flags) +{ + return -1; +} + +static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path, + const char *name) +{ + return -1; +} + +static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path, + const char *name, V9fsPath *target) +{ + if (ctx->export_flags & V9FS_SM_MAPPED_FILE && + local_is_mapped_file_metadata(ctx, name)) { + errno = EINVAL; + return -1; + } + + if (dir_path) { + if (!strcmp(name, ".")) { + /* "." relative to "foo/bar" is "foo/bar" */ + v9fs_path_copy(target, dir_path); + } else if (!strcmp(name, "..")) { + if (!strcmp(dir_path->data, ".")) { + /* ".." relative to the root is "." */ + v9fs_path_sprintf(target, "."); + } else { + char *tmp = g_path_get_dirname(dir_path->data); + /* + * Symbolic links are resolved by the client. We can assume + * that ".." relative to "foo/bar" is equivalent to "foo" + */ + v9fs_path_sprintf(target, "%s", tmp); + g_free(tmp); + } + } else { + assert(!strchr(name, '/')); + v9fs_path_sprintf(target, "%s/%s", dir_path->data, name); + } + } else if (!strcmp(name, "/") || !strcmp(name, ".") || + !strcmp(name, "..")) { + /* This is the root fid */ + v9fs_path_sprintf(target, "."); + } else { + assert(!strchr(name, '/')); + v9fs_path_sprintf(target, "./%s", name); + } + return 0; +} + +static int local_renameat(FsContext *ctx, V9fsPath *olddir, + const char *old_name, V9fsPath *newdir, + const char *new_name) +{ + return -1; +} + +static int local_rename(FsContext *ctx, const char *oldpath, + const char *newpath) +{ + int err; + + char *full_old_name; + char *full_new_name; + + full_old_name = merge_fs_path(ctx->fs_root, oldpath); + full_new_name = merge_fs_path(ctx->fs_root, newpath); + + err = rename(full_old_name, full_new_name); + + g_free(full_old_name); + g_free(full_new_name); + + return err; +} + +static int local_unlinkat(FsContext *ctx, V9fsPath *dir, + const char *name, int flags) +{ + int ret; + + if (ctx->export_flags & V9FS_SM_MAPPED_FILE && + local_is_mapped_file_metadata(ctx, name)) { + errno = EINVAL; + return -1; + } + + ret = local_unlinkat_common(ctx, dir->data, name, flags); + + return ret; +} + +static int check_filesystem_type(char *fs_root, int export_flags) +{ + HANDLE hFile; + wchar_t FsName[MAX_PATH + 1] = {0}; + wchar_t NtfsName[5] = {'N', 'T', 'F', 'S'}; + + if ((export_flags & V9FS_SM_MAPPED) == 0) { + return 0; + } + + hFile = CreateFile(fs_root, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + return -1; + } + + /* Get file system type name */ + if (GetVolumeInformationByHandleW(hFile, NULL, 0, NULL, NULL, NULL, + FsName, MAX_PATH + 1) == 0) { + CloseHandle(hFile); + return -1; + } + CloseHandle(hFile); + + if (wcscmp(FsName, NtfsName) != 0) { + return -1; + } + + return 0; +} + +static int local_init(FsContext *ctx, Error **errp) +{ + LocalData *data = g_malloc(sizeof(*data)); + + struct stat StatBuf; + + if (stat(ctx->fs_root, &StatBuf) != 0) { + error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root); + goto err; + } + + /* + * security_model=mapped(-xattr) requires a fileystem on Windows that + * supports Alternate Data Stream (ADS). NTFS is one of them, and is + * probably most popular on Windows. It is fair enough to assume + * Windows users to use NTFS for the mapped security model. + */ + if (check_filesystem_type(ctx->fs_root, ctx->export_flags) != 0) { + error_setg_errno(errp, EINVAL, "require NTFS file system when " + "security_model is mapped or mapped-xattr"); + goto err; + } + + if (ctx->export_flags & V9FS_SM_PASSTHROUGH) { + ctx->xops = passthrough_xattr_ops; + } else if (ctx->export_flags & V9FS_SM_MAPPED) { + ctx->xops = mapped_xattr_ops; + } else if (ctx->export_flags & V9FS_SM_NONE) { + ctx->xops = none_xattr_ops; + } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) { + /* + * xattr operation for mapped-file and passthrough + * remain same. + */ + ctx->xops = passthrough_xattr_ops; + } + ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT; + + ctx->private = data; + return 0; + +err: + g_free(data); + return -1; +} + +static void local_cleanup(FsContext *ctx) +{ + LocalData *data = ctx->private; + + if (!data) { + return; + } + + close(data->mountfd); + g_free(data); +} + +static void error_append_security_model_hint(Error *const *errp) +{ + error_append_hint(errp, "Valid options are: security_model=" + "[passthrough|mapped-xattr|mapped-file|none]\n"); +} + +static int local_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp) +{ + ERRP_GUARD(); + const char *sec_model = qemu_opt_get(opts, "security_model"); + const char *path = qemu_opt_get(opts, "path"); + const char *multidevs = qemu_opt_get(opts, "multidevs"); + + if (!sec_model) { + error_setg(errp, "security_model property not set"); + error_append_security_model_hint(errp); + return -1; + } + + if (!strcmp(sec_model, "passthrough")) { + fse->export_flags |= V9FS_SM_PASSTHROUGH; + } else if (!strcmp(sec_model, "mapped") || + !strcmp(sec_model, "mapped-xattr")) { + fse->export_flags |= V9FS_SM_MAPPED; + } else if (!strcmp(sec_model, "none")) { + fse->export_flags |= V9FS_SM_NONE; + } else if (!strcmp(sec_model, "mapped-file")) { + fse->export_flags |= V9FS_SM_MAPPED_FILE; + } else { + error_setg(errp, "invalid security_model property '%s'", sec_model); + error_append_security_model_hint(errp); + return -1; + } + + if (multidevs) { + if (!strcmp(multidevs, "remap")) { + fse->export_flags &= ~V9FS_FORBID_MULTIDEVS; + fse->export_flags |= V9FS_REMAP_INODES; + } else if (!strcmp(multidevs, "forbid")) { + fse->export_flags &= ~V9FS_REMAP_INODES; + fse->export_flags |= V9FS_FORBID_MULTIDEVS; + } else if (!strcmp(multidevs, "warn")) { + fse->export_flags &= ~V9FS_FORBID_MULTIDEVS; + fse->export_flags &= ~V9FS_REMAP_INODES; + } else { + error_setg(errp, "invalid multidevs property '%s'", + multidevs); + error_append_hint(errp, "Valid options are: multidevs=" + "[remap|forbid|warn]\n"); + return -1; + } + } + + if (!path) { + error_setg(errp, "path property not set"); + return -1; + } + + if (fsdev_throttle_parse_opts(opts, &fse->fst, errp)) { + error_prepend(errp, "invalid throttle configuration: "); + return -1; + } + + if (fse->export_flags & V9FS_SM_MAPPED || + fse->export_flags & V9FS_SM_MAPPED_FILE) { + fse->fmode = + qemu_opt_get_number(opts, "fmode", SM_LOCAL_MODE_BITS) & 0777; + fse->dmode = + qemu_opt_get_number(opts, "dmode", SM_LOCAL_DIR_MODE_BITS) & 0777; + } else { + if (qemu_opt_find(opts, "fmode")) { + error_setg(errp, "fmode is only valid for mapped security modes"); + return -1; + } + if (qemu_opt_find(opts, "dmode")) { + error_setg(errp, "dmode is only valid for mapped security modes"); + return -1; + } + } + + fse->path = g_strdup(path); + + return 0; +} + +FileOperations local_ops = { + .parse_opts = local_parse_opts, + .init = local_init, + .cleanup = local_cleanup, + .lstat = local_lstat, + .readlink = local_readlink, + .close = local_close, + .closedir = local_closedir, + .open = local_open, + .opendir = local_opendir, + .rewinddir = local_rewinddir, + .telldir = local_telldir, + .readdir = local_readdir, + .seekdir = local_seekdir, + .preadv = local_preadv, + .pwritev = local_pwritev, + .chmod = local_chmod, + .mknod = local_mknod, + .mkdir = local_mkdir, + .fstat = local_fstat, + .open2 = local_open2, + .symlink = local_symlink, + .link = local_link, + .truncate = local_truncate, + .rename = local_rename, + .chown = local_chown, + .utimensat = local_utimensat, + .remove = local_remove, + .fsync = local_fsync, + .statfs = local_statfs, + .lgetxattr = local_lgetxattr, + .llistxattr = local_llistxattr, + .lsetxattr = local_lsetxattr, + .lremovexattr = local_lremovexattr, + .name_to_path = local_name_to_path, + .renameat = local_renameat, + .unlinkat = local_unlinkat, +}; diff --git a/hw/9pfs/9p-util-win32.c b/hw/9pfs/9p-util-win32.c new file mode 100644 index 0000000000..d9b35e7425 --- /dev/null +++ b/hw/9pfs/9p-util-win32.c @@ -0,0 +1,303 @@ +/* + * 9p utilities (Windows Implementation) + * + * Copyright (c) 2022 Wind River Systems, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "9p.h" +#include "9p-util.h" +#include "9p-linux-errno.h" +#include +#include + +#ifndef V9FS_MAGIC +#define V9FS_MAGIC 0x53465039 /* string "9PFS" */ +#endif + +static int build_ads_name(char *namebuf, size_t namebuflen, + const char *dirname, const char *filename, + const char *ads_name) +{ + size_t totalsize; + + totalsize = strlen(dirname) + strlen(filename) + strlen(ads_name) + 3; + if (totalsize > namebuflen) { + return -1; + } + + /* + * NTFS ADS (Alternate Data Streams) name format: + * filename:ads_name + * e.g. + * d:\1.txt:my_ads_name + */ + strcpy(namebuf, dirname); + strcat(namebuf, "\\"); + strcat(namebuf, filename); + strcat(namebuf, ":"); + strcat(namebuf, ads_name); + + return 0; +} + +static ssize_t copy_ads_name(char *namebuf, size_t namebuflen, + char *fulladsname) +{ + char *p1, *p2; + + /* + * NTFS ADS (Alternate Data Streams) name from emurate data format: + * :ads_name:$DATA + * e.g. + * :my_ads_name:$DATA + * + * ADS name from FindNextStreamW() always have ":$DATA" string at the end + * + * This function copy ADS name to namebuf. + */ + + p1 = strchr(fulladsname, ':'); + if (p1 == NULL) { + return -1; + } + + p2 = strchr(p1 + 1, ':'); + if (p2 == NULL) { + return -1; + } + + /* skip empty ads name */ + if (p2 - p1 == 1) { + return 0; + } + + if (p2 - p1 + 1 > namebuflen) { + return -1; + } + + memcpy(namebuf, p1 + 1, p2 - p1 - 1); + namebuf[p2 - p1 - 1] = '\0'; + + return p2 - p1; +} + +ssize_t fgetxattrat_nofollow(const char *dirname, const char *filename, + const char *name, void *value, size_t size) +{ + HANDLE hStream; + char ADSFileName[NAME_MAX + 1] = {0}; + DWORD dwBytesRead; + + if (build_ads_name(ADSFileName, NAME_MAX, dirname, filename, name) < 0) { + errno = EIO; + return -1; + } + + hStream = CreateFile(ADSFileName, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hStream == INVALID_HANDLE_VALUE && + GetLastError() == ERROR_FILE_NOT_FOUND) { + errno = ENODATA; + return -1; + } + + if (ReadFile(hStream, value, size, &dwBytesRead, NULL) == FALSE) { + errno = EIO; + CloseHandle(hStream); + return -1; + } + + CloseHandle(hStream); + + return dwBytesRead; +} + +ssize_t flistxattrat_nofollow(const char *dirname, const char *filename, + char *list, size_t size) +{ + WCHAR WideCharStr[NAME_MAX + 1] = { 0 }; + char fulladsname[NAME_MAX + 1]; + char *full_fs_name = merge_fs_path(dirname, filename); + int ret; + HANDLE hFind; + WIN32_FIND_STREAM_DATA fsd; + BOOL bFindNext; + char *listptr = list; + size_t listleftsize = size; + + /* + * ADS emurate function only have WCHAR version, need to covert filename + * to WCHAR string. + */ + + ret = MultiByteToWideChar(CP_UTF8, 0, full_fs_name, + strlen(full_fs_name), WideCharStr, NAME_MAX); + g_free(full_fs_name); + if (ret == 0) { + errno = EIO; + return -1; + } + + hFind = FindFirstStreamW(WideCharStr, FindStreamInfoStandard, &fsd, 0); + if (hFind == INVALID_HANDLE_VALUE) { + errno = ENODATA; + return -1; + } + + do { + memset(fulladsname, 0, sizeof(fulladsname)); + + /* + * ADS emurate function only have WCHAR version, need to covert + * cStreamName to utf-8 string. + */ + + ret = WideCharToMultiByte(CP_UTF8, 0, + fsd.cStreamName, wcslen(fsd.cStreamName) + 1, + fulladsname, sizeof(fulladsname) - 1, + NULL, NULL); + + if (ret == 0) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + errno = ERANGE; + } + CloseHandle(hFind); + return -1; + } + + ret = copy_ads_name(listptr, listleftsize, fulladsname); + if (ret < 0) { + errno = ERANGE; + CloseHandle(hFind); + return -1; + } + + listptr = listptr + ret; + listleftsize = listleftsize - ret; + + bFindNext = FindNextStreamW(hFind, &fsd); + } while (bFindNext); + + CloseHandle(hFind); + + return size - listleftsize; +} + +ssize_t fremovexattrat_nofollow(const char *dirname, const char *filename, + const char *name) +{ + char ADSFileName[NAME_MAX + 1] = {0}; + + if (build_ads_name(ADSFileName, NAME_MAX, dirname, filename, name) < 0) { + errno = EIO; + return -1; + } + + if (DeleteFile(ADSFileName) != 0) { + if (GetLastError() == ERROR_FILE_NOT_FOUND) { + errno = ENODATA; + return -1; + } + } + + return 0; +} + +int fsetxattrat_nofollow(const char *dirname, const char *filename, + const char *name, void *value, size_t size, int flags) +{ + HANDLE hStream; + char ADSFileName[NAME_MAX + 1] = {0}; + DWORD dwBytesWrite; + + if (build_ads_name(ADSFileName, NAME_MAX, dirname, filename, name) < 0) { + errno = EIO; + return -1; + } + + hStream = CreateFile(ADSFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (hStream == INVALID_HANDLE_VALUE) { + errno = EIO; + return -1; + } + + if (WriteFile(hStream, value, size, &dwBytesWrite, NULL) == FALSE) { + errno = EIO; + CloseHandle(hStream); + return -1; + } + + CloseHandle(hStream); + + return 0; +} + +int qemu_mknodat(const char *dirname, const char *filename, + mode_t mode, dev_t dev) +{ + errno = ENOTSUP; + return -1; +} + +int qemu_statfs(const char *fs_root, struct statfs *stbuf) +{ + HANDLE hFile; + char RealPath[NAME_MAX + 1]; + unsigned long SectorsPerCluster; + unsigned long BytesPerSector; + unsigned long NumberOfFreeClusters; + unsigned long TotalNumberOfClusters; + + hFile = CreateFile(fs_root, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + errno = EIO; + return -1; + } + + /* get real path of root */ + if (GetFinalPathNameByHandle(hFile, RealPath, sizeof(RealPath), + FILE_NAME_NORMALIZED) == 0) { + errno = EIO; + CloseHandle(hFile); + return -1; + } + + CloseHandle(hFile); + + /* + * GetFinalPathNameByHandle will return real path start with "\\\\?\\". + * "C:\\123" will be "\\\\?\\C:\\123" + * Skip first 4 bytes and truncate the string at offset 7, it will get + * the real root directory like "C:\\", this is parameter GetDiskFreeSpace + * needed. + */ + + RealPath[7] = '\0'; + + if (GetDiskFreeSpace(RealPath + 4, &SectorsPerCluster, &BytesPerSector, + &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) { + errno = EIO; + return -1; + } + + stbuf->f_type = V9FS_MAGIC; + stbuf->f_bsize = (__fsword_t)(SectorsPerCluster * BytesPerSector); + stbuf->f_blocks = (fsblkcnt_t)TotalNumberOfClusters; + stbuf->f_bfree = (fsblkcnt_t)NumberOfFreeClusters; + stbuf->f_bavail = (fsblkcnt_t)NumberOfFreeClusters; + stbuf->f_files = -1; + stbuf->f_ffree = -1; + stbuf->f_namelen = NAME_MAX; + stbuf->f_frsize = 0; + stbuf->f_flags = 0; + + return 0; +} diff --git a/hw/9pfs/9p-xattr.c b/hw/9pfs/9p-xattr.c index 9ae69dd8db..5623f0e2ef 100644 --- a/hw/9pfs/9p-xattr.c +++ b/hw/9pfs/9p-xattr.c @@ -78,10 +78,45 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, char *orig_value, *orig_value_start; ssize_t xattr_len, parsed_len = 0, attr_len; char *dirpath, *name; +#ifdef CONFIG_WIN32 + char *full_dir_path; + DIR *dir; +#else int dirfd; +#endif /* Get the actual len */ dirpath = g_path_get_dirname(path); + +#ifdef CONFIG_WIN32 + dir = local_opendir_nofollow(ctx, dirpath); + if (dir == NULL) { + return -1; + } + closedir(dir); + + full_dir_path = merge_fs_path(ctx->fs_root, dirpath); + g_free(dirpath); + + name = g_path_get_basename(path); + xattr_len = flistxattrat_nofollow(full_dir_path, name, value, 0); + if (xattr_len <= 0) { + g_free(name); + g_free(full_dir_path); + return xattr_len; + } + + /* Now fetch the xattr and find the actual size */ + orig_value = g_malloc(xattr_len); + xattr_len = flistxattrat_nofollow(full_dir_path, name, orig_value, + xattr_len); + g_free(name); + g_free(full_dir_path); + if (xattr_len < 0) { + g_free(orig_value); + return -1; + } +#else dirfd = local_opendir_nofollow(ctx, dirpath); g_free(dirpath); if (dirfd == -1) { @@ -105,6 +140,7 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, g_free(orig_value); return -1; } +#endif /* store the orig pointer */ orig_value_start = orig_value; @@ -166,6 +202,31 @@ int v9fs_remove_xattr(FsContext *ctx, ssize_t local_getxattr_nofollow(FsContext *ctx, const char *path, const char *name, void *value, size_t size) { +#ifdef CONFIG_WIN32 + char *dirpath = g_path_get_dirname(path); + char *filename = g_path_get_basename(path); + char *full_dir_path; + DIR *dir; + ssize_t ret = -1; + + full_dir_path = merge_fs_path(ctx->fs_root, dirpath); + + dir = local_opendir_nofollow(ctx, dirpath); + if (dir == NULL) { + goto out; + } + closedir(dir); + + ret = fgetxattrat_nofollow(full_dir_path, filename, + name, value, size); + +out: + g_free(full_dir_path); + g_free(dirpath); + g_free(filename); + + return ret; +#else char *dirpath = g_path_get_dirname(path); char *filename = g_path_get_basename(path); int dirfd; @@ -177,11 +238,13 @@ ssize_t local_getxattr_nofollow(FsContext *ctx, const char *path, } ret = fgetxattrat_nofollow(dirfd, filename, name, value, size); + close_preserve_errno(dirfd); out: g_free(dirpath); g_free(filename); return ret; +#endif } ssize_t pt_getxattr(FsContext *ctx, const char *path, const char *name, @@ -194,6 +257,30 @@ ssize_t local_setxattr_nofollow(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) { +#ifdef CONFIG_WIN32 + char *dirpath = g_path_get_dirname(path); + char *filename = g_path_get_basename(path); + char *full_dir_path; + DIR *dir; + ssize_t ret = -1; + + full_dir_path = merge_fs_path(ctx->fs_root, dirpath); + + dir = local_opendir_nofollow(ctx, dirpath); + if (dir == NULL) { + goto out; + } + closedir(dir); + + ret = fsetxattrat_nofollow(full_dir_path, filename, name, + value, size, flags); +out: + g_free(full_dir_path); + g_free(dirpath); + g_free(filename); + return ret; + +#else char *dirpath = g_path_get_dirname(path); char *filename = g_path_get_basename(path); int dirfd; @@ -210,6 +297,7 @@ out: g_free(dirpath); g_free(filename); return ret; +#endif } int pt_setxattr(FsContext *ctx, const char *path, const char *name, void *value, @@ -221,6 +309,30 @@ int pt_setxattr(FsContext *ctx, const char *path, const char *name, void *value, ssize_t local_removexattr_nofollow(FsContext *ctx, const char *path, const char *name) { +#ifdef CONFIG_WIN32 + char *dirpath = g_path_get_dirname(path); + char *filename = g_path_get_basename(path); + char *full_dir_path; + DIR *dir; + ssize_t ret = -1; + + full_dir_path = merge_fs_path(ctx->fs_root, dirpath); + + dir = local_opendir_nofollow(ctx, dirpath); + if (dir == NULL) { + goto out; + } + closedir(dir); + + ret = fremovexattrat_nofollow(full_dir_path, filename, name); + +out: + g_free(full_dir_path); + g_free(dirpath); + g_free(filename); + return ret; + +#else char *dirpath = g_path_get_dirname(path); char *filename = g_path_get_basename(path); int dirfd; @@ -237,6 +349,7 @@ out: g_free(dirpath); g_free(filename); return ret; +#endif } int pt_removexattr(FsContext *ctx, const char *path, const char *name) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 225f31fc31..a04889c1d6 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -38,6 +38,10 @@ #include "migration/blocker.h" #include "qemu/xxhash.h" #include +#ifdef CONFIG_WIN32 +#define UTIME_NOW ((1l << 30) - 1l) +#define UTIME_OMIT ((1l << 30) - 2l) +#endif int open_fd_hw; int total_open_fd; @@ -986,9 +990,11 @@ static int stat_to_qid(V9fsPDU *pdu, const struct stat *stbuf, V9fsQID *qidp) if (S_ISDIR(stbuf->st_mode)) { qidp->type |= P9_QID_TYPE_DIR; } +#ifndef CONFIG_WIN32 if (S_ISLNK(stbuf->st_mode)) { qidp->type |= P9_QID_TYPE_SYMLINK; } +#endif return 0; } @@ -1095,6 +1101,7 @@ static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension) ret |= S_IFDIR; } +#ifndef CONFIG_WIN32 if (mode & P9_STAT_MODE_SYMLINK) { ret |= S_IFLNK; } @@ -1104,6 +1111,7 @@ static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension) if (mode & P9_STAT_MODE_NAMED_PIPE) { ret |= S_IFIFO; } +#endif if (mode & P9_STAT_MODE_DEVICE) { if (extension->size && extension->data[0] == 'c') { ret |= S_IFCHR; @@ -1116,6 +1124,7 @@ static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension) ret |= S_IFREG; } +#ifndef CONFIG_WIN32 if (mode & P9_STAT_MODE_SETUID) { ret |= S_ISUID; } @@ -1125,6 +1134,7 @@ static mode_t v9mode_to_mode(uint32_t mode, V9fsString *extension) if (mode & P9_STAT_MODE_SETVTX) { ret |= S_ISVTX; } +#endif return ret; } @@ -1180,6 +1190,7 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf) mode |= P9_STAT_MODE_DIR; } +#ifndef CONFIG_WIN32 if (S_ISLNK(stbuf->st_mode)) { mode |= P9_STAT_MODE_SYMLINK; } @@ -1191,11 +1202,13 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf) if (S_ISFIFO(stbuf->st_mode)) { mode |= P9_STAT_MODE_NAMED_PIPE; } +#endif if (S_ISBLK(stbuf->st_mode) || S_ISCHR(stbuf->st_mode)) { mode |= P9_STAT_MODE_DEVICE; } +#ifndef CONFIG_WIN32 if (stbuf->st_mode & S_ISUID) { mode |= P9_STAT_MODE_SETUID; } @@ -1207,6 +1220,7 @@ static uint32_t stat_to_v9mode(const struct stat *stbuf) if (stbuf->st_mode & S_ISVTX) { mode |= P9_STAT_MODE_SETVTX; } +#endif return mode; } @@ -1245,9 +1259,16 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path, return err; } } else if (v9stat->mode & P9_STAT_MODE_DEVICE) { +#ifndef CONFIG_WIN32 v9fs_string_sprintf(&v9stat->extension, "%c %u %u", S_ISCHR(stbuf->st_mode) ? 'c' : 'b', major(stbuf->st_rdev), minor(stbuf->st_rdev)); +#else + v9fs_string_sprintf(&v9stat->extension, "%c %u %u", + S_ISCHR(stbuf->st_mode) ? 'c' : 'b', + 0, 0); +#endif + } else if (S_ISDIR(stbuf->st_mode) || S_ISREG(stbuf->st_mode)) { v9fs_string_sprintf(&v9stat->extension, "%s %lu", "HARDLINKCOUNT", (unsigned long)stbuf->st_nlink); @@ -1315,7 +1336,11 @@ static int32_t blksize_to_iounit(const V9fsPDU *pdu, int32_t blksize) static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) { +#ifndef CONFIG_WIN32 return blksize_to_iounit(pdu, stbuf->st_blksize); +#else + return blksize_to_iounit(pdu, 0); +#endif } static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf, @@ -1329,6 +1354,14 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf, v9lstat->st_gid = stbuf->st_gid; v9lstat->st_rdev = stbuf->st_rdev; v9lstat->st_size = stbuf->st_size; + +#ifdef CONFIG_WIN32 + v9lstat->st_blksize = stat_to_iounit(pdu, stbuf); + v9lstat->st_blocks = 0; + v9lstat->st_atime_sec = stbuf->st_atime; + v9lstat->st_mtime_sec = stbuf->st_mtime; + v9lstat->st_ctime_sec = stbuf->st_ctime; +#else /* !CONFIG_WIN32 */ v9lstat->st_blksize = stat_to_iounit(pdu, stbuf); v9lstat->st_blocks = stbuf->st_blocks; v9lstat->st_atime_sec = stbuf->st_atime; @@ -1343,6 +1376,8 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf, v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec; v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec; #endif +#endif /* CONFIG_WIN32 */ + /* Currently we only support BASIC fields in stat */ v9lstat->st_result_mask = P9_STATS_BASIC; @@ -1759,7 +1794,11 @@ static bool name_is_illegal(const char *name) static bool same_stat_id(const struct stat *a, const struct stat *b) { +#ifdef CONFIG_WIN32 + return 0; +#else return a->st_dev == b->st_dev && a->st_ino == b->st_ino; +#endif /* CONFIG_WIN32 */ } static void coroutine_fn v9fs_walk(void *opaque) @@ -2300,7 +2339,11 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); +#ifndef CONFIG_WIN32 saved_dir_pos = qemu_dirent_off(dent); +#else + saved_dir_pos = v9fs_co_telldir(pdu, fidp); +#endif } v9fs_readdir_unlock(&fidp->fs.dir); @@ -2501,14 +2544,32 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, qid.version = 0; } +#ifdef CONFIG_WIN32 + /* + * Windows does not have dent->d_off, get offset by calling telldir() + * manually. + */ + off = v9fs_co_telldir(pdu, fidp); +#else off = qemu_dirent_off(dent); +#endif v9fs_string_init(&name); v9fs_string_sprintf(&name, "%s", dent->d_name); +#ifdef CONFIG_WIN32 + /* + * Windows does not have dent->d_type + */ + + len = pdu_marshal(pdu, 11 + count, "Qqbs", + &qid, off, + 0, &name); +#else /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ len = pdu_marshal(pdu, 11 + count, "Qqbs", &qid, off, dent->d_type, &name); +#endif v9fs_string_free(&name); @@ -2838,8 +2899,14 @@ static void coroutine_fn v9fs_create(void *opaque) } nmode |= perm & 0777; + +#ifndef CONFIG_WIN32 err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, makedev(major, minor), nmode, &stbuf); +#else + err = -ENOTSUP; +#endif + if (err < 0) { goto out; } @@ -2864,8 +2931,12 @@ static void coroutine_fn v9fs_create(void *opaque) v9fs_path_copy(&fidp->path, &path); v9fs_path_unlock(s); } else if (perm & P9_STAT_MODE_SOCKET) { +#ifndef CONFIG_WIN32 err = v9fs_co_mknod(pdu, fidp, &name, fidp->uid, -1, 0, S_IFSOCK | (perm & 0777), &stbuf); +#else + err = -ENOTSUP; +#endif if (err < 0) { goto out; } @@ -3600,6 +3671,7 @@ out_nofid: static void coroutine_fn v9fs_mknod(void *opaque) { +#ifndef CONFIG_WIN32 int mode; gid_t gid; int32_t fid; @@ -3656,6 +3728,11 @@ out: out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); +#else + V9fsPDU *pdu = opaque; + + pdu_complete(pdu, -1); +#endif } /* @@ -3928,7 +4005,7 @@ out_nofid: #if defined(CONFIG_LINUX) /* Currently, only Linux has XATTR_SIZE_MAX */ #define P9_XATTR_SIZE_MAX XATTR_SIZE_MAX -#elif defined(CONFIG_DARWIN) +#elif defined(CONFIG_DARWIN) || defined(CONFIG_WIN32) /* * Darwin doesn't seem to define a maximum xattr size in its user * space header, so manually configure it across platforms as 64k. @@ -3945,6 +4022,7 @@ out_nofid: static void coroutine_fn v9fs_xattrcreate(void *opaque) { +#ifndef CONFIG_WIN32 int flags, rflags = 0; int32_t fid; uint64_t size; @@ -4006,10 +4084,15 @@ out_put_fid: out_nofid: pdu_complete(pdu, err); v9fs_string_free(&name); +#else + V9fsPDU *pdu = opaque; + pdu_complete(pdu, -1); +#endif } static void coroutine_fn v9fs_readlink(void *opaque) { +#ifndef CONFIG_WIN32 V9fsPDU *pdu = opaque; size_t offset = 7; V9fsString target; @@ -4045,6 +4128,10 @@ out: put_fid(pdu, fidp); out_nofid: pdu_complete(pdu, err); +#else + V9fsPDU *pdu = opaque; + pdu_complete(pdu, -1); +#endif } static CoroutineEntry *pdu_co_handlers[] = { @@ -4306,6 +4393,7 @@ void v9fs_reset(V9fsState *s) static void __attribute__((__constructor__)) v9fs_set_fd_limit(void) { +#ifndef CONFIG_WIN32 struct rlimit rlim; if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) { error_report("Failed to get the resource limit"); @@ -4313,4 +4401,5 @@ static void __attribute__((__constructor__)) v9fs_set_fd_limit(void) } open_fd_hw = rlim.rlim_cur - MIN(400, rlim.rlim_cur / 3); open_fd_rc = rlim.rlim_cur / 2; +#endif } diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 93ba44fb75..2fbe7b831b 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -78,6 +78,9 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, int len, err = 0; int32_t size = 0; off_t saved_dir_pos; +#ifdef CONFIG_WIN32 + off_t next_dir_pos; +#endif struct dirent *dent; struct V9fsDirEnt *e = NULL; V9fsPath path; @@ -124,6 +127,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, break; } +#ifdef CONFIG_WIN32 + next_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs); + if (next_dir_pos < 0) { + err = next_dir_pos; + goto out; + } +#endif + /* * stop this loop as soon as it would exceed the allowed maximum * response message size for the directory entries collected so far, @@ -168,7 +179,11 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, } size += len; +#ifndef CONFIG_WIN32 saved_dir_pos = qemu_dirent_off(dent); +#else + saved_dir_pos = next_dir_pos; +#endif } /* restore (last) saved position */ From patchwork Mon Apr 25 14:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4CA2CC433F5 for ; Mon, 25 Apr 2022 14:54:00 +0000 (UTC) Received: from localhost ([::1]:45962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj06B-0001Q0-DH for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:53:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgf-0006XW-Da for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:39 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:40520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgd-0004kH-Tw for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:37 -0400 Received: by mail-pl1-x634.google.com with SMTP id k4so15742289plk.7 for ; Mon, 25 Apr 2022 07:27:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ommSiCLRSnB1NKyyuvvOu0Qu05aukfUm25ZKPYRc2Gg=; b=PeaDwyi/AhWIzDpwt/QP61meXyFpNbdMwK0znwV2OSKrYgx0OEV1v2E4V1XyOpLMxp YwX54udaP6TEKMp+9pp40KipLuchsaWu4wT3aSR9Ln5CqX54WebXETrMQp5ClVGs1L67 7T1/zp8xkM20vBdHfXBx7qcKy+9t35tZA4OuLmCbn1C7248ugLtUSP3WxzXJEcyUF8Xs qmeF2JM121EwNiU1qR+fpsR9vFNRr5o6gOOCciLeVwNXPBqsgcGUqhWcTmkI4F5LjmAK RrqQ5P1F+CsLXYkRWwWvTJ/TUQR4UOl/7s4yosvSkGLCMGdaWWQ8OeVEPBEBgQPSD4Vc O2OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ommSiCLRSnB1NKyyuvvOu0Qu05aukfUm25ZKPYRc2Gg=; b=ywnE1tBv0N/nL4MI0+GVKXiIK2Co+RELvLCNY/TtoiGaYzMVfzuk54hUZierB8NxNU sebZ5drSnqgesH2ZLep8pObNNRbOwzPxdvETVBmo0OKPrTh4wFucd9Xb+Zal+IanTHCY SknfJE0EFUIYiFr+7EqOjfR/yGkqGjFiCc1YAm66yCv4ve3YTsvLHDrg8r2ngfE/2AR6 9cXii3VIqlwKxWJ0B6Bh2E3bTVZbZfAkmvSkEcY3ixMaa/hYFrsiKgTeEB8QUZFhS6YR lvLQiPijkyGSOzefGIWBDX2GeUxj7qlfnn1C5wHw0yMydOU8EVRUn0kfqoPV9xMfgEny xRvg== X-Gm-Message-State: AOAM532LLrvcJN0U9jdOqO5OmtJwbbfcZIzOjrXw8+J95GGPADYlpaos dKjZ95IMxLmL7i5Kb45SX3s= X-Google-Smtp-Source: ABdhPJzfmkLyZnRRCDNdDL3qIfAIm7Bj/deERGLRha97WnesAN0B4W545CkH0zxTI++iRN7guwG0KQ== X-Received: by 2002:a17:90b:38cb:b0:1d5:3ca0:cf8 with SMTP id nn11-20020a17090b38cb00b001d53ca00cf8mr27252495pjb.51.1650896854725; Mon, 25 Apr 2022 07:27:34 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:34 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 6/9] hw/9pfs: Update 9p-synth.c for Windows build Date: Mon, 25 Apr 2022 22:27:02 +0800 Message-Id: <20220425142705.2099270-7-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi This updates 9p synth backend driver for Windows build. Funtionalities are not tested as test cases do not run on Windows at present. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- hw/9pfs/9p-synth.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index d99d263985..ce28943b2d 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -152,8 +152,10 @@ static void synth_fill_statbuf(V9fsSynthNode *node, struct stat *stbuf) stbuf->st_gid = 0; stbuf->st_rdev = 0; stbuf->st_size = 0; +#ifndef CONFIG_WIN32 stbuf->st_blksize = 0; stbuf->st_blocks = 0; +#endif stbuf->st_atime = 0; stbuf->st_mtime = 0; stbuf->st_ctime = 0; @@ -236,7 +238,8 @@ static void synth_direntry(V9fsSynthNode *node, entry->d_ino = node->attr->inode; #ifdef CONFIG_DARWIN entry->d_seekoff = off + 1; -#else +#endif +#ifdef CONFIG_LINUX entry->d_off = off + 1; #endif } From patchwork Mon Apr 25 14:27:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2AE0C433EF for ; Mon, 25 Apr 2022 14:47:34 +0000 (UTC) Received: from localhost ([::1]:58552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizzx-0007a1-RV for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:47:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgo-0006bS-0a for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:48 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:51848) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgh-0004nD-Js for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:40 -0400 Received: by mail-pj1-x102f.google.com with SMTP id p6so78301pjm.1 for ; Mon, 25 Apr 2022 07:27:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uF55zfRGZGLp8oLCUwGZ2krUtjYw224zyy5ygc5qPWk=; b=PwNXe3HWc5sk/asa8EHJwPDQT+U2YuMUe7wXMbOA9EMR2jrCAsVxd71k4Acj3I6U8I kLQxWB7BLHvzSrrO7FoXJF1HdLuLrPuu9bv05tZ5aPq6ysdplFlFCqlsgI41Ymc7sYH0 p28r3f26KPdUb53rFyYjKSkXCFNYQAUOPLXhX1LoKTKPGWg7pLYWNSWqCYGlw/DlVUyR vE0FzcFh72oyhpqSOykksd/HVpYeYWtLGru1EnYjA0R75Tr6neo0ic8fzBxsW+14do8g 3xetHWF0Llv9SUe5XIQ+RXZBdH1h2Sxok9mwxWBD1mHACii9MZYE39tkgzDx4p5onFmI Ssfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uF55zfRGZGLp8oLCUwGZ2krUtjYw224zyy5ygc5qPWk=; b=pJUZEki7ZfiPV39X4cMI1gqBu++mLsbgexi2Li4f61B8MXbXllekpxAZRunivMzAWI UKvFlWgGIowYSP02HLpb3nBJKRnVISLOEwiZI7TmeReDzgSzktFzHJI16S8Ulqy+SbHn eLnMxi3NF2CAHyi8TekCKJMnk9iK3x4bgNyJYDLUpjEB+mICz6nSr8lBn7Xn6s911Q05 Ykxv549/M4u4Oh+l963LzPbUwntQvN673VQYTSuuSOoiqO6I7F/uNUCPZcK6fZ5NzRwf DpGnYpKQ4k0hEen8P2rmhnI6d5lM97cFhMW127qlFl7KFWWxtKPB7FCtW6mhHuvhWKeN q+1w== X-Gm-Message-State: AOAM5313SeQGzIDfxU6fl0ag8P4537Y/qVfDQyR8yBPJVA+dmQ7D70Fp 39NtmHTJDf/f1koT2vlgT/c= X-Google-Smtp-Source: ABdhPJyEZ89kZqYMvcerQ4bWot/pg9iJ/wnvLYtD62XARTmNKKgo6bBX7e1ObOikAVJlIyQoLRO06g== X-Received: by 2002:a17:902:b286:b0:15b:335b:53e6 with SMTP id u6-20020a170902b28600b0015b335b53e6mr18068383plr.169.1650896858442; Mon, 25 Apr 2022 07:27:38 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:38 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 7/9] fsdev: Enable 'local' file system driver backend for Windows Date: Mon, 25 Apr 2022 22:27:03 +0800 Message-Id: <20220425142705.2099270-8-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Only 'local' file system driver will be supported for Windows host. 'proxy' or 'synth' are not supported. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- fsdev/qemu-fsdev.c | 2 ++ fsdev/meson.build | 1 + 2 files changed, 3 insertions(+) diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 3da64e9f72..e1cc677ad8 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -81,6 +81,7 @@ static FsDriverTable FsDrivers[] = { NULL }, }, +#ifndef CONFIG_WIN32 { .name = "synth", .ops = &synth_ops, @@ -100,6 +101,7 @@ static FsDriverTable FsDrivers[] = { NULL }, }, +#endif }; static int validate_opt(void *opaque, const char *name, const char *value, diff --git a/fsdev/meson.build b/fsdev/meson.build index b632b66348..2aad081aef 100644 --- a/fsdev/meson.build +++ b/fsdev/meson.build @@ -8,6 +8,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files( ), if_false: files('qemu-fsdev-dummy.c')) softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss) softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss) +softmmu_ss.add_all(when: 'CONFIG_WIN32', if_true: fsdev_ss) if have_virtfs_proxy_helper executable('virtfs-proxy-helper', From patchwork Mon Apr 25 14:27:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825870 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 903F9C433F5 for ; Mon, 25 Apr 2022 14:39:29 +0000 (UTC) Received: from localhost ([::1]:40360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nizs8-0003kT-K1 for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:39:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgp-0006bs-FN for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:48 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:33955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgn-0004p0-RT for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:47 -0400 Received: by mail-pj1-x1032.google.com with SMTP id d23-20020a17090a115700b001d2bde6c234so48508pje.1 for ; Mon, 25 Apr 2022 07:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xVhmwJN1yacivhyyGJyPocmRV53ZU/rr69UEm8cytaM=; b=Wt/Xj3bef2u9D8YwqQTNKLY0reHLK+6gFJOcQ0DvCU994XBoZo4yAoCNnrh10VrJFO TlbKJf/h/eYGAYoz2ppf8sJZUZ6AbkwlFWHGHh6aXpJBdCSeRRf2ZXkSOxae0CeREujV vsep1Yqq+lLw6O4i6hynGY7Rgh7d+ENmhMcTFg7qCjDn0cemDPy3OEExNLtqYNQ9RPRm /GaAMF6NTkGYcyKN3LaYXYr0e0r27eAM3kexIQM40ZzfD6tz5W/Lauw75p9HoiJFhC49 rcYMQghGPs5Puup86xDHxW/0KOxER7ydvU/VJ1+7fbRFbhg2FvHpx17kcfpSkY52e3Md dG4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xVhmwJN1yacivhyyGJyPocmRV53ZU/rr69UEm8cytaM=; b=bcvV3tUD3Esjs9eSS6EMSSw8bevQdwwCEzSXBmtkN67bXTjRbgwu0Lh0y1WkWATmwG ITJtYFFMJyO1Vxg29yLSnQPBenXrFCze7+d/TgIVlU0XPCxxfy7MoGlsLZWApyT/ZwN1 bpqL7n/QOqpOXBq75vrPd2LP6Z3PU9N3BwtlWHhYObBG3+09LITcDJiy4IbpSK5ZbeB2 N3LXRHXegVuDfbu2QsSZSJyyYsqPwm2lkEA0DOfrk60rGmm5fcB0IpmZLp6nV0u8YZps OH1aD0jvKc4ICh2sWOduwiLQ07KCR4yM6tkY0LrDlADBquD37w50wxaEQHN3WFxFxBUz /7Bw== X-Gm-Message-State: AOAM533IHMb85zyJsxBKyXzx9MkQTxvnJba19F7QNdpRl6b62k9JlrhA /Lr4PdIaYWjUdYWb4A5yBeU= X-Google-Smtp-Source: ABdhPJzLJz/pFNwiwTGJygq4t6Q3EyYcZgZYpSyWM7Xeqf26zXnSzQW7uGKv5M7TcLMLfpQupl1lJw== X-Received: by 2002:a17:90b:3c84:b0:1d9:2a4c:5ee9 with SMTP id pv4-20020a17090b3c8400b001d92a4c5ee9mr13879208pjb.121.1650896862638; Mon, 25 Apr 2022 07:27:42 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:42 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 8/9] meson.build: Turn on virtfs for Windows host Date: Mon, 25 Apr 2022 22:27:04 +0800 Message-Id: <20220425142705.2099270-9-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Enable virtfs configuration option for Windows host. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- meson.build | 10 +++++----- hw/9pfs/meson.build | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index d083c6b7bf..46f61b2a9d 100644 --- a/meson.build +++ b/meson.build @@ -1465,16 +1465,16 @@ dbus_display = get_option('dbus_display') \ .allowed() have_virtfs = get_option('virtfs') \ - .require(targetos == 'linux' or targetos == 'darwin', - error_message: 'virtio-9p (virtfs) requires Linux or macOS') \ - .require(targetos == 'linux' or cc.has_function('pthread_fchdir_np'), + .require(targetos == 'linux' or targetos == 'darwin' or targetos == 'windows', + error_message: 'virtio-9p (virtfs) requires Linux or macOS or Windows') \ + .require(targetos == 'linux' or targetos == 'windows' or cc.has_function('pthread_fchdir_np'), error_message: 'virtio-9p (virtfs) on macOS requires the presence of pthread_fchdir_np') \ - .require(targetos == 'darwin' or (libattr.found() and libcap_ng.found()), + .require(targetos == 'darwin' or targetos == 'windows' or (libattr.found() and libcap_ng.found()), error_message: 'virtio-9p (virtfs) on Linux requires libcap-ng-devel and libattr-devel') \ .disable_auto_if(not have_tools and not have_system) \ .allowed() -have_virtfs_proxy_helper = targetos != 'darwin' and have_virtfs and have_tools +have_virtfs_proxy_helper = targetos != 'darwin' and targetos != 'windows' and have_virtfs and have_tools foreach k : get_option('trace_backends') config_host_data.set('CONFIG_TRACE_' + k.to_upper(), true) diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build index b4a8ff0913..50401848d9 100644 --- a/hw/9pfs/meson.build +++ b/hw/9pfs/meson.build @@ -17,6 +17,8 @@ fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-local.c', fs_ss.add(when: 'CONFIG_DARWIN', if_true: files('9p-local.c', '9p-proxy.c', '9p-util-darwin.c')) +fs_ss.add(when: 'CONFIG_WIN32', if_true: files('9p-local-win32.c', + '9p-util-win32.c')) fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c')) softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss) From patchwork Mon Apr 25 14:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12825880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7516C433F5 for ; Mon, 25 Apr 2022 14:50:37 +0000 (UTC) Received: from localhost ([::1]:35864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj02u-0002vk-Rs for qemu-devel@archiver.kernel.org; Mon, 25 Apr 2022 10:50:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nizgr-0006e8-Ml for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:52 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:35399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nizgp-0004pp-85 for qemu-devel@nongnu.org; Mon, 25 Apr 2022 10:27:49 -0400 Received: by mail-pj1-x102e.google.com with SMTP id w5-20020a17090aaf8500b001d74c754128so1324267pjq.0 for ; Mon, 25 Apr 2022 07:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MD+TlSLDLHY/kSu2Q8HsMnto1MgxQkrIjJ5UvAZq3eQ=; b=GErlpZe44nq39km9zcAD9LtPCWaNJ4/ntka10jdJ1iTfjdpyDY9+1N8mOw+52pZf61 A6uk6gPUSy+mu6tjKP25mvJDY2aLwITv1S5xFPiY2bf+TAIGqm5i2OTuHs150snkmuP+ nGOyGMBRkz7NKrAPUwGggQDip3P7PeGElSJVcMr4wGWduBzgsT0BCYEm5OHu8WGByMah HXTfsn3XEqIB104nGOLpf9VyjXShjjOIPHBV99ahwY9tNN4em1ss7xBuGtwBoPLtURe7 jhKwjf3CzE00N7LSOSGsbwXTEFta9k/PaG8wwWCx9vq116qFQ+FZUZsgALWsIp7FsHjr eLLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MD+TlSLDLHY/kSu2Q8HsMnto1MgxQkrIjJ5UvAZq3eQ=; b=h4tKRnLPDNikaxk+8VnKPmorR2XmKsfbpZ+H29RVy/dXoztWxTuWzBvg9ZTtRGTLui 2vDwPxd1c0IqBCME6uOD1325W9C5I0xakq4+/jQMBhPkhWMf9CclXmvkewDwTa+wt0yH 0H3o1ETJAH+M8Z26aI968HWL22N0/8mu1hJDPGC3hkcn2wuCWN6RZTBXYfHalh2fX8C/ cVJKxAmtvpkVzWdCyCiUvsRqDz+m0dt/PByzedEBJTwPYHbPBy7l1HmG862AE/IsoWRX 9c1jLs2TfFofCF4Iq1VLuYDeHm26FA18eVdjoGLQ/z+4W7sLJdvfYPptVPzEfOL6R9h5 AASA== X-Gm-Message-State: AOAM530kf2znEC0vW46mLBo+dFpsDzkj3QaBQ0J4+/k1nXCBrHy6Utew 889m6wEhijnkP+F8M+hmyLHotfarNrs= X-Google-Smtp-Source: ABdhPJyCrCXkfbOtCmPVZoqh9j8OTDRv0lihKhnECWo5xXCSyhxr3VjAKrfCsSxymUzmU+hWoUKsLw== X-Received: by 2002:a17:903:1246:b0:155:c376:e5a0 with SMTP id u6-20020a170903124600b00155c376e5a0mr17637946plh.167.1650896866046; Mon, 25 Apr 2022 07:27:46 -0700 (PDT) Received: from pek-vx-bsp2.wrs.com (unknown-176-192.windriver.com. [147.11.176.192]) by smtp.gmail.com with ESMTPSA id t1-20020a628101000000b0050d47199857sm2437968pfd.73.2022.04.25.07.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:27:45 -0700 (PDT) From: Bin Meng To: Christian Schoenebeck , Greg Kurz , qemu-devel@nongnu.org Subject: [PATCH 9/9] hw/9p: win32: Translate Windows error number to Linux value Date: Mon, 25 Apr 2022 22:27:05 +0800 Message-Id: <20220425142705.2099270-10-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425142705.2099270-1-bmeng.cn@gmail.com> References: <20220425142705.2099270-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bin Meng , Guohuai Shi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Guohuai Shi Some of Windows error numbers have different value from Linux ones. For example, ENOTEMPTY is defined to 39 in Linux, but is defined to 41 in Windows. So deleting a directory from a Linux guest on top of QEMU from a Windows host complains: # rmdir tmp rmdir: 'tmp': Unknown error 41 This commit provides error number traslation from Windows to Linux. It can make Linux guest OS happy with the error number when running on top of QEMU from a Windows host. This has a side effet that it requires all guest OSes' 9pfs drivers to use the same errno. It looks like macOS has different errno too so using 9p in a Linux on top of QEMU from a macOS host may also fail in the above case. I suspect we only tested 9p from a macOS guest on top of QEMU from a macOS host, so this issue was not exposed. I am not aware of Windows's native support for 9pfs so I think using the Linux errnor as the standard is probably okay, but I am open for suggestions. Signed-off-by: Guohuai Shi Signed-off-by: Bin Meng --- hw/9pfs/9p.h | 4 ++++ hw/9pfs/9p-util-win32.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/9pfs/9p.c | 7 +++++++ 3 files changed, 49 insertions(+) diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 87e8eac840..db2013d549 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -490,6 +490,10 @@ void pdu_free(V9fsPDU *pdu); void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); void v9fs_reset(V9fsState *s); +#ifdef CONFIG_WIN32 +int errno_translate_win32(int errno_win32); +#endif + struct V9fsTransport { ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt, va_list ap); diff --git a/hw/9pfs/9p-util-win32.c b/hw/9pfs/9p-util-win32.c index d9b35e7425..c4f90c6503 100644 --- a/hw/9pfs/9p-util-win32.c +++ b/hw/9pfs/9p-util-win32.c @@ -20,6 +20,11 @@ #define V9FS_MAGIC 0x53465039 /* string "9PFS" */ #endif +struct translate_map { + int output; /* Linux error number */ + int input; /* Windows error number */ +}; + static int build_ads_name(char *namebuf, size_t namebuflen, const char *dirname, const char *filename, const char *ads_name) @@ -301,3 +306,36 @@ int qemu_statfs(const char *fs_root, struct statfs *stbuf) return 0; } + +int errno_translate_win32(int errno_win32) + { + unsigned int i; + + /* + * The translation table only contains values which could be returned + * as a result of a filesystem operation, i.e. network/socket related + * errno values need not be considered for translation. + */ + static struct translate_map errno_map[] = { + /* Linux errno Windows errno */ + { L_EDEADLK, EDEADLK }, + { L_ENAMETOOLONG, ENAMETOOLONG }, + { L_ENOLCK, ENOLCK }, + { L_ENOSYS, ENOSYS }, + { L_ENOTEMPTY, ENOTEMPTY }, + { L_EILSEQ, EILSEQ }, + { L_ELOOP, ELOOP }, + }; + + /* scan errno_win32 table for a matching Linux errno value */ + + for (i = 0; i < sizeof(errno_map) / sizeof(errno_map[0]); i++) { + if (errno_win32 == errno_map[i].input) { + return errno_map[i].output; + } + } + + /* no translation necessary */ + + return errno_win32; + } diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index a04889c1d6..0a9c0a509e 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1062,6 +1062,13 @@ static void coroutine_fn pdu_complete(V9fsPDU *pdu, ssize_t len) id = P9_RERROR; } +#ifdef CONFIG_WIN32 + /* + * Some Windows errnos have different value from Linux, + * and they need to be translated to the Linux value. + */ + err = errno_translate_win32(err); +#endif ret = pdu_marshal(pdu, len, "d", err); if (ret < 0) { goto out_notify;