From patchwork Tue Jun 14 04:20:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Warner Losh X-Patchwork-Id: 12880407 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 25B40C433EF for ; Tue, 14 Jun 2022 04:29:02 +0000 (UTC) Received: from localhost ([::1]:50096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0yAn-0007oO-2p for qemu-devel@archiver.kernel.org; Tue, 14 Jun 2022 00:29:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0y2E-0003js-5N for qemu-devel@nongnu.org; Tue, 14 Jun 2022 00:20:10 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]:44989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0y2C-0001qY-LT for qemu-devel@nongnu.org; Tue, 14 Jun 2022 00:20:09 -0400 Received: by mail-il1-x130.google.com with SMTP id y17so5735494ilj.11 for ; Mon, 13 Jun 2022 21:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wJEGbDyUIR4TgYHaYi6XpxnqSx1t+dwpAGBFG5Z8F5Q=; b=mdKMSmITyKIZszHugUUg77IaBGAjt+A/alOG63l+gf7qagzfd2xNkPkpfHZHuFrUjA esY809lTS3+5qlBdtKKMaEEneDIuV3FNUJ2VEMrxLiGu3osGutQOBH61B1US9DUuI+AS sFxYc8lXQMbfgEmwaHdqGUbp0nL9u3tcZeTrzEF0e4vqoAu6YVEnmV0+5iJXIq1GPgFC xUAmjJb47DQo78GkgbBBhdEsIY0oTmb8mhl862R3H9W6WttKkxmd8vl7DSOIZA2OBrfR +j2+X2Fk8CRSshutB3USHWbyoTBdf5mOvZ+nNqhIqkL4pkklcMGiLkVCozD6LiBKorXu Ov4g== 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=wJEGbDyUIR4TgYHaYi6XpxnqSx1t+dwpAGBFG5Z8F5Q=; b=mEVKwwo03QMp1e2ZZxgMIKlCnz7XQxx42T/Uefy0BnbaIKq4Z3kFF3xY+eNte0tbgY ATzf7GnH0VRS2yDOAWBVDWxTov1PyHDCc0k7OuAzJuv0gLWjGM02qZkWKRdv0FtcxMiP 7i77Q2371O88CeeRmPYNXluALTGkoojJhPEj1VXIP1uIb7ToT3TRaW+FZIOt9vtC6h/D gs7DAtiGLSJqbGu1KLCOjJ4YnV7tzToTLVJsZxFAnpJyGzIgT+mASHtPYK4Oj/RvssJL Ov2JxEcdtK64rtb6+6Eco8mPqOq6Sw/JWBOhK1GJcsbiiiQ9mGs3Nx9iatxicsZiulay 3l5Q== X-Gm-Message-State: AJIora9e+29eQ5VPID5zywYMo8ZxvXLU/0nfO0OXf5VRGbcYhVXhm+5U ezq/qaOqVITNQC7ArOXz0JFrL/CEv53hNA== X-Google-Smtp-Source: AGRyM1tHBPoYcb9nBGqBDzSisJ2TcN4Fdctazy2LjKOvqrG4HW39dxnEuu+/L4kj9EqqBMP8EGztBQ== X-Received: by 2002:a05:6e02:168a:b0:2d3:c56d:8042 with SMTP id f10-20020a056e02168a00b002d3c56d8042mr1917273ila.236.1655180407472; Mon, 13 Jun 2022 21:20:07 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a3-20020a5ec303000000b0066579afd3cbsm4803742iok.50.2022.06.13.21.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 21:20:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Kyle Evans , arrowd@freebsd.org, Richard Henderson , jrtc27@FreeBSD.org, Warner Losh , def@FreeBSD.org, Stacey Son Subject: [PATCH v2 10/11] bsd-user: Implement trunctate and ftruncate Date: Mon, 13 Jun 2022 22:20:09 -0600 Message-Id: <20220614042010.40327-11-imp@bsdimp.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220614042010.40327-1-imp@bsdimp.com> References: <20220614042010.40327-1-imp@bsdimp.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::130; envelope-from=imp@bsdimp.com; helo=mail-il1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Stacey Son Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/bsd-file.h | 29 +++++++++++++++++++++++++++++ bsd-user/freebsd/os-syscall.c | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h index 021541ad2e0..fda36894605 100644 --- a/bsd-user/bsd-file.h +++ b/bsd-user/bsd-file.h @@ -497,4 +497,33 @@ static abi_long do_bsd_dup2(abi_long arg1, abi_long arg2) return get_errno(dup2(arg1, arg2)); } +/* truncate(2) */ +static abi_long do_bsd_truncate(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4) +{ + abi_long ret; + void *p; + + LOCK_PATH(p, arg1); + if (regpairs_aligned(cpu_env) != 0) { + arg2 = arg3; + arg3 = arg4; + } + ret = get_errno(truncate(p, target_arg64(arg2, arg3))); + UNLOCK_PATH(p, arg1); + + return ret; +} + +/* ftruncate(2) */ +static abi_long do_bsd_ftruncate(void *cpu_env, abi_long arg1, + abi_long arg2, abi_long arg3, abi_long arg4) +{ + if (regpairs_aligned(cpu_env) != 0) { + arg2 = arg3; + arg3 = arg4; + } + return get_errno(ftruncate(arg1, target_arg64(arg2, arg3))); +} + #endif /* BSD_FILE_H */ diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c index d9ebb9d50d6..3c8f6cad0e8 100644 --- a/bsd-user/freebsd/os-syscall.c +++ b/bsd-user/freebsd/os-syscall.c @@ -357,6 +357,14 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1, ret = do_bsd_dup2(arg1, arg2); break; + case TARGET_FREEBSD_NR_truncate: /* truncate(2) */ + ret = do_bsd_truncate(cpu_env, arg1, arg2, arg3, arg4); + break; + + case TARGET_FREEBSD_NR_ftruncate: /* ftruncate(2) */ + ret = do_bsd_ftruncate(cpu_env, arg1, arg2, arg3, arg4); + break; + default: qemu_log_mask(LOG_UNIMP, "Unsupported syscall: %d\n", num); ret = -TARGET_ENOSYS;