From patchwork Sun Aug 13 08:41:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karim Taha X-Patchwork-Id: 1820763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=cTAqmOYv; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RP7LK46BKz1yf2 for ; Mon, 14 Aug 2023 05:45:45 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVGzn-0007sf-RR; Sun, 13 Aug 2023 15:43:27 -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 1qVGzm-0007sF-6z for qemu-devel@nongnu.org; Sun, 13 Aug 2023 15:43:26 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVGzk-0002Rf-LK for qemu-devel@nongnu.org; Sun, 13 Aug 2023 15:43:25 -0400 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fe5695b180so32849145e9.2 for ; Sun, 13 Aug 2023 12:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691955803; x=1692560603; 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=cTAqmOYvZNPRbzXdLSPER2UH3nXK07P+MYYDnNxxPjEuOEqwscLWvusa4i2vvYsZ/J mZg0vz0+NdhvLIM9owU+1HGHZFLlQRduIY1byR57Nn9afa4k/C5ItNX4AnHp+bW0/HZu ZaROdx0+A+dJAYQwbTGA8z32AUpTvi8kSvelATn6Ei8ZpUiI55n1wF3dGXX/NRjKNdhc 5UYMj6vyNZYXLml6cLfojWQfjQvk3MxjhXwINAJyUaDlgcVpiHFsbaH1fqPGx3DeseKO owysjggy7W6PjN+U78FYtNgM5H4vwbT0nFgaxcJf9k6RtF91X060g+ojEkr0UhfSahto YR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691955803; x=1692560603; 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=DhPcyQ547181cIb5xZh4UNWriCJGEriwt/o2SgzFigLzTsVIfO/+LeozfRlqabNTym MAgKOYr002LhO9pg7kVqmLnLVRTn0oBtE7MdUauMB3nsY7ZWeZVAxd5Up/F99/AtUzKA DVxxE9bTnYSVthAPVYubSt/h4VaqkSDoG8d+DimHUh21j7Sixy+8QFXnLchaXXSEg8m+ QjiO2AA1ka6RQOfK9tUgtwuwLZXhqaDq2K/aR3LqLHm/1ffM7Xg1u8aVLu6oSMTARrZH R0BJi2dT/uNQM3ujs7jim4DPuC16J/Nd7s+A9x9RqtTmHGE+unTp5MSKUiTbgkuuNzHN sANQ== X-Gm-Message-State: AOJu0YwMKijlEoz3iN8utyjKyt4LMzVny/QxlS/cvp6DM/A28sVzBS6d DnQl6OjrRpDWMm2ku1ue16dlhpfhB88= X-Google-Smtp-Source: AGHT+IGnLcsWXDdbKPnD3IRkofX5D0TsKqbwRd6ySJFTSG6kWi5nBHX4XLUvKgVTZ3ogcgAfz2Y2PA== X-Received: by 2002:a05:600c:2258:b0:3fe:2f80:8394 with SMTP id a24-20020a05600c225800b003fe2f808394mr5812407wmm.15.1691955802800; Sun, 13 Aug 2023 12:43:22 -0700 (PDT) Received: from karim.my.domain ([197.39.204.50]) by smtp.gmail.com with ESMTPSA id t20-20020a7bc3d4000000b003fe263dab33sm12234536wmj.9.2023.08.13.12.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 12:43:22 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Stacey Son , Karim Taha , Richard Henderson Subject: [PATCH v3 19/32] Implement stat related syscalls Date: Sun, 13 Aug 2023 10:41:40 +0200 Message-Id: <20230813084153.6510-20-kariem.taha2.7@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230813084153.6510-1-kariem.taha2.7@gmail.com> References: <20230813084153.6510-1-kariem.taha2.7@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x330.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 target_fhp_addr, return h2t_freebsd_statfs(target_stfs_addr, &host_stfs); } +/* 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 = 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_addr) +{ + abi_long ret; + struct statfs host_stfs; + + ret = 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 = bufsize / sizeof(struct target_statfs); + + /* if user buffer is NULL then return number of mounted FS's */ + if (target_addr == 0 || count == 0) { + return get_errno(freebsd11_getfsstat(NULL, 0, flags)); + } + + /* XXX check count to be reasonable */ + host_bufsize = sizeof(struct statfs) * count; + host_stfs = alloca(host_bufsize); + if (!host_stfs) { + return -TARGET_EINVAL; + } + + ret = count = 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 */