Skip to content

Use linux_dirent64 type with sys_getdents64#1207

Merged
xuyao0127 merged 2 commits intodmtcp:mainfrom
xuyao0127:getdents64_fix
Jun 3, 2025
Merged

Use linux_dirent64 type with sys_getdents64#1207
xuyao0127 merged 2 commits intodmtcp:mainfrom
xuyao0127:getdents64_fix

Conversation

@xuyao0127
Copy link
Copy Markdown
Collaborator

Use sys_getdents64 and linux_dirent64 on 64-bit machines.

@xuyao0127 xuyao0127 requested review from gc00 and karya0 May 31, 2025 05:22
@xuyao0127
Copy link
Copy Markdown
Collaborator Author

In the man page of getdents, it says:

Consequently, Linux 2.4 added getdents64(), with wider types for the d_ino and d_off fields. In addition, getdents64() supports an explicit d_type field.

I think this implies that the availability of getdents64 depends only on the kernel version (greater than 2.4). It doesn't depend on whether the CPU architecture is 32-bit or 64-bit. If we can test it on a 32-bit machine, we can sys_getdents64 everywhere.

This comment was marked as outdated.

@gc00
Copy link
Copy Markdown
Contributor

gc00 commented Jun 1, 2025

@xuyao0127
The 'man' page says why getdents64 was created (from man7.org):

The original Linux getdents() system call did not handle large
filesystems and large file offsets. Consequently, Linux 2.4 added
getdents64(), with wider types for the d_ino and d_off fields. In
addition, getdents64() supports an explicit d_type field.

There's no need to test on a 32-bit architecture. The system call will work on both, and it is intended simply for large filesystems, which can be accessed by any Linux architecture. RISC-V and ARM64 implementations of the Linux kernel omitted getdents because getdents64 is a superset of those capabilities. So, there's never any need to call getdents. We don't care if glibc on 32-bit x86 chose to use getdents or getdents64. We only need to know that the 32-bit Linux kernel does support getdents64.

@xuyao0127
Copy link
Copy Markdown
Collaborator Author

@gc00 I have updated the code to use getdents64 everywhere.

@karya0 karya0 requested a review from Copilot June 3, 2025 19:36
@xuyao0127 xuyao0127 merged commit c8e757f into dmtcp:main Jun 3, 2025
1 check passed
@xuyao0127 xuyao0127 deleted the getdents64_fix branch June 3, 2025 19:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates directory-reading logic to use the 64-bit getdents64 syscall and corresponding linux_dirent64 structure on 64-bit platforms.

  • Replace uses of SYS_getdents and linux_dirent with SYS_getdents64 and linux_dirent64
  • Remove legacy linux_dirent definition from the header
  • Introduce linux_dirent64 in the implementation

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
jalib/jfilesystem.h Removed old linux_dirent struct; no 64-bit struct defined here
jalib/jfilesystem.cpp Added linux_dirent64, switched syscall invocation to SYS_getdents64
Comments suppressed due to low confidence (2)

jalib/jfilesystem.h:29

  • The header still needs a public definition of linux_dirent64 so consumers of the filesystem API can compile against it; consider moving the struct definition from the .cpp into this header under namespace jalib.
-  struct linux_dirent {

jalib/jfilesystem.cpp:36

  • The code uses SYS_getdents64 but there’s no inclusion of <sys/syscall.h>, which may lead to undefined SYS_getdents64; add the proper header so the syscall constant is defined.
struct linux_dirent64 {

@@ -33,14 +33,13 @@
#include <sys/utsname.h>
#include <unistd.h>

Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining linux_dirent64 in the global namespace may conflict with other symbols; wrap this struct in the jalib (or jalib::Filesystem) namespace to mirror the header’s organization.

Suggested change
namespace jalib {
namespace Filesystem {

Copilot uses AI. Check for mistakes.
Comment on lines 334 to +335

while (true) {
int nread = jalib::syscall(SYS_getdents, fd, buf, allocation);
int nread = jalib::syscall(SYS_getdents64, fd, buf, allocation);
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using SYS_getdents64 unconditionally may break on non-64-bit architectures; consider guarding this call with an #if check for supported ABIs or providing a fallback to SYS_getdents where appropriate.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants