From patchwork Thu Jan 26 19:29:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 55439 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6543538493F2 for ; Thu, 26 Jan 2023 19:30:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6543538493F2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674761424; bh=2NWlbv8SqbNnBcALH5didywZd+idKOJJ2xTrGdoD4js=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=I4HXvzIguVvTGVM19Lc71QOldvEsuaRNagc+8O1nQqAyI9PyeInMGdXA3Nb9HRFY6 Ygdq7oMiSc4FxiE6XLfPMybzykUeDRsS0mLd9PTzGNIRytLf2JpzQf5I3NUogLC7KD y8FZcySh1aWihCDC+d0fBIs44VezdCcR8RhTDc6o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id DDDF63858D28 for ; Thu, 26 Jan 2023 19:29:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDDF63858D28 Received: by mail-ot1-x329.google.com with SMTP id e21-20020a9d5615000000b006884e5dce99so1240439oti.5 for ; Thu, 26 Jan 2023 11:29:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2NWlbv8SqbNnBcALH5didywZd+idKOJJ2xTrGdoD4js=; b=cDKOo7EghYnnClZqsfizUo047ULBwcX5y8jUHFU1iFudypBxzAoU5EeTG5x0M4ZmdC M1defjapRV1Z3pTgRrRJl6OpbjbRI42RMI7i/4sVGFf7RO//KzLUPkv0L/PhYVNqKJuh WXxYi47Lmc6dtM35iB11ydVQbPbw3sFYv/bwC7ZHthWK+XotGh2kyPCofWO7463s16iK CfBwlCA4uCZro8PH86gfll3NALftJBTvM5Qx/0YkKtwei/2K5XZjq9dfDQ0svUVIV4Ix zWkSJnHX4aA07sCneV1D3d/EsksNHaXfFnLJ+iiGYd90Nw5K9VQEFWkpZyJkH/qJxA6p 46zA== X-Gm-Message-State: AO0yUKVaQPONmQb32vEKKL7qEi5U1a3F3bfv0V5yrhL5kmRotiLY1xTp F2ABP9+2ea5qg0wfkMSzCoU+aNBRdTjoQkLcCVo= X-Google-Smtp-Source: AK7set8NixeOQjFgDQXNkVmmm7jQJtODrJKCj6TF5PE/abNe8e63UN+rgbfX8oFDelw9HZf//24Bfg== X-Received: by 2002:a05:6830:4189:b0:684:b059:4569 with SMTP id r9-20020a056830418900b00684b0594569mr1589265otu.5.1674761397591; Thu, 26 Jan 2023 11:29:57 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:732:4c6b:2122:8111]) by smtp.gmail.com with ESMTPSA id v23-20020a056830091700b00670641eb272sm872939ott.20.2023.01.26.11.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 11:29:56 -0800 (PST) To: libc-alpha@sourceware.org, "Andreas K . Huettel" Subject: [PATCH v4 0/5] Fix opendir regression on some FS Date: Thu, 26 Jan 2023 16:29:48 -0300 Message-Id: <20230126192953.2990973-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Some filesystem might return a non-representable d_off on getdents call, even if there are few entries in the directories (for instance ext4, which returns a hash). This trigger issues with non-LFS readdir when it finds the first non representable entry, and also for LFS interface when used along with telldir (which return a 'long int', while d_off is potentially off64_t). This patch changes non-LFS readdir so it ignore non representable entries. The opendir now uses getdents64, even for non-LFS and uses a translation buffer to return the getdents entry from the getdents64 buffer. The second part fixes the broken telldir on non LP64 ABIs, where returning d_off as stream position might overflow. For these ABIs, telldir mantains an internal list that maps the DIR object off64_t offsets to the returned long int (the function return value). The seekdir will then set the correct offset from the internal list using the telldir as the list key. One drawback of such strategy is now telldir might silent fail if seekdir fails to allocate the off64_t map entry, however non-LFS is a compat interface and overflowed entries currently also does not fully work even for LFS interface. I have checked on x86_64-linux-gnu, i686-linux-gnu, and arm-linux-gnueabihf. Changes from v3: * Rebase against master. * Fixed a missing lock unlock on telldir. * Renamed tst-seekdir2 to tst-opendir-nolfs and check the opendir result against getdents64. Adhemerval Zanella (5): linux: Use getdents64 on non-LFS readdir linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050) linux: Add __readdir64_unlocked linux: Add __old_readdir64_unlocked linux: Use getdents64 on readdir64 compat implementation dirent/tst-scandir.c | 6 +- dirent/tst-seekdir.c | 8 + include/dirent.h | 1 + sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/closedir.c | 7 + sysdeps/unix/sysv/linux/dirstream.h | 11 +- sysdeps/unix/sysv/linux/getdents64.c | 93 ------------ sysdeps/unix/sysv/linux/olddirent.h | 4 +- sysdeps/unix/sysv/linux/opendir.c | 37 +++++ sysdeps/unix/sysv/linux/readdir.c | 90 +++++++---- sysdeps/unix/sysv/linux/readdir64.c | 104 ++++++++++--- sysdeps/unix/sysv/linux/readdir64_r.c | 159 +++++--------------- sysdeps/unix/sysv/linux/rewinddir.c | 5 + sysdeps/unix/sysv/linux/seekdir.c | 36 ++++- sysdeps/unix/sysv/linux/telldir.c | 45 +++++- sysdeps/unix/sysv/linux/telldir.h | 65 ++++++++ sysdeps/unix/sysv/linux/tst-opendir-nolfs.c | 146 ++++++++++++++++++ 17 files changed, 539 insertions(+), 279 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/telldir.h create mode 100644 sysdeps/unix/sysv/linux/tst-opendir-nolfs.c