Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File control: fcntl raw and higher-level support. #44

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

milseman
Copy link
Contributor

@milseman milseman commented Apr 6, 2021

Add in support for fcntl and all the raw commands and flags it supports. Add in Swiftier representations of common and important invocations.

System Sketch

New design patterns:

  • We provide rawer, but complete, FileDescriptor.fcntl() and FileDescriptor.Command interfaces and wrappers.
  • We provide Swiftier type-safe interfaces for a common and important subset.
  • FileDescriptor.FileLock is our first RR wrapper of a real C struct.

Externals:

  • PID, and PIDOrGPID.
  • flock to coordinate design with get/setLock().
  • fsync to coordinate design with F_FULLFSYNC etc.

Unknowns:

  • Headers have even more locking commands/variants, should we promote these to the Swifty APIs?
  • Is Errno.resourceTemporarilyUnavailable too removed from EAGAIN? Should we introduce Errno.again alias?
  • Are there other Swiftier interfaces we should provide?

Testing needs:

  • Normal mocking tests
  • Sample code, especially for provided Swiftier interfaces

@milseman milseman requested a review from lorentey April 6, 2021 15:32
@milseman milseman marked this pull request as draft April 6, 2021 15:35
@milseman
Copy link
Contributor Author

milseman commented Apr 6, 2021

In light of the.... poorly imagined aspects of POSIX fcntl locks, we might drop the Swiftier lock interface, pending on how flock turns out.

lorentey
lorentey previously approved these changes May 10, 2021
Sources/System/FileControl.swift Outdated Show resolved Hide resolved
Sources/System/FileControl.swift Outdated Show resolved Hide resolved
Sources/System/FileControl.swift Outdated Show resolved Hide resolved
Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
///
/// The corresponding C constant is `F_FULLFSYNC`.
@_alwaysEmitIntoClient
public static var fullFsync: Command { Command(F_FULLFSYNC) }
Copy link
Member

Choose a reason for hiding this comment

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

What are we going to call fsync(2)? I think I'd suggest FileDescriptor.sync or synchronize. We should use the same name here.

Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
Sources/System/FileControlRaw.swift Outdated Show resolved Hide resolved
@_alwaysEmitIntoClient
public static var append: StatusFlags { StatusFlags(O_APPEND) }

/// Enable the SIGIO signal to be sent to the process
Copy link
Member

Choose a reason for hiding this comment

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

does anybody still use this? Do we really want to offer it?

@milseman milseman marked this pull request as ready for review March 8, 2023 16:49
@milseman
Copy link
Contributor Author

milseman commented Mar 8, 2023

Rebased on top of #111 and closer to being merge-worthy.

Needs some simple tests, some differences between Linux and Darwin dissected, and version annotations.

@milseman milseman changed the title [SKETCH] Add in fcntl raw, and higher-level support. File control: fcntl raw and higher-level support. Mar 8, 2023
@milseman milseman requested a review from lorentey March 8, 2023 16:51
@milseman
Copy link
Contributor Author

milseman commented Mar 8, 2023

Also, we need to probably figure out some kind of fallocate(2) API to unify with F_PREALLOCATE's struct fstore.

@milseman
Copy link
Contributor Author

milseman commented Mar 8, 2023

@swift-ci please test

@milseman
Copy link
Contributor Author

Early draft of API doc: https://gist.github.com/milseman/2e59c10299f04c682c4090c4d2ecc0e0

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.

None yet

3 participants