From nobody Mon Feb 9 16:53:56 2026 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=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1646401326; cv=none; d=zohomail.com; s=zohoarc; b=ChDcYVetnObyvCMMay8UuairjwbrdaLYJN6ryJny7CV2AIK3yYdLnzoD8n1zNmX9xQrApVezGezeKtqoPV8z7g8DIinFUnlcW47kfM1cML0qncFxsiZg1xked8S/0/VdOMGX5Tc+UJjrlv1x6YZ2Ilh5mhaUn/JyxHRCQ0mgB/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646401326; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=3u34sir+ZeZHfQZGfZ8IvSlB23QK/T53fLss006PEqs=; b=l/LHOMV7QhCs50Klb3ZDCH+8N76LM+3ysgqBe3mH2urEcPtUoN2NCmEWa1WqaxrXdyDNQRp7Zq4TDrajqcUdtDakDqDSsqfGPQD89U1/LRj6rNVlEt+Rhq3wZDQFl1LbFf4nRg8Lw2OhGtn3TaW3RATR0lZ/+aYuRYWAEJy+Vlw= 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646401326814187.78459442835208; Fri, 4 Mar 2022 05:42:06 -0800 (PST) Received: from localhost ([::1]:57666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ8C6-00036o-Bu for importer@patchew.org; Fri, 04 Mar 2022 08:42:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ7q3-00046I-Ag for qemu-devel@nongnu.org; Fri, 04 Mar 2022 08:19:22 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:50537) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ7pz-0006xU-Hk for qemu-devel@nongnu.org; Fri, 04 Mar 2022 08:19:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=3u34sir+ZeZHfQZGfZ8IvSlB23QK/T53fLss006PEqs=; b=ph8Pm 2j92lahBMNwTjJ6VVGAJO0q2KWhXRN1BoRTy7TAYqGrPsmJ/aQqUvt106LaGC1qu3PQWKUl6EnGwT Ce1i2rUgfxfKqChKTT+jdsoVV86+aeIF5Q6vIhkrNGaLo+CzXC/qJ+pmYdadq4kxxB9TCMlW6kkR+ LOxyS4PSGIW/Swrwg1uZeU92Hl1YX3Sl+j5uIQfNUz5aKL29wWi4LQz4UsqfZGZhXrzxwYZrfPyQF hIwUVBsLTqdYKJjKYep8+fR+0LXOnU4NnRve4dz3Fsei+AtNyXkG3Lzbx2WTNsDE3jlXmd7aaqxPP mX6IXSQ5yK7iXNllD70mnr8b7igRg==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Fri, 04 Mar 2022 13:27:49 +0100 Subject: [PULL 04/19] 9p: darwin: Handle struct dirent differences To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz 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: none client-ip=91.194.90.13; envelope-from=cff1ca391fd7c6af90edb8f237f15a756eaffafe@lizzy.crudebyte.com; helo=lizzy.crudebyte.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, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1646401328313100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Keno Fischer On darwin d_seekoff exists, but is optional and does not seem to be commonly used by file systems. Use `telldir` instead to obtain the seek offset and inject it into d_seekoff, and create a qemu_dirent_off helper to call it appropriately when appropriate. Signed-off-by: Keno Fischer [Michael Roitzsch: - Rebase for NixOS] Signed-off-by: Michael Roitzsch [Will Cohen: - Adjust to pass testing - Ensure that d_seekoff is filled using telldir on darwin, and create qemu_dirent_off helper to decide which to access] [Fabian Franz: - Add telldir error handling for darwin] Signed-off-by: Fabian Franz [Will Cohen: - Ensure that telldir error handling uses signed int - Cleanup of telldir error handling - Remove superfluous error handling for qemu_dirent_off - Adjust formatting - Use qemu_dirent_off in codir.c - Declare qemu_dirent_off as static to prevent linker error - Move qemu_dirent_off above the end-of-file endif to fix compilation] Signed-off-by: Will Cohen Message-Id: <20220227223522.91937-5-wwcohen@gmail.com> Signed-off-by: Christian Schoenebeck Reviewed-by: Christian Schoenebeck --- hw/9pfs/9p-local.c | 9 +++++++++ hw/9pfs/9p-proxy.c | 16 +++++++++++++++- hw/9pfs/9p-synth.c | 4 ++++ hw/9pfs/9p-util.h | 16 ++++++++++++++++ hw/9pfs/9p.c | 7 +++++-- hw/9pfs/codir.c | 4 +++- 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 1a5e3eed73..f3272f0b43 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -562,6 +562,15 @@ again: if (!entry) { return NULL; } +#ifdef CONFIG_DARWIN + int off; + off =3D telldir(fs->dir.stream); + /* If telldir fails, fail the entire readdir call */ + if (off < 0) { + return NULL; + } + entry->d_seekoff =3D off; +#endif =20 if (ctx->export_flags & V9FS_SM_MAPPED) { entry->d_type =3D DT_UNKNOWN; diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index b1664080d8..8b4b5cf7dc 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx, V9fsFidOpen= State *fs) =20 static struct dirent *proxy_readdir(FsContext *ctx, V9fsFidOpenState *fs) { - return readdir(fs->dir.stream); + struct dirent *entry; + entry =3D readdir(fs->dir.stream); +#ifdef CONFIG_DARWIN + if (!entry) { + return NULL; + } + int td; + td =3D telldir(fs->dir.stream); + /* If telldir fails, fail the entire readdir call */ + if (td < 0) { + return NULL; + } + entry->d_seekoff =3D td; +#endif + return entry; } =20 static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index bf9b0c5ddd..b3080e415b 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -234,7 +234,11 @@ static void synth_direntry(V9fsSynthNode *node, offsetof(struct dirent, d_name) + sz); memcpy(entry->d_name, node->name, sz); entry->d_ino =3D node->attr->inode; +#ifdef CONFIG_DARWIN + entry->d_seekoff =3D off + 1; +#else entry->d_off =3D off + 1; +#endif } =20 static struct dirent *synth_get_dentry(V9fsSynthNode *dir, diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 546f46dc7d..7449733c15 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -78,4 +78,20 @@ ssize_t flistxattrat_nofollow(int dirfd, const char *fil= ename, ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name); =20 +/** + * Darwin has d_seekoff, which appears to function similarly to d_off. + * However, it does not appear to be supported on all file systems, + * so ensure it is manually injected earlier and call here when + * needed. + */ +static inline off_t qemu_dirent_off(struct dirent *dent) +{ +#ifdef CONFIG_DARWIN + return dent->d_seekoff; +#else + return dent->d_off; +#endif +} + + #endif diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 1563d7b7c6..caf3b240fe 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -27,6 +27,7 @@ #include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h" @@ -2281,7 +2282,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9f= sPDU *pdu, count +=3D len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); - saved_dir_pos =3D dent->d_off; + saved_dir_pos =3D qemu_dirent_off(dent); } =20 v9fs_readdir_unlock(&fidp->fs.dir); @@ -2420,6 +2421,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu,= V9fsFidState *fidp, V9fsString name; int len, err =3D 0; int32_t count =3D 0; + off_t off; struct dirent *dent; struct stat *st; struct V9fsDirEnt *entries =3D NULL; @@ -2480,12 +2482,13 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pd= u, V9fsFidState *fidp, qid.version =3D 0; } =20 + off =3D qemu_dirent_off(dent); v9fs_string_init(&name); v9fs_string_sprintf(&name, "%s", dent->d_name); =20 /* 11 =3D 7 + 4 (7 =3D start offset, 4 =3D space for storing count= ) */ len =3D pdu_marshal(pdu, 11 + count, "Qqbs", - &qid, dent->d_off, + &qid, off, dent->d_type, &name); =20 v9fs_string_free(&name); diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index c0873bde16..f96d8ac4e6 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -22,6 +22,8 @@ #include "qemu/coroutine.h" #include "qemu/main-loop.h" #include "coth.h" +#include "9p-xattr.h" +#include "9p-util.h" =20 /* * Intended to be called from bottom-half (e.g. background I/O thread) @@ -166,7 +168,7 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *= fidp, } =20 size +=3D len; - saved_dir_pos =3D dent->d_off; + saved_dir_pos =3D qemu_dirent_off(dent); } =20 /* restore (last) saved position */ --=20 2.20.1