From nobody Thu Dec 18 08:16:00 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691936370; cv=none; d=zohomail.com; s=zohoarc; b=DiTlpMgpdX02zHcgUCvxhYnfF/+40Aj/PjFoL6J/WAJCf+Gm64DKIff+Kb/itqu88dpKI6X67UPMrgfO8/CiQ8svWGn872N96X6VJCXpsVQ8KbEulqNicgeDgJjfjciYnPt40u14Kqku+K78I8eWQF2d8n2269AauGW49qDUCv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691936370; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tytNoWwd4l2oWWKY6hZbDrOZveBwceyNmveWX7P6eu0=; b=oDG+7P8+tRwYHjMD4o3bnIhcsYY5mVZ+vKbJ1yexrGd9dqGa9GUFIHuAvzWcpJgUqYwd89LgVTTC3usiX9PEk8XWd9gTGJRhRjcZXK0G6NIRTVJ5FiX1apUEmTZEm/EEy7pokXNGpUgSYHabcrwXyOpXLsk/ajuilRWMJOOB0qU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691936370459915.0063917763895; Sun, 13 Aug 2023 07:19:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVBpv-0008GF-PW; Sun, 13 Aug 2023 10:12:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qVBpc-0008Av-7b for qemu-devel@nongnu.org; Sun, 13 Aug 2023 10:12:38 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVBpa-0000sF-3R for qemu-devel@nongnu.org; Sun, 13 Aug 2023 10:12:35 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbea14706eso31527405e9.2 for ; Sun, 13 Aug 2023 07:12:32 -0700 (PDT) Received: from karim.my.domain ([197.39.204.50]) by smtp.gmail.com with ESMTPSA id l18-20020a5d4112000000b003144b95e1ecsm11409101wrp.93.2023.08.13.07.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 07:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691935952; x=1692540752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tytNoWwd4l2oWWKY6hZbDrOZveBwceyNmveWX7P6eu0=; b=qrHULHUjop1hD9soqGB53Y64bUXC7X0Nl5WhA3CdFAhsUDHnlnwKxu4G8vUEQXnFn+ a9MK0W+pd4jW5yMhv8mDr/WlaPlkO/OQ7r23Miccf0+tEYB+kUFILH+6gISnctYBTPKi 6rlY6r0X4a0JoMDq3vONezFbnkv6eckJknqBA9iQfqojXU/yXN6ktejluwxORXDtYsP+ cx2UhNJs1ygNuZNTWoi+Ya7Qq+TFJX8UFntdE5lxTLm680tjZ2K8kK2kEhCvavIpK/3x gGmxJJDn4Yl2JM5sqlqiQZ8oKG56ZNWwANRUgIUkQrla+bs+7pHGCKjk5GEsQ7/+l8oK EC0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691935952; x=1692540752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tytNoWwd4l2oWWKY6hZbDrOZveBwceyNmveWX7P6eu0=; b=Cwm4KB3V2QQbA6E+eGzEWbQnXbnwPIdiOKWKbML6pm+1Ir1TQjwMr89MvP7gDvc+GS nnorJxB26rm5fRkc0FxTFcyYrIp3YWYaHNSjF0+ywJfvaEacnp4dhnLYfGWLQNSXr/U+ IY1bAkj1wAFXGLrm0cl+k6eAI6DAcncUyUKB0dC6LUS3megsrN5n5dLjedy4g1GJZhLU 3VeJXdF0x0GsFG1aUUFzhl+sU1NDupN74RmZv7SKDi0ywd/yb1SLHedFtG1Nd6Glk2Qe /P2SvitxtlOnYAfM1cqVGTx1C8STy4ACqwoCWIXsgm+H1MIJdmVR5kUxNDJhm46xpHyR qXtw== X-Gm-Message-State: AOJu0YzHd0rtQWqOcEaN5ciDsd8idvIfbnEmSiwNji3PFz7RB8vJv7ag YX3G841+ReLFaBnqspjAJM6/X+VpR+w= X-Google-Smtp-Source: AGHT+IEBpybv657wgdmmLaFcBYukxRTqJOnXjlqX8/9kDVLkFG7xYAHZ74xKD7l3O3MP0FJLCP1Cng== X-Received: by 2002:a5d:4a47:0:b0:317:3f64:4901 with SMTP id v7-20020a5d4a47000000b003173f644901mr4719807wrs.41.1691935951682; Sun, 13 Aug 2023 07:12:31 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Stacey Son , Karim Taha , Richard Henderson Subject: [PATCH v2 19/32] Implement stat related syscalls Date: Sun, 13 Aug 2023 05:10:00 +0200 Message-Id: <20230813031013.1743-20-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230813031013.1743-1-kariem.taha2.7@gmail.com> References: <20230813031013.1743-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_06_12=1.543, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691936371157100001 Content-Type: text/plain; charset="utf-8" From: Stacey Son Implement the following syscalls: statfs(2) fstatfs(2) getfsstat(2) Signed-off-by: Stacey Son Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-stat.h | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/bsd-user/freebsd/os-stat.h b/bsd-user/freebsd/os-stat.h index 935663c071..9492c93c55 100644 --- a/bsd-user/freebsd/os-stat.h +++ b/bsd-user/freebsd/os-stat.h @@ -210,4 +210,73 @@ static inline abi_long do_freebsd_fhstatfs(abi_ulong t= arget_fhp_addr, return h2t_freebsd_statfs(target_stfs_addr, &host_stfs); } =20 +/* statfs(2) */ +static inline abi_long do_freebsd_statfs(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + struct statfs host_stfs; + + LOCK_PATH(p, arg1); + ret =3D get_errno(statfs(path(p), &host_stfs)); + UNLOCK_PATH(p, arg1); + if (is_error(ret)) { + return ret; + } + + return h2t_freebsd_statfs(arg2, &host_stfs); +} + +/* fstatfs(2) */ +static inline abi_long do_freebsd_fstatfs(abi_long fd, abi_ulong target_ad= dr) +{ + abi_long ret; + struct statfs host_stfs; + + ret =3D get_errno(fstatfs(fd, &host_stfs)); + if (is_error(ret)) { + return ret; + } + + return h2t_freebsd_statfs(target_addr, &host_stfs); +} + +/* getfsstat(2) */ +static inline abi_long do_freebsd_getfsstat(abi_ulong target_addr, + abi_long bufsize, abi_long flags) +{ + abi_long ret; + struct statfs *host_stfs; + int count; + long host_bufsize; + + count =3D bufsize / sizeof(struct target_statfs); + + /* if user buffer is NULL then return number of mounted FS's */ + if (target_addr =3D=3D 0 || count =3D=3D 0) { + return get_errno(freebsd11_getfsstat(NULL, 0, flags)); + } + + /* XXX check count to be reasonable */ + host_bufsize =3D sizeof(struct statfs) * count; + host_stfs =3D alloca(host_bufsize); + if (!host_stfs) { + return -TARGET_EINVAL; + } + + ret =3D count =3D get_errno(getfsstat(host_stfs, host_bufsize, flags)); + if (is_error(ret)) { + return ret; + } + + while (count--) { + if (h2t_freebsd_statfs((target_addr + + (count * sizeof(struct target_statfs))), + &host_stfs[count])) { + return -TARGET_EFAULT; + } + } + return ret; +} + #endif /* BSD_USER_FREEBSD_OS_STAT_H */ --=20 2.40.0