From nobody Thu Dec 18 08:24:58 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=1691936355; cv=none; d=zohomail.com; s=zohoarc; b=AcT42caTIOYs7O+WNtfX93qRU8egS/zGnzE6U8c7/5kKmLEDKJrAl3F2FOqNKvNSPBF1J8YVTapG2QgGsXMqD2aB3pbcrfu5HBpKfpOHq/CnRXc5K1YvqJi1DyrCgcZ+40wLuKqQq8gbdoxCPRvRFCuicwMmzWwe3lG2962cd9E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691936355; 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=0MONonAVf/x+5s65BrH15EWH3H62fPVv1nAh+5Em/Wk=; b=P4nVt4YFBob1E+FTlMzNTSggEMUpiO0/xoEpiEh7e8QZTkf0iAV9wifnDfz4LvUDVLZqYDxW0VAcx2HXMXipOkrIuS6r49HMLXYLoHV8i9WBfWWD/6YwXXQUU4iWvWuhnIdZNmvi4K8DKjMkmFC+5YpwgV+N7w7ScIDdVRL7Nwc= 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 1691936355402729.3800163700953; Sun, 13 Aug 2023 07:19:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qVBpv-0008GD-Au; 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 1qVBph-0008C7-H9 for qemu-devel@nongnu.org; Sun, 13 Aug 2023 10:12:42 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qVBpf-0000u5-Ig for qemu-devel@nongnu.org; Sun, 13 Aug 2023 10:12:40 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fe1a17f983so31497465e9.3 for ; Sun, 13 Aug 2023 07:12:39 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 07:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691935958; x=1692540758; 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=0MONonAVf/x+5s65BrH15EWH3H62fPVv1nAh+5Em/Wk=; b=HAZ4wCuodd/LUniGxU76phqFz1/GDn2C+3ZT4bC06fsTVaPUx3tdFX7alQqgN2rhLY HB7gIOTZBucBcgJWmwMvLSdm66vu+AeHmSyaYlMGBnlLcKn2SMZg6KafUYwOVXyHWjbo Jn80yv7AalgFQuH0Tn46pI8Shq68X285QDGmE+TteIRu7Uq/DfjB9SpAq0K2Rp28pKJN VCxC0Q6z468rG2yXe0mbJGN1RyF0E+f0N47fBm5r/ao5o2XGJnewejHXCUQxonnFSN3T RqUl73NlHziTUXrF0/7h3568G64+yo6jhbObl7kLq3d2Q2ycOHu30+x3Kp9TNsr6mn+S uhPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691935958; x=1692540758; 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=0MONonAVf/x+5s65BrH15EWH3H62fPVv1nAh+5Em/Wk=; b=fDsR+XRR3Ikb8alPDvDfia5DW38dqziQ1rvyHr+vj3eo9d5FS65YpYhxaO0AF48u+T DkU6Vez1tbqOK5Bpm7By2xoj8c8n5WnIs1TaiNvnaVTlKDo4CJFacaoxhh+Ph34uixck pk2eeFf9buWpJmmLfpEyqfG/kJbGk3oXgiJuPI4llr5uHV3RejwaNxsAY4vpIJtHCh1I 8xN0hKaxDypUguAKmpvE5IKRgwV1T03kwYC6y3efEnX1Jf1pG1jna7Fs+9BB/tM1iiH9 u1WiJohAE4QhDhGDJP2elPq6QMBAlNibGdejsGRz7L0YtZb9CDtki/EaChfnLFBbEntt nM6g== X-Gm-Message-State: AOJu0Yxot+2Dlrl3db41D0fB6t+IK6rOWbIqQjwWDixUKF5kHFML7mEV a0L8deRFXbDIP9ZHL6u8+zkMSp4po0A= X-Google-Smtp-Source: AGHT+IExw3Cw4vUs6nM2Ws9z0kOonYRhwDgiwWtXWyKasEh1bC6+VO1E7ZSsIZEcrf/1wIvLPY2WpQ== X-Received: by 2002:adf:f086:0:b0:318:fa5:d84e with SMTP id n6-20020adff086000000b003180fa5d84emr4361985wro.70.1691935957801; Sun, 13 Aug 2023 07:12:37 -0700 (PDT) From: Karim Taha To: qemu-devel@nongnu.org Cc: imp@bsdimp.com, Michal Meloun , Stacey Son , Karim Taha , Richard Henderson Subject: [PATCH v2 24/32] Implement freebsd11 stat related syscalls Date: Sun, 13 Aug 2023 05:10:05 +0200 Message-Id: <20230813031013.1743-25-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::32b; envelope-from=kariem.taha2.7@gmail.com; helo=mail-wm1-x32b.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: 1691936356908100001 Content-Type: text/plain; charset="utf-8" From: Michal Meloun Implement the freebsd11 variant of the following syscalls: statfs(2) fstatfs(2) getfsstat(2) Co-authored-by: Stacey Son Signed-off-by: Stacey Son Signed-off-by: Michal Meloun Signed-off-by: Karim Taha Reviewed-by: Richard Henderson --- bsd-user/freebsd/os-stat.h | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/bsd-user/freebsd/os-stat.h b/bsd-user/freebsd/os-stat.h index 2e0c7245df..04a61fabd1 100644 --- a/bsd-user/freebsd/os-stat.h +++ b/bsd-user/freebsd/os-stat.h @@ -32,9 +32,15 @@ __sym_compat(fstatat, freebsd11_fstatat, FBSD_1.1); =20 int freebsd11_fhstat(const fhandle_t *fhandle, struct freebsd11_stat *stat= ); __sym_compat(fhstat, freebsd11_fhstat, FBSD_1.0); +int freebsd11_getfsstat(struct freebsd11_statfs *buf, long bufsize, int mo= de); +__sym_compat(getfsstat, freebsd11_getfsstat, FBSD_1.0); int freebsd11_fhstatfs(const fhandle_t *fhandle, struct freebsd11_statfs *= buf); __sym_compat(fhstatfs, freebsd11_fhstatfs, FBSD_1.0); int freebsd11_statfs(const char *path, struct freebsd11_statfs *buf); +__sym_compat(statfs, freebsd11_statfs, FBSD_1.0); +int freebsd11_fstatfs(int fd, struct freebsd11_statfs *buf); +__sym_compat(fstatfs, freebsd11_fstatfs, FBSD_1.0); + =20 /* stat(2) */ static inline abi_long do_freebsd11_stat(abi_long arg1, abi_long arg2) @@ -293,6 +299,23 @@ 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_freebsd11_statfs(abi_long arg1, abi_long arg2) +{ + abi_long ret; + void *p; + struct freebsd11_statfs host_stfs; + + LOCK_PATH(p, arg1); + ret =3D get_errno(freebsd11_statfs(path(p), &host_stfs)); + UNLOCK_PATH(p, arg1); + if (is_error(ret)) { + return ret; + } + + return h2t_freebsd11_statfs(arg2, &host_stfs); +} + /* statfs(2) */ static inline abi_long do_freebsd_statfs(abi_long arg1, abi_long arg2) { @@ -310,6 +333,20 @@ static inline abi_long do_freebsd_statfs(abi_long arg1= , abi_long arg2) return h2t_freebsd_statfs(arg2, &host_stfs); } =20 +/* fstatfs(2) */ +static inline abi_long do_freebsd11_fstatfs(abi_long fd, abi_ulong target_= addr) +{ + abi_long ret; + struct freebsd11_statfs host_stfs; + + ret =3D get_errno(freebsd11_fstatfs(fd, &host_stfs)); + if (is_error(ret)) { + return ret; + } + + return h2t_freebsd11_statfs(target_addr, &host_stfs); +} + /* fstatfs(2) */ static inline abi_long do_freebsd_fstatfs(abi_long fd, abi_ulong target_ad= dr) { @@ -324,6 +361,44 @@ static inline abi_long do_freebsd_fstatfs(abi_long fd,= abi_ulong target_addr) return h2t_freebsd_statfs(target_addr, &host_stfs); } =20 +/* getfsstat(2) */ +static inline abi_long do_freebsd11_getfsstat(abi_ulong target_addr, + abi_long bufsize, abi_long flags) +{ + abi_long ret; + struct freebsd11_statfs *host_stfs; + int count; + long host_bufsize; + + count =3D bufsize / sizeof(struct target_freebsd11_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 freebsd11_statfs) * count; + host_stfs =3D alloca(host_bufsize); + if (!host_stfs) { + return -TARGET_EINVAL; + } + + ret =3D count =3D get_errno(freebsd11_getfsstat(host_stfs, host_bufsiz= e, flags)); + if (is_error(ret)) { + return ret; + } + + while (count--) { + if (h2t_freebsd11_statfs((target_addr + + (count * sizeof(struct target_freebsd11_statfs))), + &host_stfs[count])) { + return -TARGET_EFAULT; + } + } + return ret; +} + /* getfsstat(2) */ static inline abi_long do_freebsd_getfsstat(abi_ulong target_addr, abi_long bufsize, abi_long flags) --=20 2.40.0