From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id E276A3858C2F for ; Fri, 27 Jan 2023 17:28:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E276A3858C2F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x22c.google.com with SMTP id p185so4758436oif.2 for ; Fri, 27 Jan 2023 09:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U6Xc/c3qzSHP1pleomGtBR06jv/Vm8Y9JhMa08jvCGM=; b=KNNVl9PccC1A9+i8bs4238KflUgkRxWb4qECJwh9szyXWEK/AMO6OadX5qfvkvvaK7 EbhSO60Odf4C9Y9PE8udZP8TEcbb84+httnGCgYpEDHwUKVTGamViN0KhV992Afm3WBA 4QX6X42ocl8+CbHGeumerIfSs2pH5/YnivBoY8e32VtKzFy1siKuFyaRApys8dSug/d8 IF8qQ9yTySHM1KsaIX25X+uHAkdxTPSR18X2T2chSk5TMtHyxGu0P+TYJYXyVNRpdZtQ I3scxwqcwAi2n8eeNjjnbVddJQ9X+2W68Hh2zfI/QHNqY2mlmRsDCBYV8sgGTQNRtnsX 5wTg== 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=U6Xc/c3qzSHP1pleomGtBR06jv/Vm8Y9JhMa08jvCGM=; b=NPR7WerddKGQ1M8tlBy82E5miJVdgSLCXStCvAZbktoAtUylmJW4wvqOn4pxkF3+lE KfaYaGTRBofh9JVNIRlMLCLZg+5OMRHpq/ThHBVKNgceAKrEMgbqf6IiGilM47DhC+4S PQoDTWJnJToxAPyldPgNofTtWX9g/wphDcrYpa23eVMeUU2RiSCfP3kVCSi/IS3DL54e nU1wTBxlg+eW1iFnYmRHpflQkxGpJwA9+gYHj4NJ23fZOAMbHs5vmy0aQ9M8T55E4oew 3X2MmdkFaCVbVVhgBRBh4eKLAXVJor90gFUDuci76bqnFqpHLWr2CXVWFnvR5cflJTcl 7QLw== X-Gm-Message-State: AFqh2koxaVopGErP1Bbp23x8LRRCD9T1iF/2/bXcEFYQdiCXc1mwpS1D +maY44Cx+bSvqW3uxgQoIVQmf8oc/y4TFEmdPZ0= X-Google-Smtp-Source: AMrXdXtcWm2qWmN9OoyHvah3XKwTl36Ks2GujXktbnVQu0AVmxsiVW5RjeGB9HonAVYqcebN0jWt/g== X-Received: by 2002:a05:6808:1686:b0:364:8678:2208 with SMTP id bb6-20020a056808168600b0036486782208mr25069577oib.16.1674840519117; Fri, 27 Jan 2023 09:28:39 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:7e99:a00f:8f3d:7ba5:11f1]) by smtp.gmail.com with ESMTPSA id r131-20020acada89000000b0035aa617156bsm1803940oig.17.2023.01.27.09.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 09:28:37 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org, "Andreas K . Huettel" , Paul Eggert , Florian Weimer Subject: [PATCH v5 0/5] Fix opendir regression on some FS Date: Fri, 27 Jan 2023 14:28:29 -0300 Message-Id: <20230127172834.391311-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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, readdir updates 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. I have checked on x86_64-linux-gnu, i686-linux-gnu, and arm-linux-gnueabihf. Changes from v4: * Allocate the telldir map an readdir, thus avoid telldir failure. * The translation buffer now uses a fixed size struct. * Fixed the condition to use the long to off64_t map. 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 | 3 +- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/alpha/bits/dirent.h | 3 + sysdeps/unix/sysv/linux/bits/dirent.h | 4 + sysdeps/unix/sysv/linux/closedir.c | 4 + sysdeps/unix/sysv/linux/dirstream.h | 22 ++- sysdeps/unix/sysv/linux/getdents64.c | 93 ------------ sysdeps/unix/sysv/linux/olddirent.h | 4 +- sysdeps/unix/sysv/linux/opendir.c | 3 + sysdeps/unix/sysv/linux/readdir.c | 88 ++++++++--- sysdeps/unix/sysv/linux/readdir64.c | 92 ++++++++--- sysdeps/unix/sysv/linux/readdir64_r.c | 159 +++++--------------- sysdeps/unix/sysv/linux/rewinddir.c | 5 + sysdeps/unix/sysv/linux/seekdir.c | 35 ++++- sysdeps/unix/sysv/linux/telldir.c | 35 +++++ sysdeps/unix/sysv/linux/telldir.h | 65 ++++++++ sysdeps/unix/sysv/linux/tst-opendir-nolfs.c | 146 ++++++++++++++++++ 19 files changed, 499 insertions(+), 277 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/telldir.h create mode 100644 sysdeps/unix/sysv/linux/tst-opendir-nolfs.c -- 2.34.1