Skip to content

Conversation

@wdcui
Copy link
Member

@wdcui wdcui commented Feb 1, 2026

Summary

Add support for the utimensat(2) and futimens(3) syscalls which allow setting file access and modification times with nanosecond precision.

Changes

litebox_common_linux

  • Add UTIME_NOW (0x3fffffff) and UTIME_OMIT (0x3ffffffe) constants
  • Add Timespec helper methods: is_utime_now(), is_utime_omit(), is_valid_for_utimensat()
  • Add syscall parsing for Sysno::utimensat, Sysno::utimensat_time64, and Sysno::futimens

litebox (core)

  • Add SetTimesError enum for filesystem time-setting errors
  • Add set_times() and fd_set_times() methods to FileSystem trait
  • Default implementations are no-ops for compatibility with filesystems that don't track timestamps

litebox_shim_linux

  • Implement sys_utimensat() with full path resolution and flag handling
  • Implement sys_futimens() for fd-based timestamp modification
  • Support AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH flags
  • Use platform's TimeProvider for current time when UTIME_NOW is specified

Testing

  • cargo build passes
  • cargo clippy --all-targets --all-features passes with no new warnings
  • cargo test -p litebox passes (85 tests)
  • cargo test -p litebox_common_linux passes

Known Limitations (documented as TODOs in code)

  • AT_SYMLINK_NOFOLLOW flag is accepted but not fully functional until symlinks are implemented
  • FdRelative path resolution returns ENOSYS
  • Permission checks are simplified (allow all changes)

Related

This addresses one of the syscalls commonly needed by applications. See docs/link_syscall_design.md for context on recent syscall implementations.

wdcui added 2 commits February 1, 2026 23:44
Add support for the utimensat(2) and futimens(3) syscalls which allow
setting file access and modification times with nanosecond precision.

Changes:
- Add UTIME_NOW (0x3fffffff) and UTIME_OMIT (0x3ffffffe) constants
- Add Timespec helper methods for validating utimensat arguments
- Add SetTimesError enum for filesystem time-setting errors
- Add set_times() and fd_set_times() methods to FileSystem trait
- Implement sys_utimensat() with full path resolution and flag handling
- Implement sys_futimens() for fd-based timestamp modification
- Support AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH flags

The implementation uses the platform's TimeProvider for current time
and includes proper validation of the Timespec nanosecond fields.
Filesystems that don't track timestamps can use the default no-op
implementations.

TODO items documented in code:
- AT_SYMLINK_NOFOLLOW not fully supported until symlinks are implemented
- FdRelative path resolution not yet implemented
- Permission checks are simplified (allow all changes)
Review feedback addressed:

1. Add EINVAL check for AT_SYMLINK_NOFOLLOW with NULL pathname
   - Per Linux man page: return EINVAL when pathname is NULL, dirfd
     is not AT_FDCWD, and flags contains AT_SYMLINK_NOFOLLOW

2. Return Ok(()) for pipes and sockets instead of ENOENT
   - Linux silently succeeds on these fd types (no-op)
   - ENOENT was semantically incorrect

3. Handle get_current_time() error gracefully
   - Return EINVAL instead of panicking if clock is before Unix epoch
   - Prevents crashes on misconfigured or uninitialized clocks

4. Use explicit "." for current directory path
   - Clearer semantics than empty string
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants